Browse Source

Line: Handle indexed geometry more gracefully

Mugen87 7 years ago
parent
commit
0286198717
1 changed files with 18 additions and 10 deletions
  1. 18 10
      src/objects/Line.js

+ 18 - 10
src/objects/Line.js

@@ -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 ) {