UNPKG

1.67 kBJavaScriptView Raw
1( function () {
2
3 class LineGeometry extends THREE.LineSegmentsGeometry {
4
5 constructor() {
6
7 super();
8 this.type = 'LineGeometry';
9
10 }
11
12 setPositions( array ) {
13
14 // converts [ x1, y1, z1, x2, y2, z2, ... ] to pairs format
15 var length = array.length - 3;
16 var points = new Float32Array( 2 * length );
17
18 for ( var i = 0; i < length; i += 3 ) {
19
20 points[ 2 * i ] = array[ i ];
21 points[ 2 * i + 1 ] = array[ i + 1 ];
22 points[ 2 * i + 2 ] = array[ i + 2 ];
23 points[ 2 * i + 3 ] = array[ i + 3 ];
24 points[ 2 * i + 4 ] = array[ i + 4 ];
25 points[ 2 * i + 5 ] = array[ i + 5 ];
26
27 }
28
29 super.setPositions( points );
30 return this;
31
32 }
33
34 setColors( array ) {
35
36 // converts [ r1, g1, b1, r2, g2, b2, ... ] to pairs format
37 var length = array.length - 3;
38 var colors = new Float32Array( 2 * length );
39
40 for ( var i = 0; i < length; i += 3 ) {
41
42 colors[ 2 * i ] = array[ i ];
43 colors[ 2 * i + 1 ] = array[ i + 1 ];
44 colors[ 2 * i + 2 ] = array[ i + 2 ];
45 colors[ 2 * i + 3 ] = array[ i + 3 ];
46 colors[ 2 * i + 4 ] = array[ i + 4 ];
47 colors[ 2 * i + 5 ] = array[ i + 5 ];
48
49 }
50
51 super.setColors( colors );
52 return this;
53
54 }
55
56 fromLine( line ) {
57
58 var geometry = line.geometry;
59
60 if ( geometry.isGeometry ) {
61
62 console.error( 'THREE.LineGeometry no longer supports Geometry. Use THREE.BufferGeometry instead.' );
63 return;
64
65 } else if ( geometry.isBufferGeometry ) {
66
67 this.setPositions( geometry.attributes.position.array ); // assumes non-indexed
68
69 } // set colors, maybe
70
71
72 return this;
73
74 }
75
76 }
77
78 LineGeometry.prototype.isLineGeometry = true;
79
80 THREE.LineGeometry = LineGeometry;
81
82} )();