three-stdlib 2.23.4 → 2.23.6
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +23 -12
- package/loaders/GLTFLoader.cjs +51 -6
- package/loaders/GLTFLoader.js +51 -6
- package/package.json +1 -1
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
|
-
|
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
|
-
`
|
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
|
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
|
-
-
|
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
|
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
|
-
|
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
|
-
-
|
42
|
-
-
|
43
|
-
-
|
44
|
-
-
|
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
|
package/loaders/GLTFLoader.cjs
CHANGED
@@ -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
|
});
|
@@ -229,6 +232,7 @@ const EXTENSIONS = {
|
|
229
232
|
KHR_MATERIALS_SPECULAR: "KHR_materials_specular",
|
230
233
|
KHR_MATERIALS_TRANSMISSION: "KHR_materials_transmission",
|
231
234
|
KHR_MATERIALS_IRIDESCENCE: "KHR_materials_iridescence",
|
235
|
+
KHR_MATERIALS_ANISOTROPY: "KHR_materials_anisotropy",
|
232
236
|
KHR_MATERIALS_UNLIT: "KHR_materials_unlit",
|
233
237
|
KHR_MATERIALS_VOLUME: "KHR_materials_volume",
|
234
238
|
KHR_TEXTURE_BASISU: "KHR_texture_basisu",
|
@@ -610,6 +614,38 @@ class GLTFMaterialsSpecularExtension {
|
|
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;
|
@@ -1205,13 +1241,18 @@ function updateMorphTargets(mesh, meshDef) {
|
|
1205
1241
|
}
|
1206
1242
|
}
|
1207
1243
|
function createPrimitiveKey(primitiveDef) {
|
1208
|
-
const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION];
|
1209
1244
|
let geometryKey;
|
1245
|
+
const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION];
|
1210
1246
|
if (dracoExtension) {
|
1211
1247
|
geometryKey = "draco:" + dracoExtension.bufferView + ":" + dracoExtension.indices + ":" + createAttributesKey(dracoExtension.attributes);
|
1212
1248
|
} else {
|
1213
1249
|
geometryKey = primitiveDef.indices + ":" + createAttributesKey(primitiveDef.attributes) + ":" + primitiveDef.mode;
|
1214
1250
|
}
|
1251
|
+
if (primitiveDef.targets !== void 0) {
|
1252
|
+
for (let i = 0, il = primitiveDef.targets.length; i < il; i++) {
|
1253
|
+
geometryKey += ":" + createAttributesKey(primitiveDef.targets[i]);
|
1254
|
+
}
|
1255
|
+
}
|
1215
1256
|
return geometryKey;
|
1216
1257
|
}
|
1217
1258
|
function createAttributesKey(attributes) {
|
@@ -1915,12 +1956,12 @@ class GLTFParser {
|
|
1915
1956
|
/** When Object3D instances are targeted by animation, they need unique names. */
|
1916
1957
|
createUniqueName(originalName) {
|
1917
1958
|
const sanitizedName = THREE.PropertyBinding.sanitizeNodeName(originalName || "");
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1959
|
+
if (sanitizedName in this.nodeNamesUsed) {
|
1960
|
+
return sanitizedName + "_" + ++this.nodeNamesUsed[sanitizedName];
|
1961
|
+
} else {
|
1962
|
+
this.nodeNamesUsed[sanitizedName] = 0;
|
1963
|
+
return sanitizedName;
|
1921
1964
|
}
|
1922
|
-
this.nodeNamesUsed[name] = true;
|
1923
|
-
return name;
|
1924
1965
|
}
|
1925
1966
|
/**
|
1926
1967
|
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
|
@@ -2023,9 +2064,13 @@ class GLTFParser {
|
|
2023
2064
|
});
|
2024
2065
|
}
|
2025
2066
|
if (meshes.length === 1) {
|
2067
|
+
if (meshDef.extensions)
|
2068
|
+
addUnknownExtensionsToUserData(extensions, meshes[0], meshDef);
|
2026
2069
|
return meshes[0];
|
2027
2070
|
}
|
2028
2071
|
const group = new THREE.Group();
|
2072
|
+
if (meshDef.extensions)
|
2073
|
+
addUnknownExtensionsToUserData(extensions, group, meshDef);
|
2029
2074
|
parser.associations.set(group, { meshes: meshIndex });
|
2030
2075
|
for (let i = 0, il = meshes.length; i < il; i++) {
|
2031
2076
|
group.add(meshes[i]);
|
package/loaders/GLTFLoader.js
CHANGED
@@ -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
|
});
|
@@ -227,6 +230,7 @@ const EXTENSIONS = {
|
|
227
230
|
KHR_MATERIALS_SPECULAR: "KHR_materials_specular",
|
228
231
|
KHR_MATERIALS_TRANSMISSION: "KHR_materials_transmission",
|
229
232
|
KHR_MATERIALS_IRIDESCENCE: "KHR_materials_iridescence",
|
233
|
+
KHR_MATERIALS_ANISOTROPY: "KHR_materials_anisotropy",
|
230
234
|
KHR_MATERIALS_UNLIT: "KHR_materials_unlit",
|
231
235
|
KHR_MATERIALS_VOLUME: "KHR_materials_volume",
|
232
236
|
KHR_TEXTURE_BASISU: "KHR_texture_basisu",
|
@@ -608,6 +612,38 @@ class GLTFMaterialsSpecularExtension {
|
|
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;
|
@@ -1203,13 +1239,18 @@ function updateMorphTargets(mesh, meshDef) {
|
|
1203
1239
|
}
|
1204
1240
|
}
|
1205
1241
|
function createPrimitiveKey(primitiveDef) {
|
1206
|
-
const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION];
|
1207
1242
|
let geometryKey;
|
1243
|
+
const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION];
|
1208
1244
|
if (dracoExtension) {
|
1209
1245
|
geometryKey = "draco:" + dracoExtension.bufferView + ":" + dracoExtension.indices + ":" + createAttributesKey(dracoExtension.attributes);
|
1210
1246
|
} else {
|
1211
1247
|
geometryKey = primitiveDef.indices + ":" + createAttributesKey(primitiveDef.attributes) + ":" + primitiveDef.mode;
|
1212
1248
|
}
|
1249
|
+
if (primitiveDef.targets !== void 0) {
|
1250
|
+
for (let i = 0, il = primitiveDef.targets.length; i < il; i++) {
|
1251
|
+
geometryKey += ":" + createAttributesKey(primitiveDef.targets[i]);
|
1252
|
+
}
|
1253
|
+
}
|
1213
1254
|
return geometryKey;
|
1214
1255
|
}
|
1215
1256
|
function createAttributesKey(attributes) {
|
@@ -1913,12 +1954,12 @@ class GLTFParser {
|
|
1913
1954
|
/** When Object3D instances are targeted by animation, they need unique names. */
|
1914
1955
|
createUniqueName(originalName) {
|
1915
1956
|
const sanitizedName = PropertyBinding.sanitizeNodeName(originalName || "");
|
1916
|
-
|
1917
|
-
|
1918
|
-
|
1957
|
+
if (sanitizedName in this.nodeNamesUsed) {
|
1958
|
+
return sanitizedName + "_" + ++this.nodeNamesUsed[sanitizedName];
|
1959
|
+
} else {
|
1960
|
+
this.nodeNamesUsed[sanitizedName] = 0;
|
1961
|
+
return sanitizedName;
|
1919
1962
|
}
|
1920
|
-
this.nodeNamesUsed[name] = true;
|
1921
|
-
return name;
|
1922
1963
|
}
|
1923
1964
|
/**
|
1924
1965
|
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
|
@@ -2021,9 +2062,13 @@ class GLTFParser {
|
|
2021
2062
|
});
|
2022
2063
|
}
|
2023
2064
|
if (meshes.length === 1) {
|
2065
|
+
if (meshDef.extensions)
|
2066
|
+
addUnknownExtensionsToUserData(extensions, meshes[0], meshDef);
|
2024
2067
|
return meshes[0];
|
2025
2068
|
}
|
2026
2069
|
const group = new Group();
|
2070
|
+
if (meshDef.extensions)
|
2071
|
+
addUnknownExtensionsToUserData(extensions, group, meshDef);
|
2027
2072
|
parser.associations.set(group, { meshes: meshIndex });
|
2028
2073
|
for (let i = 0, il = meshes.length; i < il; i++) {
|
2029
2074
|
group.add(meshes[i]);
|