zincjs 2.4.0 → 2.4.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/build/zinc.js +3 -486
  2. package/build/zinc.js.map +1 -1
  3. package/package.json +3 -4
  4. package/src/controls.js +1 -1
  5. package/src/geometryCSG.js +1 -1
  6. package/src/glyphsetCSG.js +1 -1
  7. package/src/loaders/GLTFToZincJSLoader.js +1 -1
  8. package/src/loaders/JSONLoader.js +204 -377
  9. package/src/loaders/OBJLoader.js +1 -1
  10. package/src/loaders/STLLoader.js +1 -1
  11. package/src/loaders/niftiReader.js +6 -4
  12. package/src/loaders/primitivesLoader.js +7 -9
  13. package/src/minimap.js +1 -1
  14. package/src/primitives/geometry.js +11 -29
  15. package/src/primitives/glyph.js +1 -1
  16. package/src/primitives/glyphset.js +2 -4
  17. package/src/primitives/label.js +1 -1
  18. package/src/primitives/lines.js +12 -5
  19. package/src/primitives/lines2.js +4 -8
  20. package/src/primitives/lod.js +9 -3
  21. package/src/primitives/marker.js +1 -1
  22. package/src/primitives/markerCluster.js +1 -1
  23. package/src/primitives/pointset.js +368 -52
  24. package/src/primitives/textureSlides.js +59 -16
  25. package/src/primitives/textureVolume.js +1 -1
  26. package/src/primitives/tubeLines.js +20 -3
  27. package/src/primitives/zincObject.js +13 -1
  28. package/src/region.js +1 -1
  29. package/src/renderer.js +17 -13
  30. package/src/scene.js +20 -8
  31. package/src/sceneLoader.js +1 -1
  32. package/src/shaders/rgbVolumeRender.js +1 -1
  33. package/src/shaders/textureSlide.js +1 -1
  34. package/src/texture/texture.js +1 -1
  35. package/src/texture/textureArray.js +9 -2
  36. package/src/three/GLTFExporter.js +55 -2
  37. package/src/three/InstancedPoints.js +73 -0
  38. package/src/three/Loader.js +1 -1
  39. package/src/three/line/Line.js +1 -1
  40. package/src/three/line/LineSegments.js +1 -1
  41. package/src/three/line/LineSegments2.js +24 -39
  42. package/src/three/line/LineSegmentsGeometry.js +1 -1
  43. package/src/tls/morphColorMaterial.js +65 -0
  44. package/src/tls/pointsMaterial.js +79 -0
  45. package/src/tls/textureSlides.js +126 -0
  46. package/src/utilities.js +47 -70
  47. package/src/videoHandler.js +1 -2
  48. package/src/workers/geometryCSG.worker.js +1 -1
  49. package/src/workers/geometryCSGInternal.js +1 -1
  50. package/src/zinc.js +1 -1
  51. package/vite.config.js +3 -1
  52. package/src/primitives/augmentShader.js +0 -45
  53. package/src/three/Geometry.js +0 -2176
  54. package/src/three/Points.js +0 -224
  55. package/src/three/line/LineMaterial.js +0 -726
@@ -1,2176 +0,0 @@
1
- import {
2
- Box3,
3
- BufferAttribute,
4
- BufferGeometry,
5
- Color,
6
- EventDispatcher,
7
- Float32BufferAttribute,
8
- Matrix3,
9
- Matrix4,
10
- MathUtils,
11
- Object3D,
12
- Sphere,
13
- Vector2,
14
- Vector3
15
- } from 'three';
16
- import {
17
- copyColorsArray,
18
- copyVector2sArray,
19
- copyVector3sArray,
20
- copyVector4sArray
21
- } from "../utilities";
22
-
23
- const _m1 = new Matrix4();
24
- const _obj = new Object3D();
25
- const _offset = new Vector3();
26
- const _temp = new Vector3();
27
-
28
- function Geometry() {
29
-
30
- this.uuid = MathUtils.generateUUID();
31
-
32
- this.name = '';
33
- this.type = 'Geometry';
34
-
35
- this.vertices = [];
36
- this.colors = [];
37
- this.faces = [];
38
- this.faceVertexUvs = [[]];
39
- this.normals = [];
40
- this.uvs = [];
41
-
42
- this.morphTargets = [];
43
- this.morphNormals = [];
44
-
45
- this.skinWeights = [];
46
- this.skinIndices = [];
47
-
48
- this.lineDistances = [];
49
-
50
- this.boundingBox = null;
51
- this.boundingSphere = null;
52
-
53
- // update flags
54
-
55
- this.elementsNeedUpdate = false;
56
- this.verticesNeedUpdate = false;
57
- this.uvsNeedUpdate = false;
58
- this.normalsNeedUpdate = false;
59
- this.colorsNeedUpdate = false;
60
- this.lineDistancesNeedUpdate = false;
61
- this.groupsNeedUpdate = false;
62
- this.morphNormalsReady = false;
63
-
64
- }
65
-
66
- Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
67
-
68
- constructor: Geometry,
69
-
70
- isGeometry: true,
71
-
72
- applyMatrix4: function ( matrix ) {
73
-
74
- const normalMatrix = new Matrix3().getNormalMatrix( matrix );
75
-
76
- for ( let i = 0, il = this.vertices.length; i < il; i ++ ) {
77
-
78
- const vertex = this.vertices[ i ];
79
- vertex.applyMatrix4( matrix );
80
-
81
- }
82
-
83
- for ( let i = 0, il = this.faces.length; i < il; i ++ ) {
84
-
85
- const face = this.faces[ i ];
86
- face.normal.applyMatrix3( normalMatrix ).normalize();
87
-
88
- for ( let j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
89
-
90
- face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
91
-
92
- }
93
-
94
- }
95
-
96
- if ( this.boundingBox !== null ) {
97
-
98
- this.computeBoundingBox();
99
-
100
- }
101
-
102
- if ( this.boundingSphere !== null ) {
103
-
104
- this.computeBoundingSphere();
105
-
106
- }
107
-
108
- this.verticesNeedUpdate = true;
109
- this.normalsNeedUpdate = true;
110
-
111
- return this;
112
-
113
- },
114
-
115
- rotateX: function ( angle ) {
116
-
117
- // rotate geometry around world x-axis
118
-
119
- _m1.makeRotationX( angle );
120
-
121
- this.applyMatrix4( _m1 );
122
-
123
- return this;
124
-
125
- },
126
-
127
- rotateY: function ( angle ) {
128
-
129
- // rotate geometry around world y-axis
130
-
131
- _m1.makeRotationY( angle );
132
-
133
- this.applyMatrix4( _m1 );
134
-
135
- return this;
136
-
137
- },
138
-
139
- rotateZ: function ( angle ) {
140
-
141
- // rotate geometry around world z-axis
142
-
143
- _m1.makeRotationZ( angle );
144
-
145
- this.applyMatrix4( _m1 );
146
-
147
- return this;
148
-
149
- },
150
-
151
- translate: function ( x, y, z ) {
152
-
153
- // translate geometry
154
-
155
- _m1.makeTranslation( x, y, z );
156
-
157
- this.applyMatrix4( _m1 );
158
-
159
- return this;
160
-
161
- },
162
-
163
- scale: function ( x, y, z ) {
164
-
165
- // scale geometry
166
-
167
- _m1.makeScale( x, y, z );
168
-
169
- this.applyMatrix4( _m1 );
170
-
171
- return this;
172
-
173
- },
174
-
175
- lookAt: function ( vector ) {
176
-
177
- _obj.lookAt( vector );
178
-
179
- _obj.updateMatrix();
180
-
181
- this.applyMatrix4( _obj.matrix );
182
-
183
- return this;
184
-
185
- },
186
-
187
- fromBufferGeometry: function ( geometry ) {
188
-
189
- const scope = this;
190
-
191
- const index = geometry.index !== null ? geometry.index : undefined;
192
- const attributes = geometry.attributes;
193
-
194
- if ( attributes.position === undefined ) {
195
-
196
- console.error( 'THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.' );
197
- return this;
198
-
199
- }
200
-
201
- const position = attributes.position;
202
- const normal = attributes.normal;
203
- const color = attributes.color;
204
- const uv = attributes.uv;
205
- const uv2 = attributes.uv2;
206
-
207
- if ( uv2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
208
-
209
- for ( let i = 0; i < position.count; i ++ ) {
210
-
211
- scope.vertices.push( new Vector3().fromBufferAttribute( position, i ) );
212
-
213
- if ( color !== undefined ) {
214
-
215
- scope.colors.push( new Color().fromBufferAttribute( color, i ) );
216
-
217
- }
218
-
219
- }
220
-
221
- function addFace( a, b, c, materialIndex ) {
222
-
223
- const vertexColors = ( color === undefined ) ? [] : [
224
- scope.colors[ a ].clone(),
225
- scope.colors[ b ].clone(),
226
- scope.colors[ c ].clone()
227
- ];
228
-
229
- const vertexNormals = ( normal === undefined ) ? [] : [
230
- new Vector3().fromBufferAttribute( normal, a ),
231
- new Vector3().fromBufferAttribute( normal, b ),
232
- new Vector3().fromBufferAttribute( normal, c )
233
- ];
234
-
235
- const face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
236
-
237
- scope.faces.push( face );
238
-
239
- if ( uv !== undefined ) {
240
-
241
- scope.faceVertexUvs[ 0 ].push( [
242
- new Vector2().fromBufferAttribute( uv, a ),
243
- new Vector2().fromBufferAttribute( uv, b ),
244
- new Vector2().fromBufferAttribute( uv, c )
245
- ] );
246
-
247
- }
248
-
249
- if ( uv2 !== undefined ) {
250
-
251
- scope.faceVertexUvs[ 1 ].push( [
252
- new Vector2().fromBufferAttribute( uv2, a ),
253
- new Vector2().fromBufferAttribute( uv2, b ),
254
- new Vector2().fromBufferAttribute( uv2, c )
255
- ] );
256
-
257
- }
258
-
259
- }
260
-
261
- const groups = geometry.groups;
262
-
263
- if ( groups.length > 0 ) {
264
-
265
- for ( let i = 0; i < groups.length; i ++ ) {
266
-
267
- const group = groups[ i ];
268
-
269
- const start = group.start;
270
- const count = group.count;
271
-
272
- for ( let j = start, jl = start + count; j < jl; j += 3 ) {
273
-
274
- if ( index !== undefined ) {
275
-
276
- addFace( index.getX( j ), index.getX( j + 1 ), index.getX( j + 2 ), group.materialIndex );
277
-
278
- } else {
279
-
280
- addFace( j, j + 1, j + 2, group.materialIndex );
281
-
282
- }
283
-
284
- }
285
-
286
- }
287
-
288
- } else {
289
-
290
- if ( index !== undefined ) {
291
-
292
- for ( let i = 0; i < index.count; i += 3 ) {
293
-
294
- addFace( index.getX( i ), index.getX( i + 1 ), index.getX( i + 2 ) );
295
-
296
- }
297
-
298
- } else {
299
-
300
- for ( let i = 0; i < position.count; i += 3 ) {
301
-
302
- addFace( i, i + 1, i + 2 );
303
-
304
- }
305
-
306
- }
307
-
308
- }
309
-
310
- this.computeFaceNormals();
311
-
312
- if ( geometry.boundingBox !== null ) {
313
-
314
- this.boundingBox = geometry.boundingBox.clone();
315
-
316
- }
317
-
318
- if ( geometry.boundingSphere !== null ) {
319
-
320
- this.boundingSphere = geometry.boundingSphere.clone();
321
-
322
- }
323
-
324
- return this;
325
-
326
- },
327
-
328
- center: function () {
329
-
330
- this.computeBoundingBox();
331
-
332
- this.boundingBox.getCenter( _offset ).negate();
333
-
334
- this.translate( _offset.x, _offset.y, _offset.z );
335
-
336
- return this;
337
-
338
- },
339
-
340
- normalize: function () {
341
-
342
- this.computeBoundingSphere();
343
-
344
- const center = this.boundingSphere.center;
345
- const radius = this.boundingSphere.radius;
346
-
347
- const s = radius === 0 ? 1 : 1.0 / radius;
348
-
349
- const matrix = new Matrix4();
350
- matrix.set(
351
- s, 0, 0, - s * center.x,
352
- 0, s, 0, - s * center.y,
353
- 0, 0, s, - s * center.z,
354
- 0, 0, 0, 1
355
- );
356
-
357
- this.applyMatrix4( matrix );
358
-
359
- return this;
360
-
361
- },
362
-
363
- computeFaceNormals: function () {
364
-
365
- const cb = new Vector3(), ab = new Vector3();
366
-
367
- for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
368
-
369
- const face = this.faces[ f ];
370
-
371
- const vA = this.vertices[ face.a ];
372
- const vB = this.vertices[ face.b ];
373
- const vC = this.vertices[ face.c ];
374
-
375
- cb.subVectors( vC, vB );
376
- ab.subVectors( vA, vB );
377
- cb.cross( ab );
378
-
379
- cb.normalize();
380
-
381
- face.normal.copy( cb );
382
-
383
- }
384
-
385
- },
386
-
387
- computeVertexNormals: function ( areaWeighted = true ) {
388
-
389
- const vertices = new Array( this.vertices.length );
390
-
391
- for ( let v = 0, vl = this.vertices.length; v < vl; v ++ ) {
392
-
393
- vertices[ v ] = new Vector3();
394
-
395
- }
396
-
397
- if ( areaWeighted ) {
398
-
399
- // vertex normals weighted by triangle areas
400
- // http://www.iquilezles.org/www/articles/normals/normals.htm
401
-
402
- const cb = new Vector3(), ab = new Vector3();
403
-
404
- for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
405
-
406
- const face = this.faces[ f ];
407
-
408
- const vA = this.vertices[ face.a ];
409
- const vB = this.vertices[ face.b ];
410
- const vC = this.vertices[ face.c ];
411
-
412
- cb.subVectors( vC, vB );
413
- ab.subVectors( vA, vB );
414
- cb.cross( ab );
415
-
416
- vertices[ face.a ].add( cb );
417
- vertices[ face.b ].add( cb );
418
- vertices[ face.c ].add( cb );
419
-
420
- }
421
-
422
- } else {
423
-
424
- this.computeFaceNormals();
425
-
426
- for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
427
-
428
- const face = this.faces[ f ];
429
-
430
- vertices[ face.a ].add( face.normal );
431
- vertices[ face.b ].add( face.normal );
432
- vertices[ face.c ].add( face.normal );
433
-
434
- }
435
-
436
- }
437
-
438
- for ( let v = 0, vl = this.vertices.length; v < vl; v ++ ) {
439
-
440
- vertices[ v ].normalize();
441
-
442
- }
443
-
444
- for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
445
-
446
- const face = this.faces[ f ];
447
-
448
- const vertexNormals = face.vertexNormals;
449
-
450
- if ( vertexNormals.length === 3 ) {
451
-
452
- vertexNormals[ 0 ].copy( vertices[ face.a ] );
453
- vertexNormals[ 1 ].copy( vertices[ face.b ] );
454
- vertexNormals[ 2 ].copy( vertices[ face.c ] );
455
-
456
- } else {
457
-
458
- vertexNormals[ 0 ] = vertices[ face.a ].clone();
459
-
460
- vertexNormals[ 1 ] = vertices[ face.b ].clone();
461
- vertexNormals[ 2 ] = vertices[ face.c ].clone();
462
-
463
- }
464
-
465
- }
466
-
467
- if ( this.faces.length > 0 ) {
468
-
469
- this.normalsNeedUpdate = true;
470
-
471
- }
472
-
473
- return vertices;
474
-
475
- },
476
-
477
- computeFlatVertexNormals: function () {
478
-
479
- this.computeFaceNormals();
480
-
481
- for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
482
-
483
- const face = this.faces[ f ];
484
-
485
- const vertexNormals = face.vertexNormals;
486
-
487
- if ( vertexNormals.length === 3 ) {
488
-
489
- vertexNormals[ 0 ].copy( face.normal );
490
- vertexNormals[ 1 ].copy( face.normal );
491
- vertexNormals[ 2 ].copy( face.normal );
492
-
493
- } else {
494
-
495
- vertexNormals[ 0 ] = face.normal.clone();
496
- vertexNormals[ 1 ] = face.normal.clone();
497
- vertexNormals[ 2 ] = face.normal.clone();
498
-
499
- }
500
-
501
- }
502
-
503
- if ( this.faces.length > 0 ) {
504
-
505
- this.normalsNeedUpdate = true;
506
-
507
- }
508
-
509
- },
510
-
511
- computeMorphNormals: function () {
512
-
513
- // save original normals
514
- // - create temp variables on first access
515
- // otherwise just copy (for faster repeated calls)
516
-
517
- for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
518
-
519
- const face = this.faces[ f ];
520
-
521
- if ( ! face.__originalFaceNormal ) {
522
-
523
- face.__originalFaceNormal = face.normal.clone();
524
-
525
- } else {
526
-
527
- face.__originalFaceNormal.copy( face.normal );
528
-
529
- }
530
-
531
- if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
532
-
533
- for ( let i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
534
-
535
- if ( ! face.__originalVertexNormals[ i ] ) {
536
-
537
- face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
538
-
539
- } else {
540
-
541
- face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
542
-
543
- }
544
-
545
- }
546
-
547
- }
548
-
549
- // use temp geometry to compute face and vertex normals for each morph
550
-
551
- const tmpGeo = new Geometry();
552
- tmpGeo.faces = this.faces;
553
-
554
- for ( let i = 0, il = this.morphTargets.length; i < il; i ++ ) {
555
-
556
- // create on first access
557
-
558
- if ( ! this.morphNormals[ i ] ) {
559
-
560
- this.morphNormals[ i ] = {};
561
- this.morphNormals[ i ].faceNormals = [];
562
- this.morphNormals[ i ].vertexNormals = [];
563
-
564
- const dstNormalsFace = this.morphNormals[ i ].faceNormals;
565
- const dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
566
-
567
- for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
568
-
569
- const faceNormal = new Vector3();
570
- const vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
571
-
572
- dstNormalsFace.push( faceNormal );
573
- dstNormalsVertex.push( vertexNormals );
574
-
575
- }
576
-
577
- }
578
-
579
- const morphNormals = this.morphNormals[ i ];
580
-
581
- // set vertices to morph target
582
-
583
- tmpGeo.vertices = this.morphTargets[ i ].vertices;
584
-
585
- // compute morph normals
586
-
587
- tmpGeo.computeFaceNormals();
588
- let vertexNormals = tmpGeo.computeVertexNormals();
589
-
590
- if (vertexNormals && vertexNormals.length > 0) {
591
- this.morphTargets[i].normals = new Array( this.vertices.length );
592
-
593
- for ( let v = 0; v < vertexNormals.length; v ++ ) {
594
-
595
- this.morphTargets[i].normals[ v ] = vertexNormals[v].clone();
596
-
597
- }
598
- }
599
-
600
- // store morph normals
601
-
602
- for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
603
-
604
- const face = this.faces[ f ];
605
-
606
- const faceNormal = morphNormals.faceNormals[ f ];
607
- const vertexNormals = morphNormals.vertexNormals[ f ];
608
-
609
- faceNormal.copy( face.normal );
610
-
611
- vertexNormals.a.copy( face.vertexNormals[ 0 ] );
612
- vertexNormals.b.copy( face.vertexNormals[ 1 ] );
613
- vertexNormals.c.copy( face.vertexNormals[ 2 ] );
614
-
615
- }
616
-
617
- }
618
-
619
- // restore original normals
620
-
621
- for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
622
-
623
- const face = this.faces[ f ];
624
-
625
- face.normal = face.__originalFaceNormal;
626
- face.vertexNormals = face.__originalVertexNormals;
627
-
628
- }
629
-
630
- this.morphNormalsReady = true;
631
-
632
- },
633
-
634
- computeBoundingBox: function () {
635
-
636
- if ( this.boundingBox === null ) {
637
-
638
- this.boundingBox = new Box3();
639
-
640
- }
641
-
642
- this.boundingBox.setFromPoints( this.vertices );
643
-
644
- },
645
-
646
- computeBoundingSphere: function () {
647
-
648
- if ( this.boundingSphere === null ) {
649
-
650
- this.boundingSphere = new Sphere();
651
-
652
- }
653
-
654
- this.boundingSphere.setFromPoints( this.vertices );
655
-
656
- },
657
-
658
- mergeMorph: function ( geometry, matrix ) {
659
-
660
- const m = this.morphTargets.length,
661
- morphTargets1 = this.morphTargets,
662
- morphTargets2 = geometry.morphTargets,
663
- n = this.morphColors.length,
664
- morphColors1 = this.morphColors,
665
- morphColors2 = geometry.morphColors;
666
-
667
- if ( m > 0 && m == morphTargets2.length) {
668
-
669
- for ( let i = 0, l = morphTargets1.length; i < l; i ++ ) {
670
-
671
- const morphTarget1 = morphTargets1[ i ];
672
- const morphTarget2 = morphTargets2[ i ];
673
-
674
- for ( let k = 0, kl = morphTarget2.vertices.length; k < kl; k ++ ) {
675
-
676
- const vertex = morphTarget2.vertices[ k ];
677
-
678
- const vertexCopy = vertex.clone();
679
-
680
- if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
681
-
682
- morphTarget1.vertices.push( vertexCopy );
683
-
684
- }
685
-
686
- if ( morphTarget1.normals && morphTarget2.normals ) {
687
-
688
- for ( let k = 0; k < morphTarget2.normals.length; k = k + 3) {
689
-
690
- _temp.set(morphTarget2.normals2[k], morphTarget2.normals2[k + 1], morphTarget2.normals2[k + 2]);
691
-
692
- if ( matrix !== undefined ) _temp.applyMatrix4( matrix );
693
-
694
- morphTarget1.normals.push(_temp.x, _temp.y, _temp.z);
695
-
696
- }
697
-
698
- }
699
-
700
- }
701
-
702
- }
703
-
704
- if ( n > 0 && n == morphColors2.length) {
705
-
706
- for ( let i = 0, l = morphColors1.length; i < l; i ++ ) {
707
-
708
- const morphColor1 = morphColors1[ i ];
709
- const morphColor2 = morphColors2[ i ];
710
-
711
- for ( let k = 0, kl = morphColor2.colors; k < kl; k ++ ) {
712
-
713
- morphColor1.colors.push( morphColor2.colors[ k ].clone() );
714
-
715
- }
716
-
717
- }
718
-
719
- }
720
-
721
- },
722
-
723
- merge: function ( geometry, matrix, materialIndexOffset = 0 ) {
724
-
725
- if ( ! ( geometry && geometry.isGeometry ) ) {
726
-
727
- console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
728
- return;
729
-
730
- }
731
-
732
- let normalMatrix;
733
- const vertexOffset = this.vertices.length,
734
- vertices1 = this.vertices,
735
- vertices2 = geometry.vertices,
736
- normals2 = geometry.normals,
737
- faces1 = this.faces,
738
- faces2 = geometry.faces,
739
- colors1 = this.colors,
740
- colors2 = geometry.colors;
741
-
742
- if ( matrix !== undefined ) {
743
-
744
- normalMatrix = new Matrix3().getNormalMatrix( matrix );
745
-
746
- }
747
-
748
- // vertices
749
-
750
- for ( let i = 0, il = vertices2.length; i < il; i ++ ) {
751
-
752
- const vertex = vertices2[ i ];
753
-
754
- const vertexCopy = vertex.clone();
755
-
756
- if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
757
-
758
- vertices1.push( vertexCopy );
759
-
760
- }
761
-
762
- for ( let i = 0; i < normals2.length; i = i + 3) {
763
-
764
- _temp.set(normals2[i], normals2[i + 1], normals2[i + 2]);
765
-
766
- if ( matrix !== undefined ) _temp.applyMatrix4( matrix );
767
-
768
- this.normals.push(_temp.x, _temp.y, _temp.z);
769
-
770
- }
771
-
772
- // colors
773
-
774
- for ( let i = 0, il = colors2.length; i < il; i ++ ) {
775
- if ((typeof colors2[ i ] === "number")) {
776
- colors1.push( colors2[ i ] );
777
- } else {
778
- colors1.push( colors2[ i ].clone() );
779
- }
780
- }
781
-
782
- // faces
783
-
784
- for ( let i = 0, il = faces2.length; i < il; i ++ ) {
785
-
786
- const face = faces2[ i ];
787
- let normal, color;
788
- const faceVertexNormals = face.vertexNormals,
789
- faceVertexColors = face.vertexColors;
790
-
791
- const faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
792
- faceCopy.normal.copy( face.normal );
793
-
794
- if ( normalMatrix !== undefined ) {
795
-
796
- faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
797
-
798
- }
799
-
800
- for ( let j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
801
-
802
- normal = faceVertexNormals[ j ].clone();
803
-
804
- if ( normalMatrix !== undefined ) {
805
-
806
- normal.applyMatrix3( normalMatrix ).normalize();
807
-
808
- }
809
-
810
- faceCopy.vertexNormals.push( normal );
811
-
812
- }
813
-
814
- faceCopy.color.copy( face.color );
815
-
816
- for ( let j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
817
-
818
- color = faceVertexColors[ j ];
819
- faceCopy.vertexColors.push( color.clone() );
820
-
821
- }
822
-
823
- faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
824
-
825
- faces1.push( faceCopy );
826
-
827
- }
828
-
829
- // uvs
830
-
831
- for ( let i = 0, il = geometry.faceVertexUvs.length; i < il; i ++ ) {
832
-
833
- const faceVertexUvs2 = geometry.faceVertexUvs[ i ];
834
-
835
- if ( this.faceVertexUvs[ i ] === undefined ) this.faceVertexUvs[ i ] = [];
836
-
837
- for ( let j = 0, jl = faceVertexUvs2.length; j < jl; j ++ ) {
838
-
839
- const uvs2 = faceVertexUvs2[ j ], uvsCopy = [];
840
-
841
- for ( let k = 0, kl = uvs2.length; k < kl; k ++ ) {
842
-
843
- uvsCopy.push( uvs2[ k ].clone() );
844
-
845
- }
846
-
847
- this.faceVertexUvs[ i ].push( uvsCopy );
848
-
849
- }
850
-
851
- }
852
-
853
- this.mergeMorph( geometry, matrix );
854
-
855
- },
856
-
857
- mergeMesh: function ( mesh ) {
858
-
859
- if ( ! ( mesh && mesh.isMesh ) ) {
860
-
861
- console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
862
- return;
863
-
864
- }
865
-
866
- if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
867
-
868
- this.merge( mesh.geometry, mesh.matrix );
869
-
870
- },
871
-
872
- /*
873
- * Checks for duplicate vertices with hashmap.
874
- * Duplicated vertices are removed
875
- * and faces' vertices are updated.
876
- */
877
-
878
- mergeVertices: function ( precisionPoints = 4 ) {
879
-
880
- const verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
881
- const unique = [], changes = [];
882
-
883
- const precision = Math.pow( 10, precisionPoints );
884
-
885
- for ( let i = 0, il = this.vertices.length; i < il; i ++ ) {
886
-
887
- const v = this.vertices[ i ];
888
- const key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
889
-
890
- if ( verticesMap[ key ] === undefined ) {
891
-
892
- verticesMap[ key ] = i;
893
- unique.push( this.vertices[ i ] );
894
- changes[ i ] = unique.length - 1;
895
-
896
- } else {
897
-
898
- //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
899
- changes[ i ] = changes[ verticesMap[ key ] ];
900
-
901
- }
902
-
903
- }
904
-
905
-
906
- // if faces are completely degenerate after merging vertices, we
907
- // have to remove them from the geometry.
908
- const faceIndicesToRemove = [];
909
-
910
- for ( let i = 0, il = this.faces.length; i < il; i ++ ) {
911
-
912
- const face = this.faces[ i ];
913
-
914
- face.a = changes[ face.a ];
915
- face.b = changes[ face.b ];
916
- face.c = changes[ face.c ];
917
-
918
- const indices = [ face.a, face.b, face.c ];
919
-
920
- // if any duplicate vertices are found in a Face3
921
- // we have to remove the face as nothing can be saved
922
- for ( let n = 0; n < 3; n ++ ) {
923
-
924
- if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
925
-
926
- faceIndicesToRemove.push( i );
927
- break;
928
-
929
- }
930
-
931
- }
932
-
933
- }
934
-
935
- for ( let i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
936
-
937
- const idx = faceIndicesToRemove[ i ];
938
-
939
- this.faces.splice( idx, 1 );
940
-
941
- for ( let j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
942
-
943
- this.faceVertexUvs[ j ].splice( idx, 1 );
944
-
945
- }
946
-
947
- }
948
-
949
- // Use unique set of vertices
950
-
951
- const diff = this.vertices.length - unique.length;
952
- this.vertices = unique;
953
- return diff;
954
-
955
- },
956
-
957
- setFromPoints: function ( points ) {
958
-
959
- this.vertices = [];
960
-
961
- for ( let i = 0, l = points.length; i < l; i ++ ) {
962
-
963
- const point = points[ i ];
964
- this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
965
-
966
- }
967
-
968
- return this;
969
-
970
- },
971
-
972
- sortFacesByMaterialIndex: function () {
973
-
974
- const faces = this.faces;
975
- const length = faces.length;
976
-
977
- // tag faces
978
-
979
- for ( let i = 0; i < length; i ++ ) {
980
-
981
- faces[ i ]._id = i;
982
-
983
- }
984
-
985
- // sort faces
986
-
987
- function materialIndexSort( a, b ) {
988
-
989
- return a.materialIndex - b.materialIndex;
990
-
991
- }
992
-
993
- faces.sort( materialIndexSort );
994
-
995
- // sort uvs
996
-
997
- const uvs1 = this.faceVertexUvs[ 0 ];
998
- const uvs2 = this.faceVertexUvs[ 1 ];
999
-
1000
- let newUvs1, newUvs2;
1001
-
1002
- if ( uvs1 && uvs1.length === length ) newUvs1 = [];
1003
- if ( uvs2 && uvs2.length === length ) newUvs2 = [];
1004
-
1005
- for ( let i = 0; i < length; i ++ ) {
1006
-
1007
- const id = faces[ i ]._id;
1008
-
1009
- if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
1010
- if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
1011
-
1012
- }
1013
-
1014
- if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
1015
- if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
1016
-
1017
- },
1018
-
1019
- toJSON: function () {
1020
-
1021
- const data = {
1022
- metadata: {
1023
- version: 4.5,
1024
- type: 'Geometry',
1025
- generator: 'Geometry.toJSON'
1026
- }
1027
- };
1028
-
1029
- // standard Geometry serialization
1030
-
1031
- data.uuid = this.uuid;
1032
- data.type = this.type;
1033
- if ( this.name !== '' ) data.name = this.name;
1034
-
1035
- if ( this.parameters !== undefined ) {
1036
-
1037
- const parameters = this.parameters;
1038
-
1039
- for ( const key in parameters ) {
1040
-
1041
- if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
1042
-
1043
- }
1044
-
1045
- return data;
1046
-
1047
- }
1048
-
1049
- const vertices = [];
1050
-
1051
- for ( let i = 0; i < this.vertices.length; i ++ ) {
1052
-
1053
- const vertex = this.vertices[ i ];
1054
- vertices.push( vertex.x, vertex.y, vertex.z );
1055
-
1056
- }
1057
-
1058
- const faces = [];
1059
- const normals = [];
1060
- const normalsHash = {};
1061
- const colors = [];
1062
- const colorsHash = {};
1063
- const uvs = [];
1064
- const uvsHash = {};
1065
-
1066
- for ( let i = 0; i < this.faces.length; i ++ ) {
1067
-
1068
- const face = this.faces[ i ];
1069
-
1070
- const hasMaterial = true;
1071
- const hasFaceUv = false; // deprecated
1072
- const hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
1073
- const hasFaceNormal = face.normal.length() > 0;
1074
- const hasFaceVertexNormal = face.vertexNormals.length > 0;
1075
- const hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
1076
- const hasFaceVertexColor = face.vertexColors.length > 0;
1077
-
1078
- let faceType = 0;
1079
-
1080
- faceType = setBit( faceType, 0, 0 ); // isQuad
1081
- faceType = setBit( faceType, 1, hasMaterial );
1082
- faceType = setBit( faceType, 2, hasFaceUv );
1083
- faceType = setBit( faceType, 3, hasFaceVertexUv );
1084
- faceType = setBit( faceType, 4, hasFaceNormal );
1085
- faceType = setBit( faceType, 5, hasFaceVertexNormal );
1086
- faceType = setBit( faceType, 6, hasFaceColor );
1087
- faceType = setBit( faceType, 7, hasFaceVertexColor );
1088
-
1089
- faces.push( faceType );
1090
- faces.push( face.a, face.b, face.c );
1091
- faces.push( face.materialIndex );
1092
-
1093
- if ( hasFaceVertexUv ) {
1094
-
1095
- const faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
1096
-
1097
- faces.push(
1098
- getUvIndex( faceVertexUvs[ 0 ] ),
1099
- getUvIndex( faceVertexUvs[ 1 ] ),
1100
- getUvIndex( faceVertexUvs[ 2 ] )
1101
- );
1102
-
1103
- }
1104
-
1105
- if ( hasFaceNormal ) {
1106
-
1107
- faces.push( getNormalIndex( face.normal ) );
1108
-
1109
- }
1110
-
1111
- if ( hasFaceVertexNormal ) {
1112
-
1113
- const vertexNormals = face.vertexNormals;
1114
-
1115
- faces.push(
1116
- getNormalIndex( vertexNormals[ 0 ] ),
1117
- getNormalIndex( vertexNormals[ 1 ] ),
1118
- getNormalIndex( vertexNormals[ 2 ] )
1119
- );
1120
-
1121
- }
1122
-
1123
- if ( hasFaceColor ) {
1124
-
1125
- faces.push( getColorIndex( face.color ) );
1126
-
1127
- }
1128
-
1129
- if ( hasFaceVertexColor ) {
1130
-
1131
- const vertexColors = face.vertexColors;
1132
-
1133
- faces.push(
1134
- getColorIndex( vertexColors[ 0 ] ),
1135
- getColorIndex( vertexColors[ 1 ] ),
1136
- getColorIndex( vertexColors[ 2 ] )
1137
- );
1138
-
1139
- }
1140
-
1141
- }
1142
-
1143
- function setBit( value, position, enabled ) {
1144
-
1145
- return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
1146
-
1147
- }
1148
-
1149
- function getNormalIndex( normal ) {
1150
-
1151
- const hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
1152
-
1153
- if ( normalsHash[ hash ] !== undefined ) {
1154
-
1155
- return normalsHash[ hash ];
1156
-
1157
- }
1158
-
1159
- normalsHash[ hash ] = normals.length / 3;
1160
- normals.push( normal.x, normal.y, normal.z );
1161
-
1162
- return normalsHash[ hash ];
1163
-
1164
- }
1165
-
1166
- function getColorIndex( color ) {
1167
-
1168
- const hash = color.r.toString() + color.g.toString() + color.b.toString();
1169
-
1170
- if ( colorsHash[ hash ] !== undefined ) {
1171
-
1172
- return colorsHash[ hash ];
1173
-
1174
- }
1175
-
1176
- colorsHash[ hash ] = colors.length;
1177
- colors.push( color.getHex() );
1178
-
1179
- return colorsHash[ hash ];
1180
-
1181
- }
1182
-
1183
- function getUvIndex( uv ) {
1184
-
1185
- const hash = uv.x.toString() + uv.y.toString();
1186
-
1187
- if ( uvsHash[ hash ] !== undefined ) {
1188
-
1189
- return uvsHash[ hash ];
1190
-
1191
- }
1192
-
1193
- uvsHash[ hash ] = uvs.length / 2;
1194
- uvs.push( uv.x, uv.y );
1195
-
1196
- return uvsHash[ hash ];
1197
-
1198
- }
1199
-
1200
- data.data = {};
1201
-
1202
- data.data.vertices = vertices;
1203
- data.data.normals = normals;
1204
- if ( colors.length > 0 ) data.data.colors = colors;
1205
- if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
1206
- data.data.faces = faces;
1207
-
1208
- return data;
1209
-
1210
- },
1211
-
1212
- clone: function () {
1213
-
1214
- /*
1215
- // Handle primitives
1216
-
1217
- const parameters = this.parameters;
1218
-
1219
- if ( parameters !== undefined ) {
1220
-
1221
- const values = [];
1222
-
1223
- for ( const key in parameters ) {
1224
-
1225
- values.push( parameters[ key ] );
1226
-
1227
- }
1228
-
1229
- const geometry = Object.create( this.constructor.prototype );
1230
- this.constructor.apply( geometry, values );
1231
- return geometry;
1232
-
1233
- }
1234
-
1235
- return new this.constructor().copy( this );
1236
- */
1237
-
1238
- return new Geometry().copy( this );
1239
-
1240
- },
1241
-
1242
- copy: function ( source ) {
1243
-
1244
- // reset
1245
-
1246
- this.vertices = [];
1247
- this.colors = [];
1248
- this.faces = [];
1249
- this.faceVertexUvs = [[]];
1250
- this.morphTargets = [];
1251
- this.morphNormals = [];
1252
- this.skinWeights = [];
1253
- this.skinIndices = [];
1254
- this.lineDistances = [];
1255
- this.boundingBox = null;
1256
- this.boundingSphere = null;
1257
-
1258
- // name
1259
-
1260
- this.name = source.name;
1261
-
1262
- // vertices
1263
-
1264
- const vertices = source.vertices;
1265
-
1266
- for ( let i = 0, il = vertices.length; i < il; i ++ ) {
1267
-
1268
- this.vertices.push( vertices[ i ].clone() );
1269
-
1270
- }
1271
-
1272
- // colors
1273
-
1274
- const colors = source.colors;
1275
-
1276
- for ( let i = 0, il = colors.length; i < il; i ++ ) {
1277
-
1278
- this.colors.push( colors[ i ].clone() );
1279
-
1280
- }
1281
-
1282
- // faces
1283
-
1284
- const faces = source.faces;
1285
-
1286
- for ( let i = 0, il = faces.length; i < il; i ++ ) {
1287
-
1288
- this.faces.push( faces[ i ].clone() );
1289
-
1290
- }
1291
-
1292
- // face vertex uvs
1293
-
1294
- for ( let i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
1295
-
1296
- const faceVertexUvs = source.faceVertexUvs[ i ];
1297
-
1298
- if ( this.faceVertexUvs[ i ] === undefined ) {
1299
-
1300
- this.faceVertexUvs[ i ] = [];
1301
-
1302
- }
1303
-
1304
- for ( let j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
1305
-
1306
- const uvs = faceVertexUvs[ j ], uvsCopy = [];
1307
-
1308
- for ( let k = 0, kl = uvs.length; k < kl; k ++ ) {
1309
-
1310
- const uv = uvs[ k ];
1311
-
1312
- uvsCopy.push( uv.clone() );
1313
-
1314
- }
1315
-
1316
- this.faceVertexUvs[ i ].push( uvsCopy );
1317
-
1318
- }
1319
-
1320
- }
1321
-
1322
- // morph targets
1323
-
1324
- const morphTargets = source.morphTargets;
1325
-
1326
- for ( let i = 0, il = morphTargets.length; i < il; i ++ ) {
1327
-
1328
- const morphTarget = {};
1329
- morphTarget.name = morphTargets[ i ].name;
1330
-
1331
- // vertices
1332
-
1333
- if ( morphTargets[ i ].vertices !== undefined ) {
1334
-
1335
- morphTarget.vertices = [];
1336
-
1337
- for ( let j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
1338
-
1339
- morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
1340
-
1341
- }
1342
-
1343
- }
1344
-
1345
- // normals
1346
-
1347
- if ( morphTargets[ i ].normals !== undefined ) {
1348
-
1349
- morphTarget.normals = [];
1350
-
1351
- for ( let j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
1352
-
1353
- morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
1354
-
1355
- }
1356
-
1357
- }
1358
-
1359
- this.morphTargets.push( morphTarget );
1360
-
1361
- }
1362
-
1363
- // morph normals
1364
-
1365
- const morphNormals = source.morphNormals;
1366
-
1367
- for ( let i = 0, il = morphNormals.length; i < il; i ++ ) {
1368
-
1369
- const morphNormal = {};
1370
-
1371
- // vertex normals
1372
-
1373
- if ( morphNormals[ i ].vertexNormals !== undefined ) {
1374
-
1375
- morphNormal.vertexNormals = [];
1376
-
1377
- for ( let j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
1378
-
1379
- const srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
1380
- const destVertexNormal = {};
1381
-
1382
- destVertexNormal.a = srcVertexNormal.a.clone();
1383
- destVertexNormal.b = srcVertexNormal.b.clone();
1384
- destVertexNormal.c = srcVertexNormal.c.clone();
1385
-
1386
- morphNormal.vertexNormals.push( destVertexNormal );
1387
-
1388
- }
1389
-
1390
- }
1391
-
1392
- // face normals
1393
-
1394
- if ( morphNormals[ i ].faceNormals !== undefined ) {
1395
-
1396
- morphNormal.faceNormals = [];
1397
-
1398
- for ( let j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
1399
-
1400
- morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
1401
-
1402
- }
1403
-
1404
- }
1405
-
1406
- this.morphNormals.push( morphNormal );
1407
-
1408
- }
1409
-
1410
- // skin weights
1411
-
1412
- const skinWeights = source.skinWeights;
1413
-
1414
- for ( let i = 0, il = skinWeights.length; i < il; i ++ ) {
1415
-
1416
- this.skinWeights.push( skinWeights[ i ].clone() );
1417
-
1418
- }
1419
-
1420
- // skin indices
1421
-
1422
- const skinIndices = source.skinIndices;
1423
-
1424
- for ( let i = 0, il = skinIndices.length; i < il; i ++ ) {
1425
-
1426
- this.skinIndices.push( skinIndices[ i ].clone() );
1427
-
1428
- }
1429
-
1430
- // line distances
1431
-
1432
- const lineDistances = source.lineDistances;
1433
-
1434
- for ( let i = 0, il = lineDistances.length; i < il; i ++ ) {
1435
-
1436
- this.lineDistances.push( lineDistances[ i ] );
1437
-
1438
- }
1439
-
1440
- // bounding box
1441
-
1442
- const boundingBox = source.boundingBox;
1443
-
1444
- if ( boundingBox !== null ) {
1445
-
1446
- this.boundingBox = boundingBox.clone();
1447
-
1448
- }
1449
-
1450
- // bounding sphere
1451
-
1452
- const boundingSphere = source.boundingSphere;
1453
-
1454
- if ( boundingSphere !== null ) {
1455
-
1456
- this.boundingSphere = boundingSphere.clone();
1457
-
1458
- }
1459
-
1460
- // update flags
1461
-
1462
- this.elementsNeedUpdate = source.elementsNeedUpdate;
1463
- this.verticesNeedUpdate = source.verticesNeedUpdate;
1464
- this.uvsNeedUpdate = source.uvsNeedUpdate;
1465
- this.normalsNeedUpdate = source.normalsNeedUpdate;
1466
- this.colorsNeedUpdate = source.colorsNeedUpdate;
1467
- this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
1468
- this.groupsNeedUpdate = source.groupsNeedUpdate;
1469
-
1470
- return this;
1471
-
1472
- },
1473
-
1474
-
1475
- computeGroups( ) {
1476
-
1477
- const groups = [];
1478
-
1479
- let group, i;
1480
- let materialIndex = undefined;
1481
-
1482
- const faces = this.faces;
1483
-
1484
- for ( i = 0; i < faces.length; i ++ ) {
1485
-
1486
- const face = faces[ i ];
1487
-
1488
- // materials
1489
-
1490
- if ( face.materialIndex !== materialIndex ) {
1491
-
1492
- materialIndex = face.materialIndex;
1493
-
1494
- if ( group !== undefined ) {
1495
-
1496
- group.count = ( i * 3 ) - group.start;
1497
- groups.push( group );
1498
-
1499
- }
1500
-
1501
- group = {
1502
- start: i * 3,
1503
- materialIndex: materialIndex
1504
- };
1505
-
1506
- }
1507
-
1508
- }
1509
-
1510
- if ( group !== undefined ) {
1511
-
1512
- group.count = ( i * 3 ) - group.start;
1513
- groups.push( group );
1514
-
1515
- }
1516
-
1517
- return groups;
1518
-
1519
- },
1520
-
1521
- toBufferGeometry: function () {
1522
-
1523
- const geometry = new DirectGeometry().fromGeometry( this );
1524
-
1525
- const buffergeometry = new BufferGeometry();
1526
-
1527
- const positions = new Float32Array( geometry.vertices.length * 3 );
1528
- buffergeometry.setAttribute( 'position', copyVector3sArray(new BufferAttribute( positions, 3 ), geometry.vertices ) );
1529
-
1530
- if ( geometry.normals.length > 0 ) {
1531
-
1532
- const normals = new Float32Array( geometry.normals.length * 3 );
1533
- buffergeometry.setAttribute( 'normal', copyVector3sArray(new BufferAttribute( normals, 3 ), geometry.normals ) );
1534
-
1535
- }
1536
-
1537
- if ( geometry.colors.length > 0 ) {
1538
-
1539
- const colors = new Float32Array( geometry.colors.length * 3 );
1540
- buffergeometry.setAttribute( 'color', copyVector3sArray(new BufferAttribute( colors, 3 ), geometry.colors ) );
1541
-
1542
- }
1543
-
1544
- if ( geometry.uvs.length > 0 ) {
1545
-
1546
- const uvs = new Float32Array( geometry.uvs.length * 2 );
1547
- buffergeometry.setAttribute( 'uv', copyVector2sArray(new BufferAttribute( uvs, 2 ), geometry.uvs ) );
1548
-
1549
- }
1550
-
1551
- if ( geometry.uvs2.length > 0 ) {
1552
-
1553
- const uvs2 = new Float32Array( geometry.uvs2.length * 2 );
1554
- buffergeometry.setAttribute( 'uv2', copyVector2sArray(new BufferAttribute( uvs2, 2 ), geometry.uvs2 ) );
1555
-
1556
- }
1557
-
1558
- // groups
1559
-
1560
- buffergeometry.groups = geometry.groups;
1561
-
1562
- // morphs
1563
-
1564
- for ( const name in geometry.morphTargets ) {
1565
-
1566
- const array = [];
1567
- const morphTargets = geometry.morphTargets[ name ];
1568
-
1569
- for ( let i = 0, l = morphTargets.length; i < l; i ++ ) {
1570
-
1571
- const morphTarget = morphTargets[ i ];
1572
-
1573
- const attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 );
1574
- attribute.name = morphTarget.name;
1575
-
1576
- array.push( copyVector3sArray(attribute, morphTarget.data ) );
1577
-
1578
- }
1579
-
1580
- buffergeometry.morphAttributes[ name ] = array;
1581
-
1582
- }
1583
-
1584
- // skinning
1585
-
1586
- if ( geometry.skinIndices.length > 0 ) {
1587
-
1588
- const skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
1589
- copyVector4sArray(skinIndices, geometry.skinIndices);
1590
- buffergeometry.setAttribute( 'skinIndex', skinIndices);
1591
-
1592
- }
1593
-
1594
- if ( geometry.skinWeights.length > 0 ) {
1595
-
1596
- const skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
1597
- copyVector4sArray(skinWeights, geometry.skinWeights);
1598
- buffergeometry.setAttribute( 'skinWeight', skinWeights );
1599
-
1600
- }
1601
-
1602
- //
1603
-
1604
- if ( geometry.boundingSphere !== null ) {
1605
-
1606
- buffergeometry.boundingSphere = geometry.boundingSphere.clone();
1607
-
1608
- }
1609
-
1610
- if ( geometry.boundingBox !== null ) {
1611
-
1612
- buffergeometry.boundingBox = geometry.boundingBox.clone();
1613
-
1614
- }
1615
-
1616
- return buffergeometry;
1617
-
1618
- },
1619
-
1620
- toIndexedBufferGeometry: function () {
1621
-
1622
- //const geometry = new DirectGeometry().fromGeometry( this );
1623
-
1624
- const buffergeometry = new BufferGeometry();
1625
-
1626
- const positions = new Float32Array( this.vertices.length * 3 );
1627
- buffergeometry.setAttribute( 'position', copyVector3sArray(new BufferAttribute( positions, 3 ), this.vertices ) );
1628
-
1629
- if ( this.normals.length > 0 ) {
1630
- const normals = new Float32Array( this.normals.length );
1631
- let buffer = new BufferAttribute( normals, 3 ).copyArray( this.normals );
1632
- buffergeometry.setAttribute( 'normal', buffer);
1633
- }
1634
- if ( this.uvs.length > 0 && this.uvs[0].length > 0 ) {
1635
-
1636
- const uvs = new Float32Array( this.uvs[0].length * 2 );
1637
- buffergeometry.setAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyArray( this.uvs[0] ) );
1638
- }
1639
-
1640
- if ( this.uvs.length > 1 && this.uvs[1].length > 0 ) {
1641
- const uvs2 = new Float32Array( this.uvs[1].length * 2 );
1642
- buffergeometry.setAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyArray( this.uvs[1] ) );
1643
- }
1644
-
1645
- if ( this.colors.length > 0) {
1646
-
1647
- const colorArray = [];
1648
- for (let i = 0 ; i < this.colors.length; i++) {
1649
- colorArray.push(new Color( this.colors[ i ] ));
1650
- }
1651
- const colors = new Float32Array( colorArray.length * 3 );
1652
- buffergeometry.setAttribute( 'color', copyColorsArray(new BufferAttribute( colors, 3 ), colorArray ) );
1653
-
1654
- } else {
1655
-
1656
- const colorsArray = new Float32Array( this.vertices.length * 3 );
1657
- for (let i = 0; i < this.vertices.length * 3; i++) {
1658
- colorsArray[i] = 1.0;
1659
- }
1660
- buffergeometry.setAttribute( 'color', new BufferAttribute( colorsArray, 3 ) );
1661
-
1662
- }
1663
-
1664
- if (this.faces.length > 0) {
1665
-
1666
- let colors = [];
1667
-
1668
- let indices = [];
1669
-
1670
- for (let i = 0 ; i < this.faces.length; i++) {
1671
-
1672
- indices.push(this.faces[i].a, this.faces[i].b, this.faces[i].c);
1673
-
1674
- const vertexColors = this.faces[i].vertexColors;
1675
-
1676
- if ( vertexColors.length === 3 ) {
1677
-
1678
- colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
1679
-
1680
- } else {
1681
-
1682
- const color = this.faces[i].color;
1683
-
1684
- colors.push( color, color, color );
1685
-
1686
- }
1687
-
1688
- }
1689
-
1690
- // if ( colors.length > 0 ) {
1691
-
1692
- // const colorsArray = new Float32Array( colors.length * 3 );
1693
- // buffergeometry.setAttribute( 'color', new BufferAttribute( colorsArray, 3 ).copyColorsArray( colors ) );
1694
-
1695
- // }
1696
-
1697
- buffergeometry.setIndex( indices );
1698
-
1699
- buffergeometry.groups = this.computeGroups();
1700
-
1701
- }
1702
-
1703
- // morphs
1704
-
1705
- if (this.morphTargets.length > 0) {
1706
-
1707
- const array = [];
1708
- const normalsArray = [];
1709
-
1710
- for ( let i = 0, l = this.morphTargets.length; i < l; i ++ ) {
1711
-
1712
- const morphTarget = this.morphTargets[ i ];
1713
-
1714
- const attribute = new Float32BufferAttribute( morphTarget.vertices.length * 3, 3 );
1715
- attribute.name = morphTarget.name;
1716
-
1717
- array.push( copyVector3sArray(attribute, morphTarget.vertices ) );
1718
-
1719
- if (morphTarget.normals) {
1720
-
1721
-
1722
- const attribute = new Float32BufferAttribute( morphTarget.normals.length * 3, 3 );
1723
- attribute.name = morphTarget.name;
1724
-
1725
- normalsArray.push( copyVector3sArray(attribute, morphTarget.normals ) );
1726
-
1727
- }
1728
-
1729
- }
1730
-
1731
- buffergeometry.morphAttributes.position = array;
1732
- buffergeometry.morphAttributes.normal = normalsArray;
1733
-
1734
- }
1735
-
1736
- // skinning
1737
-
1738
- if ( this.skinIndices.length > 0 ) {
1739
-
1740
- const skinIndices = new Float32BufferAttribute( this.skinIndices.length * 4, 4 );
1741
- buffergeometry.setAttribute( 'skinIndex', skinIndices.copyVector4sArray( this.skinIndices ) );
1742
-
1743
- }
1744
-
1745
- if ( this.skinWeights.length > 0 ) {
1746
-
1747
- const skinWeights = new Float32BufferAttribute( this.skinWeights.length * 4, 4 );
1748
- buffergeometry.setAttribute( 'skinWeight', skinWeights.copyVector4sArray( this.skinWeights ) );
1749
-
1750
- }
1751
-
1752
- //
1753
-
1754
- if ( this.boundingSphere !== null ) {
1755
-
1756
- buffergeometry.boundingSphere = this.boundingSphere.clone();
1757
-
1758
- }
1759
-
1760
- if ( this.boundingBox !== null ) {
1761
-
1762
- buffergeometry.boundingBox = this.boundingBox.clone();
1763
-
1764
- }
1765
-
1766
- return buffergeometry;
1767
-
1768
- },
1769
-
1770
- computeTangents: function () {
1771
-
1772
- console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
1773
-
1774
- },
1775
-
1776
- computeLineDistances: function () {
1777
-
1778
- console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
1779
-
1780
- },
1781
-
1782
- applyMatrix: function ( matrix ) {
1783
-
1784
- console.warn( 'THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().' );
1785
- return this.applyMatrix4( matrix );
1786
-
1787
- },
1788
-
1789
- dispose: function () {
1790
-
1791
- this.dispatchEvent( { type: 'dispose' } );
1792
-
1793
- }
1794
-
1795
- } );
1796
-
1797
- Geometry.createBufferGeometryFromObject = function ( object ) {
1798
-
1799
- let buffergeometry = new BufferGeometry();
1800
-
1801
- const geometry = object.geometry;
1802
-
1803
- if ( object.isPoints || object.isLine ) {
1804
-
1805
- const positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
1806
- copyVector3sArray(positions, geometry.vertices );
1807
-
1808
- const colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
1809
- copyColorsArray(colors, geometry.colors);
1810
-
1811
- buffergeometry.setAttribute( 'position', positions );
1812
- buffergeometry.setAttribute( 'color', colors );
1813
-
1814
- if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
1815
-
1816
- const lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
1817
-
1818
- buffergeometry.setAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
1819
-
1820
- }
1821
-
1822
- if ( geometry.boundingSphere !== null ) {
1823
-
1824
- buffergeometry.boundingSphere = geometry.boundingSphere.clone();
1825
-
1826
- }
1827
-
1828
- if ( geometry.boundingBox !== null ) {
1829
-
1830
- buffergeometry.boundingBox = geometry.boundingBox.clone();
1831
-
1832
- }
1833
-
1834
- } else if ( object.isMesh ) {
1835
-
1836
- buffergeometry = geometry.toBufferGeometry();
1837
-
1838
- }
1839
-
1840
- return buffergeometry;
1841
-
1842
- };
1843
-
1844
- class DirectGeometry {
1845
-
1846
- constructor() {
1847
-
1848
- this.vertices = [];
1849
- this.normals = [];
1850
- this.colors = [];
1851
- this.uvs = [];
1852
- this.uvs2 = [];
1853
-
1854
- this.groups = [];
1855
-
1856
- this.morphTargets = {};
1857
-
1858
- this.skinWeights = [];
1859
- this.skinIndices = [];
1860
-
1861
- // this.lineDistances = [];
1862
-
1863
- this.boundingBox = null;
1864
- this.boundingSphere = null;
1865
-
1866
- // update flags
1867
-
1868
- this.verticesNeedUpdate = false;
1869
- this.normalsNeedUpdate = false;
1870
- this.colorsNeedUpdate = false;
1871
- this.uvsNeedUpdate = false;
1872
- this.groupsNeedUpdate = false;
1873
-
1874
- }
1875
-
1876
- computeGroups( geometry ) {
1877
-
1878
- const groups = [];
1879
-
1880
- let group, i;
1881
- let materialIndex = undefined;
1882
-
1883
- const faces = geometry.faces;
1884
-
1885
- for ( i = 0; i < faces.length; i ++ ) {
1886
-
1887
- const face = faces[ i ];
1888
-
1889
- // materials
1890
-
1891
- if ( face.materialIndex !== materialIndex ) {
1892
-
1893
- materialIndex = face.materialIndex;
1894
-
1895
- if ( group !== undefined ) {
1896
-
1897
- group.count = ( i * 3 ) - group.start;
1898
- groups.push( group );
1899
-
1900
- }
1901
-
1902
- group = {
1903
- start: i * 3,
1904
- materialIndex: materialIndex
1905
- };
1906
-
1907
- }
1908
-
1909
- }
1910
-
1911
- if ( group !== undefined ) {
1912
-
1913
- group.count = ( i * 3 ) - group.start;
1914
- groups.push( group );
1915
-
1916
- }
1917
-
1918
- this.groups = groups;
1919
-
1920
- }
1921
-
1922
- fromGeometry( geometry ) {
1923
-
1924
- const faces = geometry.faces;
1925
- const vertices = geometry.vertices;
1926
- const faceVertexUvs = geometry.faceVertexUvs;
1927
-
1928
- const hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
1929
- const hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
1930
-
1931
- // morphs
1932
-
1933
- const morphTargets = geometry.morphTargets;
1934
- const morphTargetsLength = morphTargets.length;
1935
-
1936
- let morphTargetsPosition;
1937
-
1938
- if ( morphTargetsLength > 0 ) {
1939
-
1940
- morphTargetsPosition = [];
1941
-
1942
- for ( let i = 0; i < morphTargetsLength; i ++ ) {
1943
-
1944
- morphTargetsPosition[ i ] = {
1945
- name: morphTargets[ i ].name,
1946
- data: []
1947
- };
1948
-
1949
- }
1950
-
1951
- this.morphTargets.position = morphTargetsPosition;
1952
-
1953
- }
1954
-
1955
- const morphNormals = geometry.morphNormals;
1956
- const morphNormalsLength = morphNormals.length;
1957
-
1958
- let morphTargetsNormal;
1959
-
1960
- if ( morphNormalsLength > 0 ) {
1961
-
1962
- morphTargetsNormal = [];
1963
-
1964
- for ( let i = 0; i < morphNormalsLength; i ++ ) {
1965
-
1966
- morphTargetsNormal[ i ] = {
1967
- name: morphNormals[ i ].name,
1968
- data: []
1969
- };
1970
-
1971
- }
1972
-
1973
- this.morphTargets.normal = morphTargetsNormal;
1974
-
1975
- }
1976
-
1977
- // skins
1978
-
1979
- const skinIndices = geometry.skinIndices;
1980
- const skinWeights = geometry.skinWeights;
1981
-
1982
- const hasSkinIndices = skinIndices.length === vertices.length;
1983
- const hasSkinWeights = skinWeights.length === vertices.length;
1984
-
1985
- //
1986
-
1987
- if ( vertices.length > 0 && faces.length === 0 ) {
1988
-
1989
- console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
1990
-
1991
- }
1992
-
1993
- for ( let i = 0; i < faces.length; i ++ ) {
1994
-
1995
- const face = faces[ i ];
1996
-
1997
- this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
1998
-
1999
- const vertexNormals = face.vertexNormals;
2000
-
2001
- if ( vertexNormals.length === 3 ) {
2002
-
2003
- this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
2004
-
2005
- } else {
2006
-
2007
- const normal = face.normal;
2008
-
2009
- this.normals.push( normal, normal, normal );
2010
-
2011
- }
2012
-
2013
- const vertexColors = face.vertexColors;
2014
-
2015
- if ( vertexColors.length === 3 ) {
2016
-
2017
- this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
2018
-
2019
- } else {
2020
-
2021
- const color = face.color;
2022
-
2023
- this.colors.push( color, color, color );
2024
-
2025
- }
2026
-
2027
- if ( hasFaceVertexUv === true ) {
2028
-
2029
- const vertexUvs = faceVertexUvs[ 0 ][ i ];
2030
-
2031
- if ( vertexUvs !== undefined ) {
2032
-
2033
- this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
2034
-
2035
- } else {
2036
-
2037
- console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
2038
-
2039
- this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
2040
-
2041
- }
2042
-
2043
- }
2044
-
2045
- if ( hasFaceVertexUv2 === true ) {
2046
-
2047
- const vertexUvs = faceVertexUvs[ 1 ][ i ];
2048
-
2049
- if ( vertexUvs !== undefined ) {
2050
-
2051
- this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
2052
-
2053
- } else {
2054
-
2055
- console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
2056
-
2057
- this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
2058
-
2059
- }
2060
-
2061
- }
2062
-
2063
- // morphs
2064
-
2065
- for ( let j = 0; j < morphTargetsLength; j ++ ) {
2066
-
2067
- const morphTarget = morphTargets[ j ].vertices;
2068
-
2069
- morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
2070
-
2071
- }
2072
-
2073
- for ( let j = 0; j < morphNormalsLength; j ++ ) {
2074
-
2075
- const morphNormal = morphNormals[ j ].vertexNormals[ i ];
2076
-
2077
- morphTargetsNormal[ j ].data.push( morphNormal.a, morphNormal.b, morphNormal.c );
2078
-
2079
- }
2080
-
2081
- // skins
2082
-
2083
- if ( hasSkinIndices ) {
2084
-
2085
- this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
2086
-
2087
- }
2088
-
2089
- if ( hasSkinWeights ) {
2090
-
2091
- this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
2092
-
2093
- }
2094
-
2095
- }
2096
-
2097
- this.computeGroups( geometry );
2098
-
2099
- this.verticesNeedUpdate = geometry.verticesNeedUpdate;
2100
- this.normalsNeedUpdate = geometry.normalsNeedUpdate;
2101
- this.colorsNeedUpdate = geometry.colorsNeedUpdate;
2102
- this.uvsNeedUpdate = geometry.uvsNeedUpdate;
2103
- this.groupsNeedUpdate = geometry.groupsNeedUpdate;
2104
-
2105
- if ( geometry.boundingSphere !== null ) {
2106
-
2107
- this.boundingSphere = geometry.boundingSphere.clone();
2108
-
2109
- }
2110
-
2111
- if ( geometry.boundingBox !== null ) {
2112
-
2113
- this.boundingBox = geometry.boundingBox.clone();
2114
-
2115
- }
2116
-
2117
- return this;
2118
-
2119
- }
2120
-
2121
- }
2122
-
2123
- class Face3 {
2124
-
2125
- constructor( a, b, c, normal, color, materialIndex = 0 ) {
2126
-
2127
- this.a = a;
2128
- this.b = b;
2129
- this.c = c;
2130
-
2131
- this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
2132
- this.vertexNormals = Array.isArray( normal ) ? normal : [];
2133
-
2134
- this.color = ( color && color.isColor ) ? color : new Color();
2135
- this.vertexColors = Array.isArray( color ) ? color : [];
2136
-
2137
- this.materialIndex = materialIndex;
2138
-
2139
- }
2140
-
2141
- clone() {
2142
-
2143
- return new this.constructor().copy( this );
2144
-
2145
- }
2146
-
2147
- copy( source ) {
2148
-
2149
- this.a = source.a;
2150
- this.b = source.b;
2151
- this.c = source.c;
2152
-
2153
- this.normal.copy( source.normal );
2154
- this.color.copy( source.color );
2155
-
2156
- this.materialIndex = source.materialIndex;
2157
-
2158
- for ( let i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
2159
-
2160
- this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
2161
-
2162
- }
2163
-
2164
- for ( let i = 0, il = source.vertexColors.length; i < il; i ++ ) {
2165
-
2166
- this.vertexColors[ i ] = source.vertexColors[ i ].clone();
2167
-
2168
- }
2169
-
2170
- return this;
2171
-
2172
- }
2173
-
2174
- }
2175
-
2176
- export { Face3, Geometry };