@damienmortini/three 0.1.167 → 0.1.170

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.
@@ -117,6 +117,12 @@ class GLTFLoader extends Loader {
117
117
 
118
118
  } );
119
119
 
120
+ this.register( function ( parser ) {
121
+
122
+ return new GLTFMaterialsEmissiveStrengthExtension( parser );
123
+
124
+ } );
125
+
120
126
  this.register( function ( parser ) {
121
127
 
122
128
  return new GLTFMaterialsSpecularExtension( parser );
@@ -453,6 +459,7 @@ const EXTENSIONS = {
453
459
  KHR_TEXTURE_BASISU: 'KHR_texture_basisu',
454
460
  KHR_TEXTURE_TRANSFORM: 'KHR_texture_transform',
455
461
  KHR_MESH_QUANTIZATION: 'KHR_mesh_quantization',
462
+ KHR_MATERIALS_EMISSIVE_STRENGTH: 'KHR_materials_emissive_strength',
456
463
  EXT_TEXTURE_WEBP: 'EXT_texture_webp',
457
464
  EXT_MESHOPT_COMPRESSION: 'EXT_meshopt_compression'
458
465
  };
@@ -638,6 +645,45 @@ class GLTFMaterialsUnlitExtension {
638
645
 
639
646
  }
640
647
 
648
+ /**
649
+ * Materials Emissive Strength Extension
650
+ *
651
+ * Specification: https://github.com/KhronosGroup/glTF/blob/5768b3ce0ef32bc39cdf1bef10b948586635ead3/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md
652
+ */
653
+ class GLTFMaterialsEmissiveStrengthExtension {
654
+
655
+ constructor( parser ) {
656
+
657
+ this.parser = parser;
658
+ this.name = EXTENSIONS.KHR_MATERIALS_EMISSIVE_STRENGTH;
659
+
660
+ }
661
+
662
+ extendMaterialParams( materialIndex, materialParams ) {
663
+
664
+ const parser = this.parser;
665
+ const materialDef = parser.json.materials[ materialIndex ];
666
+
667
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
668
+
669
+ return Promise.resolve();
670
+
671
+ }
672
+
673
+ const emissiveStrength = materialDef.extensions[ this.name ].emissiveStrength;
674
+
675
+ if ( emissiveStrength !== undefined ) {
676
+
677
+ materialParams.emissiveIntensity = emissiveStrength;
678
+
679
+ }
680
+
681
+ return Promise.resolve();
682
+
683
+ }
684
+
685
+ }
686
+
641
687
  /**
642
688
  * Clearcoat Materials Extension
643
689
  *
@@ -1116,7 +1162,7 @@ class GLTFTextureWebPExtension {
1116
1162
 
1117
1163
  return this.detectSupport().then( function ( isSupported ) {
1118
1164
 
1119
- if ( isSupported ) return parser.loadTextureImage( textureIndex, source, loader );
1165
+ if ( isSupported ) return parser.loadTextureImage( textureIndex, extension.source, loader );
1120
1166
 
1121
1167
  if ( json.extensionsRequired && json.extensionsRequired.indexOf( name ) >= 0 ) {
1122
1168
 
@@ -1733,7 +1779,7 @@ class GLTFMaterialsPbrSpecularGlossinessExtension {
1733
1779
  material.aoMapIntensity = 1.0;
1734
1780
 
1735
1781
  material.emissive = materialParams.emissive;
1736
- material.emissiveIntensity = 1.0;
1782
+ material.emissiveIntensity = materialParams.emissiveIntensity === undefined ? 1.0 : materialParams.emissiveIntensity;
1737
1783
  material.emissiveMap = materialParams.emissiveMap === undefined ? null : materialParams.emissiveMap;
1738
1784
 
1739
1785
  material.bumpMap = materialParams.bumpMap === undefined ? null : materialParams.bumpMap;
@@ -2269,14 +2315,19 @@ class GLTFParser {
2269
2315
 
2270
2316
  // Use an ImageBitmapLoader if imageBitmaps are supported. Moves much of the
2271
2317
  // expensive work of uploading a texture to the GPU off the main thread.
2272
- if ( typeof createImageBitmap !== 'undefined' && /^((?!chrome|android).)*safari/i.test( navigator.userAgent ) === false ) {
2273
2318
 
2274
- this.textureLoader = new ImageBitmapLoader( this.options.manager );
2319
+ const isSafari = /^((?!chrome|android).)*safari/i.test( navigator.userAgent ) === true;
2320
+ const isFirefox = navigator.userAgent.indexOf( 'Firefox' ) > - 1;
2321
+ const firefoxVersion = isFirefox ? navigator.userAgent.match( /Firefox\/([0-9]+)\./ )[ 1 ] : - 1;
2275
2322
 
2276
- } else {
2323
+ if ( typeof createImageBitmap === 'undefined' || isSafari || ( isFirefox && firefoxVersion < 98 ) ) {
2277
2324
 
2278
2325
  this.textureLoader = new TextureLoader( this.options.manager );
2279
2326
 
2327
+ } else {
2328
+
2329
+ this.textureLoader = new ImageBitmapLoader( this.options.manager );
2330
+
2280
2331
  }
2281
2332
 
2282
2333
  this.textureLoader.setCrossOrigin( this.options.crossOrigin );
@@ -2580,7 +2631,11 @@ class GLTFParser {
2580
2631
  break;
2581
2632
 
2582
2633
  case 'animation':
2583
- dependency = this.loadAnimation( index );
2634
+ dependency = this._invokeOne( function ( ext ) {
2635
+
2636
+ return ext.loadAnimation && ext.loadAnimation( index );
2637
+
2638
+ } );
2584
2639
  break;
2585
2640
 
2586
2641
  case 'camera':
@@ -10,10 +10,26 @@ import {
10
10
  TrianglesDrawMode,
11
11
  Vector3,
12
12
  } from '../../../../three/src/Three.js';
13
- import { generateTangents } from '../libs/mikktspace.module.js';
14
13
 
14
+ function computeTangents() {
15
15
 
16
- function computeTangents( geometry, negateSign = true ) {
16
+ throw new Error( 'BufferGeometryUtils: computeTangents renamed to computeMikkTSpaceTangents.' );
17
+
18
+ }
19
+
20
+ function computeMikkTSpaceTangents( geometry, MikkTSpace, negateSign = true ) {
21
+
22
+ if ( ! MikkTSpace || ! MikkTSpace.isReady ) {
23
+
24
+ throw new Error( 'BufferGeometryUtils: Initialized MikkTSpace library required.' );
25
+
26
+ }
27
+
28
+ if ( ! geometry.hasAttribute( 'position' ) || ! geometry.hasAttribute( 'normal' ) || ! geometry.hasAttribute( 'uv' ) ) {
29
+
30
+ throw new Error( 'BufferGeometryUtils: Tangents require "position", "normal", and "uv" attributes.' );
31
+
32
+ }
17
33
 
18
34
  function getAttributeArray( attribute ) {
19
35
 
@@ -55,7 +71,7 @@ function computeTangents( geometry, negateSign = true ) {
55
71
 
56
72
  // Compute vertex tangents.
57
73
 
58
- const tangents = generateTangents(
74
+ const tangents = MikkTSpace.generateTangents(
59
75
 
60
76
  getAttributeArray( _geometry.attributes.position ),
61
77
  getAttributeArray( _geometry.attributes.normal ),
@@ -80,7 +96,13 @@ function computeTangents( geometry, negateSign = true ) {
80
96
 
81
97
  _geometry.setAttribute( 'tangent', new BufferAttribute( tangents, 4 ) );
82
98
 
83
- return geometry.copy( _geometry );
99
+ if ( geometry !== _geometry ) {
100
+
101
+ geometry.copy( _geometry )
102
+
103
+ }
104
+
105
+ return geometry;
84
106
 
85
107
  }
86
108
 
@@ -415,6 +437,97 @@ function interleaveAttributes( attributes ) {
415
437
 
416
438
  }
417
439
 
440
+ // returns a new, non-interleaved version of the provided attribute
441
+ export function deinterleaveAttribute( attribute ) {
442
+
443
+ const cons = attribute.data.array.constructor;
444
+ const count = attribute.count;
445
+ const itemSize = attribute.itemSize;
446
+ const normalized = attribute.normalized;
447
+
448
+ const array = new cons( count * itemSize );
449
+ let newAttribute;
450
+ if ( attribute.isInstancedInterleavedBufferAttribute ) {
451
+
452
+ newAttribute = new InstancedBufferAttribute( array, itemSize, normalized, attribute.meshPerAttribute );
453
+
454
+ } else {
455
+
456
+ newAttribute = new BufferAttribute( array, itemSize, normalized );
457
+
458
+ }
459
+
460
+ for ( let i = 0; i < count; i ++ ) {
461
+
462
+ newAttribute.setX( i, attribute.getX( i ) );
463
+
464
+ if ( itemSize >= 2 ) {
465
+
466
+ newAttribute.setY( i, attribute.getY( i ) );
467
+
468
+ }
469
+
470
+ if ( itemSize >= 3 ) {
471
+
472
+ newAttribute.setZ( i, attribute.getZ( i ) );
473
+
474
+ }
475
+
476
+ if ( itemSize >= 4 ) {
477
+
478
+ newAttribute.setW( i, attribute.getW( i ) );
479
+
480
+ }
481
+
482
+ }
483
+
484
+ return newAttribute;
485
+
486
+ }
487
+
488
+ // deinterleaves all attributes on the geometry
489
+ export function deinterleaveGeometry( geometry ) {
490
+
491
+ const attributes = geometry.attributes;
492
+ const morphTargets = geometry.morphTargets;
493
+ const attrMap = new Map();
494
+
495
+ for ( const key in attributes ) {
496
+
497
+ const attr = attributes[ key ];
498
+ if ( attr.isInterleavedBufferAttribute ) {
499
+
500
+ if ( ! attrMap.has( attr ) ) {
501
+
502
+ attrMap.set( attr, deinterleaveAttribute( attr ) );
503
+
504
+ }
505
+
506
+ attributes[ key ] = attrMap.get( attr );
507
+
508
+ }
509
+
510
+ }
511
+
512
+ for ( const key in morphTargets ) {
513
+
514
+ const attr = morphTargets[ key ];
515
+ if ( attr.isInterleavedBufferAttribute ) {
516
+
517
+ if ( ! attrMap.has( attr ) ) {
518
+
519
+ attrMap.set( attr, deinterleaveAttribute( attr ) );
520
+
521
+ }
522
+
523
+ morphTargets[ key ] = attrMap.get( attr );
524
+
525
+ }
526
+
527
+ }
528
+
529
+ }
530
+
418
531
  /**
419
532
  * @param {Array<BufferGeometry>} geometry
420
533
  * @return {number}
@@ -726,7 +839,6 @@ function computeMorphedAttributes( object ) {
726
839
 
727
840
  function _calculateMorphedAttributeData(
728
841
  object,
729
- material,
730
842
  attribute,
731
843
  morphAttribute,
732
844
  morphTargetsRelative,
@@ -742,7 +854,7 @@ function computeMorphedAttributes( object ) {
742
854
 
743
855
  const morphInfluences = object.morphTargetInfluences;
744
856
 
745
- if ( material.morphTargets && morphAttribute && morphInfluences ) {
857
+ if ( morphAttribute && morphInfluences ) {
746
858
 
747
859
  _morphA.set( 0, 0, 0 );
748
860
  _morphB.set( 0, 0, 0 );
@@ -815,7 +927,7 @@ function computeMorphedAttributes( object ) {
815
927
  const groups = geometry.groups;
816
928
  const drawRange = geometry.drawRange;
817
929
  let i, j, il, jl;
818
- let group, groupMaterial;
930
+ let group;
819
931
  let start, end;
820
932
 
821
933
  const modifiedPosition = new Float32Array( positionAttribute.count * positionAttribute.itemSize );
@@ -830,7 +942,6 @@ function computeMorphedAttributes( object ) {
830
942
  for ( i = 0, il = groups.length; i < il; i ++ ) {
831
943
 
832
944
  group = groups[ i ];
833
- groupMaterial = material[ group.materialIndex ];
834
945
 
835
946
  start = Math.max( group.start, drawRange.start );
836
947
  end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
@@ -843,7 +954,6 @@ function computeMorphedAttributes( object ) {
843
954
 
844
955
  _calculateMorphedAttributeData(
845
956
  object,
846
- groupMaterial,
847
957
  positionAttribute,
848
958
  morphPosition,
849
959
  morphTargetsRelative,
@@ -853,7 +963,6 @@ function computeMorphedAttributes( object ) {
853
963
 
854
964
  _calculateMorphedAttributeData(
855
965
  object,
856
- groupMaterial,
857
966
  normalAttribute,
858
967
  morphNormal,
859
968
  morphTargetsRelative,
@@ -878,7 +987,6 @@ function computeMorphedAttributes( object ) {
878
987
 
879
988
  _calculateMorphedAttributeData(
880
989
  object,
881
- material,
882
990
  positionAttribute,
883
991
  morphPosition,
884
992
  morphTargetsRelative,
@@ -888,7 +996,6 @@ function computeMorphedAttributes( object ) {
888
996
 
889
997
  _calculateMorphedAttributeData(
890
998
  object,
891
- material,
892
999
  normalAttribute,
893
1000
  morphNormal,
894
1001
  morphTargetsRelative,
@@ -909,7 +1016,6 @@ function computeMorphedAttributes( object ) {
909
1016
  for ( i = 0, il = groups.length; i < il; i ++ ) {
910
1017
 
911
1018
  group = groups[ i ];
912
- groupMaterial = material[ group.materialIndex ];
913
1019
 
914
1020
  start = Math.max( group.start, drawRange.start );
915
1021
  end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
@@ -922,7 +1028,6 @@ function computeMorphedAttributes( object ) {
922
1028
 
923
1029
  _calculateMorphedAttributeData(
924
1030
  object,
925
- groupMaterial,
926
1031
  positionAttribute,
927
1032
  morphPosition,
928
1033
  morphTargetsRelative,
@@ -932,7 +1037,6 @@ function computeMorphedAttributes( object ) {
932
1037
 
933
1038
  _calculateMorphedAttributeData(
934
1039
  object,
935
- groupMaterial,
936
1040
  normalAttribute,
937
1041
  morphNormal,
938
1042
  morphTargetsRelative,
@@ -957,7 +1061,6 @@ function computeMorphedAttributes( object ) {
957
1061
 
958
1062
  _calculateMorphedAttributeData(
959
1063
  object,
960
- material,
961
1064
  positionAttribute,
962
1065
  morphPosition,
963
1066
  morphTargetsRelative,
@@ -967,7 +1070,6 @@ function computeMorphedAttributes( object ) {
967
1070
 
968
1071
  _calculateMorphedAttributeData(
969
1072
  object,
970
- material,
971
1073
  normalAttribute,
972
1074
  morphNormal,
973
1075
  morphTargetsRelative,
@@ -1099,6 +1201,7 @@ function mergeGroups( geometry ) {
1099
1201
 
1100
1202
  export {
1101
1203
  computeTangents,
1204
+ computeMikkTSpaceTangents,
1102
1205
  mergeBufferGeometries,
1103
1206
  mergeBufferAttributes,
1104
1207
  interleaveAttributes,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@damienmortini/three",
3
- "version": "0.1.167",
3
+ "version": "0.1.170",
4
4
  "description": "Three.js helpers",
5
5
  "scripts": {
6
6
  "install": "npm run copyexamples",
@@ -25,9 +25,9 @@
25
25
  "bugs": "https://github.com/damienmortini/lib/issues",
26
26
  "homepage": "https://github.com/damienmortini/lib/tree/main/packages/three",
27
27
  "dependencies": {
28
- "@damienmortini/core": "^0.2.131",
28
+ "@damienmortini/core": "^0.2.133",
29
29
  "fs-extra": "^10.0.1",
30
- "three": "0.139.0"
30
+ "three": "0.140.2"
31
31
  },
32
- "gitHead": "212228c077e3dd31b65117e24ec84c80a9bfb984"
32
+ "gitHead": "d01a174f8b8a88763a27c2964f6f918a9c2b4075"
33
33
  }