@@ -9,29 +9,30 @@ import {
99 WireframeGeometry
1010} from '../../../build/three.module.js' ;
1111
12- var LineSegmentsGeometry = function ( ) {
12+ const box = new Box3 ( ) ;
13+ const vector = new Vector3 ( ) ;
1314
14- InstancedBufferGeometry . call ( this ) ;
15+ class LineSegmentsGeometry extends InstancedBufferGeometry {
1516
16- this . type = 'LineSegmentsGeometry' ;
17+ constructor ( ) {
1718
18- var positions = [ - 1 , 2 , 0 , 1 , 2 , 0 , - 1 , 1 , 0 , 1 , 1 , 0 , - 1 , 0 , 0 , 1 , 0 , 0 , - 1 , - 1 , 0 , 1 , - 1 , 0 ] ;
19- var uvs = [ - 1 , 2 , 1 , 2 , - 1 , 1 , 1 , 1 , - 1 , - 1 , 1 , - 1 , - 1 , - 2 , 1 , - 2 ] ;
20- var index = [ 0 , 2 , 1 , 2 , 3 , 1 , 2 , 4 , 3 , 4 , 5 , 3 , 4 , 6 , 5 , 6 , 7 , 5 ] ;
19+ super ( ) ;
2120
22- this . setIndex ( index ) ;
23- this . setAttribute ( 'position' , new Float32BufferAttribute ( positions , 3 ) ) ;
24- this . setAttribute ( 'uv' , new Float32BufferAttribute ( uvs , 2 ) ) ;
21+ Object . defineProperty ( this , 'isLineSegmentsGeometry' , { value : true } ) ;
2522
26- } ;
23+ this . type = 'LineSegmentsGeometry' ;
2724
28- LineSegmentsGeometry . prototype = Object . assign ( Object . create ( InstancedBufferGeometry . prototype ) , {
25+ var positions = [ - 1 , 2 , 0 , 1 , 2 , 0 , - 1 , 1 , 0 , 1 , 1 , 0 , - 1 , 0 , 0 , 1 , 0 , 0 , - 1 , - 1 , 0 , 1 , - 1 , 0 ] ;
26+ var uvs = [ - 1 , 2 , 1 , 2 , - 1 , 1 , 1 , 1 , - 1 , - 1 , 1 , - 1 , - 1 , - 2 , 1 , - 2 ] ;
27+ var index = [ 0 , 2 , 1 , 2 , 3 , 1 , 2 , 4 , 3 , 4 , 5 , 3 , 4 , 6 , 5 , 6 , 7 , 5 ] ;
2928
30- constructor : LineSegmentsGeometry ,
29+ this . setIndex ( index ) ;
30+ this . setAttribute ( 'position' , new Float32BufferAttribute ( positions , 3 ) ) ;
31+ this . setAttribute ( 'uv' , new Float32BufferAttribute ( uvs , 2 ) ) ;
3132
32- isLineSegmentsGeometry : true ,
33+ }
3334
34- applyMatrix4 : function ( matrix ) {
35+ applyMatrix4 ( matrix ) {
3536
3637 var start = this . attributes . instanceStart ;
3738 var end = this . attributes . instanceEnd ;
@@ -60,9 +61,9 @@ LineSegmentsGeometry.prototype = Object.assign( Object.create( InstancedBufferGe
6061
6162 return this ;
6263
63- } ,
64+ }
6465
65- setPositions : function ( array ) {
66+ setPositions ( array ) {
6667
6768 var lineSegments ;
6869
@@ -88,9 +89,9 @@ LineSegmentsGeometry.prototype = Object.assign( Object.create( InstancedBufferGe
8889
8990 return this ;
9091
91- } ,
92+ }
9293
93- setColors : function ( array ) {
94+ setColors ( array ) {
9495
9596 var colors ;
9697
@@ -111,35 +112,35 @@ LineSegmentsGeometry.prototype = Object.assign( Object.create( InstancedBufferGe
111112
112113 return this ;
113114
114- } ,
115+ }
115116
116- fromWireframeGeometry : function ( geometry ) {
117+ fromWireframeGeometry ( geometry ) {
117118
118119 this . setPositions ( geometry . attributes . position . array ) ;
119120
120121 return this ;
121122
122- } ,
123+ }
123124
124- fromEdgesGeometry : function ( geometry ) {
125+ fromEdgesGeometry ( geometry ) {
125126
126127 this . setPositions ( geometry . attributes . position . array ) ;
127128
128129 return this ;
129130
130- } ,
131+ }
131132
132- fromMesh : function ( mesh ) {
133+ fromMesh ( mesh ) {
133134
134135 this . fromWireframeGeometry ( new WireframeGeometry ( mesh . geometry ) ) ;
135136
136137 // set colors, maybe
137138
138139 return this ;
139140
140- } ,
141+ }
141142
142- fromLineSegments : function ( lineSegments ) {
143+ fromLineSegments ( lineSegments ) {
143144
144145 var geometry = lineSegments . geometry ;
145146
@@ -158,104 +159,92 @@ LineSegmentsGeometry.prototype = Object.assign( Object.create( InstancedBufferGe
158159
159160 return this ;
160161
161- } ,
162-
163- computeBoundingBox : function ( ) {
164-
165- var box = new Box3 ( ) ;
166-
167- return function computeBoundingBox ( ) {
168-
169- if ( this . boundingBox === null ) {
170-
171- this . boundingBox = new Box3 ( ) ;
172-
173- }
162+ }
174163
175- var start = this . attributes . instanceStart ;
176- var end = this . attributes . instanceEnd ;
164+ computeBoundingBox ( ) {
177165
178- if ( start !== undefined && end !== undefined ) {
166+ if ( this . boundingBox === null ) {
179167
180- this . boundingBox . setFromBufferAttribute ( start ) ;
168+ this . boundingBox = new Box3 ( ) ;
181169
182- box . setFromBufferAttribute ( end ) ;
170+ }
183171
184- this . boundingBox . union ( box ) ;
172+ var start = this . attributes . instanceStart ;
173+ var end = this . attributes . instanceEnd ;
185174
186- }
175+ if ( start !== undefined && end !== undefined ) {
187176
188- } ;
177+ this . boundingBox . setFromBufferAttribute ( start ) ;
189178
190- } ( ) ,
179+ box . setFromBufferAttribute ( end ) ;
191180
192- computeBoundingSphere : function ( ) {
181+ this . boundingBox . union ( box ) ;
193182
194- var vector = new Vector3 ( ) ;
183+ }
195184
196- return function computeBoundingSphere ( ) {
185+ }
197186
198- if ( this . boundingSphere === null ) {
187+ computeBoundingSphere ( ) {
199188
200- this . boundingSphere = new Sphere ( ) ;
189+ if ( this . boundingSphere === null ) {
201190
202- }
191+ this . boundingSphere = new Sphere ( ) ;
203192
204- if ( this . boundingBox === null ) {
193+ }
205194
206- this . computeBoundingBox ( ) ;
195+ if ( this . boundingBox === null ) {
207196
208- }
197+ this . computeBoundingBox ( ) ;
209198
210- var start = this . attributes . instanceStart ;
211- var end = this . attributes . instanceEnd ;
199+ }
212200
213- if ( start !== undefined && end !== undefined ) {
201+ var start = this . attributes . instanceStart ;
202+ var end = this . attributes . instanceEnd ;
214203
215- var center = this . boundingSphere . center ;
204+ if ( start !== undefined && end !== undefined ) {
216205
217- this . boundingBox . getCenter ( center ) ;
206+ var center = this . boundingSphere . center ;
218207
219- var maxRadiusSq = 0 ;
208+ this . boundingBox . getCenter ( center ) ;
220209
221- for ( var i = 0 , il = start . count ; i < il ; i ++ ) {
210+ var maxRadiusSq = 0 ;
222211
223- vector . fromBufferAttribute ( start , i ) ;
224- maxRadiusSq = Math . max ( maxRadiusSq , center . distanceToSquared ( vector ) ) ;
212+ for ( var i = 0 , il = start . count ; i < il ; i ++ ) {
225213
226- vector . fromBufferAttribute ( end , i ) ;
227- maxRadiusSq = Math . max ( maxRadiusSq , center . distanceToSquared ( vector ) ) ;
214+ vector . fromBufferAttribute ( start , i ) ;
215+ maxRadiusSq = Math . max ( maxRadiusSq , center . distanceToSquared ( vector ) ) ;
228216
229- }
217+ vector . fromBufferAttribute ( end , i ) ;
218+ maxRadiusSq = Math . max ( maxRadiusSq , center . distanceToSquared ( vector ) ) ;
230219
231- this . boundingSphere . radius = Math . sqrt ( maxRadiusSq ) ;
220+ }
232221
233- if ( isNaN ( this . boundingSphere . radius ) ) {
222+ this . boundingSphere . radius = Math . sqrt ( maxRadiusSq ) ;
234223
235- console . error ( 'THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.' , this ) ;
224+ if ( isNaN ( this . boundingSphere . radius ) ) {
236225
237- }
226+ console . error ( 'THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.' , this ) ;
238227
239228 }
240229
241- } ;
230+ }
242231
243- } ( ) ,
232+ }
244233
245- toJSON : function ( ) {
234+ toJSON ( ) {
246235
247236 // todo
248237
249- } ,
238+ }
250239
251- applyMatrix : function ( matrix ) {
240+ applyMatrix ( matrix ) {
252241
253242 console . warn ( 'THREE.LineSegmentsGeometry: applyMatrix() has been renamed to applyMatrix4().' ) ;
254243
255244 return this . applyMatrix4 ( matrix ) ;
256245
257246 }
258247
259- } ) ;
248+ }
260249
261250export { LineSegmentsGeometry } ;
0 commit comments