three-stdlib 2.23.4 → 2.23.5

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -10,7 +10,9 @@ Stand-alone version of [threejs/examples/jsm](https://github.com/mrdoob/three.js
10
10
 
11
11
  ## Basic usage
12
12
 
13
- npm install three-stdlib
13
+ ```bash
14
+ npm install three-stdlib
15
+ ```
14
16
 
15
17
  ```ts
16
18
  // Export collection
@@ -21,24 +23,33 @@ import { OrbitControls, ... } from 'three-stdlib'
21
23
 
22
24
  ## Problem
23
25
 
24
- `threejs/examples` are usually regarded as something that you copy/paste into your project and adapt to your needs. That's not how people use it, and this has caused numerous issues in the past.
26
+ `three/examples` are usually regarded as something that you copy/paste into your project and adapt to your needs. That's not how people use it, and this has caused numerous issues in the past.
25
27
 
26
28
  ## Solution
27
29
 
28
- - A build system for esm and cjs
29
- - Version managed dependencies
30
+ - A build system for ESM and CJS, compatible with browser, workers, and Node
30
31
  - Class based, optimized for tree-shaking, no globals, exports instead of collections
31
- - Single flatbundle as well as individual transpiles
32
32
  - Typesafety with simple annotation-like types
33
- - CI, tests, linting, formatting (prettier)
33
+ - SemVer and NPM managed dependencies
34
34
 
35
35
  But most importantly, allowing more people that use and rely on these primitives to hold a little stake, and to share the weight of maintaining it.
36
36
 
37
- ## How to contribute
37
+ ## How to Contribute
38
+
39
+ 1. Fork and clone the repo
40
+ 2. Run `yarn install` to install dependencies
41
+ 3. Create a branch for your PR with `git checkout -b pr-type/issue-number-your-branch-name beta
42
+ 4. Let's get cooking! 👨🏻‍🍳🥓
43
+
44
+ ### Commit Guidelines
45
+
46
+ Be sure your commit messages follow this specification: https://conventionalcommits.org/en/v1.0.0-beta.4
47
+
48
+ ## Publishing
38
49
 
39
- If you want to get involved you could do any of the following:
50
+ We use `semantic-release-action` to deploy the package. Because of this only certain commits will trigger the action of creating a release:
40
51
 
41
- - Help to maintain and sync the existing primitives
42
- - Create stories for these examples for our dedicated storybook
43
- - Convert some of the files to Typescript
44
- - Add new examples for the library you think could be helpful for others
52
+ - `chore` will not release a new version
53
+ - `fix:` will create a `0.0.x` version
54
+ - `feat:` will create a `0.x.0` version
55
+ - `BREAKING CHANGE:` will create a `x.0.0` version
@@ -42,6 +42,9 @@ class GLTFLoader extends THREE.Loader {
42
42
  this.register(function(parser) {
43
43
  return new GLTFMaterialsIridescenceExtension(parser);
44
44
  });
45
+ this.register(function(parser) {
46
+ return new GLTFMaterialsAnisotropyExtension(parser);
47
+ });
45
48
  this.register(function(parser) {
46
49
  return new GLTFLightsExtension(parser);
47
50
  });
@@ -129,10 +132,11 @@ class GLTFLoader extends THREE.Loader {
129
132
  let json;
130
133
  const extensions = {};
131
134
  const plugins = {};
135
+ const textDecoder = new TextDecoder();
132
136
  if (typeof data === "string") {
133
137
  json = JSON.parse(data);
134
138
  } else if (data instanceof ArrayBuffer) {
135
- const magic = THREE.LoaderUtils.decodeText(new Uint8Array(data.slice(0, 4)));
139
+ const magic = textDecoder.decode(new Uint8Array(data, 0, 4));
136
140
  if (magic === BINARY_EXTENSION_HEADER_MAGIC) {
137
141
  try {
138
142
  extensions[EXTENSIONS.KHR_BINARY_GLTF] = new GLTFBinaryExtension(data);
@@ -143,7 +147,7 @@ class GLTFLoader extends THREE.Loader {
143
147
  }
144
148
  json = JSON.parse(extensions[EXTENSIONS.KHR_BINARY_GLTF].content);
145
149
  } else {
146
- json = JSON.parse(THREE.LoaderUtils.decodeText(new Uint8Array(data)));
150
+ json = JSON.parse(textDecoder.decode(data));
147
151
  }
148
152
  } else {
149
153
  json = data;
@@ -229,6 +233,7 @@ const EXTENSIONS = {
229
233
  KHR_MATERIALS_SPECULAR: "KHR_materials_specular",
230
234
  KHR_MATERIALS_TRANSMISSION: "KHR_materials_transmission",
231
235
  KHR_MATERIALS_IRIDESCENCE: "KHR_materials_iridescence",
236
+ KHR_MATERIALS_ANISOTROPY: "KHR_materials_anisotropy",
232
237
  KHR_MATERIALS_UNLIT: "KHR_materials_unlit",
233
238
  KHR_MATERIALS_VOLUME: "KHR_materials_volume",
234
239
  KHR_TEXTURE_BASISU: "KHR_texture_basisu",
@@ -343,7 +348,7 @@ class GLTFMaterialsUnlitExtension {
343
348
  materialParams.opacity = array[3];
344
349
  }
345
350
  if (metallicRoughness.baseColorTexture !== void 0) {
346
- pending.push(parser.assignTexture(materialParams, "map", metallicRoughness.baseColorTexture, 3001));
351
+ pending.push(parser.assignTexture(materialParams, "map", metallicRoughness.baseColorTexture, THREE.SRGBColorSpace));
347
352
  }
348
353
  }
349
354
  return Promise.all(pending);
@@ -485,7 +490,7 @@ class GLTFMaterialsSheenExtension {
485
490
  materialParams.sheenRoughness = extension.sheenRoughnessFactor;
486
491
  }
487
492
  if (extension.sheenColorTexture !== void 0) {
488
- pending.push(parser.assignTexture(materialParams, "sheenColorMap", extension.sheenColorTexture, 3001));
493
+ pending.push(parser.assignTexture(materialParams, "sheenColorMap", extension.sheenColorTexture, THREE.SRGBColorSpace));
489
494
  }
490
495
  if (extension.sheenRoughnessTexture !== void 0) {
491
496
  pending.push(parser.assignTexture(materialParams, "sheenRoughnessMap", extension.sheenRoughnessTexture));
@@ -603,13 +608,44 @@ class GLTFMaterialsSpecularExtension {
603
608
  materialParams.specularColor = new THREE.Color(colorArray[0], colorArray[1], colorArray[2]);
604
609
  if (extension.specularColorTexture !== void 0) {
605
610
  pending.push(
606
- parser.assignTexture(materialParams, "specularColorMap", extension.specularColorTexture, 3001)
607
- // sRGBEncoding
611
+ parser.assignTexture(materialParams, "specularColorMap", extension.specularColorTexture, THREE.SRGBColorSpace)
608
612
  );
609
613
  }
610
614
  return Promise.all(pending);
611
615
  }
612
616
  }
617
+ class GLTFMaterialsAnisotropyExtension {
618
+ constructor(parser) {
619
+ this.parser = parser;
620
+ this.name = EXTENSIONS.KHR_MATERIALS_ANISOTROPY;
621
+ }
622
+ getMaterialType(materialIndex) {
623
+ const parser = this.parser;
624
+ const materialDef = parser.json.materials[materialIndex];
625
+ if (!materialDef.extensions || !materialDef.extensions[this.name])
626
+ return null;
627
+ return THREE.MeshPhysicalMaterial;
628
+ }
629
+ extendMaterialParams(materialIndex, materialParams) {
630
+ const parser = this.parser;
631
+ const materialDef = parser.json.materials[materialIndex];
632
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) {
633
+ return Promise.resolve();
634
+ }
635
+ const pending = [];
636
+ const extension = materialDef.extensions[this.name];
637
+ if (extension.anisotropyStrength !== void 0) {
638
+ materialParams.anisotropy = extension.anisotropyStrength;
639
+ }
640
+ if (extension.anisotropyRotation !== void 0) {
641
+ materialParams.anisotropyRotation = extension.anisotropyRotation;
642
+ }
643
+ if (extension.anisotropyTexture !== void 0) {
644
+ pending.push(parser.assignTexture(materialParams, "anisotropyMap", extension.anisotropyTexture));
645
+ }
646
+ return Promise.all(pending);
647
+ }
648
+ }
613
649
  class GLTFTextureBasisUExtension {
614
650
  constructor(parser) {
615
651
  this.parser = parser;
@@ -854,8 +890,9 @@ class GLTFBinaryExtension {
854
890
  this.content = null;
855
891
  this.body = null;
856
892
  const headerView = new DataView(data, 0, BINARY_EXTENSION_HEADER_LENGTH);
893
+ const textDecoder = new TextDecoder();
857
894
  this.header = {
858
- magic: THREE.LoaderUtils.decodeText(new Uint8Array(data.slice(0, 4))),
895
+ magic: textDecoder.decode(new Uint8Array(data.slice(0, 4))),
859
896
  version: headerView.getUint32(4, true),
860
897
  length: headerView.getUint32(8, true)
861
898
  };
@@ -874,7 +911,7 @@ class GLTFBinaryExtension {
874
911
  chunkIndex += 4;
875
912
  if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON) {
876
913
  const contentArray = new Uint8Array(data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength);
877
- this.content = THREE.LoaderUtils.decodeText(contentArray);
914
+ this.content = textDecoder.decode(contentArray);
878
915
  } else if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN) {
879
916
  const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
880
917
  this.body = data.slice(byteOffset, byteOffset + chunkLength);
@@ -1004,7 +1041,7 @@ class GLTFCubicSplineInterpolant extends THREE.Interpolant {
1004
1041
  return result;
1005
1042
  }
1006
1043
  }
1007
- const _q = /* @__PURE__ */ new THREE.Quaternion();
1044
+ const _q = new THREE.Quaternion();
1008
1045
  class GLTFCubicSplineQuaternionInterpolant extends GLTFCubicSplineInterpolant {
1009
1046
  interpolate_(i1, t0, t, t1) {
1010
1047
  const result = super.interpolate_(i1, t0, t, t1);
@@ -1067,18 +1104,10 @@ const ATTRIBUTES = {
1067
1104
  POSITION: "position",
1068
1105
  NORMAL: "normal",
1069
1106
  TANGENT: "tangent",
1070
- // uv => uv1, 4 uv channels
1071
- // https://github.com/mrdoob/three.js/pull/25943
1072
- // https://github.com/mrdoob/three.js/pull/25788
1073
- ...THREE.REVISION.replace(/\D+/g, "") >= 152 ? {
1074
- TEXCOORD_0: "uv",
1075
- TEXCOORD_1: "uv1",
1076
- TEXCOORD_2: "uv2",
1077
- TEXCOORD_3: "uv3"
1078
- } : {
1079
- TEXCOORD_0: "uv",
1080
- TEXCOORD_1: "uv2"
1081
- },
1107
+ TEXCOORD_0: "uv",
1108
+ TEXCOORD_1: "uv1",
1109
+ TEXCOORD_2: "uv2",
1110
+ TEXCOORD_3: "uv3",
1082
1111
  COLOR_0: "color",
1083
1112
  WEIGHTS_0: "skinWeight",
1084
1113
  JOINTS_0: "skinIndex"
@@ -1205,13 +1234,18 @@ function updateMorphTargets(mesh, meshDef) {
1205
1234
  }
1206
1235
  }
1207
1236
  function createPrimitiveKey(primitiveDef) {
1208
- const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION];
1209
1237
  let geometryKey;
1238
+ const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION];
1210
1239
  if (dracoExtension) {
1211
1240
  geometryKey = "draco:" + dracoExtension.bufferView + ":" + dracoExtension.indices + ":" + createAttributesKey(dracoExtension.attributes);
1212
1241
  } else {
1213
1242
  geometryKey = primitiveDef.indices + ":" + createAttributesKey(primitiveDef.attributes) + ":" + primitiveDef.mode;
1214
1243
  }
1244
+ if (primitiveDef.targets !== void 0) {
1245
+ for (let i = 0, il = primitiveDef.targets.length; i < il; i++) {
1246
+ geometryKey += ":" + createAttributesKey(primitiveDef.targets[i]);
1247
+ }
1248
+ }
1215
1249
  return geometryKey;
1216
1250
  }
1217
1251
  function createAttributesKey(attributes) {
@@ -1243,7 +1277,7 @@ function getImageURIMimeType(uri) {
1243
1277
  return "image/webp";
1244
1278
  return "image/png";
1245
1279
  }
1246
- const _identityMatrix = /* @__PURE__ */ new THREE.Matrix4();
1280
+ const _identityMatrix = new THREE.Matrix4();
1247
1281
  class GLTFParser {
1248
1282
  constructor(json = {}, options = {}) {
1249
1283
  this.json = json;
@@ -1725,7 +1759,7 @@ class GLTFParser {
1725
1759
  * @param {Object} mapDef
1726
1760
  * @return {Promise<Texture>}
1727
1761
  */
1728
- assignTexture(materialParams, mapName, mapDef, encoding) {
1762
+ assignTexture(materialParams, mapName, mapDef, colorSpace) {
1729
1763
  const parser = this;
1730
1764
  return this.getDependency("texture", mapDef.index).then(function(texture) {
1731
1765
  if (!texture)
@@ -1742,11 +1776,8 @@ class GLTFParser {
1742
1776
  parser.associations.set(texture, gltfReference);
1743
1777
  }
1744
1778
  }
1745
- if (encoding !== void 0) {
1746
- if ("colorSpace" in texture)
1747
- texture.colorSpace = encoding === 3001 ? "srgb" : "srgb-linear";
1748
- else
1749
- texture.encoding = encoding;
1779
+ if (colorSpace !== void 0) {
1780
+ texture.colorSpace = colorSpace;
1750
1781
  }
1751
1782
  materialParams[mapName] = texture;
1752
1783
  return texture;
@@ -1849,7 +1880,7 @@ class GLTFParser {
1849
1880
  materialParams.opacity = array[3];
1850
1881
  }
1851
1882
  if (metallicRoughness.baseColorTexture !== void 0) {
1852
- pending.push(parser.assignTexture(materialParams, "map", metallicRoughness.baseColorTexture, 3001));
1883
+ pending.push(parser.assignTexture(materialParams, "map", metallicRoughness.baseColorTexture, THREE.SRGBColorSpace));
1853
1884
  }
1854
1885
  materialParams.metalness = metallicRoughness.metallicFactor !== void 0 ? metallicRoughness.metallicFactor : 1;
1855
1886
  materialParams.roughness = metallicRoughness.roughnessFactor !== void 0 ? metallicRoughness.roughnessFactor : 1;
@@ -1899,7 +1930,7 @@ class GLTFParser {
1899
1930
  materialParams.emissive = new THREE.Color().fromArray(materialDef.emissiveFactor);
1900
1931
  }
1901
1932
  if (materialDef.emissiveTexture !== void 0 && materialType !== THREE.MeshBasicMaterial) {
1902
- pending.push(parser.assignTexture(materialParams, "emissiveMap", materialDef.emissiveTexture, 3001));
1933
+ pending.push(parser.assignTexture(materialParams, "emissiveMap", materialDef.emissiveTexture, THREE.SRGBColorSpace));
1903
1934
  }
1904
1935
  return Promise.all(pending).then(function() {
1905
1936
  const material = new materialType(materialParams);
@@ -1915,12 +1946,12 @@ class GLTFParser {
1915
1946
  /** When Object3D instances are targeted by animation, they need unique names. */
1916
1947
  createUniqueName(originalName) {
1917
1948
  const sanitizedName = THREE.PropertyBinding.sanitizeNodeName(originalName || "");
1918
- let name = sanitizedName;
1919
- for (let i = 1; this.nodeNamesUsed[name]; ++i) {
1920
- name = sanitizedName + "_" + i;
1949
+ if (sanitizedName in this.nodeNamesUsed) {
1950
+ return sanitizedName + "_" + ++this.nodeNamesUsed[sanitizedName];
1951
+ } else {
1952
+ this.nodeNamesUsed[sanitizedName] = 0;
1953
+ return sanitizedName;
1921
1954
  }
1922
- this.nodeNamesUsed[name] = true;
1923
- return name;
1924
1955
  }
1925
1956
  /**
1926
1957
  * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
@@ -2023,9 +2054,13 @@ class GLTFParser {
2023
2054
  });
2024
2055
  }
2025
2056
  if (meshes.length === 1) {
2057
+ if (meshDef.extensions)
2058
+ addUnknownExtensionsToUserData(extensions, meshes[0], meshDef);
2026
2059
  return meshes[0];
2027
2060
  }
2028
2061
  const group = new THREE.Group();
2062
+ if (meshDef.extensions)
2063
+ addUnknownExtensionsToUserData(extensions, group, meshDef);
2029
2064
  parser.associations.set(group, { meshes: meshIndex });
2030
2065
  for (let i = 0, il = meshes.length; i < il; i++) {
2031
2066
  group.add(meshes[i]);
@@ -1,4 +1,4 @@
1
- import { Loader, LoaderUtils, FileLoader, Color, SpotLight, PointLight, DirectionalLight, MeshBasicMaterial, MeshPhysicalMaterial, Vector2, Matrix4, Vector3, Quaternion, InstancedMesh, Object3D, Interpolant, NearestFilter, LinearFilter, NearestMipmapNearestFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, LinearMipmapLinearFilter, ClampToEdgeWrapping, MirroredRepeatWrapping, RepeatWrapping, REVISION, InterpolateLinear, InterpolateDiscrete, MeshStandardMaterial, FrontSide, TextureLoader, ImageBitmapLoader, BufferAttribute, InterleavedBuffer, InterleavedBufferAttribute, Texture, PointsMaterial, Material, LineBasicMaterial, DoubleSide, PropertyBinding, BufferGeometry, SkinnedMesh, Mesh, TriangleStripDrawMode, TriangleFanDrawMode, LineSegments, Line, LineLoop, Points, Group, PerspectiveCamera, MathUtils, OrthographicCamera, Skeleton, VectorKeyframeTrack, QuaternionKeyframeTrack, NumberKeyframeTrack, AnimationClip, Bone, Box3, Sphere } from "three";
1
+ import { Loader, LoaderUtils, FileLoader, Color, SpotLight, PointLight, DirectionalLight, MeshBasicMaterial, SRGBColorSpace, MeshPhysicalMaterial, Vector2, Matrix4, Vector3, Quaternion, InstancedMesh, Object3D, Interpolant, NearestFilter, LinearFilter, NearestMipmapNearestFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, LinearMipmapLinearFilter, ClampToEdgeWrapping, MirroredRepeatWrapping, RepeatWrapping, InterpolateLinear, InterpolateDiscrete, MeshStandardMaterial, FrontSide, TextureLoader, ImageBitmapLoader, BufferAttribute, InterleavedBuffer, InterleavedBufferAttribute, Texture, PointsMaterial, Material, LineBasicMaterial, DoubleSide, PropertyBinding, BufferGeometry, SkinnedMesh, Mesh, TriangleStripDrawMode, TriangleFanDrawMode, LineSegments, Line, LineLoop, Points, Group, PerspectiveCamera, MathUtils, OrthographicCamera, Skeleton, VectorKeyframeTrack, QuaternionKeyframeTrack, NumberKeyframeTrack, AnimationClip, Bone, Box3, Sphere } from "three";
2
2
  import { toTrianglesDrawMode } from "../utils/BufferGeometryUtils.js";
3
3
  class GLTFLoader extends Loader {
4
4
  constructor(manager) {
@@ -40,6 +40,9 @@ class GLTFLoader extends Loader {
40
40
  this.register(function(parser) {
41
41
  return new GLTFMaterialsIridescenceExtension(parser);
42
42
  });
43
+ this.register(function(parser) {
44
+ return new GLTFMaterialsAnisotropyExtension(parser);
45
+ });
43
46
  this.register(function(parser) {
44
47
  return new GLTFLightsExtension(parser);
45
48
  });
@@ -127,10 +130,11 @@ class GLTFLoader extends Loader {
127
130
  let json;
128
131
  const extensions = {};
129
132
  const plugins = {};
133
+ const textDecoder = new TextDecoder();
130
134
  if (typeof data === "string") {
131
135
  json = JSON.parse(data);
132
136
  } else if (data instanceof ArrayBuffer) {
133
- const magic = LoaderUtils.decodeText(new Uint8Array(data.slice(0, 4)));
137
+ const magic = textDecoder.decode(new Uint8Array(data, 0, 4));
134
138
  if (magic === BINARY_EXTENSION_HEADER_MAGIC) {
135
139
  try {
136
140
  extensions[EXTENSIONS.KHR_BINARY_GLTF] = new GLTFBinaryExtension(data);
@@ -141,7 +145,7 @@ class GLTFLoader extends Loader {
141
145
  }
142
146
  json = JSON.parse(extensions[EXTENSIONS.KHR_BINARY_GLTF].content);
143
147
  } else {
144
- json = JSON.parse(LoaderUtils.decodeText(new Uint8Array(data)));
148
+ json = JSON.parse(textDecoder.decode(data));
145
149
  }
146
150
  } else {
147
151
  json = data;
@@ -227,6 +231,7 @@ const EXTENSIONS = {
227
231
  KHR_MATERIALS_SPECULAR: "KHR_materials_specular",
228
232
  KHR_MATERIALS_TRANSMISSION: "KHR_materials_transmission",
229
233
  KHR_MATERIALS_IRIDESCENCE: "KHR_materials_iridescence",
234
+ KHR_MATERIALS_ANISOTROPY: "KHR_materials_anisotropy",
230
235
  KHR_MATERIALS_UNLIT: "KHR_materials_unlit",
231
236
  KHR_MATERIALS_VOLUME: "KHR_materials_volume",
232
237
  KHR_TEXTURE_BASISU: "KHR_texture_basisu",
@@ -341,7 +346,7 @@ class GLTFMaterialsUnlitExtension {
341
346
  materialParams.opacity = array[3];
342
347
  }
343
348
  if (metallicRoughness.baseColorTexture !== void 0) {
344
- pending.push(parser.assignTexture(materialParams, "map", metallicRoughness.baseColorTexture, 3001));
349
+ pending.push(parser.assignTexture(materialParams, "map", metallicRoughness.baseColorTexture, SRGBColorSpace));
345
350
  }
346
351
  }
347
352
  return Promise.all(pending);
@@ -483,7 +488,7 @@ class GLTFMaterialsSheenExtension {
483
488
  materialParams.sheenRoughness = extension.sheenRoughnessFactor;
484
489
  }
485
490
  if (extension.sheenColorTexture !== void 0) {
486
- pending.push(parser.assignTexture(materialParams, "sheenColorMap", extension.sheenColorTexture, 3001));
491
+ pending.push(parser.assignTexture(materialParams, "sheenColorMap", extension.sheenColorTexture, SRGBColorSpace));
487
492
  }
488
493
  if (extension.sheenRoughnessTexture !== void 0) {
489
494
  pending.push(parser.assignTexture(materialParams, "sheenRoughnessMap", extension.sheenRoughnessTexture));
@@ -601,13 +606,44 @@ class GLTFMaterialsSpecularExtension {
601
606
  materialParams.specularColor = new Color(colorArray[0], colorArray[1], colorArray[2]);
602
607
  if (extension.specularColorTexture !== void 0) {
603
608
  pending.push(
604
- parser.assignTexture(materialParams, "specularColorMap", extension.specularColorTexture, 3001)
605
- // sRGBEncoding
609
+ parser.assignTexture(materialParams, "specularColorMap", extension.specularColorTexture, SRGBColorSpace)
606
610
  );
607
611
  }
608
612
  return Promise.all(pending);
609
613
  }
610
614
  }
615
+ class GLTFMaterialsAnisotropyExtension {
616
+ constructor(parser) {
617
+ this.parser = parser;
618
+ this.name = EXTENSIONS.KHR_MATERIALS_ANISOTROPY;
619
+ }
620
+ getMaterialType(materialIndex) {
621
+ const parser = this.parser;
622
+ const materialDef = parser.json.materials[materialIndex];
623
+ if (!materialDef.extensions || !materialDef.extensions[this.name])
624
+ return null;
625
+ return MeshPhysicalMaterial;
626
+ }
627
+ extendMaterialParams(materialIndex, materialParams) {
628
+ const parser = this.parser;
629
+ const materialDef = parser.json.materials[materialIndex];
630
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) {
631
+ return Promise.resolve();
632
+ }
633
+ const pending = [];
634
+ const extension = materialDef.extensions[this.name];
635
+ if (extension.anisotropyStrength !== void 0) {
636
+ materialParams.anisotropy = extension.anisotropyStrength;
637
+ }
638
+ if (extension.anisotropyRotation !== void 0) {
639
+ materialParams.anisotropyRotation = extension.anisotropyRotation;
640
+ }
641
+ if (extension.anisotropyTexture !== void 0) {
642
+ pending.push(parser.assignTexture(materialParams, "anisotropyMap", extension.anisotropyTexture));
643
+ }
644
+ return Promise.all(pending);
645
+ }
646
+ }
611
647
  class GLTFTextureBasisUExtension {
612
648
  constructor(parser) {
613
649
  this.parser = parser;
@@ -852,8 +888,9 @@ class GLTFBinaryExtension {
852
888
  this.content = null;
853
889
  this.body = null;
854
890
  const headerView = new DataView(data, 0, BINARY_EXTENSION_HEADER_LENGTH);
891
+ const textDecoder = new TextDecoder();
855
892
  this.header = {
856
- magic: LoaderUtils.decodeText(new Uint8Array(data.slice(0, 4))),
893
+ magic: textDecoder.decode(new Uint8Array(data.slice(0, 4))),
857
894
  version: headerView.getUint32(4, true),
858
895
  length: headerView.getUint32(8, true)
859
896
  };
@@ -872,7 +909,7 @@ class GLTFBinaryExtension {
872
909
  chunkIndex += 4;
873
910
  if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON) {
874
911
  const contentArray = new Uint8Array(data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength);
875
- this.content = LoaderUtils.decodeText(contentArray);
912
+ this.content = textDecoder.decode(contentArray);
876
913
  } else if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN) {
877
914
  const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
878
915
  this.body = data.slice(byteOffset, byteOffset + chunkLength);
@@ -1002,7 +1039,7 @@ class GLTFCubicSplineInterpolant extends Interpolant {
1002
1039
  return result;
1003
1040
  }
1004
1041
  }
1005
- const _q = /* @__PURE__ */ new Quaternion();
1042
+ const _q = new Quaternion();
1006
1043
  class GLTFCubicSplineQuaternionInterpolant extends GLTFCubicSplineInterpolant {
1007
1044
  interpolate_(i1, t0, t, t1) {
1008
1045
  const result = super.interpolate_(i1, t0, t, t1);
@@ -1065,18 +1102,10 @@ const ATTRIBUTES = {
1065
1102
  POSITION: "position",
1066
1103
  NORMAL: "normal",
1067
1104
  TANGENT: "tangent",
1068
- // uv => uv1, 4 uv channels
1069
- // https://github.com/mrdoob/three.js/pull/25943
1070
- // https://github.com/mrdoob/three.js/pull/25788
1071
- ...REVISION.replace(/\D+/g, "") >= 152 ? {
1072
- TEXCOORD_0: "uv",
1073
- TEXCOORD_1: "uv1",
1074
- TEXCOORD_2: "uv2",
1075
- TEXCOORD_3: "uv3"
1076
- } : {
1077
- TEXCOORD_0: "uv",
1078
- TEXCOORD_1: "uv2"
1079
- },
1105
+ TEXCOORD_0: "uv",
1106
+ TEXCOORD_1: "uv1",
1107
+ TEXCOORD_2: "uv2",
1108
+ TEXCOORD_3: "uv3",
1080
1109
  COLOR_0: "color",
1081
1110
  WEIGHTS_0: "skinWeight",
1082
1111
  JOINTS_0: "skinIndex"
@@ -1203,13 +1232,18 @@ function updateMorphTargets(mesh, meshDef) {
1203
1232
  }
1204
1233
  }
1205
1234
  function createPrimitiveKey(primitiveDef) {
1206
- const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION];
1207
1235
  let geometryKey;
1236
+ const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION];
1208
1237
  if (dracoExtension) {
1209
1238
  geometryKey = "draco:" + dracoExtension.bufferView + ":" + dracoExtension.indices + ":" + createAttributesKey(dracoExtension.attributes);
1210
1239
  } else {
1211
1240
  geometryKey = primitiveDef.indices + ":" + createAttributesKey(primitiveDef.attributes) + ":" + primitiveDef.mode;
1212
1241
  }
1242
+ if (primitiveDef.targets !== void 0) {
1243
+ for (let i = 0, il = primitiveDef.targets.length; i < il; i++) {
1244
+ geometryKey += ":" + createAttributesKey(primitiveDef.targets[i]);
1245
+ }
1246
+ }
1213
1247
  return geometryKey;
1214
1248
  }
1215
1249
  function createAttributesKey(attributes) {
@@ -1241,7 +1275,7 @@ function getImageURIMimeType(uri) {
1241
1275
  return "image/webp";
1242
1276
  return "image/png";
1243
1277
  }
1244
- const _identityMatrix = /* @__PURE__ */ new Matrix4();
1278
+ const _identityMatrix = new Matrix4();
1245
1279
  class GLTFParser {
1246
1280
  constructor(json = {}, options = {}) {
1247
1281
  this.json = json;
@@ -1723,7 +1757,7 @@ class GLTFParser {
1723
1757
  * @param {Object} mapDef
1724
1758
  * @return {Promise<Texture>}
1725
1759
  */
1726
- assignTexture(materialParams, mapName, mapDef, encoding) {
1760
+ assignTexture(materialParams, mapName, mapDef, colorSpace) {
1727
1761
  const parser = this;
1728
1762
  return this.getDependency("texture", mapDef.index).then(function(texture) {
1729
1763
  if (!texture)
@@ -1740,11 +1774,8 @@ class GLTFParser {
1740
1774
  parser.associations.set(texture, gltfReference);
1741
1775
  }
1742
1776
  }
1743
- if (encoding !== void 0) {
1744
- if ("colorSpace" in texture)
1745
- texture.colorSpace = encoding === 3001 ? "srgb" : "srgb-linear";
1746
- else
1747
- texture.encoding = encoding;
1777
+ if (colorSpace !== void 0) {
1778
+ texture.colorSpace = colorSpace;
1748
1779
  }
1749
1780
  materialParams[mapName] = texture;
1750
1781
  return texture;
@@ -1847,7 +1878,7 @@ class GLTFParser {
1847
1878
  materialParams.opacity = array[3];
1848
1879
  }
1849
1880
  if (metallicRoughness.baseColorTexture !== void 0) {
1850
- pending.push(parser.assignTexture(materialParams, "map", metallicRoughness.baseColorTexture, 3001));
1881
+ pending.push(parser.assignTexture(materialParams, "map", metallicRoughness.baseColorTexture, SRGBColorSpace));
1851
1882
  }
1852
1883
  materialParams.metalness = metallicRoughness.metallicFactor !== void 0 ? metallicRoughness.metallicFactor : 1;
1853
1884
  materialParams.roughness = metallicRoughness.roughnessFactor !== void 0 ? metallicRoughness.roughnessFactor : 1;
@@ -1897,7 +1928,7 @@ class GLTFParser {
1897
1928
  materialParams.emissive = new Color().fromArray(materialDef.emissiveFactor);
1898
1929
  }
1899
1930
  if (materialDef.emissiveTexture !== void 0 && materialType !== MeshBasicMaterial) {
1900
- pending.push(parser.assignTexture(materialParams, "emissiveMap", materialDef.emissiveTexture, 3001));
1931
+ pending.push(parser.assignTexture(materialParams, "emissiveMap", materialDef.emissiveTexture, SRGBColorSpace));
1901
1932
  }
1902
1933
  return Promise.all(pending).then(function() {
1903
1934
  const material = new materialType(materialParams);
@@ -1913,12 +1944,12 @@ class GLTFParser {
1913
1944
  /** When Object3D instances are targeted by animation, they need unique names. */
1914
1945
  createUniqueName(originalName) {
1915
1946
  const sanitizedName = PropertyBinding.sanitizeNodeName(originalName || "");
1916
- let name = sanitizedName;
1917
- for (let i = 1; this.nodeNamesUsed[name]; ++i) {
1918
- name = sanitizedName + "_" + i;
1947
+ if (sanitizedName in this.nodeNamesUsed) {
1948
+ return sanitizedName + "_" + ++this.nodeNamesUsed[sanitizedName];
1949
+ } else {
1950
+ this.nodeNamesUsed[sanitizedName] = 0;
1951
+ return sanitizedName;
1919
1952
  }
1920
- this.nodeNamesUsed[name] = true;
1921
- return name;
1922
1953
  }
1923
1954
  /**
1924
1955
  * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
@@ -2021,9 +2052,13 @@ class GLTFParser {
2021
2052
  });
2022
2053
  }
2023
2054
  if (meshes.length === 1) {
2055
+ if (meshDef.extensions)
2056
+ addUnknownExtensionsToUserData(extensions, meshes[0], meshDef);
2024
2057
  return meshes[0];
2025
2058
  }
2026
2059
  const group = new Group();
2060
+ if (meshDef.extensions)
2061
+ addUnknownExtensionsToUserData(extensions, group, meshDef);
2027
2062
  parser.associations.set(group, { meshes: meshIndex });
2028
2063
  for (let i = 0, il = meshes.length; i < il; i++) {
2029
2064
  group.add(meshes[i]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-stdlib",
3
- "version": "2.23.4",
3
+ "version": "2.23.5",
4
4
  "description": "stand-alone library of threejs examples",
5
5
  "keywords": [
6
6
  "three",