Skip to content

⬅️ Back to Table of Contents

📄 LineSegments.js

📊 Analysis Summary

Metric Count
🔧 Functions 1
🧱 Classes 1
📦 Imports 3
📊 Variables & Constants 5

📚 Table of Contents

🛠️ File Location:

📂 src/objects/LineSegments.js

📦 Imports

Name Source
Line ./Line.js
Vector3 ../math/Vector3.js
Float32BufferAttribute ../core/BufferAttribute.js

Variables & Constants

Name Type Kind Value Exported
_start Vector3 let/var new Vector3()
_end Vector3 let/var new Vector3()
geometry BufferGeometry let/var this.geometry
positionAttribute any let/var geometry.attributes.position
lineDistances any[] let/var []

Functions

LineSegments.computeLineDistances(): this

Returns: this

Calls:

  • _start.fromBufferAttribute
  • _end.fromBufferAttribute
  • _start.distanceTo
  • geometry.setAttribute
  • console.warn

Internal Comments:

// we assume non-indexed geometry

Code
computeLineDistances() {

        const geometry = this.geometry;

        // we assume non-indexed geometry

        if ( geometry.index === null ) {

            const positionAttribute = geometry.attributes.position;
            const lineDistances = [];

            for ( let i = 0, l = positionAttribute.count; i < l; i += 2 ) {

                _start.fromBufferAttribute( positionAttribute, i );
                _end.fromBufferAttribute( positionAttribute, i + 1 );

                lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
                lineDistances[ i + 1 ] = lineDistances[ i ] + _start.distanceTo( _end );

            }

            geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );

        } else {

            console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );

        }

        return this;

    }

Classes

LineSegments

Class Code
class LineSegments extends Line {

    /**
     * Constructs a new line segments.
     *
     * @param {BufferGeometry} [geometry] - The line geometry.
     * @param {Material|Array<Material>} [material] - The line material.
     */
    constructor( geometry, material ) {

        super( geometry, material );

        /**
         * This flag can be used for type testing.
         *
         * @type {boolean}
         * @readonly
         * @default true
         */
        this.isLineSegments = true;

        this.type = 'LineSegments';

    }

    computeLineDistances() {

        const geometry = this.geometry;

        // we assume non-indexed geometry

        if ( geometry.index === null ) {

            const positionAttribute = geometry.attributes.position;
            const lineDistances = [];

            for ( let i = 0, l = positionAttribute.count; i < l; i += 2 ) {

                _start.fromBufferAttribute( positionAttribute, i );
                _end.fromBufferAttribute( positionAttribute, i + 1 );

                lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
                lineDistances[ i + 1 ] = lineDistances[ i ] + _start.distanceTo( _end );

            }

            geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );

        } else {

            console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );

        }

        return this;

    }

}

Methods

computeLineDistances(): this
Code
computeLineDistances() {

        const geometry = this.geometry;

        // we assume non-indexed geometry

        if ( geometry.index === null ) {

            const positionAttribute = geometry.attributes.position;
            const lineDistances = [];

            for ( let i = 0, l = positionAttribute.count; i < l; i += 2 ) {

                _start.fromBufferAttribute( positionAttribute, i );
                _end.fromBufferAttribute( positionAttribute, i + 1 );

                lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
                lineDistances[ i + 1 ] = lineDistances[ i ] + _start.distanceTo( _end );

            }

            geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );

        } else {

            console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );

        }

        return this;

    }