@loaders.gl/gltf 3.3.0-alpha.5 → 3.3.0-alpha.7
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.min.js +104 -124
- package/dist/es5/bundle.js +0 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/glb-loader.js +2 -13
- package/dist/es5/glb-loader.js.map +1 -1
- package/dist/es5/glb-writer.js +3 -6
- package/dist/es5/glb-writer.js.map +1 -1
- package/dist/es5/gltf-loader.js +11 -23
- package/dist/es5/gltf-loader.js.map +1 -1
- package/dist/es5/gltf-writer.js +2 -5
- package/dist/es5/gltf-writer.js.map +1 -1
- package/dist/es5/index.js +10 -17
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/api/gltf-extensions.js +14 -48
- package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
- package/dist/es5/lib/api/gltf-scenegraph.js +113 -96
- package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/es5/lib/api/normalize-gltf-v1.js +32 -70
- package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -1
- package/dist/es5/lib/api/post-process-gltf.js +26 -89
- package/dist/es5/lib/api/post-process-gltf.js.map +1 -1
- package/dist/es5/lib/encoders/encode-glb.js +10 -8
- package/dist/es5/lib/encoders/encode-glb.js.map +1 -1
- package/dist/es5/lib/encoders/encode-gltf.js +3 -6
- package/dist/es5/lib/encoders/encode-gltf.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js +2 -28
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_texture_webp.js +5 -18
- package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_binary_gltf.js +5 -12
- package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +11 -79
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_basisu.js +5 -14
- package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_transform.js +17 -72
- package/dist/es5/lib/extensions/KHR_texture_transform.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +0 -21
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +0 -24
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +2 -19
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +11 -29
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
- package/dist/es5/lib/gltf-utils/get-typed-array.js +1 -1
- package/dist/es5/lib/gltf-utils/get-typed-array.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js +5 -17
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-constants.js +3 -4
- package/dist/es5/lib/gltf-utils/gltf-constants.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-utils.js +1 -8
- package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/es5/lib/gltf-utils/resolve-url.js +0 -5
- package/dist/es5/lib/gltf-utils/resolve-url.js.map +1 -1
- package/dist/es5/lib/parsers/parse-glb.js +11 -17
- package/dist/es5/lib/parsers/parse-glb.js.map +1 -1
- package/dist/es5/lib/parsers/parse-gltf.js +12 -73
- package/dist/es5/lib/parsers/parse-gltf.js.map +1 -1
- package/dist/es5/lib/types/glb-types.js.map +1 -1
- package/dist/es5/lib/types/gltf-json-schema.js.map +1 -1
- package/dist/es5/lib/types/gltf-postprocessed-schema.js.map +1 -1
- package/dist/es5/lib/types/gltf-types.js.map +1 -1
- package/dist/es5/lib/utils/assert.js +0 -1
- package/dist/es5/lib/utils/assert.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/es5/lib/utils/version.js.map +1 -1
- package/dist/es5/meshopt/meshopt-decoder.js +10 -47
- package/dist/es5/meshopt/meshopt-decoder.js.map +1 -1
- package/dist/es5/webp/webp.js +3 -19
- package/dist/es5/webp/webp.js.map +1 -1
- package/dist/esm/bundle.js +1 -1
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/glb-loader.js +0 -1
- package/dist/esm/glb-loader.js.map +1 -1
- package/dist/esm/glb-writer.js +3 -1
- package/dist/esm/glb-writer.js.map +1 -1
- package/dist/esm/gltf-loader.js +9 -3
- package/dist/esm/gltf-loader.js.map +1 -1
- package/dist/esm/gltf-writer.js +3 -2
- package/dist/esm/gltf-writer.js.map +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/api/gltf-extensions.js +16 -9
- package/dist/esm/lib/api/gltf-extensions.js.map +1 -1
- package/dist/esm/lib/api/gltf-scenegraph.js +27 -68
- package/dist/esm/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/esm/lib/api/normalize-gltf-v1.js +3 -34
- package/dist/esm/lib/api/normalize-gltf-v1.js.map +1 -1
- package/dist/esm/lib/api/post-process-gltf.js +26 -93
- package/dist/esm/lib/api/post-process-gltf.js.map +1 -1
- package/dist/esm/lib/encoders/encode-glb.js +9 -2
- package/dist/esm/lib/encoders/encode-glb.js.map +1 -1
- package/dist/esm/lib/encoders/encode-gltf.js +6 -4
- package/dist/esm/lib/encoders/encode-gltf.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js +5 -6
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_texture_webp.js +4 -6
- package/dist/esm/lib/extensions/EXT_texture_webp.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_binary_gltf.js +3 -2
- package/dist/esm/lib/extensions/KHR_binary_gltf.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js +18 -17
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_texture_basisu.js +4 -3
- package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_texture_transform.js +8 -34
- package/dist/esm/lib/extensions/KHR_texture_transform.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +2 -13
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js +4 -4
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js +3 -2
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js +10 -10
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
- package/dist/esm/lib/gltf-utils/get-typed-array.js +4 -0
- package/dist/esm/lib/gltf-utils/get-typed-array.js.map +1 -1
- package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js +7 -11
- package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
- package/dist/esm/lib/gltf-utils/gltf-constants.js +1 -0
- package/dist/esm/lib/gltf-utils/gltf-constants.js.map +1 -1
- package/dist/esm/lib/gltf-utils/gltf-utils.js +0 -2
- package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/esm/lib/gltf-utils/resolve-url.js +1 -4
- package/dist/esm/lib/gltf-utils/resolve-url.js.map +1 -1
- package/dist/esm/lib/parsers/parse-glb.js +19 -16
- package/dist/esm/lib/parsers/parse-glb.js.map +1 -1
- package/dist/esm/lib/parsers/parse-gltf.js +11 -16
- package/dist/esm/lib/parsers/parse-gltf.js.map +1 -1
- package/dist/esm/lib/types/glb-types.js.map +1 -1
- package/dist/esm/lib/types/gltf-json-schema.js.map +1 -1
- package/dist/esm/lib/types/gltf-postprocessed-schema.js.map +1 -1
- package/dist/esm/lib/types/gltf-types.js.map +1 -1
- package/dist/esm/lib/utils/assert.js +1 -0
- package/dist/esm/lib/utils/assert.js.map +1 -1
- package/dist/esm/lib/utils/version.js +2 -1
- package/dist/esm/lib/utils/version.js.map +1 -1
- package/dist/esm/meshopt/meshopt-decoder.js +11 -15
- package/dist/esm/meshopt/meshopt-decoder.js.map +1 -1
- package/dist/esm/webp/webp.js +3 -5
- package/dist/esm/webp/webp.js.map +1 -1
- package/dist/lib/api/gltf-extensions.js +5 -1
- package/dist/lib/api/normalize-gltf-v1.js +5 -1
- package/dist/lib/parsers/parse-gltf.js +5 -1
- package/package.json +6 -6
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
import * as KHR_binary_glTF from '../extensions/KHR_binary_gltf';
|
|
3
|
+
|
|
3
4
|
const GLTF_ARRAYS = {
|
|
4
5
|
accessors: 'accessor',
|
|
5
6
|
animations: 'animation',
|
|
@@ -45,7 +46,6 @@ class GLTFV1Normalizer {
|
|
|
45
46
|
skins: {},
|
|
46
47
|
textures: {}
|
|
47
48
|
});
|
|
48
|
-
|
|
49
49
|
_defineProperty(this, "json", void 0);
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -60,18 +60,15 @@ class GLTFV1Normalizer {
|
|
|
60
60
|
case undefined:
|
|
61
61
|
case '1.0':
|
|
62
62
|
break;
|
|
63
|
-
|
|
64
63
|
default:
|
|
65
64
|
console.warn("glTF: Unknown version ".concat(json.asset.version));
|
|
66
65
|
return;
|
|
67
66
|
}
|
|
68
|
-
|
|
69
67
|
if (!options.normalize) {
|
|
70
68
|
throw new Error('glTF v1 is not supported.');
|
|
71
69
|
}
|
|
72
70
|
|
|
73
71
|
console.warn('Converting glTF v1 to glTF v2 format. This is experimental and may fail.');
|
|
74
|
-
|
|
75
72
|
this._addAsset(json);
|
|
76
73
|
|
|
77
74
|
this._convertTopLevelObjectsToArrays(json);
|
|
@@ -79,9 +76,7 @@ class GLTFV1Normalizer {
|
|
|
79
76
|
KHR_binary_glTF.preprocess(gltf);
|
|
80
77
|
|
|
81
78
|
this._convertObjectIdsToArrayIndices(json);
|
|
82
|
-
|
|
83
79
|
this._updateObjects(json);
|
|
84
|
-
|
|
85
80
|
this._updateMaterial(json);
|
|
86
81
|
}
|
|
87
82
|
|
|
@@ -90,7 +85,6 @@ class GLTFV1Normalizer {
|
|
|
90
85
|
json.asset.version = '2.0';
|
|
91
86
|
json.asset.generator = json.asset.generator || 'Normalized to glTF 2.0 by loaders.gl';
|
|
92
87
|
}
|
|
93
|
-
|
|
94
88
|
_convertTopLevelObjectsToArrays(json) {
|
|
95
89
|
for (const arrayName in GLTF_ARRAYS) {
|
|
96
90
|
this._convertTopLevelObjectToArray(json, arrayName);
|
|
@@ -99,13 +93,11 @@ class GLTFV1Normalizer {
|
|
|
99
93
|
|
|
100
94
|
_convertTopLevelObjectToArray(json, mapName) {
|
|
101
95
|
const objectMap = json[mapName];
|
|
102
|
-
|
|
103
96
|
if (!objectMap || Array.isArray(objectMap)) {
|
|
104
97
|
return;
|
|
105
98
|
}
|
|
106
99
|
|
|
107
100
|
json[mapName] = [];
|
|
108
|
-
|
|
109
101
|
for (const id in objectMap) {
|
|
110
102
|
const object = objectMap[id];
|
|
111
103
|
object.id = object.id || id;
|
|
@@ -119,7 +111,6 @@ class GLTFV1Normalizer {
|
|
|
119
111
|
for (const arrayName in GLTF_ARRAYS) {
|
|
120
112
|
this._convertIdsToIndices(json, arrayName);
|
|
121
113
|
}
|
|
122
|
-
|
|
123
114
|
if ('scene' in json) {
|
|
124
115
|
json.scene = this._convertIdToIndex(json.scene, 'scene');
|
|
125
116
|
}
|
|
@@ -127,26 +118,21 @@ class GLTFV1Normalizer {
|
|
|
127
118
|
for (const texture of json.textures) {
|
|
128
119
|
this._convertTextureIds(texture);
|
|
129
120
|
}
|
|
130
|
-
|
|
131
121
|
for (const mesh of json.meshes) {
|
|
132
122
|
this._convertMeshIds(mesh);
|
|
133
123
|
}
|
|
134
|
-
|
|
135
124
|
for (const node of json.nodes) {
|
|
136
125
|
this._convertNodeIds(node);
|
|
137
126
|
}
|
|
138
|
-
|
|
139
127
|
for (const node of json.scenes) {
|
|
140
128
|
this._convertSceneIds(node);
|
|
141
129
|
}
|
|
142
130
|
}
|
|
143
|
-
|
|
144
131
|
_convertTextureIds(texture) {
|
|
145
132
|
if (texture.source) {
|
|
146
133
|
texture.source = this._convertIdToIndex(texture.source, 'image');
|
|
147
134
|
}
|
|
148
135
|
}
|
|
149
|
-
|
|
150
136
|
_convertMeshIds(mesh) {
|
|
151
137
|
for (const primitive of mesh.primitives) {
|
|
152
138
|
const {
|
|
@@ -154,31 +140,25 @@ class GLTFV1Normalizer {
|
|
|
154
140
|
indices,
|
|
155
141
|
material
|
|
156
142
|
} = primitive;
|
|
157
|
-
|
|
158
143
|
for (const attributeName in attributes) {
|
|
159
144
|
attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], 'accessor');
|
|
160
145
|
}
|
|
161
|
-
|
|
162
146
|
if (indices) {
|
|
163
147
|
primitive.indices = this._convertIdToIndex(indices, 'accessor');
|
|
164
148
|
}
|
|
165
|
-
|
|
166
149
|
if (material) {
|
|
167
150
|
primitive.material = this._convertIdToIndex(material, 'material');
|
|
168
151
|
}
|
|
169
152
|
}
|
|
170
153
|
}
|
|
171
|
-
|
|
172
154
|
_convertNodeIds(node) {
|
|
173
155
|
if (node.children) {
|
|
174
156
|
node.children = node.children.map(child => this._convertIdToIndex(child, 'node'));
|
|
175
157
|
}
|
|
176
|
-
|
|
177
158
|
if (node.meshes) {
|
|
178
159
|
node.meshes = node.meshes.map(mesh => this._convertIdToIndex(mesh, 'mesh'));
|
|
179
160
|
}
|
|
180
161
|
}
|
|
181
|
-
|
|
182
162
|
_convertSceneIds(scene) {
|
|
183
163
|
if (scene.nodes) {
|
|
184
164
|
scene.nodes = scene.nodes.map(node => this._convertIdToIndex(node, 'node'));
|
|
@@ -190,31 +170,23 @@ class GLTFV1Normalizer {
|
|
|
190
170
|
console.warn("gltf v1: json doesn't contain attribute ".concat(topLevelArrayName));
|
|
191
171
|
json[topLevelArrayName] = [];
|
|
192
172
|
}
|
|
193
|
-
|
|
194
173
|
for (const object of json[topLevelArrayName]) {
|
|
195
174
|
for (const key in object) {
|
|
196
175
|
const id = object[key];
|
|
197
|
-
|
|
198
176
|
const index = this._convertIdToIndex(id, key);
|
|
199
|
-
|
|
200
177
|
object[key] = index;
|
|
201
178
|
}
|
|
202
179
|
}
|
|
203
180
|
}
|
|
204
|
-
|
|
205
181
|
_convertIdToIndex(id, key) {
|
|
206
182
|
const arrayName = GLTF_KEYS[key];
|
|
207
|
-
|
|
208
183
|
if (arrayName in this.idToIndexMap) {
|
|
209
184
|
const index = this.idToIndexMap[arrayName][id];
|
|
210
|
-
|
|
211
185
|
if (!Number.isFinite(index)) {
|
|
212
186
|
throw new Error("gltf v1: failed to resolve ".concat(key, " with id ").concat(id));
|
|
213
187
|
}
|
|
214
|
-
|
|
215
188
|
return index;
|
|
216
189
|
}
|
|
217
|
-
|
|
218
190
|
return id;
|
|
219
191
|
}
|
|
220
192
|
|
|
@@ -227,7 +199,6 @@ class GLTFV1Normalizer {
|
|
|
227
199
|
_updateMaterial(json) {
|
|
228
200
|
for (const material of json.materials) {
|
|
229
201
|
var _material$values, _material$values2, _material$values3;
|
|
230
|
-
|
|
231
202
|
material.pbrMetallicRoughness = {
|
|
232
203
|
baseColorFactor: [1, 1, 1, 1],
|
|
233
204
|
metallicFactor: 1,
|
|
@@ -235,7 +206,6 @@ class GLTFV1Normalizer {
|
|
|
235
206
|
};
|
|
236
207
|
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);
|
|
237
208
|
const textureIndex = json.textures.findIndex(texture => texture.id === textureId);
|
|
238
|
-
|
|
239
209
|
if (textureIndex !== -1) {
|
|
240
210
|
material.pbrMetallicRoughness.baseColorTexture = {
|
|
241
211
|
index: textureIndex
|
|
@@ -243,10 +213,9 @@ class GLTFV1Normalizer {
|
|
|
243
213
|
}
|
|
244
214
|
}
|
|
245
215
|
}
|
|
246
|
-
|
|
247
216
|
}
|
|
248
|
-
|
|
249
|
-
|
|
217
|
+
export function normalizeGLTFV1(gltf) {
|
|
218
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
250
219
|
return new GLTFV1Normalizer().normalize(gltf, options);
|
|
251
220
|
}
|
|
252
221
|
//# sourceMappingURL=normalize-gltf-v1.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/api/normalize-gltf-v1.ts"],"names":["KHR_binary_glTF","GLTF_ARRAYS","accessors","animations","buffers","bufferViews","images","materials","meshes","nodes","samplers","scenes","skins","textures","GLTF_KEYS","accessor","buffer","bufferView","image","material","mesh","node","sampler","scene","skin","texture","GLTFV1Normalizer","normalize","gltf","options","json","asset","version","undefined","console","warn","Error","_addAsset","_convertTopLevelObjectsToArrays","preprocess","_convertObjectIdsToArrayIndices","_updateObjects","_updateMaterial","generator","arrayName","_convertTopLevelObjectToArray","mapName","objectMap","Array","isArray","id","object","index","length","push","idToIndexMap","_convertIdsToIndices","_convertIdToIndex","_convertTextureIds","_convertMeshIds","_convertNodeIds","_convertSceneIds","source","primitive","primitives","attributes","indices","attributeName","children","map","child","topLevelArrayName","key","Number","isFinite","type","pbrMetallicRoughness","baseColorFactor","metallicFactor","roughnessFactor","textureId","values","tex","tex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AR,SAAjD;AACD;AACF;AACF;;AAlOoB;;AAqOvB,OAAO,SAASG,eAAT,CAAyB5D,IAAzB,EAA+BC,OAAO,GAAG,EAAzC,EAA6C;AAClD,SAAO,IAAIH,gBAAJ,GAAuBC,SAAvB,CAAiCC,IAAjC,EAAuCC,OAAvC,CAAP;AACD","sourcesContent":["/* eslint-disable camelcase */\nimport * as KHR_binary_glTF from '../extensions/KHR_binary_gltf';\n\n// Binary format changes (mainly implemented by GLBLoader)\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF\n\n// JSON format changes:\n// https://github.com/khronosgroup/gltf/issues/605\n\n// - [x] Top-level JSON objects are arrays now\n// - [ ] Removed indirection from animation: sampler now refers directly to accessors, #712\n// - [ ] material.parameter.value and technique.parameter.value must be an array, #690\n// - [ ] Node can have only one mesh #821\n// - [ ] Added reqs on JSON encoding\n// - [ ] Added reqs on binary data alignment #802 (comment)\n\n// Additions:\n// - [ ] Added accessor.normalized, #691, #706\n// - [ ] Added glExtensionsUsed property and 5125 (UNSIGNED_INT) accessor.componentType value, #619\n// - [ ] Added extensionsRequired property, #720, #721\n// - [ ] Added \"STEP\" as valid animation.sampler.interpolation value, #712\n\n// Removals:\n// - [x] Removed buffer.type, #786, #629\n// - [ ] Removed revision number from profile.version, #709\n// - [ ] Removed technique.functions.scissor and removed 3089 (SCISSOR_TEST) as a valid value for technique.states.enable, #681\n// - [ ] Techniques, programs, and shaders were moved out to KHR_technique_webgl extension.\n\n// Other edits:\n// - [x] asset is now required, #642\n// - [ ] buffer.byteLength and bufferView.byteLength are now required, #560.\n// - [ ] accessor.min and accessor.max are now required, #593, and clarified that the JSON value and binary data must be the same, #628.\n// - [ ] Clarified animation.sampler and animation.channel restrictions, #712\n// - [ ] skin.inverseBindMatrices is now optional, #461.\n// - [ ] Attribute parameters can't have a value defined in the technique or parameter, #563 (comment).\n// - [ ] Only TEXCOORD and COLOR attribute semantics can be written in the form [semantic]_[set_index], #563 (comment).\n// - [ ] 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\n// - [ ] camera.perspective.aspectRatio and camera.perspective.yfov must now be > 0, not >= 0, #563 (comment).\n// - [ ] Application-specific parameter semantics must start with an underscore, e.g., _TEMPERATURE and _SIMULATION_TIME, #563 (comment).\n// - [ ] Properties in technique.parameters must be defined in technique.uniforms or technique.attributes,\n\n// #563 (comment).\n// - [ ] 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\n// - [ ] technique.parameter.semantic is required when the parameter is an attribute, 28e113d\n// - [ ] Mesh-only models are allowed, e.g., without materials, #642\n// - [ ] Skeleton hierarchies (nodes containing jointName) must be separated from non-skeleton hierarchies., #647\n// - [ ] technique.states.functions.blendColor and technique.states.functions.depthRange parameters now must match WebGL function min/max, #707\n\nconst GLTF_ARRAYS = {\n accessors: 'accessor',\n animations: 'animation',\n buffers: 'buffer',\n bufferViews: 'bufferView',\n images: 'image',\n materials: 'material',\n meshes: 'mesh',\n nodes: 'node',\n samplers: 'sampler',\n scenes: 'scene',\n skins: 'skin',\n textures: 'texture'\n};\n\nconst GLTF_KEYS = {\n accessor: 'accessors',\n animations: 'animation',\n buffer: 'buffers',\n bufferView: 'bufferViews',\n image: 'images',\n material: 'materials',\n mesh: 'meshes',\n node: 'nodes',\n sampler: 'samplers',\n scene: 'scenes',\n skin: 'skins',\n texture: 'textures'\n};\n\n/**\n * Converts (normalizes) glTF v1 to v2\n */\nclass GLTFV1Normalizer {\n idToIndexMap = {\n animations: {},\n accessors: {},\n buffers: {},\n bufferViews: {},\n images: {},\n materials: {},\n meshes: {},\n nodes: {},\n samplers: {},\n scenes: {},\n skins: {},\n textures: {}\n };\n\n json;\n\n // constructor() {}\n\n /**\n * Convert (normalize) glTF < 2.0 to glTF 2.0\n * @param gltf - object with json and binChunks\n * @param options\n * @param options normalize Whether to actually normalize\n */\n normalize(gltf, options) {\n this.json = gltf.json;\n const json = gltf.json;\n\n // Check version\n switch (json.asset && json.asset.version) {\n // We are converting to v2 format. Return if there is nothing to do\n case '2.0':\n return;\n\n // This class is written to convert 1.0\n case undefined:\n case '1.0':\n break;\n\n default:\n // eslint-disable-next-line no-undef, no-console\n console.warn(`glTF: Unknown version ${json.asset.version}`);\n return;\n }\n\n if (!options.normalize) {\n // We are still missing a few conversion tricks, remove once addressed\n throw new Error('glTF v1 is not supported.');\n }\n\n // eslint-disable-next-line no-undef, no-console\n console.warn('Converting glTF v1 to glTF v2 format. This is experimental and may fail.');\n\n this._addAsset(json);\n\n // In glTF2 top-level fields are Arrays not Object maps\n this._convertTopLevelObjectsToArrays(json);\n\n // Extract bufferView indices for images\n // (this extension needs to be invoked early in the normalization process)\n // TODO can this be handled by standard extension processing instead of called explicitly?\n KHR_binary_glTF.preprocess(gltf);\n\n // Convert object references from ids to indices\n this._convertObjectIdsToArrayIndices(json);\n\n this._updateObjects(json);\n\n this._updateMaterial(json);\n }\n\n // asset is now required, #642 https://github.com/KhronosGroup/glTF/issues/639\n _addAsset(json) {\n json.asset = json.asset || {};\n // We are normalizing to glTF v2, so change version to \"2.0\"\n json.asset.version = '2.0';\n json.asset.generator = json.asset.generator || 'Normalized to glTF 2.0 by loaders.gl';\n }\n\n _convertTopLevelObjectsToArrays(json) {\n // TODO check that all arrays are covered\n for (const arrayName in GLTF_ARRAYS) {\n this._convertTopLevelObjectToArray(json, arrayName);\n }\n }\n\n /** Convert one top level object to array */\n _convertTopLevelObjectToArray(json, mapName) {\n const objectMap = json[mapName];\n if (!objectMap || Array.isArray(objectMap)) {\n return;\n }\n\n // Rewrite the top-level field as an array\n json[mapName] = [];\n // Copy the map key into object.id\n for (const id in objectMap) {\n const object = objectMap[id];\n object.id = object.id || id; // Mutates the loaded object\n const index = json[mapName].length;\n json[mapName].push(object);\n this.idToIndexMap[mapName][id] = index;\n }\n }\n\n /** Go through all objects in all top-level arrays and replace ids with indices */\n _convertObjectIdsToArrayIndices(json) {\n for (const arrayName in GLTF_ARRAYS) {\n this._convertIdsToIndices(json, arrayName);\n }\n if ('scene' in json) {\n json.scene = this._convertIdToIndex(json.scene, 'scene');\n }\n\n // Convert any index references that are not using array names\n\n // texture.source (image)\n for (const texture of json.textures) {\n this._convertTextureIds(texture);\n }\n for (const mesh of json.meshes) {\n this._convertMeshIds(mesh);\n }\n for (const node of json.nodes) {\n this._convertNodeIds(node);\n }\n for (const node of json.scenes) {\n this._convertSceneIds(node);\n }\n }\n\n _convertTextureIds(texture) {\n if (texture.source) {\n texture.source = this._convertIdToIndex(texture.source, 'image');\n }\n }\n\n _convertMeshIds(mesh) {\n for (const primitive of mesh.primitives) {\n const {attributes, indices, material} = primitive;\n for (const attributeName in attributes) {\n attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], 'accessor');\n }\n if (indices) {\n primitive.indices = this._convertIdToIndex(indices, 'accessor');\n }\n if (material) {\n primitive.material = this._convertIdToIndex(material, 'material');\n }\n }\n }\n\n _convertNodeIds(node) {\n if (node.children) {\n node.children = node.children.map((child) => this._convertIdToIndex(child, 'node'));\n }\n if (node.meshes) {\n node.meshes = node.meshes.map((mesh) => this._convertIdToIndex(mesh, 'mesh'));\n }\n }\n\n _convertSceneIds(scene) {\n if (scene.nodes) {\n scene.nodes = scene.nodes.map((node) => this._convertIdToIndex(node, 'node'));\n }\n }\n\n /** Go through all objects in a top-level array and replace ids with indices */\n _convertIdsToIndices(json, topLevelArrayName) {\n if (!json[topLevelArrayName]) {\n console.warn(`gltf v1: json doesn't contain attribute ${topLevelArrayName}`); // eslint-disable-line no-console, no-undef\n json[topLevelArrayName] = [];\n }\n for (const object of json[topLevelArrayName]) {\n for (const key in object) {\n const id = object[key];\n const index = this._convertIdToIndex(id, key);\n object[key] = index;\n }\n }\n }\n\n _convertIdToIndex(id, key) {\n const arrayName = GLTF_KEYS[key];\n if (arrayName in this.idToIndexMap) {\n const index = this.idToIndexMap[arrayName][id];\n if (!Number.isFinite(index)) {\n throw new Error(`gltf v1: failed to resolve ${key} with id ${id}`);\n }\n return index;\n }\n return id;\n }\n\n /**\n *\n * @param {*} json\n */\n _updateObjects(json) {\n for (const buffer of this.json.buffers) {\n // - [x] Removed buffer.type, #786, #629\n delete buffer.type;\n }\n }\n\n /**\n * Update material (set pbrMetallicRoughness)\n * @param {*} json\n */\n _updateMaterial(json) {\n for (const material of json.materials) {\n material.pbrMetallicRoughness = {\n baseColorFactor: [1, 1, 1, 1],\n metallicFactor: 1,\n roughnessFactor: 1\n };\n\n const textureId =\n material.values?.tex || material.values?.texture2d_0 || material.values?.diffuseTex;\n const textureIndex = json.textures.findIndex((texture) => texture.id === textureId);\n if (textureIndex !== -1) {\n material.pbrMetallicRoughness.baseColorTexture = {index: textureIndex};\n }\n }\n }\n}\n\nexport function normalizeGLTFV1(gltf, options = {}) {\n return new GLTFV1Normalizer().normalize(gltf, options);\n}\n"],"file":"normalize-gltf-v1.js"}
|
|
1
|
+
{"version":3,"file":"normalize-gltf-v1.js","names":["KHR_binary_glTF","GLTF_ARRAYS","accessors","animations","buffers","bufferViews","images","materials","meshes","nodes","samplers","scenes","skins","textures","GLTF_KEYS","accessor","buffer","bufferView","image","material","mesh","node","sampler","scene","skin","texture","GLTFV1Normalizer","normalize","gltf","options","json","asset","version","undefined","console","warn","Error","_addAsset","_convertTopLevelObjectsToArrays","preprocess","_convertObjectIdsToArrayIndices","_updateObjects","_updateMaterial","generator","arrayName","_convertTopLevelObjectToArray","mapName","objectMap","Array","isArray","id","object","index","length","push","idToIndexMap","_convertIdsToIndices","_convertIdToIndex","_convertTextureIds","_convertMeshIds","_convertNodeIds","_convertSceneIds","source","primitive","primitives","attributes","indices","attributeName","children","map","child","topLevelArrayName","key","Number","isFinite","type","pbrMetallicRoughness","baseColorFactor","metallicFactor","roughnessFactor","textureId","values","tex","texture2d_0","diffuseTex","textureIndex","findIndex","baseColorTexture","normalizeGLTFV1"],"sources":["../../../../src/lib/api/normalize-gltf-v1.ts"],"sourcesContent":["/* eslint-disable camelcase */\nimport * as KHR_binary_glTF from '../extensions/KHR_binary_gltf';\n\n// Binary format changes (mainly implemented by GLBLoader)\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF\n\n// JSON format changes:\n// https://github.com/khronosgroup/gltf/issues/605\n\n// - [x] Top-level JSON objects are arrays now\n// - [ ] Removed indirection from animation: sampler now refers directly to accessors, #712\n// - [ ] material.parameter.value and technique.parameter.value must be an array, #690\n// - [ ] Node can have only one mesh #821\n// - [ ] Added reqs on JSON encoding\n// - [ ] Added reqs on binary data alignment #802 (comment)\n\n// Additions:\n// - [ ] Added accessor.normalized, #691, #706\n// - [ ] Added glExtensionsUsed property and 5125 (UNSIGNED_INT) accessor.componentType value, #619\n// - [ ] Added extensionsRequired property, #720, #721\n// - [ ] Added \"STEP\" as valid animation.sampler.interpolation value, #712\n\n// Removals:\n// - [x] Removed buffer.type, #786, #629\n// - [ ] Removed revision number from profile.version, #709\n// - [ ] Removed technique.functions.scissor and removed 3089 (SCISSOR_TEST) as a valid value for technique.states.enable, #681\n// - [ ] Techniques, programs, and shaders were moved out to KHR_technique_webgl extension.\n\n// Other edits:\n// - [x] asset is now required, #642\n// - [ ] buffer.byteLength and bufferView.byteLength are now required, #560.\n// - [ ] accessor.min and accessor.max are now required, #593, and clarified that the JSON value and binary data must be the same, #628.\n// - [ ] Clarified animation.sampler and animation.channel restrictions, #712\n// - [ ] skin.inverseBindMatrices is now optional, #461.\n// - [ ] Attribute parameters can't have a value defined in the technique or parameter, #563 (comment).\n// - [ ] Only TEXCOORD and COLOR attribute semantics can be written in the form [semantic]_[set_index], #563 (comment).\n// - [ ] 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\n// - [ ] camera.perspective.aspectRatio and camera.perspective.yfov must now be > 0, not >= 0, #563 (comment).\n// - [ ] Application-specific parameter semantics must start with an underscore, e.g., _TEMPERATURE and _SIMULATION_TIME, #563 (comment).\n// - [ ] Properties in technique.parameters must be defined in technique.uniforms or technique.attributes,\n\n// #563 (comment).\n// - [ ] 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\n// - [ ] technique.parameter.semantic is required when the parameter is an attribute, 28e113d\n// - [ ] Mesh-only models are allowed, e.g., without materials, #642\n// - [ ] Skeleton hierarchies (nodes containing jointName) must be separated from non-skeleton hierarchies., #647\n// - [ ] technique.states.functions.blendColor and technique.states.functions.depthRange parameters now must match WebGL function min/max, #707\n\nconst GLTF_ARRAYS = {\n accessors: 'accessor',\n animations: 'animation',\n buffers: 'buffer',\n bufferViews: 'bufferView',\n images: 'image',\n materials: 'material',\n meshes: 'mesh',\n nodes: 'node',\n samplers: 'sampler',\n scenes: 'scene',\n skins: 'skin',\n textures: 'texture'\n};\n\nconst GLTF_KEYS = {\n accessor: 'accessors',\n animations: 'animation',\n buffer: 'buffers',\n bufferView: 'bufferViews',\n image: 'images',\n material: 'materials',\n mesh: 'meshes',\n node: 'nodes',\n sampler: 'samplers',\n scene: 'scenes',\n skin: 'skins',\n texture: 'textures'\n};\n\n/**\n * Converts (normalizes) glTF v1 to v2\n */\nclass GLTFV1Normalizer {\n idToIndexMap = {\n animations: {},\n accessors: {},\n buffers: {},\n bufferViews: {},\n images: {},\n materials: {},\n meshes: {},\n nodes: {},\n samplers: {},\n scenes: {},\n skins: {},\n textures: {}\n };\n\n json;\n\n // constructor() {}\n\n /**\n * Convert (normalize) glTF < 2.0 to glTF 2.0\n * @param gltf - object with json and binChunks\n * @param options\n * @param options normalize Whether to actually normalize\n */\n normalize(gltf, options) {\n this.json = gltf.json;\n const json = gltf.json;\n\n // Check version\n switch (json.asset && json.asset.version) {\n // We are converting to v2 format. Return if there is nothing to do\n case '2.0':\n return;\n\n // This class is written to convert 1.0\n case undefined:\n case '1.0':\n break;\n\n default:\n // eslint-disable-next-line no-undef, no-console\n console.warn(`glTF: Unknown version ${json.asset.version}`);\n return;\n }\n\n if (!options.normalize) {\n // We are still missing a few conversion tricks, remove once addressed\n throw new Error('glTF v1 is not supported.');\n }\n\n // eslint-disable-next-line no-undef, no-console\n console.warn('Converting glTF v1 to glTF v2 format. This is experimental and may fail.');\n\n this._addAsset(json);\n\n // In glTF2 top-level fields are Arrays not Object maps\n this._convertTopLevelObjectsToArrays(json);\n\n // Extract bufferView indices for images\n // (this extension needs to be invoked early in the normalization process)\n // TODO can this be handled by standard extension processing instead of called explicitly?\n KHR_binary_glTF.preprocess(gltf);\n\n // Convert object references from ids to indices\n this._convertObjectIdsToArrayIndices(json);\n\n this._updateObjects(json);\n\n this._updateMaterial(json);\n }\n\n // asset is now required, #642 https://github.com/KhronosGroup/glTF/issues/639\n _addAsset(json) {\n json.asset = json.asset || {};\n // We are normalizing to glTF v2, so change version to \"2.0\"\n json.asset.version = '2.0';\n json.asset.generator = json.asset.generator || 'Normalized to glTF 2.0 by loaders.gl';\n }\n\n _convertTopLevelObjectsToArrays(json) {\n // TODO check that all arrays are covered\n for (const arrayName in GLTF_ARRAYS) {\n this._convertTopLevelObjectToArray(json, arrayName);\n }\n }\n\n /** Convert one top level object to array */\n _convertTopLevelObjectToArray(json, mapName) {\n const objectMap = json[mapName];\n if (!objectMap || Array.isArray(objectMap)) {\n return;\n }\n\n // Rewrite the top-level field as an array\n json[mapName] = [];\n // Copy the map key into object.id\n for (const id in objectMap) {\n const object = objectMap[id];\n object.id = object.id || id; // Mutates the loaded object\n const index = json[mapName].length;\n json[mapName].push(object);\n this.idToIndexMap[mapName][id] = index;\n }\n }\n\n /** Go through all objects in all top-level arrays and replace ids with indices */\n _convertObjectIdsToArrayIndices(json) {\n for (const arrayName in GLTF_ARRAYS) {\n this._convertIdsToIndices(json, arrayName);\n }\n if ('scene' in json) {\n json.scene = this._convertIdToIndex(json.scene, 'scene');\n }\n\n // Convert any index references that are not using array names\n\n // texture.source (image)\n for (const texture of json.textures) {\n this._convertTextureIds(texture);\n }\n for (const mesh of json.meshes) {\n this._convertMeshIds(mesh);\n }\n for (const node of json.nodes) {\n this._convertNodeIds(node);\n }\n for (const node of json.scenes) {\n this._convertSceneIds(node);\n }\n }\n\n _convertTextureIds(texture) {\n if (texture.source) {\n texture.source = this._convertIdToIndex(texture.source, 'image');\n }\n }\n\n _convertMeshIds(mesh) {\n for (const primitive of mesh.primitives) {\n const {attributes, indices, material} = primitive;\n for (const attributeName in attributes) {\n attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], 'accessor');\n }\n if (indices) {\n primitive.indices = this._convertIdToIndex(indices, 'accessor');\n }\n if (material) {\n primitive.material = this._convertIdToIndex(material, 'material');\n }\n }\n }\n\n _convertNodeIds(node) {\n if (node.children) {\n node.children = node.children.map((child) => this._convertIdToIndex(child, 'node'));\n }\n if (node.meshes) {\n node.meshes = node.meshes.map((mesh) => this._convertIdToIndex(mesh, 'mesh'));\n }\n }\n\n _convertSceneIds(scene) {\n if (scene.nodes) {\n scene.nodes = scene.nodes.map((node) => this._convertIdToIndex(node, 'node'));\n }\n }\n\n /** Go through all objects in a top-level array and replace ids with indices */\n _convertIdsToIndices(json, topLevelArrayName) {\n if (!json[topLevelArrayName]) {\n console.warn(`gltf v1: json doesn't contain attribute ${topLevelArrayName}`); // eslint-disable-line no-console, no-undef\n json[topLevelArrayName] = [];\n }\n for (const object of json[topLevelArrayName]) {\n for (const key in object) {\n const id = object[key];\n const index = this._convertIdToIndex(id, key);\n object[key] = index;\n }\n }\n }\n\n _convertIdToIndex(id, key) {\n const arrayName = GLTF_KEYS[key];\n if (arrayName in this.idToIndexMap) {\n const index = this.idToIndexMap[arrayName][id];\n if (!Number.isFinite(index)) {\n throw new Error(`gltf v1: failed to resolve ${key} with id ${id}`);\n }\n return index;\n }\n return id;\n }\n\n /**\n *\n * @param {*} json\n */\n _updateObjects(json) {\n for (const buffer of this.json.buffers) {\n // - [x] Removed buffer.type, #786, #629\n delete buffer.type;\n }\n }\n\n /**\n * Update material (set pbrMetallicRoughness)\n * @param {*} json\n */\n _updateMaterial(json) {\n for (const material of json.materials) {\n material.pbrMetallicRoughness = {\n baseColorFactor: [1, 1, 1, 1],\n metallicFactor: 1,\n roughnessFactor: 1\n };\n\n const textureId =\n material.values?.tex || material.values?.texture2d_0 || material.values?.diffuseTex;\n const textureIndex = json.textures.findIndex((texture) => texture.id === textureId);\n if (textureIndex !== -1) {\n material.pbrMetallicRoughness.baseColorTexture = {index: textureIndex};\n }\n }\n }\n}\n\nexport function normalizeGLTFV1(gltf, options = {}) {\n return new GLTFV1Normalizer().normalize(gltf, options);\n}\n"],"mappings":";AACA,OAAO,KAAKA,eAAe,MAAM,+BAA+B;;AA+ChE,MAAMC,WAAW,GAAG;EAClBC,SAAS,EAAE,UAAU;EACrBC,UAAU,EAAE,WAAW;EACvBC,OAAO,EAAE,QAAQ;EACjBC,WAAW,EAAE,YAAY;EACzBC,MAAM,EAAE,OAAO;EACfC,SAAS,EAAE,UAAU;EACrBC,MAAM,EAAE,MAAM;EACdC,KAAK,EAAE,MAAM;EACbC,QAAQ,EAAE,SAAS;EACnBC,MAAM,EAAE,OAAO;EACfC,KAAK,EAAE,MAAM;EACbC,QAAQ,EAAE;AACZ,CAAC;AAED,MAAMC,SAAS,GAAG;EAChBC,QAAQ,EAAE,WAAW;EACrBZ,UAAU,EAAE,WAAW;EACvBa,MAAM,EAAE,SAAS;EACjBC,UAAU,EAAE,aAAa;EACzBC,KAAK,EAAE,QAAQ;EACfC,QAAQ,EAAE,WAAW;EACrBC,IAAI,EAAE,QAAQ;EACdC,IAAI,EAAE,OAAO;EACbC,OAAO,EAAE,UAAU;EACnBC,KAAK,EAAE,QAAQ;EACfC,IAAI,EAAE,OAAO;EACbC,OAAO,EAAE;AACX,CAAC;;AAKD,MAAMC,gBAAgB,CAAC;EAAA;IAAA,sCACN;MACbvB,UAAU,EAAE,CAAC,CAAC;MACdD,SAAS,EAAE,CAAC,CA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AC,CAAC;EAChD,OAAO,IAAIH,gBAAgB,EAAE,CAACC,SAAS,CAACC,IAAI,EAAEC,OAAO,CAAC;AACxD"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
import { assert } from '../utils/assert';
|
|
3
3
|
import { getAccessorArrayTypeAndLength } from '../gltf-utils/gltf-utils';
|
|
4
|
+
|
|
4
5
|
const COMPONENTS = {
|
|
5
6
|
SCALAR: 1,
|
|
6
7
|
VEC2: 2,
|
|
@@ -18,6 +19,7 @@ const BYTES = {
|
|
|
18
19
|
5125: 4,
|
|
19
20
|
5126: 4
|
|
20
21
|
};
|
|
22
|
+
|
|
21
23
|
const GL_SAMPLER = {
|
|
22
24
|
TEXTURE_MAG_FILTER: 0x2800,
|
|
23
25
|
TEXTURE_MIN_FILTER: 0x2801,
|
|
@@ -33,33 +35,28 @@ const SAMPLER_PARAMETER_GLTF_TO_GL = {
|
|
|
33
35
|
wrapS: GL_SAMPLER.TEXTURE_WRAP_S,
|
|
34
36
|
wrapT: GL_SAMPLER.TEXTURE_WRAP_T
|
|
35
37
|
};
|
|
38
|
+
|
|
36
39
|
const DEFAULT_SAMPLER = {
|
|
37
40
|
[GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR,
|
|
38
41
|
[GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR,
|
|
39
42
|
[GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT,
|
|
40
43
|
[GL_SAMPLER.TEXTURE_WRAP_T]: GL_SAMPLER.REPEAT
|
|
41
44
|
};
|
|
42
|
-
|
|
43
45
|
function getBytesFromComponentType(componentType) {
|
|
44
46
|
return BYTES[componentType];
|
|
45
47
|
}
|
|
46
|
-
|
|
47
48
|
function getSizeFromAccessorType(type) {
|
|
48
49
|
return COMPONENTS[type];
|
|
49
50
|
}
|
|
50
|
-
|
|
51
51
|
class GLTFPostProcessor {
|
|
52
52
|
constructor() {
|
|
53
53
|
_defineProperty(this, "baseUri", '');
|
|
54
|
-
|
|
55
54
|
_defineProperty(this, "json", {});
|
|
56
|
-
|
|
57
55
|
_defineProperty(this, "buffers", []);
|
|
58
|
-
|
|
59
56
|
_defineProperty(this, "images", []);
|
|
60
57
|
}
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
postProcess(gltf) {
|
|
59
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
63
60
|
const {
|
|
64
61
|
json,
|
|
65
62
|
buffers = [],
|
|
@@ -71,82 +68,64 @@ class GLTFPostProcessor {
|
|
|
71
68
|
this.json = json;
|
|
72
69
|
this.buffers = buffers;
|
|
73
70
|
this.images = images;
|
|
74
|
-
|
|
75
71
|
this._resolveTree(this.json, options);
|
|
76
|
-
|
|
77
72
|
return this.json;
|
|
78
73
|
}
|
|
79
74
|
|
|
80
|
-
_resolveTree(json
|
|
75
|
+
_resolveTree(json) {
|
|
76
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
81
77
|
if (json.bufferViews) {
|
|
82
78
|
json.bufferViews = json.bufferViews.map((bufView, i) => this._resolveBufferView(bufView, i));
|
|
83
79
|
}
|
|
84
|
-
|
|
85
80
|
if (json.images) {
|
|
86
81
|
json.images = json.images.map((image, i) => this._resolveImage(image, i));
|
|
87
82
|
}
|
|
88
|
-
|
|
89
83
|
if (json.samplers) {
|
|
90
84
|
json.samplers = json.samplers.map((sampler, i) => this._resolveSampler(sampler, i));
|
|
91
85
|
}
|
|
92
|
-
|
|
93
86
|
if (json.textures) {
|
|
94
87
|
json.textures = json.textures.map((texture, i) => this._resolveTexture(texture, i));
|
|
95
88
|
}
|
|
96
|
-
|
|
97
89
|
if (json.accessors) {
|
|
98
90
|
json.accessors = json.accessors.map((accessor, i) => this._resolveAccessor(accessor, i));
|
|
99
91
|
}
|
|
100
|
-
|
|
101
92
|
if (json.materials) {
|
|
102
93
|
json.materials = json.materials.map((material, i) => this._resolveMaterial(material, i));
|
|
103
94
|
}
|
|
104
|
-
|
|
105
95
|
if (json.meshes) {
|
|
106
96
|
json.meshes = json.meshes.map((mesh, i) => this._resolveMesh(mesh, i));
|
|
107
97
|
}
|
|
108
|
-
|
|
109
98
|
if (json.nodes) {
|
|
110
99
|
json.nodes = json.nodes.map((node, i) => this._resolveNode(node, i));
|
|
111
100
|
}
|
|
112
|
-
|
|
113
101
|
if (json.skins) {
|
|
114
102
|
json.skins = json.skins.map((skin, i) => this._resolveSkin(skin, i));
|
|
115
103
|
}
|
|
116
|
-
|
|
117
104
|
if (json.scenes) {
|
|
118
105
|
json.scenes = json.scenes.map((scene, i) => this._resolveScene(scene, i));
|
|
119
106
|
}
|
|
120
|
-
|
|
121
107
|
if (json.scene !== undefined) {
|
|
122
108
|
json.scene = json.scenes[this.json.scene];
|
|
123
109
|
}
|
|
124
110
|
}
|
|
125
|
-
|
|
126
111
|
getScene(index) {
|
|
127
112
|
return this._get('scenes', index);
|
|
128
113
|
}
|
|
129
|
-
|
|
130
114
|
getNode(index) {
|
|
131
115
|
return this._get('nodes', index);
|
|
132
116
|
}
|
|
133
|
-
|
|
134
117
|
getSkin(index) {
|
|
135
118
|
return this._get('skins', index);
|
|
136
119
|
}
|
|
137
|
-
|
|
138
120
|
getMesh(index) {
|
|
139
121
|
return this._get('meshes', index);
|
|
140
122
|
}
|
|
141
|
-
|
|
142
123
|
getMaterial(index) {
|
|
143
124
|
return this._get('materials', index);
|
|
144
125
|
}
|
|
145
|
-
|
|
146
126
|
getAccessor(index) {
|
|
147
127
|
return this._get('accessors', index);
|
|
148
128
|
}
|
|
149
|
-
|
|
150
129
|
getCamera(index) {
|
|
151
130
|
return null;
|
|
152
131
|
}
|
|
@@ -154,30 +133,23 @@ class GLTFPostProcessor {
|
|
|
154
133
|
getTexture(index) {
|
|
155
134
|
return this._get('textures', index);
|
|
156
135
|
}
|
|
157
|
-
|
|
158
136
|
getSampler(index) {
|
|
159
137
|
return this._get('samplers', index);
|
|
160
138
|
}
|
|
161
|
-
|
|
162
139
|
getImage(index) {
|
|
163
140
|
return this._get('images', index);
|
|
164
141
|
}
|
|
165
|
-
|
|
166
142
|
getBufferView(index) {
|
|
167
143
|
return this._get('bufferViews', index);
|
|
168
144
|
}
|
|
169
|
-
|
|
170
145
|
getBuffer(index) {
|
|
171
146
|
return this._get('buffers', index);
|
|
172
147
|
}
|
|
173
|
-
|
|
174
148
|
_get(array, index) {
|
|
175
149
|
if (typeof index === 'object') {
|
|
176
150
|
return index;
|
|
177
151
|
}
|
|
178
|
-
|
|
179
152
|
const object = this.json[array] && this.json[array][index];
|
|
180
|
-
|
|
181
153
|
if (!object) {
|
|
182
154
|
console.warn("glTF file error: Could not find ".concat(array, "[").concat(index, "]"));
|
|
183
155
|
}
|
|
@@ -190,14 +162,11 @@ class GLTFPostProcessor {
|
|
|
190
162
|
scene.nodes = (scene.nodes || []).map(node => this.getNode(node));
|
|
191
163
|
return scene;
|
|
192
164
|
}
|
|
193
|
-
|
|
194
165
|
_resolveNode(node, index) {
|
|
195
166
|
node.id = node.id || "node-".concat(index);
|
|
196
|
-
|
|
197
167
|
if (node.children) {
|
|
198
168
|
node.children = node.children.map(child => this.getNode(child));
|
|
199
169
|
}
|
|
200
|
-
|
|
201
170
|
if (node.mesh !== undefined) {
|
|
202
171
|
node.mesh = this.getMesh(node.mesh);
|
|
203
172
|
} else if (node.meshes !== undefined && node.meshes.length) {
|
|
@@ -210,102 +179,87 @@ class GLTFPostProcessor {
|
|
|
210
179
|
primitives: []
|
|
211
180
|
});
|
|
212
181
|
}
|
|
213
|
-
|
|
214
182
|
if (node.camera !== undefined) {
|
|
215
183
|
node.camera = this.getCamera(node.camera);
|
|
216
184
|
}
|
|
217
|
-
|
|
218
185
|
if (node.skin !== undefined) {
|
|
219
186
|
node.skin = this.getSkin(node.skin);
|
|
220
187
|
}
|
|
221
|
-
|
|
222
188
|
return node;
|
|
223
189
|
}
|
|
224
|
-
|
|
225
190
|
_resolveSkin(skin, index) {
|
|
226
191
|
skin.id = skin.id || "skin-".concat(index);
|
|
227
192
|
skin.inverseBindMatrices = this.getAccessor(skin.inverseBindMatrices);
|
|
228
193
|
return skin;
|
|
229
194
|
}
|
|
230
|
-
|
|
231
195
|
_resolveMesh(mesh, index) {
|
|
232
196
|
mesh.id = mesh.id || "mesh-".concat(index);
|
|
233
|
-
|
|
234
197
|
if (mesh.primitives) {
|
|
235
198
|
mesh.primitives = mesh.primitives.map(primitive => {
|
|
236
|
-
primitive = {
|
|
199
|
+
primitive = {
|
|
200
|
+
...primitive
|
|
237
201
|
};
|
|
238
202
|
const attributes = primitive.attributes;
|
|
239
203
|
primitive.attributes = {};
|
|
240
|
-
|
|
241
204
|
for (const attribute in attributes) {
|
|
242
205
|
primitive.attributes[attribute] = this.getAccessor(attributes[attribute]);
|
|
243
206
|
}
|
|
244
|
-
|
|
245
207
|
if (primitive.indices !== undefined) {
|
|
246
208
|
primitive.indices = this.getAccessor(primitive.indices);
|
|
247
209
|
}
|
|
248
|
-
|
|
249
210
|
if (primitive.material !== undefined) {
|
|
250
211
|
primitive.material = this.getMaterial(primitive.material);
|
|
251
212
|
}
|
|
252
|
-
|
|
253
213
|
return primitive;
|
|
254
214
|
});
|
|
255
215
|
}
|
|
256
|
-
|
|
257
216
|
return mesh;
|
|
258
217
|
}
|
|
259
|
-
|
|
260
218
|
_resolveMaterial(material, index) {
|
|
261
219
|
material.id = material.id || "material-".concat(index);
|
|
262
|
-
|
|
263
220
|
if (material.normalTexture) {
|
|
264
|
-
material.normalTexture = {
|
|
221
|
+
material.normalTexture = {
|
|
222
|
+
...material.normalTexture
|
|
265
223
|
};
|
|
266
224
|
material.normalTexture.texture = this.getTexture(material.normalTexture.index);
|
|
267
225
|
}
|
|
268
|
-
|
|
269
226
|
if (material.occlusionTexture) {
|
|
270
|
-
material.occlustionTexture = {
|
|
227
|
+
material.occlustionTexture = {
|
|
228
|
+
...material.occlustionTexture
|
|
271
229
|
};
|
|
272
230
|
material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);
|
|
273
231
|
}
|
|
274
|
-
|
|
275
232
|
if (material.emissiveTexture) {
|
|
276
|
-
material.emmisiveTexture = {
|
|
233
|
+
material.emmisiveTexture = {
|
|
234
|
+
...material.emmisiveTexture
|
|
277
235
|
};
|
|
278
236
|
material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index);
|
|
279
237
|
}
|
|
280
|
-
|
|
281
238
|
if (!material.emissiveFactor) {
|
|
282
239
|
material.emissiveFactor = material.emmisiveTexture ? [1, 1, 1] : [0, 0, 0];
|
|
283
240
|
}
|
|
284
|
-
|
|
285
241
|
if (material.pbrMetallicRoughness) {
|
|
286
|
-
material.pbrMetallicRoughness = {
|
|
242
|
+
material.pbrMetallicRoughness = {
|
|
243
|
+
...material.pbrMetallicRoughness
|
|
287
244
|
};
|
|
288
245
|
const mr = material.pbrMetallicRoughness;
|
|
289
|
-
|
|
290
246
|
if (mr.baseColorTexture) {
|
|
291
|
-
mr.baseColorTexture = {
|
|
247
|
+
mr.baseColorTexture = {
|
|
248
|
+
...mr.baseColorTexture
|
|
292
249
|
};
|
|
293
250
|
mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index);
|
|
294
251
|
}
|
|
295
|
-
|
|
296
252
|
if (mr.metallicRoughnessTexture) {
|
|
297
|
-
mr.metallicRoughnessTexture = {
|
|
253
|
+
mr.metallicRoughnessTexture = {
|
|
254
|
+
...mr.metallicRoughnessTexture
|
|
298
255
|
};
|
|
299
256
|
mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index);
|
|
300
257
|
}
|
|
301
258
|
}
|
|
302
|
-
|
|
303
259
|
return material;
|
|
304
260
|
}
|
|
305
|
-
|
|
306
261
|
_resolveAccessor(accessor, index) {
|
|
307
262
|
accessor.id = accessor.id || "accessor-".concat(index);
|
|
308
|
-
|
|
309
263
|
if (accessor.bufferView !== undefined) {
|
|
310
264
|
accessor.bufferView = this.getBufferView(accessor.bufferView);
|
|
311
265
|
}
|
|
@@ -322,70 +276,54 @@ class GLTFPostProcessor {
|
|
|
322
276
|
} = getAccessorArrayTypeAndLength(accessor, accessor.bufferView);
|
|
323
277
|
const byteOffset = (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;
|
|
324
278
|
let cutBuffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength);
|
|
325
|
-
|
|
326
279
|
if (accessor.bufferView.byteStride) {
|
|
327
280
|
cutBuffer = this._getValueFromInterleavedBuffer(buffer, byteOffset, accessor.bufferView.byteStride, accessor.bytesPerElement, accessor.count);
|
|
328
281
|
}
|
|
329
|
-
|
|
330
282
|
accessor.value = new ArrayType(cutBuffer);
|
|
331
283
|
}
|
|
332
|
-
|
|
333
284
|
return accessor;
|
|
334
285
|
}
|
|
335
286
|
|
|
336
287
|
_getValueFromInterleavedBuffer(buffer, byteOffset, byteStride, bytesPerElement, count) {
|
|
337
288
|
const result = new Uint8Array(count * bytesPerElement);
|
|
338
|
-
|
|
339
289
|
for (let i = 0; i < count; i++) {
|
|
340
290
|
const elementOffset = byteOffset + i * byteStride;
|
|
341
291
|
result.set(new Uint8Array(buffer.arrayBuffer.slice(elementOffset, elementOffset + bytesPerElement)), i * bytesPerElement);
|
|
342
292
|
}
|
|
343
|
-
|
|
344
293
|
return result.buffer;
|
|
345
294
|
}
|
|
346
|
-
|
|
347
295
|
_resolveTexture(texture, index) {
|
|
348
296
|
texture.id = texture.id || "texture-".concat(index);
|
|
349
297
|
texture.sampler = 'sampler' in texture ? this.getSampler(texture.sampler) : DEFAULT_SAMPLER;
|
|
350
298
|
texture.source = this.getImage(texture.source);
|
|
351
299
|
return texture;
|
|
352
300
|
}
|
|
353
|
-
|
|
354
301
|
_resolveSampler(sampler, index) {
|
|
355
302
|
sampler.id = sampler.id || "sampler-".concat(index);
|
|
356
303
|
sampler.parameters = {};
|
|
357
|
-
|
|
358
304
|
for (const key in sampler) {
|
|
359
305
|
const glEnum = this._enumSamplerParameter(key);
|
|
360
|
-
|
|
361
306
|
if (glEnum !== undefined) {
|
|
362
307
|
sampler.parameters[glEnum] = sampler[key];
|
|
363
308
|
}
|
|
364
309
|
}
|
|
365
|
-
|
|
366
310
|
return sampler;
|
|
367
311
|
}
|
|
368
|
-
|
|
369
312
|
_enumSamplerParameter(key) {
|
|
370
313
|
return SAMPLER_PARAMETER_GLTF_TO_GL[key];
|
|
371
314
|
}
|
|
372
|
-
|
|
373
315
|
_resolveImage(image, index) {
|
|
374
316
|
image.id = image.id || "image-".concat(index);
|
|
375
|
-
|
|
376
317
|
if (image.bufferView !== undefined) {
|
|
377
318
|
image.bufferView = this.getBufferView(image.bufferView);
|
|
378
319
|
}
|
|
379
320
|
|
|
380
321
|
const preloadedImage = this.images[index];
|
|
381
|
-
|
|
382
322
|
if (preloadedImage) {
|
|
383
323
|
image.image = preloadedImage;
|
|
384
324
|
}
|
|
385
|
-
|
|
386
325
|
return image;
|
|
387
326
|
}
|
|
388
|
-
|
|
389
327
|
_resolveBufferView(bufferView, index) {
|
|
390
328
|
const bufferIndex = bufferView.buffer;
|
|
391
329
|
const result = {
|
|
@@ -393,29 +331,24 @@ class GLTFPostProcessor {
|
|
|
393
331
|
...bufferView,
|
|
394
332
|
buffer: this.buffers[bufferIndex]
|
|
395
333
|
};
|
|
334
|
+
|
|
396
335
|
const arrayBuffer = this.buffers[bufferIndex].arrayBuffer;
|
|
397
336
|
let byteOffset = this.buffers[bufferIndex].byteOffset || 0;
|
|
398
|
-
|
|
399
337
|
if ('byteOffset' in bufferView) {
|
|
400
338
|
byteOffset += bufferView.byteOffset;
|
|
401
339
|
}
|
|
402
|
-
|
|
403
340
|
result.data = new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);
|
|
404
341
|
return result;
|
|
405
342
|
}
|
|
406
|
-
|
|
407
343
|
_resolveCamera(camera, index) {
|
|
408
344
|
camera.id = camera.id || "camera-".concat(index);
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
345
|
+
if (camera.perspective) {
|
|
346
|
+
}
|
|
347
|
+
if (camera.orthographic) {
|
|
348
|
+
}
|
|
414
349
|
return camera;
|
|
415
350
|
}
|
|
416
|
-
|
|
417
351
|
}
|
|
418
|
-
|
|
419
352
|
export function postProcessGLTF(gltf, options) {
|
|
420
353
|
return new GLTFPostProcessor().postProcess(gltf, options);
|
|
421
354
|
}
|