@loaders.gl/gltf 4.2.0-alpha.4 → 4.2.0-alpha.6
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/dist/dist.dev.js +1056 -524
- package/dist/dist.min.js +9 -0
- package/dist/glb-loader.d.ts +2 -2
- package/dist/glb-loader.d.ts.map +1 -1
- package/dist/glb-loader.js +22 -21
- package/dist/glb-writer.d.ts +2 -2
- package/dist/glb-writer.d.ts.map +1 -1
- package/dist/glb-writer.js +27 -24
- package/dist/gltf-loader.d.ts +3 -3
- package/dist/gltf-loader.d.ts.map +1 -1
- package/dist/gltf-loader.js +31 -36
- package/dist/gltf-writer.js +24 -26
- package/dist/index.cjs +138 -330
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +17 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/api/gltf-extensions.d.ts +2 -2
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/lib/api/gltf-extensions.js +45 -22
- package/dist/lib/api/gltf-scenegraph.d.ts +2 -2
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
- package/dist/lib/api/gltf-scenegraph.js +565 -438
- package/dist/lib/api/normalize-gltf-v1.js +249 -181
- package/dist/lib/api/post-process-gltf.d.ts +3 -3
- package/dist/lib/api/post-process-gltf.d.ts.map +1 -1
- package/dist/lib/api/post-process-gltf.js +378 -340
- package/dist/lib/encoders/encode-glb.js +62 -48
- package/dist/lib/encoders/encode-gltf.js +24 -10
- package/dist/lib/extensions/EXT_mesh_features.d.ts +2 -2
- package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_mesh_features.js +55 -33
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +2 -2
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js +27 -31
- package/dist/lib/extensions/EXT_structural_metadata.d.ts +2 -2
- package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_structural_metadata.js +434 -230
- package/dist/lib/extensions/EXT_texture_webp.d.ts +2 -2
- package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_texture_webp.js +24 -17
- package/dist/lib/extensions/KHR_binary_gltf.d.ts +1 -1
- package/dist/lib/extensions/KHR_binary_gltf.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_binary_gltf.js +29 -15
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +2 -2
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +110 -87
- package/dist/lib/extensions/KHR_texture_basisu.d.ts +2 -2
- package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.js +19 -12
- package/dist/lib/extensions/KHR_texture_transform.d.ts +2 -2
- package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_transform.js +188 -156
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +2 -2
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +263 -143
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +44 -32
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +30 -24
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +65 -52
- package/dist/lib/extensions/utils/3d-tiles-utils.d.ts +2 -2
- package/dist/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -1
- package/dist/lib/extensions/utils/3d-tiles-utils.js +298 -181
- package/dist/lib/gltf-utils/get-typed-array.d.ts +1 -1
- package/dist/lib/gltf-utils/get-typed-array.d.ts.map +1 -1
- package/dist/lib/gltf-utils/get-typed-array.js +54 -42
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +1 -1
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-attribute-utils.js +58 -52
- package/dist/lib/gltf-utils/gltf-constants.js +27 -27
- package/dist/lib/gltf-utils/gltf-utils.d.ts +1 -1
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-utils.js +67 -60
- package/dist/lib/gltf-utils/resolve-url.js +12 -10
- package/dist/lib/parsers/parse-glb.d.ts +1 -1
- package/dist/lib/parsers/parse-glb.d.ts.map +1 -1
- package/dist/lib/parsers/parse-glb.js +132 -89
- package/dist/lib/parsers/parse-gltf.d.ts +3 -3
- package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-gltf.js +155 -126
- package/dist/lib/types/glb-types.js +0 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts +1 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.js +0 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts +1 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.js +0 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts +1 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.js +0 -1
- package/dist/lib/types/gltf-json-schema.js +2 -1
- package/dist/lib/types/gltf-postprocessed-schema.js +2 -1
- package/dist/lib/types/gltf-types.d.ts +3 -3
- package/dist/lib/types/gltf-types.d.ts.map +1 -1
- package/dist/lib/types/gltf-types.js +1 -1
- package/dist/lib/utils/assert.js +6 -4
- package/dist/lib/utils/version.js +4 -2
- package/dist/meshopt/meshopt-decoder.js +86 -67
- package/dist/webp/webp.js +28 -19
- package/package.json +13 -8
- package/src/lib/extensions/KHR_texture_transform.ts +18 -24
- package/dist/glb-loader.js.map +0 -1
- package/dist/glb-writer.js.map +0 -1
- package/dist/gltf-loader.js.map +0 -1
- package/dist/gltf-writer.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/api/gltf-extensions.js.map +0 -1
- package/dist/lib/api/gltf-scenegraph.js.map +0 -1
- package/dist/lib/api/normalize-gltf-v1.js.map +0 -1
- package/dist/lib/api/post-process-gltf.js.map +0 -1
- package/dist/lib/encoders/encode-glb.js.map +0 -1
- package/dist/lib/encoders/encode-gltf.js.map +0 -1
- package/dist/lib/extensions/EXT_mesh_features.js.map +0 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js.map +0 -1
- package/dist/lib/extensions/EXT_structural_metadata.js.map +0 -1
- package/dist/lib/extensions/EXT_texture_webp.js.map +0 -1
- package/dist/lib/extensions/KHR_binary_gltf.js.map +0 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.js.map +0 -1
- package/dist/lib/extensions/KHR_texture_basisu.js.map +0 -1
- package/dist/lib/extensions/KHR_texture_transform.js.map +0 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js.map +0 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js.map +0 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js.map +0 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js.map +0 -1
- package/dist/lib/extensions/utils/3d-tiles-utils.js.map +0 -1
- package/dist/lib/gltf-utils/get-typed-array.js.map +0 -1
- package/dist/lib/gltf-utils/gltf-attribute-utils.js.map +0 -1
- package/dist/lib/gltf-utils/gltf-constants.js.map +0 -1
- package/dist/lib/gltf-utils/gltf-utils.js.map +0 -1
- package/dist/lib/gltf-utils/resolve-url.js.map +0 -1
- package/dist/lib/parsers/parse-glb.js.map +0 -1
- package/dist/lib/parsers/parse-gltf.js.map +0 -1
- package/dist/lib/types/glb-types.js.map +0 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.js.map +0 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.js.map +0 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.js.map +0 -1
- package/dist/lib/types/gltf-json-schema.js.map +0 -1
- package/dist/lib/types/gltf-postprocessed-schema.js.map +0 -1
- package/dist/lib/types/gltf-types.js.map +0 -1
- package/dist/lib/utils/assert.js.map +0 -1
- package/dist/lib/utils/version.js.map +0 -1
- package/dist/meshopt/meshopt-decoder.js.map +0 -1
- package/dist/meshopt/meshopt-encoder.ts.disabled +0 -409
- package/dist/webp/webp.js.map +0 -1
|
@@ -1,203 +1,271 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
1
2
|
import * as KHR_binary_glTF from "../extensions/KHR_binary_gltf.js";
|
|
3
|
+
// Binary format changes (mainly implemented by GLBLoader)
|
|
4
|
+
// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF
|
|
5
|
+
// JSON format changes:
|
|
6
|
+
// https://github.com/khronosgroup/gltf/issues/605
|
|
7
|
+
// - [x] Top-level JSON objects are arrays now
|
|
8
|
+
// - [ ] Removed indirection from animation: sampler now refers directly to accessors, #712
|
|
9
|
+
// - [ ] material.parameter.value and technique.parameter.value must be an array, #690
|
|
10
|
+
// - [ ] Node can have only one mesh #821
|
|
11
|
+
// - [ ] Added reqs on JSON encoding
|
|
12
|
+
// - [ ] Added reqs on binary data alignment #802 (comment)
|
|
13
|
+
// Additions:
|
|
14
|
+
// - [ ] Added accessor.normalized, #691, #706
|
|
15
|
+
// - [ ] Added glExtensionsUsed property and 5125 (UNSIGNED_INT) accessor.componentType value, #619
|
|
16
|
+
// - [ ] Added extensionsRequired property, #720, #721
|
|
17
|
+
// - [ ] Added "STEP" as valid animation.sampler.interpolation value, #712
|
|
18
|
+
// Removals:
|
|
19
|
+
// - [x] Removed buffer.type, #786, #629
|
|
20
|
+
// - [ ] Removed revision number from profile.version, #709
|
|
21
|
+
// - [ ] Removed technique.functions.scissor and removed 3089 (SCISSOR_TEST) as a valid value for technique.states.enable, #681
|
|
22
|
+
// - [ ] Techniques, programs, and shaders were moved out to KHR_technique_webgl extension.
|
|
23
|
+
// Other edits:
|
|
24
|
+
// - [x] asset is now required, #642
|
|
25
|
+
// - [ ] buffer.byteLength and bufferView.byteLength are now required, #560.
|
|
26
|
+
// - [ ] accessor.min and accessor.max are now required, #593, and clarified that the JSON value and binary data must be the same, #628.
|
|
27
|
+
// - [ ] Clarified animation.sampler and animation.channel restrictions, #712
|
|
28
|
+
// - [ ] skin.inverseBindMatrices is now optional, #461.
|
|
29
|
+
// - [ ] Attribute parameters can't have a value defined in the technique or parameter, #563 (comment).
|
|
30
|
+
// - [ ] Only TEXCOORD and COLOR attribute semantics can be written in the form [semantic]_[set_index], #563 (comment).
|
|
31
|
+
// - [ ] TEXCOORD and COLOR attribute semantics must be written in the form [semantic]_[set_index], e.g., just TEXCOORD should be TEXCOORD_0, and just COLOR should be COLOR_0, #649
|
|
32
|
+
// - [ ] camera.perspective.aspectRatio and camera.perspective.yfov must now be > 0, not >= 0, #563 (comment).
|
|
33
|
+
// - [ ] Application-specific parameter semantics must start with an underscore, e.g., _TEMPERATURE and _SIMULATION_TIME, #563 (comment).
|
|
34
|
+
// - [ ] Properties in technique.parameters must be defined in technique.uniforms or technique.attributes,
|
|
35
|
+
// #563 (comment).
|
|
36
|
+
// - [ ] technique.parameter.count can only be defined when the semantic is JOINTMATRIX or an application-specific semantic is used. It can never be defined for attribute parameters; only uniforms, d2f6945
|
|
37
|
+
// - [ ] technique.parameter.semantic is required when the parameter is an attribute, 28e113d
|
|
38
|
+
// - [ ] Mesh-only models are allowed, e.g., without materials, #642
|
|
39
|
+
// - [ ] Skeleton hierarchies (nodes containing jointName) must be separated from non-skeleton hierarchies., #647
|
|
40
|
+
// - [ ] technique.states.functions.blendColor and technique.states.functions.depthRange parameters now must match WebGL function min/max, #707
|
|
2
41
|
const GLTF_ARRAYS = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
42
|
+
accessors: 'accessor',
|
|
43
|
+
animations: 'animation',
|
|
44
|
+
buffers: 'buffer',
|
|
45
|
+
bufferViews: 'bufferView',
|
|
46
|
+
images: 'image',
|
|
47
|
+
materials: 'material',
|
|
48
|
+
meshes: 'mesh',
|
|
49
|
+
nodes: 'node',
|
|
50
|
+
samplers: 'sampler',
|
|
51
|
+
scenes: 'scene',
|
|
52
|
+
skins: 'skin',
|
|
53
|
+
textures: 'texture'
|
|
15
54
|
};
|
|
16
55
|
const GLTF_KEYS = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
56
|
+
accessor: 'accessors',
|
|
57
|
+
animations: 'animation',
|
|
58
|
+
buffer: 'buffers',
|
|
59
|
+
bufferView: 'bufferViews',
|
|
60
|
+
image: 'images',
|
|
61
|
+
material: 'materials',
|
|
62
|
+
mesh: 'meshes',
|
|
63
|
+
node: 'nodes',
|
|
64
|
+
sampler: 'samplers',
|
|
65
|
+
scene: 'scenes',
|
|
66
|
+
skin: 'skins',
|
|
67
|
+
texture: 'textures'
|
|
29
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* Converts (normalizes) glTF v1 to v2
|
|
71
|
+
*/
|
|
30
72
|
class GLTFV1Normalizer {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
textures: {}
|
|
73
|
+
idToIndexMap = {
|
|
74
|
+
animations: {},
|
|
75
|
+
accessors: {},
|
|
76
|
+
buffers: {},
|
|
77
|
+
bufferViews: {},
|
|
78
|
+
images: {},
|
|
79
|
+
materials: {},
|
|
80
|
+
meshes: {},
|
|
81
|
+
nodes: {},
|
|
82
|
+
samplers: {},
|
|
83
|
+
scenes: {},
|
|
84
|
+
skins: {},
|
|
85
|
+
textures: {}
|
|
45
86
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
87
|
+
json;
|
|
88
|
+
// constructor() {}
|
|
89
|
+
/**
|
|
90
|
+
* Convert (normalize) glTF < 2.0 to glTF 2.0
|
|
91
|
+
* @param gltf - object with json and binChunks
|
|
92
|
+
* @param options
|
|
93
|
+
* @param options normalize Whether to actually normalize
|
|
94
|
+
*/
|
|
95
|
+
normalize(gltf, options) {
|
|
96
|
+
this.json = gltf.json;
|
|
97
|
+
const json = gltf.json;
|
|
98
|
+
// Check version
|
|
99
|
+
switch (json.asset && json.asset.version) {
|
|
100
|
+
// We are converting to v2 format. Return if there is nothing to do
|
|
101
|
+
case '2.0':
|
|
102
|
+
return;
|
|
103
|
+
// This class is written to convert 1.0
|
|
104
|
+
case undefined:
|
|
105
|
+
case '1.0':
|
|
106
|
+
break;
|
|
107
|
+
default:
|
|
108
|
+
// eslint-disable-next-line no-undef, no-console
|
|
109
|
+
console.warn(`glTF: Unknown version ${json.asset.version}`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (!options.normalize) {
|
|
113
|
+
// We are still missing a few conversion tricks, remove once addressed
|
|
114
|
+
throw new Error('glTF v1 is not supported.');
|
|
115
|
+
}
|
|
116
|
+
// eslint-disable-next-line no-undef, no-console
|
|
117
|
+
console.warn('Converting glTF v1 to glTF v2 format. This is experimental and may fail.');
|
|
118
|
+
this._addAsset(json);
|
|
119
|
+
// In glTF2 top-level fields are Arrays not Object maps
|
|
120
|
+
this._convertTopLevelObjectsToArrays(json);
|
|
121
|
+
// Extract bufferView indices for images
|
|
122
|
+
// (this extension needs to be invoked early in the normalization process)
|
|
123
|
+
// TODO can this be handled by standard extension processing instead of called explicitly?
|
|
124
|
+
KHR_binary_glTF.preprocess(gltf);
|
|
125
|
+
// Convert object references from ids to indices
|
|
126
|
+
this._convertObjectIdsToArrayIndices(json);
|
|
127
|
+
this._updateObjects(json);
|
|
128
|
+
this._updateMaterial(json);
|
|
60
129
|
}
|
|
61
|
-
|
|
62
|
-
|
|
130
|
+
// asset is now required, #642 https://github.com/KhronosGroup/glTF/issues/639
|
|
131
|
+
_addAsset(json) {
|
|
132
|
+
json.asset = json.asset || {};
|
|
133
|
+
// We are normalizing to glTF v2, so change version to "2.0"
|
|
134
|
+
json.asset.version = '2.0';
|
|
135
|
+
json.asset.generator = json.asset.generator || 'Normalized to glTF 2.0 by loaders.gl';
|
|
63
136
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this._updateObjects(json);
|
|
70
|
-
this._updateMaterial(json);
|
|
71
|
-
}
|
|
72
|
-
_addAsset(json) {
|
|
73
|
-
json.asset = json.asset || {};
|
|
74
|
-
json.asset.version = '2.0';
|
|
75
|
-
json.asset.generator = json.asset.generator || 'Normalized to glTF 2.0 by loaders.gl';
|
|
76
|
-
}
|
|
77
|
-
_convertTopLevelObjectsToArrays(json) {
|
|
78
|
-
for (const arrayName in GLTF_ARRAYS) {
|
|
79
|
-
this._convertTopLevelObjectToArray(json, arrayName);
|
|
137
|
+
_convertTopLevelObjectsToArrays(json) {
|
|
138
|
+
// TODO check that all arrays are covered
|
|
139
|
+
for (const arrayName in GLTF_ARRAYS) {
|
|
140
|
+
this._convertTopLevelObjectToArray(json, arrayName);
|
|
141
|
+
}
|
|
80
142
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
143
|
+
/** Convert one top level object to array */
|
|
144
|
+
_convertTopLevelObjectToArray(json, mapName) {
|
|
145
|
+
const objectMap = json[mapName];
|
|
146
|
+
if (!objectMap || Array.isArray(objectMap)) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
// Rewrite the top-level field as an array
|
|
150
|
+
json[mapName] = [];
|
|
151
|
+
// Copy the map key into object.id
|
|
152
|
+
for (const id in objectMap) {
|
|
153
|
+
const object = objectMap[id];
|
|
154
|
+
object.id = object.id || id; // Mutates the loaded object
|
|
155
|
+
const index = json[mapName].length;
|
|
156
|
+
json[mapName].push(object);
|
|
157
|
+
this.idToIndexMap[mapName][id] = index;
|
|
158
|
+
}
|
|
86
159
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
160
|
+
/** Go through all objects in all top-level arrays and replace ids with indices */
|
|
161
|
+
_convertObjectIdsToArrayIndices(json) {
|
|
162
|
+
for (const arrayName in GLTF_ARRAYS) {
|
|
163
|
+
this._convertIdsToIndices(json, arrayName);
|
|
164
|
+
}
|
|
165
|
+
if ('scene' in json) {
|
|
166
|
+
json.scene = this._convertIdToIndex(json.scene, 'scene');
|
|
167
|
+
}
|
|
168
|
+
// Convert any index references that are not using array names
|
|
169
|
+
// texture.source (image)
|
|
170
|
+
for (const texture of json.textures) {
|
|
171
|
+
this._convertTextureIds(texture);
|
|
172
|
+
}
|
|
173
|
+
for (const mesh of json.meshes) {
|
|
174
|
+
this._convertMeshIds(mesh);
|
|
175
|
+
}
|
|
176
|
+
for (const node of json.nodes) {
|
|
177
|
+
this._convertNodeIds(node);
|
|
178
|
+
}
|
|
179
|
+
for (const node of json.scenes) {
|
|
180
|
+
this._convertSceneIds(node);
|
|
181
|
+
}
|
|
94
182
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
183
|
+
_convertTextureIds(texture) {
|
|
184
|
+
if (texture.source) {
|
|
185
|
+
texture.source = this._convertIdToIndex(texture.source, 'image');
|
|
186
|
+
}
|
|
99
187
|
}
|
|
100
|
-
|
|
101
|
-
|
|
188
|
+
_convertMeshIds(mesh) {
|
|
189
|
+
for (const primitive of mesh.primitives) {
|
|
190
|
+
const { attributes, indices, material } = primitive;
|
|
191
|
+
for (const attributeName in attributes) {
|
|
192
|
+
attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], 'accessor');
|
|
193
|
+
}
|
|
194
|
+
if (indices) {
|
|
195
|
+
primitive.indices = this._convertIdToIndex(indices, 'accessor');
|
|
196
|
+
}
|
|
197
|
+
if (material) {
|
|
198
|
+
primitive.material = this._convertIdToIndex(material, 'material');
|
|
199
|
+
}
|
|
200
|
+
}
|
|
102
201
|
}
|
|
103
|
-
|
|
104
|
-
|
|
202
|
+
_convertNodeIds(node) {
|
|
203
|
+
if (node.children) {
|
|
204
|
+
node.children = node.children.map((child) => this._convertIdToIndex(child, 'node'));
|
|
205
|
+
}
|
|
206
|
+
if (node.meshes) {
|
|
207
|
+
node.meshes = node.meshes.map((mesh) => this._convertIdToIndex(mesh, 'mesh'));
|
|
208
|
+
}
|
|
105
209
|
}
|
|
106
|
-
|
|
107
|
-
|
|
210
|
+
_convertSceneIds(scene) {
|
|
211
|
+
if (scene.nodes) {
|
|
212
|
+
scene.nodes = scene.nodes.map((node) => this._convertIdToIndex(node, 'node'));
|
|
213
|
+
}
|
|
108
214
|
}
|
|
109
|
-
|
|
110
|
-
|
|
215
|
+
/** Go through all objects in a top-level array and replace ids with indices */
|
|
216
|
+
_convertIdsToIndices(json, topLevelArrayName) {
|
|
217
|
+
if (!json[topLevelArrayName]) {
|
|
218
|
+
console.warn(`gltf v1: json doesn't contain attribute ${topLevelArrayName}`); // eslint-disable-line no-console, no-undef
|
|
219
|
+
json[topLevelArrayName] = [];
|
|
220
|
+
}
|
|
221
|
+
for (const object of json[topLevelArrayName]) {
|
|
222
|
+
for (const key in object) {
|
|
223
|
+
const id = object[key];
|
|
224
|
+
const index = this._convertIdToIndex(id, key);
|
|
225
|
+
object[key] = index;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
111
228
|
}
|
|
112
|
-
|
|
113
|
-
|
|
229
|
+
_convertIdToIndex(id, key) {
|
|
230
|
+
const arrayName = GLTF_KEYS[key];
|
|
231
|
+
if (arrayName in this.idToIndexMap) {
|
|
232
|
+
const index = this.idToIndexMap[arrayName][id];
|
|
233
|
+
if (!Number.isFinite(index)) {
|
|
234
|
+
throw new Error(`gltf v1: failed to resolve ${key} with id ${id}`);
|
|
235
|
+
}
|
|
236
|
+
return index;
|
|
237
|
+
}
|
|
238
|
+
return id;
|
|
114
239
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
240
|
+
/**
|
|
241
|
+
*
|
|
242
|
+
* @param {*} json
|
|
243
|
+
*/
|
|
244
|
+
_updateObjects(json) {
|
|
245
|
+
for (const buffer of this.json.buffers) {
|
|
246
|
+
// - [x] Removed buffer.type, #786, #629
|
|
247
|
+
delete buffer.type;
|
|
248
|
+
}
|
|
119
249
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
250
|
+
/**
|
|
251
|
+
* Update material (set pbrMetallicRoughness)
|
|
252
|
+
* @param {*} json
|
|
253
|
+
*/
|
|
254
|
+
_updateMaterial(json) {
|
|
255
|
+
for (const material of json.materials) {
|
|
256
|
+
material.pbrMetallicRoughness = {
|
|
257
|
+
baseColorFactor: [1, 1, 1, 1],
|
|
258
|
+
metallicFactor: 1,
|
|
259
|
+
roughnessFactor: 1
|
|
260
|
+
};
|
|
261
|
+
const textureId = material.values?.tex || material.values?.texture2d_0 || material.values?.diffuseTex;
|
|
262
|
+
const textureIndex = json.textures.findIndex((texture) => texture.id === textureId);
|
|
263
|
+
if (textureIndex !== -1) {
|
|
264
|
+
material.pbrMetallicRoughness.baseColorTexture = { index: textureIndex };
|
|
265
|
+
}
|
|
266
|
+
}
|
|
137
267
|
}
|
|
138
|
-
}
|
|
139
|
-
_convertNodeIds(node) {
|
|
140
|
-
if (node.children) {
|
|
141
|
-
node.children = node.children.map(child => this._convertIdToIndex(child, 'node'));
|
|
142
|
-
}
|
|
143
|
-
if (node.meshes) {
|
|
144
|
-
node.meshes = node.meshes.map(mesh => this._convertIdToIndex(mesh, 'mesh'));
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
_convertSceneIds(scene) {
|
|
148
|
-
if (scene.nodes) {
|
|
149
|
-
scene.nodes = scene.nodes.map(node => this._convertIdToIndex(node, 'node'));
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
_convertIdsToIndices(json, topLevelArrayName) {
|
|
153
|
-
if (!json[topLevelArrayName]) {
|
|
154
|
-
console.warn(`gltf v1: json doesn't contain attribute ${topLevelArrayName}`);
|
|
155
|
-
json[topLevelArrayName] = [];
|
|
156
|
-
}
|
|
157
|
-
for (const object of json[topLevelArrayName]) {
|
|
158
|
-
for (const key in object) {
|
|
159
|
-
const id = object[key];
|
|
160
|
-
const index = this._convertIdToIndex(id, key);
|
|
161
|
-
object[key] = index;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
_convertIdToIndex(id, key) {
|
|
166
|
-
const arrayName = GLTF_KEYS[key];
|
|
167
|
-
if (arrayName in this.idToIndexMap) {
|
|
168
|
-
const index = this.idToIndexMap[arrayName][id];
|
|
169
|
-
if (!Number.isFinite(index)) {
|
|
170
|
-
throw new Error(`gltf v1: failed to resolve ${key} with id ${id}`);
|
|
171
|
-
}
|
|
172
|
-
return index;
|
|
173
|
-
}
|
|
174
|
-
return id;
|
|
175
|
-
}
|
|
176
|
-
_updateObjects(json) {
|
|
177
|
-
for (const buffer of this.json.buffers) {
|
|
178
|
-
delete buffer.type;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
_updateMaterial(json) {
|
|
182
|
-
for (const material of json.materials) {
|
|
183
|
-
var _material$values, _material$values2, _material$values3;
|
|
184
|
-
material.pbrMetallicRoughness = {
|
|
185
|
-
baseColorFactor: [1, 1, 1, 1],
|
|
186
|
-
metallicFactor: 1,
|
|
187
|
-
roughnessFactor: 1
|
|
188
|
-
};
|
|
189
|
-
const textureId = ((_material$values = material.values) === null || _material$values === void 0 ? void 0 : _material$values.tex) || ((_material$values2 = material.values) === null || _material$values2 === void 0 ? void 0 : _material$values2.texture2d_0) || ((_material$values3 = material.values) === null || _material$values3 === void 0 ? void 0 : _material$values3.diffuseTex);
|
|
190
|
-
const textureIndex = json.textures.findIndex(texture => texture.id === textureId);
|
|
191
|
-
if (textureIndex !== -1) {
|
|
192
|
-
material.pbrMetallicRoughness.baseColorTexture = {
|
|
193
|
-
index: textureIndex
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
268
|
}
|
|
199
|
-
export function normalizeGLTFV1(gltf) {
|
|
200
|
-
|
|
201
|
-
return new GLTFV1Normalizer().normalize(gltf, options);
|
|
269
|
+
export function normalizeGLTFV1(gltf, options = {}) {
|
|
270
|
+
return new GLTFV1Normalizer().normalize(gltf, options);
|
|
202
271
|
}
|
|
203
|
-
//# sourceMappingURL=normalize-gltf-v1.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { GLTFWithBuffers } from
|
|
2
|
-
import type { ParseGLTFOptions } from
|
|
3
|
-
import type { GLTFPostprocessed } from
|
|
1
|
+
import type { GLTFWithBuffers } from "../types/gltf-types.js";
|
|
2
|
+
import type { ParseGLTFOptions } from "../parsers/parse-gltf.js";
|
|
3
|
+
import type { GLTFPostprocessed } from "../types/gltf-postprocessed-schema.js";
|
|
4
4
|
export declare function postProcessGLTF(gltf: GLTFWithBuffers, options?: ParseGLTFOptions): GLTFPostprocessed;
|
|
5
5
|
//# sourceMappingURL=post-process-gltf.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-process-gltf.d.ts","sourceRoot":"","sources":["../../../src/lib/api/post-process-gltf.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,eAAe,EAAC
|
|
1
|
+
{"version":3,"file":"post-process-gltf.d.ts","sourceRoot":"","sources":["../../../src/lib/api/post-process-gltf.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,eAAe,EAAC,+BAA4B;AACzD,OAAO,KAAK,EAAC,gBAAgB,EAAC,iCAA8B;AAiB5D,OAAO,KAAK,EACV,iBAAiB,EAclB,8CAA2C;AAmgB5C,wBAAgB,eAAe,CAC7B,IAAI,EAAE,eAAe,EACrB,OAAO,CAAC,EAAE,gBAAgB,GACzB,iBAAiB,CAEnB"}
|