File size: 1,442 Bytes
2b7aae2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { Line } from './Line.js';
import { Vector3 } from '../math/Vector3.js';
import { Float32BufferAttribute } from '../core/BufferAttribute.js';

const _start = /*@__PURE__*/ new Vector3();
const _end = /*@__PURE__*/ new Vector3();

class LineSegments extends Line {
	constructor(geometry, material) {
		super(geometry, material);

		this.type = 'LineSegments';
	}

	computeLineDistances() {
		const geometry = this.geometry;

		if (geometry.isBufferGeometry) {
			// 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.');
			}
		} else if (geometry.isGeometry) {
			console.error('THREE.LineSegments.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
		}

		return this;
	}
}

LineSegments.prototype.isLineSegments = true;

export { LineSegments };