-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIncrementalLine.js
52 lines (37 loc) · 1.52 KB
/
IncrementalLine.js
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
var IncrementalLine = function (maxVertices, material) {
var geometry = new THREE.BufferGeometry();
var positionsAttr = new THREE.BufferAttribute( new Float32Array( maxVertices * 3 ), 3 );
geometry.addAttribute( 'position', positionsAttr );
var indicesAttr = new THREE.BufferAttribute( new Uint32Array( maxVertices * 2 ), 2 );
geometry.setIndex( indicesAttr );
if (material.vertexColors === THREE.VertexColors) {
var colorsAttr = new THREE.BufferAttribute( new Float32Array( maxVertices * 3), 3 );
geometry.addAttribute( 'color', colorsAttr );
this.color = new THREE.Color(1, 1, 1);
}
geometry.addGroup(0, 0);
this.vertexCount = 0;
this.pieceCount = 0;
this.addVertex = function (x, y, z, draw) {
positionsAttr.setXYZ(this.vertexCount, x, y, z);
positionsAttr.needsUpdate = true;
if (material.vertexColors === THREE.VertexColors) {
colorsAttr.setXYZ(this.vertexCount, this.color.r, this.color.g, this.color.b);
colorsAttr.needsUpdate = true;
}
if(draw && this.vertexCount > 0) {
indicesAttr.setXY(this.pieceCount++, this.vertexCount-1, this.vertexCount);
indicesAttr.needsUpdate = true;
geometry.groups[0].count = this.pieceCount * 2;
}
this.vertexCount++;
}
this.lineTo = function (x, y, z) {
this.addVertex(x, y, z, true);
};
this.moveTo = function (x, y, z) {
this.addVertex(x, y, z, false);
};
THREE.LineSegments.call(this, geometry, material);
};
IncrementalLine.prototype = Object.create(THREE.LineSegments.prototype);