@damienmortini/three 0.1.131

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.
@@ -0,0 +1,943 @@
1
+ import {
2
+ BufferAttribute,
3
+ BufferGeometry,
4
+ Float32BufferAttribute,
5
+ InterleavedBuffer,
6
+ InterleavedBufferAttribute,
7
+ TriangleFanDrawMode,
8
+ TriangleStripDrawMode,
9
+ TrianglesDrawMode,
10
+ Vector3
11
+ } from 'three';
12
+
13
+
14
+ function computeTangents( geometry ) {
15
+
16
+ geometry.computeTangents();
17
+ console.warn( 'THREE.BufferGeometryUtils: .computeTangents() has been removed. Use BufferGeometry.computeTangents() instead.' );
18
+
19
+ }
20
+
21
+ /**
22
+ * @param {Array<BufferGeometry>} geometries
23
+ * @param {Boolean} useGroups
24
+ * @return {BufferGeometry}
25
+ */
26
+ function mergeBufferGeometries( geometries, useGroups = false ) {
27
+
28
+ const isIndexed = geometries[ 0 ].index !== null;
29
+
30
+ const attributesUsed = new Set( Object.keys( geometries[ 0 ].attributes ) );
31
+ const morphAttributesUsed = new Set( Object.keys( geometries[ 0 ].morphAttributes ) );
32
+
33
+ const attributes = {};
34
+ const morphAttributes = {};
35
+
36
+ const morphTargetsRelative = geometries[ 0 ].morphTargetsRelative;
37
+
38
+ const mergedGeometry = new BufferGeometry();
39
+
40
+ let offset = 0;
41
+
42
+ for ( let i = 0; i < geometries.length; ++ i ) {
43
+
44
+ const geometry = geometries[ i ];
45
+ let attributesCount = 0;
46
+
47
+ // ensure that all geometries are indexed, or none
48
+
49
+ if ( isIndexed !== ( geometry.index !== null ) ) {
50
+
51
+ console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.' );
52
+ return null;
53
+
54
+ }
55
+
56
+ // gather attributes, exit early if they're different
57
+
58
+ for ( const name in geometry.attributes ) {
59
+
60
+ if ( ! attributesUsed.has( name ) ) {
61
+
62
+ console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. All geometries must have compatible attributes; make sure "' + name + '" attribute exists among all geometries, or in none of them.' );
63
+ return null;
64
+
65
+ }
66
+
67
+ if ( attributes[ name ] === undefined ) attributes[ name ] = [];
68
+
69
+ attributes[ name ].push( geometry.attributes[ name ] );
70
+
71
+ attributesCount ++;
72
+
73
+ }
74
+
75
+ // ensure geometries have the same number of attributes
76
+
77
+ if ( attributesCount !== attributesUsed.size ) {
78
+
79
+ console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. Make sure all geometries have the same number of attributes.' );
80
+ return null;
81
+
82
+ }
83
+
84
+ // gather morph attributes, exit early if they're different
85
+
86
+ if ( morphTargetsRelative !== geometry.morphTargetsRelative ) {
87
+
88
+ console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. .morphTargetsRelative must be consistent throughout all geometries.' );
89
+ return null;
90
+
91
+ }
92
+
93
+ for ( const name in geometry.morphAttributes ) {
94
+
95
+ if ( ! morphAttributesUsed.has( name ) ) {
96
+
97
+ console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. .morphAttributes must be consistent throughout all geometries.' );
98
+ return null;
99
+
100
+ }
101
+
102
+ if ( morphAttributes[ name ] === undefined ) morphAttributes[ name ] = [];
103
+
104
+ morphAttributes[ name ].push( geometry.morphAttributes[ name ] );
105
+
106
+ }
107
+
108
+ // gather .userData
109
+
110
+ mergedGeometry.userData.mergedUserData = mergedGeometry.userData.mergedUserData || [];
111
+ mergedGeometry.userData.mergedUserData.push( geometry.userData );
112
+
113
+ if ( useGroups ) {
114
+
115
+ let count;
116
+
117
+ if ( isIndexed ) {
118
+
119
+ count = geometry.index.count;
120
+
121
+ } else if ( geometry.attributes.position !== undefined ) {
122
+
123
+ count = geometry.attributes.position.count;
124
+
125
+ } else {
126
+
127
+ console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. The geometry must have either an index or a position attribute' );
128
+ return null;
129
+
130
+ }
131
+
132
+ mergedGeometry.addGroup( offset, count, i );
133
+
134
+ offset += count;
135
+
136
+ }
137
+
138
+ }
139
+
140
+ // merge indices
141
+
142
+ if ( isIndexed ) {
143
+
144
+ let indexOffset = 0;
145
+ const mergedIndex = [];
146
+
147
+ for ( let i = 0; i < geometries.length; ++ i ) {
148
+
149
+ const index = geometries[ i ].index;
150
+
151
+ for ( let j = 0; j < index.count; ++ j ) {
152
+
153
+ mergedIndex.push( index.getX( j ) + indexOffset );
154
+
155
+ }
156
+
157
+ indexOffset += geometries[ i ].attributes.position.count;
158
+
159
+ }
160
+
161
+ mergedGeometry.setIndex( mergedIndex );
162
+
163
+ }
164
+
165
+ // merge attributes
166
+
167
+ for ( const name in attributes ) {
168
+
169
+ const mergedAttribute = mergeBufferAttributes( attributes[ name ] );
170
+
171
+ if ( ! mergedAttribute ) {
172
+
173
+ console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the ' + name + ' attribute.' );
174
+ return null;
175
+
176
+ }
177
+
178
+ mergedGeometry.setAttribute( name, mergedAttribute );
179
+
180
+ }
181
+
182
+ // merge morph attributes
183
+
184
+ for ( const name in morphAttributes ) {
185
+
186
+ const numMorphTargets = morphAttributes[ name ][ 0 ].length;
187
+
188
+ if ( numMorphTargets === 0 ) break;
189
+
190
+ mergedGeometry.morphAttributes = mergedGeometry.morphAttributes || {};
191
+ mergedGeometry.morphAttributes[ name ] = [];
192
+
193
+ for ( let i = 0; i < numMorphTargets; ++ i ) {
194
+
195
+ const morphAttributesToMerge = [];
196
+
197
+ for ( let j = 0; j < morphAttributes[ name ].length; ++ j ) {
198
+
199
+ morphAttributesToMerge.push( morphAttributes[ name ][ j ][ i ] );
200
+
201
+ }
202
+
203
+ const mergedMorphAttribute = mergeBufferAttributes( morphAttributesToMerge );
204
+
205
+ if ( ! mergedMorphAttribute ) {
206
+
207
+ console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the ' + name + ' morphAttribute.' );
208
+ return null;
209
+
210
+ }
211
+
212
+ mergedGeometry.morphAttributes[ name ].push( mergedMorphAttribute );
213
+
214
+ }
215
+
216
+ }
217
+
218
+ return mergedGeometry;
219
+
220
+ }
221
+
222
+ /**
223
+ * @param {Array<BufferAttribute>} attributes
224
+ * @return {BufferAttribute}
225
+ */
226
+ function mergeBufferAttributes( attributes ) {
227
+
228
+ let TypedArray;
229
+ let itemSize;
230
+ let normalized;
231
+ let arrayLength = 0;
232
+
233
+ for ( let i = 0; i < attributes.length; ++ i ) {
234
+
235
+ const attribute = attributes[ i ];
236
+
237
+ if ( attribute.isInterleavedBufferAttribute ) {
238
+
239
+ console.error( 'THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. InterleavedBufferAttributes are not supported.' );
240
+ return null;
241
+
242
+ }
243
+
244
+ if ( TypedArray === undefined ) TypedArray = attribute.array.constructor;
245
+ if ( TypedArray !== attribute.array.constructor ) {
246
+
247
+ console.error( 'THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes.' );
248
+ return null;
249
+
250
+ }
251
+
252
+ if ( itemSize === undefined ) itemSize = attribute.itemSize;
253
+ if ( itemSize !== attribute.itemSize ) {
254
+
255
+ console.error( 'THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes.' );
256
+ return null;
257
+
258
+ }
259
+
260
+ if ( normalized === undefined ) normalized = attribute.normalized;
261
+ if ( normalized !== attribute.normalized ) {
262
+
263
+ console.error( 'THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes.' );
264
+ return null;
265
+
266
+ }
267
+
268
+ arrayLength += attribute.array.length;
269
+
270
+ }
271
+
272
+ const array = new TypedArray( arrayLength );
273
+ let offset = 0;
274
+
275
+ for ( let i = 0; i < attributes.length; ++ i ) {
276
+
277
+ array.set( attributes[ i ].array, offset );
278
+
279
+ offset += attributes[ i ].array.length;
280
+
281
+ }
282
+
283
+ return new BufferAttribute( array, itemSize, normalized );
284
+
285
+ }
286
+
287
+ /**
288
+ * @param {Array<BufferAttribute>} attributes
289
+ * @return {Array<InterleavedBufferAttribute>}
290
+ */
291
+ function interleaveAttributes( attributes ) {
292
+
293
+ // Interleaves the provided attributes into an InterleavedBuffer and returns
294
+ // a set of InterleavedBufferAttributes for each attribute
295
+ let TypedArray;
296
+ let arrayLength = 0;
297
+ let stride = 0;
298
+
299
+ // calculate the the length and type of the interleavedBuffer
300
+ for ( let i = 0, l = attributes.length; i < l; ++ i ) {
301
+
302
+ const attribute = attributes[ i ];
303
+
304
+ if ( TypedArray === undefined ) TypedArray = attribute.array.constructor;
305
+ if ( TypedArray !== attribute.array.constructor ) {
306
+
307
+ console.error( 'AttributeBuffers of different types cannot be interleaved' );
308
+ return null;
309
+
310
+ }
311
+
312
+ arrayLength += attribute.array.length;
313
+ stride += attribute.itemSize;
314
+
315
+ }
316
+
317
+ // Create the set of buffer attributes
318
+ const interleavedBuffer = new InterleavedBuffer( new TypedArray( arrayLength ), stride );
319
+ let offset = 0;
320
+ const res = [];
321
+ const getters = [ 'getX', 'getY', 'getZ', 'getW' ];
322
+ const setters = [ 'setX', 'setY', 'setZ', 'setW' ];
323
+
324
+ for ( let j = 0, l = attributes.length; j < l; j ++ ) {
325
+
326
+ const attribute = attributes[ j ];
327
+ const itemSize = attribute.itemSize;
328
+ const count = attribute.count;
329
+ const iba = new InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, attribute.normalized );
330
+ res.push( iba );
331
+
332
+ offset += itemSize;
333
+
334
+ // Move the data for each attribute into the new interleavedBuffer
335
+ // at the appropriate offset
336
+ for ( let c = 0; c < count; c ++ ) {
337
+
338
+ for ( let k = 0; k < itemSize; k ++ ) {
339
+
340
+ iba[ setters[ k ] ]( c, attribute[ getters[ k ] ]( c ) );
341
+
342
+ }
343
+
344
+ }
345
+
346
+ }
347
+
348
+ return res;
349
+
350
+ }
351
+
352
+ /**
353
+ * @param {Array<BufferGeometry>} geometry
354
+ * @return {number}
355
+ */
356
+ function estimateBytesUsed( geometry ) {
357
+
358
+ // Return the estimated memory used by this geometry in bytes
359
+ // Calculate using itemSize, count, and BYTES_PER_ELEMENT to account
360
+ // for InterleavedBufferAttributes.
361
+ let mem = 0;
362
+ for ( const name in geometry.attributes ) {
363
+
364
+ const attr = geometry.getAttribute( name );
365
+ mem += attr.count * attr.itemSize * attr.array.BYTES_PER_ELEMENT;
366
+
367
+ }
368
+
369
+ const indices = geometry.getIndex();
370
+ mem += indices ? indices.count * indices.itemSize * indices.array.BYTES_PER_ELEMENT : 0;
371
+ return mem;
372
+
373
+ }
374
+
375
+ /**
376
+ * @param {BufferGeometry} geometry
377
+ * @param {number} tolerance
378
+ * @return {BufferGeometry>}
379
+ */
380
+ function mergeVertices( geometry, tolerance = 1e-4 ) {
381
+
382
+ tolerance = Math.max( tolerance, Number.EPSILON );
383
+
384
+ // Generate an index buffer if the geometry doesn't have one, or optimize it
385
+ // if it's already available.
386
+ const hashToIndex = {};
387
+ const indices = geometry.getIndex();
388
+ const positions = geometry.getAttribute( 'position' );
389
+ const vertexCount = indices ? indices.count : positions.count;
390
+
391
+ // next value for triangle indices
392
+ let nextIndex = 0;
393
+
394
+ // attributes and new attribute arrays
395
+ const attributeNames = Object.keys( geometry.attributes );
396
+ const attrArrays = {};
397
+ const morphAttrsArrays = {};
398
+ const newIndices = [];
399
+ const getters = [ 'getX', 'getY', 'getZ', 'getW' ];
400
+
401
+ // initialize the arrays
402
+ for ( let i = 0, l = attributeNames.length; i < l; i ++ ) {
403
+
404
+ const name = attributeNames[ i ];
405
+
406
+ attrArrays[ name ] = [];
407
+
408
+ const morphAttr = geometry.morphAttributes[ name ];
409
+ if ( morphAttr ) {
410
+
411
+ morphAttrsArrays[ name ] = new Array( morphAttr.length ).fill().map( () => [] );
412
+
413
+ }
414
+
415
+ }
416
+
417
+ // convert the error tolerance to an amount of decimal places to truncate to
418
+ const decimalShift = Math.log10( 1 / tolerance );
419
+ const shiftMultiplier = Math.pow( 10, decimalShift );
420
+ for ( let i = 0; i < vertexCount; i ++ ) {
421
+
422
+ const index = indices ? indices.getX( i ) : i;
423
+
424
+ // Generate a hash for the vertex attributes at the current index 'i'
425
+ let hash = '';
426
+ for ( let j = 0, l = attributeNames.length; j < l; j ++ ) {
427
+
428
+ const name = attributeNames[ j ];
429
+ const attribute = geometry.getAttribute( name );
430
+ const itemSize = attribute.itemSize;
431
+
432
+ for ( let k = 0; k < itemSize; k ++ ) {
433
+
434
+ // double tilde truncates the decimal value
435
+ hash += `${ ~ ~ ( attribute[ getters[ k ] ]( index ) * shiftMultiplier ) },`;
436
+
437
+ }
438
+
439
+ }
440
+
441
+ // Add another reference to the vertex if it's already
442
+ // used by another index
443
+ if ( hash in hashToIndex ) {
444
+
445
+ newIndices.push( hashToIndex[ hash ] );
446
+
447
+ } else {
448
+
449
+ // copy data to the new index in the attribute arrays
450
+ for ( let j = 0, l = attributeNames.length; j < l; j ++ ) {
451
+
452
+ const name = attributeNames[ j ];
453
+ const attribute = geometry.getAttribute( name );
454
+ const morphAttr = geometry.morphAttributes[ name ];
455
+ const itemSize = attribute.itemSize;
456
+ const newarray = attrArrays[ name ];
457
+ const newMorphArrays = morphAttrsArrays[ name ];
458
+
459
+ for ( let k = 0; k < itemSize; k ++ ) {
460
+
461
+ const getterFunc = getters[ k ];
462
+ newarray.push( attribute[ getterFunc ]( index ) );
463
+
464
+ if ( morphAttr ) {
465
+
466
+ for ( let m = 0, ml = morphAttr.length; m < ml; m ++ ) {
467
+
468
+ newMorphArrays[ m ].push( morphAttr[ m ][ getterFunc ]( index ) );
469
+
470
+ }
471
+
472
+ }
473
+
474
+ }
475
+
476
+ }
477
+
478
+ hashToIndex[ hash ] = nextIndex;
479
+ newIndices.push( nextIndex );
480
+ nextIndex ++;
481
+
482
+ }
483
+
484
+ }
485
+
486
+ // Generate typed arrays from new attribute arrays and update
487
+ // the attributeBuffers
488
+ const result = geometry.clone();
489
+ for ( let i = 0, l = attributeNames.length; i < l; i ++ ) {
490
+
491
+ const name = attributeNames[ i ];
492
+ const oldAttribute = geometry.getAttribute( name );
493
+
494
+ const buffer = new oldAttribute.array.constructor( attrArrays[ name ] );
495
+ const attribute = new BufferAttribute( buffer, oldAttribute.itemSize, oldAttribute.normalized );
496
+
497
+ result.setAttribute( name, attribute );
498
+
499
+ // Update the attribute arrays
500
+ if ( name in morphAttrsArrays ) {
501
+
502
+ for ( let j = 0; j < morphAttrsArrays[ name ].length; j ++ ) {
503
+
504
+ const oldMorphAttribute = geometry.morphAttributes[ name ][ j ];
505
+
506
+ const buffer = new oldMorphAttribute.array.constructor( morphAttrsArrays[ name ][ j ] );
507
+ const morphAttribute = new BufferAttribute( buffer, oldMorphAttribute.itemSize, oldMorphAttribute.normalized );
508
+ result.morphAttributes[ name ][ j ] = morphAttribute;
509
+
510
+ }
511
+
512
+ }
513
+
514
+ }
515
+
516
+ // indices
517
+
518
+ result.setIndex( newIndices );
519
+
520
+ return result;
521
+
522
+ }
523
+
524
+ /**
525
+ * @param {BufferGeometry} geometry
526
+ * @param {number} drawMode
527
+ * @return {BufferGeometry>}
528
+ */
529
+ function toTrianglesDrawMode( geometry, drawMode ) {
530
+
531
+ if ( drawMode === TrianglesDrawMode ) {
532
+
533
+ console.warn( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles.' );
534
+ return geometry;
535
+
536
+ }
537
+
538
+ if ( drawMode === TriangleFanDrawMode || drawMode === TriangleStripDrawMode ) {
539
+
540
+ let index = geometry.getIndex();
541
+
542
+ // generate index if not present
543
+
544
+ if ( index === null ) {
545
+
546
+ const indices = [];
547
+
548
+ const position = geometry.getAttribute( 'position' );
549
+
550
+ if ( position !== undefined ) {
551
+
552
+ for ( let i = 0; i < position.count; i ++ ) {
553
+
554
+ indices.push( i );
555
+
556
+ }
557
+
558
+ geometry.setIndex( indices );
559
+ index = geometry.getIndex();
560
+
561
+ } else {
562
+
563
+ console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.' );
564
+ return geometry;
565
+
566
+ }
567
+
568
+ }
569
+
570
+ //
571
+
572
+ const numberOfTriangles = index.count - 2;
573
+ const newIndices = [];
574
+
575
+ if ( drawMode === TriangleFanDrawMode ) {
576
+
577
+ // gl.TRIANGLE_FAN
578
+
579
+ for ( let i = 1; i <= numberOfTriangles; i ++ ) {
580
+
581
+ newIndices.push( index.getX( 0 ) );
582
+ newIndices.push( index.getX( i ) );
583
+ newIndices.push( index.getX( i + 1 ) );
584
+
585
+ }
586
+
587
+ } else {
588
+
589
+ // gl.TRIANGLE_STRIP
590
+
591
+ for ( let i = 0; i < numberOfTriangles; i ++ ) {
592
+
593
+ if ( i % 2 === 0 ) {
594
+
595
+ newIndices.push( index.getX( i ) );
596
+ newIndices.push( index.getX( i + 1 ) );
597
+ newIndices.push( index.getX( i + 2 ) );
598
+
599
+ } else {
600
+
601
+ newIndices.push( index.getX( i + 2 ) );
602
+ newIndices.push( index.getX( i + 1 ) );
603
+ newIndices.push( index.getX( i ) );
604
+
605
+ }
606
+
607
+ }
608
+
609
+ }
610
+
611
+ if ( ( newIndices.length / 3 ) !== numberOfTriangles ) {
612
+
613
+ console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.' );
614
+
615
+ }
616
+
617
+ // build final geometry
618
+
619
+ const newGeometry = geometry.clone();
620
+ newGeometry.setIndex( newIndices );
621
+ newGeometry.clearGroups();
622
+
623
+ return newGeometry;
624
+
625
+ } else {
626
+
627
+ console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:', drawMode );
628
+ return geometry;
629
+
630
+ }
631
+
632
+ }
633
+
634
+ /**
635
+ * Calculates the morphed attributes of a morphed/skinned BufferGeometry.
636
+ * Helpful for Raytracing or Decals.
637
+ * @param {Mesh | Line | Points} object An instance of Mesh, Line or Points.
638
+ * @return {Object} An Object with original position/normal attributes and morphed ones.
639
+ */
640
+ function computeMorphedAttributes( object ) {
641
+
642
+ if ( object.geometry.isBufferGeometry !== true ) {
643
+
644
+ console.error( 'THREE.BufferGeometryUtils: Geometry is not of type BufferGeometry.' );
645
+ return null;
646
+
647
+ }
648
+
649
+ const _vA = new Vector3();
650
+ const _vB = new Vector3();
651
+ const _vC = new Vector3();
652
+
653
+ const _tempA = new Vector3();
654
+ const _tempB = new Vector3();
655
+ const _tempC = new Vector3();
656
+
657
+ const _morphA = new Vector3();
658
+ const _morphB = new Vector3();
659
+ const _morphC = new Vector3();
660
+
661
+ function _calculateMorphedAttributeData(
662
+ object,
663
+ material,
664
+ attribute,
665
+ morphAttribute,
666
+ morphTargetsRelative,
667
+ a,
668
+ b,
669
+ c,
670
+ modifiedAttributeArray
671
+ ) {
672
+
673
+ _vA.fromBufferAttribute( attribute, a );
674
+ _vB.fromBufferAttribute( attribute, b );
675
+ _vC.fromBufferAttribute( attribute, c );
676
+
677
+ const morphInfluences = object.morphTargetInfluences;
678
+
679
+ if ( material.morphTargets && morphAttribute && morphInfluences ) {
680
+
681
+ _morphA.set( 0, 0, 0 );
682
+ _morphB.set( 0, 0, 0 );
683
+ _morphC.set( 0, 0, 0 );
684
+
685
+ for ( let i = 0, il = morphAttribute.length; i < il; i ++ ) {
686
+
687
+ const influence = morphInfluences[ i ];
688
+ const morph = morphAttribute[ i ];
689
+
690
+ if ( influence === 0 ) continue;
691
+
692
+ _tempA.fromBufferAttribute( morph, a );
693
+ _tempB.fromBufferAttribute( morph, b );
694
+ _tempC.fromBufferAttribute( morph, c );
695
+
696
+ if ( morphTargetsRelative ) {
697
+
698
+ _morphA.addScaledVector( _tempA, influence );
699
+ _morphB.addScaledVector( _tempB, influence );
700
+ _morphC.addScaledVector( _tempC, influence );
701
+
702
+ } else {
703
+
704
+ _morphA.addScaledVector( _tempA.sub( _vA ), influence );
705
+ _morphB.addScaledVector( _tempB.sub( _vB ), influence );
706
+ _morphC.addScaledVector( _tempC.sub( _vC ), influence );
707
+
708
+ }
709
+
710
+ }
711
+
712
+ _vA.add( _morphA );
713
+ _vB.add( _morphB );
714
+ _vC.add( _morphC );
715
+
716
+ }
717
+
718
+ if ( object.isSkinnedMesh ) {
719
+
720
+ object.boneTransform( a, _vA );
721
+ object.boneTransform( b, _vB );
722
+ object.boneTransform( c, _vC );
723
+
724
+ }
725
+
726
+ modifiedAttributeArray[ a * 3 + 0 ] = _vA.x;
727
+ modifiedAttributeArray[ a * 3 + 1 ] = _vA.y;
728
+ modifiedAttributeArray[ a * 3 + 2 ] = _vA.z;
729
+ modifiedAttributeArray[ b * 3 + 0 ] = _vB.x;
730
+ modifiedAttributeArray[ b * 3 + 1 ] = _vB.y;
731
+ modifiedAttributeArray[ b * 3 + 2 ] = _vB.z;
732
+ modifiedAttributeArray[ c * 3 + 0 ] = _vC.x;
733
+ modifiedAttributeArray[ c * 3 + 1 ] = _vC.y;
734
+ modifiedAttributeArray[ c * 3 + 2 ] = _vC.z;
735
+
736
+ }
737
+
738
+ const geometry = object.geometry;
739
+ const material = object.material;
740
+
741
+ let a, b, c;
742
+ const index = geometry.index;
743
+ const positionAttribute = geometry.attributes.position;
744
+ const morphPosition = geometry.morphAttributes.position;
745
+ const morphTargetsRelative = geometry.morphTargetsRelative;
746
+ const normalAttribute = geometry.attributes.normal;
747
+ const morphNormal = geometry.morphAttributes.position;
748
+
749
+ const groups = geometry.groups;
750
+ const drawRange = geometry.drawRange;
751
+ let i, j, il, jl;
752
+ let group, groupMaterial;
753
+ let start, end;
754
+
755
+ const modifiedPosition = new Float32Array( positionAttribute.count * positionAttribute.itemSize );
756
+ const modifiedNormal = new Float32Array( normalAttribute.count * normalAttribute.itemSize );
757
+
758
+ if ( index !== null ) {
759
+
760
+ // indexed buffer geometry
761
+
762
+ if ( Array.isArray( material ) ) {
763
+
764
+ for ( i = 0, il = groups.length; i < il; i ++ ) {
765
+
766
+ group = groups[ i ];
767
+ groupMaterial = material[ group.materialIndex ];
768
+
769
+ start = Math.max( group.start, drawRange.start );
770
+ end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
771
+
772
+ for ( j = start, jl = end; j < jl; j += 3 ) {
773
+
774
+ a = index.getX( j );
775
+ b = index.getX( j + 1 );
776
+ c = index.getX( j + 2 );
777
+
778
+ _calculateMorphedAttributeData(
779
+ object,
780
+ groupMaterial,
781
+ positionAttribute,
782
+ morphPosition,
783
+ morphTargetsRelative,
784
+ a, b, c,
785
+ modifiedPosition
786
+ );
787
+
788
+ _calculateMorphedAttributeData(
789
+ object,
790
+ groupMaterial,
791
+ normalAttribute,
792
+ morphNormal,
793
+ morphTargetsRelative,
794
+ a, b, c,
795
+ modifiedNormal
796
+ );
797
+
798
+ }
799
+
800
+ }
801
+
802
+ } else {
803
+
804
+ start = Math.max( 0, drawRange.start );
805
+ end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
806
+
807
+ for ( i = start, il = end; i < il; i += 3 ) {
808
+
809
+ a = index.getX( i );
810
+ b = index.getX( i + 1 );
811
+ c = index.getX( i + 2 );
812
+
813
+ _calculateMorphedAttributeData(
814
+ object,
815
+ material,
816
+ positionAttribute,
817
+ morphPosition,
818
+ morphTargetsRelative,
819
+ a, b, c,
820
+ modifiedPosition
821
+ );
822
+
823
+ _calculateMorphedAttributeData(
824
+ object,
825
+ material,
826
+ normalAttribute,
827
+ morphNormal,
828
+ morphTargetsRelative,
829
+ a, b, c,
830
+ modifiedNormal
831
+ );
832
+
833
+ }
834
+
835
+ }
836
+
837
+ } else if ( positionAttribute !== undefined ) {
838
+
839
+ // non-indexed buffer geometry
840
+
841
+ if ( Array.isArray( material ) ) {
842
+
843
+ for ( i = 0, il = groups.length; i < il; i ++ ) {
844
+
845
+ group = groups[ i ];
846
+ groupMaterial = material[ group.materialIndex ];
847
+
848
+ start = Math.max( group.start, drawRange.start );
849
+ end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
850
+
851
+ for ( j = start, jl = end; j < jl; j += 3 ) {
852
+
853
+ a = j;
854
+ b = j + 1;
855
+ c = j + 2;
856
+
857
+ _calculateMorphedAttributeData(
858
+ object,
859
+ groupMaterial,
860
+ positionAttribute,
861
+ morphPosition,
862
+ morphTargetsRelative,
863
+ a, b, c,
864
+ modifiedPosition
865
+ );
866
+
867
+ _calculateMorphedAttributeData(
868
+ object,
869
+ groupMaterial,
870
+ normalAttribute,
871
+ morphNormal,
872
+ morphTargetsRelative,
873
+ a, b, c,
874
+ modifiedNormal
875
+ );
876
+
877
+ }
878
+
879
+ }
880
+
881
+ } else {
882
+
883
+ start = Math.max( 0, drawRange.start );
884
+ end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) );
885
+
886
+ for ( i = start, il = end; i < il; i += 3 ) {
887
+
888
+ a = i;
889
+ b = i + 1;
890
+ c = i + 2;
891
+
892
+ _calculateMorphedAttributeData(
893
+ object,
894
+ material,
895
+ positionAttribute,
896
+ morphPosition,
897
+ morphTargetsRelative,
898
+ a, b, c,
899
+ modifiedPosition
900
+ );
901
+
902
+ _calculateMorphedAttributeData(
903
+ object,
904
+ material,
905
+ normalAttribute,
906
+ morphNormal,
907
+ morphTargetsRelative,
908
+ a, b, c,
909
+ modifiedNormal
910
+ );
911
+
912
+ }
913
+
914
+ }
915
+
916
+ }
917
+
918
+ const morphedPositionAttribute = new Float32BufferAttribute( modifiedPosition, 3 );
919
+ const morphedNormalAttribute = new Float32BufferAttribute( modifiedNormal, 3 );
920
+
921
+ return {
922
+
923
+ positionAttribute: positionAttribute,
924
+ normalAttribute: normalAttribute,
925
+ morphedPositionAttribute: morphedPositionAttribute,
926
+ morphedNormalAttribute: morphedNormalAttribute
927
+
928
+ };
929
+
930
+ }
931
+
932
+
933
+
934
+ export {
935
+ computeTangents,
936
+ mergeBufferGeometries,
937
+ mergeBufferAttributes,
938
+ interleaveAttributes,
939
+ estimateBytesUsed,
940
+ mergeVertices,
941
+ toTrianglesDrawMode,
942
+ computeMorphedAttributes,
943
+ };