@damienmortini/three 0.1.131 → 0.1.135

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/copyExamples.js CHANGED
@@ -10,6 +10,6 @@ const files = new Map([
10
10
  for (const [source, destination] of files) {
11
11
  fs.copySync(source, destination)
12
12
  const data = fs.readFileSync(destination, 'utf-8')
13
- const newValue = data.replace('../../../build/three.module.js', '../../../../three/src/Three.js')
13
+ const newValue = data.replace('from \'three\'', 'from \'../../../../three/src/Three.js\'')
14
14
  fs.writeFileSync(destination, newValue, 'utf-8')
15
15
  }
@@ -15,7 +15,7 @@ import {
15
15
  RGB_PVRTC_4BPPV1_Format,
16
16
  RGB_S3TC_DXT1_Format,
17
17
  UnsignedByteType
18
- } from 'three';
18
+ } from '../../../../three/src/Three.js';
19
19
 
20
20
  /**
21
21
  * Loader for Basis Universal GPU Texture Codec.
@@ -3,7 +3,7 @@ import {
3
3
  BufferGeometry,
4
4
  FileLoader,
5
5
  Loader
6
- } from 'three';
6
+ } from '../../../../three/src/Three.js';
7
7
 
8
8
  const _taskCache = new WeakMap();
9
9
 
@@ -62,7 +62,7 @@ import {
62
62
  Vector3,
63
63
  VectorKeyframeTrack,
64
64
  sRGBEncoding
65
- } from 'three';
65
+ } from '../../../../three/src/Three.js';
66
66
 
67
67
  class GLTFLoader extends Loader {
68
68
 
@@ -692,8 +692,7 @@ class GLTFMaterialsClearcoatExtension {
692
692
 
693
693
  const scale = extension.clearcoatNormalTexture.scale;
694
694
 
695
- // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
696
- materialParams.clearcoatNormalScale = new Vector2( scale, - scale );
695
+ materialParams.clearcoatNormalScale = new Vector2( scale, scale );
697
696
 
698
697
  }
699
698
 
@@ -2369,6 +2368,27 @@ class GLTFParser {
2369
2368
 
2370
2369
  const ref = object.clone();
2371
2370
 
2371
+ // Propagates mappings to the cloned object, prevents mappings on the
2372
+ // original object from being lost.
2373
+ const updateMappings = ( original, clone ) => {
2374
+
2375
+ const mappings = this.associations.get( original );
2376
+ if ( mappings != null ) {
2377
+
2378
+ this.associations.set( clone, mappings );
2379
+
2380
+ }
2381
+
2382
+ for ( const [ i, child ] of original.children.entries() ) {
2383
+
2384
+ updateMappings( child, clone.children[ i ] );
2385
+
2386
+ }
2387
+
2388
+ };
2389
+
2390
+ updateMappings( object, ref );
2391
+
2372
2392
  ref.name += '_instance_' + ( cache.uses[ index ] ++ );
2373
2393
 
2374
2394
  return ref;
@@ -2761,11 +2781,6 @@ class GLTFParser {
2761
2781
 
2762
2782
  let sourceURI = source.uri || '';
2763
2783
  let isObjectURL = false;
2764
- let hasAlpha = true;
2765
-
2766
- const isJPEG = sourceURI.search( /\.jpe?g($|\?)/i ) > 0 || sourceURI.search( /^data\:image\/jpeg/ ) === 0;
2767
-
2768
- if ( source.mimeType === 'image/jpeg' || isJPEG ) hasAlpha = false;
2769
2784
 
2770
2785
  if ( source.bufferView !== undefined ) {
2771
2786
 
@@ -2773,19 +2788,6 @@ class GLTFParser {
2773
2788
 
2774
2789
  sourceURI = parser.getDependency( 'bufferView', source.bufferView ).then( function ( bufferView ) {
2775
2790
 
2776
- if ( source.mimeType === 'image/png' ) {
2777
-
2778
- // Inspect the PNG 'IHDR' chunk to determine whether the image could have an
2779
- // alpha channel. This check is conservative — the image could have an alpha
2780
- // channel with all values == 1, and the indexed type (colorType == 3) only
2781
- // sometimes contains alpha.
2782
- //
2783
- // https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header
2784
- const colorType = new DataView( bufferView, 25, 1 ).getUint8( 0, false );
2785
- hasAlpha = colorType === 6 || colorType === 4 || colorType === 3;
2786
-
2787
- }
2788
-
2789
2791
  isObjectURL = true;
2790
2792
  const blob = new Blob( [ bufferView ], { type: source.mimeType } );
2791
2793
  sourceURI = URL.createObjectURL( blob );
@@ -2836,9 +2838,6 @@ class GLTFParser {
2836
2838
 
2837
2839
  if ( textureDef.name ) texture.name = textureDef.name;
2838
2840
 
2839
- // When there is definitely no alpha channel in the texture, set RGBFormat to save space.
2840
- if ( ! hasAlpha ) texture.format = RGBFormat;
2841
-
2842
2841
  const samplers = json.samplers || {};
2843
2842
  const sampler = samplers[ textureDef.sampler ] || {};
2844
2843
 
@@ -2847,10 +2846,7 @@ class GLTFParser {
2847
2846
  texture.wrapS = WEBGL_WRAPPINGS[ sampler.wrapS ] || RepeatWrapping;
2848
2847
  texture.wrapT = WEBGL_WRAPPINGS[ sampler.wrapT ] || RepeatWrapping;
2849
2848
 
2850
- parser.associations.set( texture, {
2851
- type: 'textures',
2852
- index: textureIndex
2853
- } );
2849
+ parser.associations.set( texture, { textures: textureIndex } );
2854
2850
 
2855
2851
  return texture;
2856
2852
 
@@ -2923,7 +2919,7 @@ class GLTFParser {
2923
2919
  const geometry = mesh.geometry;
2924
2920
  let material = mesh.material;
2925
2921
 
2926
- const useVertexTangents = geometry.attributes.tangent !== undefined;
2922
+ const useDerivativeTangents = geometry.attributes.tangent === undefined;
2927
2923
  const useVertexColors = geometry.attributes.color !== undefined;
2928
2924
  const useFlatShading = geometry.attributes.normal === undefined;
2929
2925
 
@@ -2968,12 +2964,12 @@ class GLTFParser {
2968
2964
  }
2969
2965
 
2970
2966
  // Clone the material if it will be modified
2971
- if ( useVertexTangents || useVertexColors || useFlatShading ) {
2967
+ if ( useDerivativeTangents || useVertexColors || useFlatShading ) {
2972
2968
 
2973
2969
  let cacheKey = 'ClonedMaterial:' + material.uuid + ':';
2974
2970
 
2975
2971
  if ( material.isGLTFSpecularGlossinessMaterial ) cacheKey += 'specular-glossiness:';
2976
- if ( useVertexTangents ) cacheKey += 'vertex-tangents:';
2972
+ if ( useDerivativeTangents ) cacheKey += 'derivative-tangents:';
2977
2973
  if ( useVertexColors ) cacheKey += 'vertex-colors:';
2978
2974
  if ( useFlatShading ) cacheKey += 'flat-shading:';
2979
2975
 
@@ -2986,7 +2982,7 @@ class GLTFParser {
2986
2982
  if ( useVertexColors ) cachedMaterial.vertexColors = true;
2987
2983
  if ( useFlatShading ) cachedMaterial.flatShading = true;
2988
2984
 
2989
- if ( useVertexTangents ) {
2985
+ if ( useDerivativeTangents ) {
2990
2986
 
2991
2987
  // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
2992
2988
  if ( cachedMaterial.normalScale ) cachedMaterial.normalScale.y *= - 1;
@@ -3133,12 +3129,13 @@ class GLTFParser {
3133
3129
 
3134
3130
  pending.push( parser.assignTexture( materialParams, 'normalMap', materialDef.normalTexture ) );
3135
3131
 
3136
- // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
3137
- materialParams.normalScale = new Vector2( 1, - 1 );
3132
+ materialParams.normalScale = new Vector2( 1, 1 );
3138
3133
 
3139
3134
  if ( materialDef.normalTexture.scale !== undefined ) {
3140
3135
 
3141
- materialParams.normalScale.set( materialDef.normalTexture.scale, - materialDef.normalTexture.scale );
3136
+ const scale = materialDef.normalTexture.scale;
3137
+
3138
+ materialParams.normalScale.set( scale, scale );
3142
3139
 
3143
3140
  }
3144
3141
 
@@ -3190,7 +3187,7 @@ class GLTFParser {
3190
3187
 
3191
3188
  assignExtrasToUserData( material, materialDef );
3192
3189
 
3193
- parser.associations.set( material, { type: 'materials', index: materialIndex } );
3190
+ parser.associations.set( material, { materials: materialIndex } );
3194
3191
 
3195
3192
  if ( materialDef.extensions ) addUnknownExtensionsToUserData( extensions, material, materialDef );
3196
3193
 
@@ -3403,6 +3400,15 @@ class GLTFParser {
3403
3400
 
3404
3401
  }
3405
3402
 
3403
+ for ( let i = 0, il = meshes.length; i < il; i ++ ) {
3404
+
3405
+ parser.associations.set( meshes[ i ], {
3406
+ meshes: meshIndex,
3407
+ primitives: i
3408
+ } );
3409
+
3410
+ }
3411
+
3406
3412
  if ( meshes.length === 1 ) {
3407
3413
 
3408
3414
  return meshes[ 0 ];
@@ -3411,6 +3417,8 @@ class GLTFParser {
3411
3417
 
3412
3418
  const group = new Group();
3413
3419
 
3420
+ parser.associations.set( group, { meshes: meshIndex } );
3421
+
3414
3422
  for ( let i = 0, il = meshes.length; i < il; i ++ ) {
3415
3423
 
3416
3424
  group.add( meshes[ i ] );
@@ -3820,7 +3828,13 @@ class GLTFParser {
3820
3828
 
3821
3829
  }
3822
3830
 
3823
- parser.associations.set( node, { type: 'nodes', index: nodeIndex } );
3831
+ if ( ! parser.associations.has( node ) ) {
3832
+
3833
+ parser.associations.set( node, {} );
3834
+
3835
+ }
3836
+
3837
+ parser.associations.get( node ).nodes = nodeIndex;
3824
3838
 
3825
3839
  return node;
3826
3840
 
@@ -3855,12 +3869,46 @@ class GLTFParser {
3855
3869
 
3856
3870
  for ( let i = 0, il = nodeIds.length; i < il; i ++ ) {
3857
3871
 
3858
- pending.push( buildNodeHierachy( nodeIds[ i ], scene, json, parser ) );
3872
+ pending.push( buildNodeHierarchy( nodeIds[ i ], scene, json, parser ) );
3859
3873
 
3860
3874
  }
3861
3875
 
3862
3876
  return Promise.all( pending ).then( function () {
3863
3877
 
3878
+ // Removes dangling associations, associations that reference a node that
3879
+ // didn't make it into the scene.
3880
+ const reduceAssociations = ( node ) => {
3881
+
3882
+ const reducedAssociations = new Map();
3883
+
3884
+ for ( const [ key, value ] of parser.associations ) {
3885
+
3886
+ if ( key instanceof Material || key instanceof Texture ) {
3887
+
3888
+ reducedAssociations.set( key, value );
3889
+
3890
+ }
3891
+
3892
+ }
3893
+
3894
+ node.traverse( ( node ) => {
3895
+
3896
+ const mappings = parser.associations.get( node );
3897
+
3898
+ if ( mappings != null ) {
3899
+
3900
+ reducedAssociations.set( node, mappings );
3901
+
3902
+ }
3903
+
3904
+ } );
3905
+
3906
+ return reducedAssociations;
3907
+
3908
+ };
3909
+
3910
+ parser.associations = reduceAssociations( scene );
3911
+
3864
3912
  return scene;
3865
3913
 
3866
3914
  } );
@@ -3869,7 +3917,7 @@ class GLTFParser {
3869
3917
 
3870
3918
  }
3871
3919
 
3872
- function buildNodeHierachy( nodeId, parentObject, json, parser ) {
3920
+ function buildNodeHierarchy( nodeId, parentObject, json, parser ) {
3873
3921
 
3874
3922
  const nodeDef = json.nodes[ nodeId ];
3875
3923
 
@@ -3953,7 +4001,7 @@ function buildNodeHierachy( nodeId, parentObject, json, parser ) {
3953
4001
  for ( let i = 0, il = children.length; i < il; i ++ ) {
3954
4002
 
3955
4003
  const child = children[ i ];
3956
- pending.push( buildNodeHierachy( child, node, json, parser ) );
4004
+ pending.push( buildNodeHierarchy( child, node, json, parser ) );
3957
4005
 
3958
4006
  }
3959
4007
 
@@ -15,7 +15,7 @@ import {
15
15
  Vector2,
16
16
  Vector3,
17
17
  Vector4
18
- } from 'three';
18
+ } from '../../../../three/src/Three.js';
19
19
 
20
20
  class Lensflare extends Mesh {
21
21
 
@@ -8,7 +8,7 @@ import {
8
8
  TriangleStripDrawMode,
9
9
  TrianglesDrawMode,
10
10
  Vector3
11
- } from 'three';
11
+ } from '../../../../three/src/Three.js';
12
12
 
13
13
 
14
14
  function computeTangents( geometry ) {
@@ -74,7 +74,7 @@ export default class THREEPBRMaterial extends THREEShaderMaterial {
74
74
  ['start', `
75
75
  ${LightShader.Light}
76
76
  ${RayShader.Ray}
77
- ${PBRShader.PhysicallyBasedMaterial}
77
+ ${PBRShader.MetallicRoughnessMaterial}
78
78
 
79
79
  uniform vec3 baseColor;
80
80
  uniform float metalness;
@@ -94,7 +94,7 @@ export default class THREEPBRMaterial extends THREEShaderMaterial {
94
94
  `],
95
95
  ['main', `
96
96
  ${uniforms.map ? 'vec4 mapTexel = texture2D(map, vUv);' : ''}
97
- vec4 pbrColor = computePBRColor(vViewDirection, light, vPosition, vNormal, PhysicallyBasedMaterial(vec4(${uniforms.map ? 'baseColor * mapTexel.rgb' : 'baseColor'}, ${uniforms.map ? 'opacity * mapTexel.a' : 'opacity'}), metalness, roughness));
97
+ vec4 pbrColor = computePBRColor(vViewDirection, light, vPosition, vNormal, MetallicRoughnessMaterial(vec4(${uniforms.map ? 'baseColor * pow(mapTexel.rgb, vec3(2.2))' : 'baseColor'}, ${uniforms.map ? 'opacity * mapTexel.a' : 'opacity'}), metalness, roughness));
98
98
  `],
99
99
  ['end', `
100
100
  gl_FragColor = pbrColor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@damienmortini/three",
3
- "version": "0.1.131",
3
+ "version": "0.1.135",
4
4
  "description": "Three.js helpers",
5
5
  "scripts": {
6
6
  "install": "npm run copyexamples",
@@ -23,11 +23,11 @@
23
23
  "author": "Damien Mortini",
24
24
  "license": "ISC",
25
25
  "bugs": "https://github.com/damienmortini/lib/issues",
26
- "homepage": "https://github.com/damienmortini/lib/tree/master/packages/three",
26
+ "homepage": "https://github.com/damienmortini/lib/tree/main/packages/three",
27
27
  "dependencies": {
28
- "@damienmortini/core": "^0.2.106",
28
+ "@damienmortini/core": "^0.2.109",
29
29
  "fs-extra": "^10.0.0",
30
- "three": "0.132.2"
30
+ "three": "0.133.1"
31
31
  },
32
- "gitHead": "2629a6ebd623d7cd56684172d8ca6edf1af25eaf"
32
+ "gitHead": "dd17d9989f9a87e1157252c2901a204a5c332fcf"
33
33
  }