Skip to content

Commit

Permalink
Line: Handle indexed geometry more gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed Jan 21, 2018
1 parent e463b8c commit 0286198
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/objects/Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,33 @@ Line.prototype = Object.assign( Object.create( Object3D.prototype ), {

// we assume non-indexed geometry

var positionAttribute = geometry.attributes.position;
var lineDistances = [];
if ( geometry.index === null ) {

for ( var i = 0, l = positionAttribute.count; i < l; i ++ ) {
var positionAttribute = geometry.attributes.position;
var lineDistances = [];

if ( i > 0 ) {
for ( var i = 0, l = positionAttribute.count; i < l; i ++ ) {

start.fromBufferAttribute( positionAttribute, i - 1 );
end.fromBufferAttribute( positionAttribute, i );
if ( i > 0 ) {

distance += start.distanceTo( end );
start.fromBufferAttribute( positionAttribute, i - 1 );
end.fromBufferAttribute( positionAttribute, i );

distance += start.distanceTo( end );

}

lineDistances.push( distance );

}

lineDistances.push( distance );
geometry.addAttribute( 'lineDistance', new THREE.Float32BufferAttribute( lineDistances, 1 ) );

}
} else {

geometry.addAttribute( 'lineDistance', new THREE.Float32BufferAttribute( lineDistances, 1 ) );
console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );

}

} else if ( geometry.isGeometry ) {

Expand Down

0 comments on commit 0286198

Please sign in to comment.