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