Spaces:
Running
Running
File size: 1,893 Bytes
6cd9596 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
import { Line } from './Line.js';
import { Vector3 } from '../math/Vector3.js';
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
/**
* @author mrdoob / http://mrdoob.com/
*/
function LineSegments( geometry, material ) {
Line.call( this, geometry, material );
this.type = 'LineSegments';
}
LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
constructor: LineSegments,
isLineSegments: true,
computeLineDistances: ( function () {
var start = new Vector3();
var end = new Vector3();
return function computeLineDistances() {
var geometry = this.geometry;
if ( geometry.isBufferGeometry ) {
// we assume non-indexed geometry
if ( geometry.index === null ) {
var positionAttribute = geometry.attributes.position;
var lineDistances = [];
for ( var 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.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
} else {
console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
}
} else if ( geometry.isGeometry ) {
var vertices = geometry.vertices;
var lineDistances = geometry.lineDistances;
for ( var i = 0, l = vertices.length; i < l; i += 2 ) {
start.copy( vertices[ i ] );
end.copy( vertices[ i + 1 ] );
lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
}
}
return this;
};
}() )
} );
export { LineSegments };
|