@babylonjs/loaders 5.19.0 → 5.22.0
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/OBJ/mtlFileLoader.js +25 -27
- package/OBJ/mtlFileLoader.js.map +1 -1
- package/OBJ/objFileLoader.js +112 -124
- package/OBJ/objFileLoader.js.map +1 -1
- package/OBJ/solidParser.js +118 -125
- package/OBJ/solidParser.js.map +1 -1
- package/STL/stlFileLoader.js +61 -63
- package/STL/stlFileLoader.js.map +1 -1
- package/glTF/1.0/glTFBinaryExtension.js +26 -30
- package/glTF/1.0/glTFBinaryExtension.js.map +1 -1
- package/glTF/1.0/glTFLoader.js +409 -432
- package/glTF/1.0/glTFLoader.js.map +1 -1
- package/glTF/1.0/glTFLoaderUtils.js +33 -37
- package/glTF/1.0/glTFLoaderUtils.js.map +1 -1
- package/glTF/1.0/glTFMaterialsCommonExtension.js +27 -31
- package/glTF/1.0/glTFMaterialsCommonExtension.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +48 -59
- package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +24 -29
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js +13 -16
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_texture_webp.js +13 -16
- package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js +22 -26
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_animation_pointer.js +63 -76
- package/glTF/2.0/Extensions/KHR_animation_pointer.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_animation_pointer.map.js +90 -120
- package/glTF/2.0/Extensions/KHR_animation_pointer.map.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +25 -28
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +27 -30
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +25 -28
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +15 -18
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_ior.js +21 -24
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js +27 -31
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +24 -27
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +23 -26
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.js +23 -26
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_translucency.js +20 -23
- package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +82 -86
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +19 -22
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_variants.js +79 -97
- package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.js +20 -23
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js +6 -8
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_basisu.js +13 -16
- package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.js +12 -15
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +12 -15
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js +77 -95
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.js +114 -139
- package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +12 -15
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +12 -15
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
- package/glTF/2.0/glTFLoader.js +739 -823
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/glTFFileLoader.js +337 -404
- package/glTF/glTFFileLoader.js.map +1 -1
- package/glTF/glTFValidation.js +32 -39
- package/glTF/glTFValidation.js.map +1 -1
- package/legacy/legacy-glTF.js +3 -3
- package/legacy/legacy-glTF.js.map +1 -1
- package/legacy/legacy-glTF1.js +2 -2
- package/legacy/legacy-glTF1.js.map +1 -1
- package/legacy/legacy-glTF2.js +12 -12
- package/legacy/legacy-glTF2.js.map +1 -1
- package/legacy/legacy-objFileLoader.js +2 -2
- package/legacy/legacy-objFileLoader.js.map +1 -1
- package/legacy/legacy-stlFileLoader.js +2 -2
- package/legacy/legacy-stlFileLoader.js.map +1 -1
- package/package.json +3 -6
package/glTF/1.0/glTFLoader.js
CHANGED
|
@@ -36,8 +36,8 @@ var ETokenType;
|
|
|
36
36
|
ETokenType[ETokenType["UNKNOWN"] = 2] = "UNKNOWN";
|
|
37
37
|
ETokenType[ETokenType["END_OF_INPUT"] = 3] = "END_OF_INPUT";
|
|
38
38
|
})(ETokenType || (ETokenType = {}));
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
class Tokenizer {
|
|
40
|
+
constructor(toParse) {
|
|
41
41
|
this._pos = 0;
|
|
42
42
|
this.currentToken = ETokenType.UNKNOWN;
|
|
43
43
|
this.currentIdentifier = "";
|
|
@@ -46,7 +46,7 @@ var Tokenizer = /** @class */ (function () {
|
|
|
46
46
|
this._toParse = toParse;
|
|
47
47
|
this._maxPos = toParse.length;
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
getNextToken() {
|
|
50
50
|
if (this.isEnd()) {
|
|
51
51
|
return ETokenType.END_OF_INPUT;
|
|
52
52
|
}
|
|
@@ -61,50 +61,49 @@ var Tokenizer = /** @class */ (function () {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
return this.currentToken;
|
|
64
|
-
}
|
|
65
|
-
|
|
64
|
+
}
|
|
65
|
+
peek() {
|
|
66
66
|
return this._toParse[this._pos];
|
|
67
|
-
}
|
|
68
|
-
|
|
67
|
+
}
|
|
68
|
+
read() {
|
|
69
69
|
return this._toParse[this._pos++];
|
|
70
|
-
}
|
|
71
|
-
|
|
70
|
+
}
|
|
71
|
+
forward() {
|
|
72
72
|
this._pos++;
|
|
73
|
-
}
|
|
74
|
-
|
|
73
|
+
}
|
|
74
|
+
isEnd() {
|
|
75
75
|
return this._pos >= this._maxPos;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
}());
|
|
76
|
+
}
|
|
77
|
+
}
|
|
79
78
|
/**
|
|
80
79
|
* Values
|
|
81
80
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
const glTFTransforms = ["MODEL", "VIEW", "PROJECTION", "MODELVIEW", "MODELVIEWPROJECTION", "JOINTMATRIX"];
|
|
82
|
+
const babylonTransforms = ["world", "view", "projection", "worldView", "worldViewProjection", "mBones"];
|
|
83
|
+
const glTFAnimationPaths = ["translation", "rotation", "scale"];
|
|
84
|
+
const babylonAnimationPaths = ["position", "rotationQuaternion", "scaling"];
|
|
86
85
|
/**
|
|
87
86
|
* Parse
|
|
88
87
|
* @param parsedBuffers
|
|
89
88
|
* @param gltfRuntime
|
|
90
89
|
*/
|
|
91
|
-
|
|
92
|
-
for (
|
|
93
|
-
|
|
90
|
+
const parseBuffers = (parsedBuffers, gltfRuntime) => {
|
|
91
|
+
for (const buf in parsedBuffers) {
|
|
92
|
+
const parsedBuffer = parsedBuffers[buf];
|
|
94
93
|
gltfRuntime.buffers[buf] = parsedBuffer;
|
|
95
94
|
gltfRuntime.buffersCount++;
|
|
96
95
|
}
|
|
97
96
|
};
|
|
98
|
-
|
|
99
|
-
for (
|
|
100
|
-
|
|
97
|
+
const parseShaders = (parsedShaders, gltfRuntime) => {
|
|
98
|
+
for (const sha in parsedShaders) {
|
|
99
|
+
const parsedShader = parsedShaders[sha];
|
|
101
100
|
gltfRuntime.shaders[sha] = parsedShader;
|
|
102
101
|
gltfRuntime.shaderscount++;
|
|
103
102
|
}
|
|
104
103
|
};
|
|
105
|
-
|
|
106
|
-
for (
|
|
107
|
-
|
|
104
|
+
const parseObject = (parsedObjects, runtimeProperty, gltfRuntime) => {
|
|
105
|
+
for (const object in parsedObjects) {
|
|
106
|
+
const parsedObject = parsedObjects[object];
|
|
108
107
|
gltfRuntime[runtimeProperty][object] = parsedObject;
|
|
109
108
|
}
|
|
110
109
|
};
|
|
@@ -112,15 +111,15 @@ var parseObject = function (parsedObjects, runtimeProperty, gltfRuntime) {
|
|
|
112
111
|
* Utils
|
|
113
112
|
* @param buffer
|
|
114
113
|
*/
|
|
115
|
-
|
|
114
|
+
const normalizeUVs = (buffer) => {
|
|
116
115
|
if (!buffer) {
|
|
117
116
|
return;
|
|
118
117
|
}
|
|
119
|
-
for (
|
|
118
|
+
for (let i = 0; i < buffer.length / 2; i++) {
|
|
120
119
|
buffer[i * 2 + 1] = 1.0 - buffer[i * 2 + 1];
|
|
121
120
|
}
|
|
122
121
|
};
|
|
123
|
-
|
|
122
|
+
const getAttribute = (attributeParameter) => {
|
|
124
123
|
if (attributeParameter.semantic === "NORMAL") {
|
|
125
124
|
return "normal";
|
|
126
125
|
}
|
|
@@ -137,7 +136,7 @@ var getAttribute = function (attributeParameter) {
|
|
|
137
136
|
return "color";
|
|
138
137
|
}
|
|
139
138
|
else if (attributeParameter.semantic && attributeParameter.semantic.indexOf("TEXCOORD_") !== -1) {
|
|
140
|
-
|
|
139
|
+
const channel = Number(attributeParameter.semantic.split("_")[1]);
|
|
141
140
|
return "uv" + (channel === 0 ? "" : channel + 1);
|
|
142
141
|
}
|
|
143
142
|
return null;
|
|
@@ -146,22 +145,22 @@ var getAttribute = function (attributeParameter) {
|
|
|
146
145
|
* Loads and creates animations
|
|
147
146
|
* @param gltfRuntime
|
|
148
147
|
*/
|
|
149
|
-
|
|
150
|
-
for (
|
|
151
|
-
|
|
148
|
+
const loadAnimations = (gltfRuntime) => {
|
|
149
|
+
for (const anim in gltfRuntime.animations) {
|
|
150
|
+
const animation = gltfRuntime.animations[anim];
|
|
152
151
|
if (!animation.channels || !animation.samplers) {
|
|
153
152
|
continue;
|
|
154
153
|
}
|
|
155
|
-
|
|
156
|
-
for (
|
|
154
|
+
let lastAnimation = null;
|
|
155
|
+
for (let i = 0; i < animation.channels.length; i++) {
|
|
157
156
|
// Get parameters and load buffers
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
const channel = animation.channels[i];
|
|
158
|
+
const sampler = animation.samplers[channel.sampler];
|
|
160
159
|
if (!sampler) {
|
|
161
160
|
continue;
|
|
162
161
|
}
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
let inputData = null;
|
|
163
|
+
let outputData = null;
|
|
165
164
|
if (animation.parameters) {
|
|
166
165
|
inputData = animation.parameters[sampler.input];
|
|
167
166
|
outputData = animation.parameters[sampler.output];
|
|
@@ -170,10 +169,10 @@ var loadAnimations = function (gltfRuntime) {
|
|
|
170
169
|
inputData = sampler.input;
|
|
171
170
|
outputData = sampler.output;
|
|
172
171
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
172
|
+
const bufferInput = GLTFUtils.GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[inputData]);
|
|
173
|
+
const bufferOutput = GLTFUtils.GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[outputData]);
|
|
174
|
+
const targetId = channel.target.id;
|
|
175
|
+
let targetNode = gltfRuntime.scene.getNodeById(targetId);
|
|
177
176
|
if (targetNode === null) {
|
|
178
177
|
targetNode = gltfRuntime.scene.getNodeByName(targetId);
|
|
179
178
|
}
|
|
@@ -181,15 +180,15 @@ var loadAnimations = function (gltfRuntime) {
|
|
|
181
180
|
Tools.Warn("Creating animation named " + anim + ". But cannot find node named " + targetId + " to attach to");
|
|
182
181
|
continue;
|
|
183
182
|
}
|
|
184
|
-
|
|
183
|
+
const isBone = targetNode instanceof Bone;
|
|
185
184
|
// Get target path (position, rotation or scaling)
|
|
186
|
-
|
|
187
|
-
|
|
185
|
+
let targetPath = channel.target.path;
|
|
186
|
+
const targetPathIndex = glTFAnimationPaths.indexOf(targetPath);
|
|
188
187
|
if (targetPathIndex !== -1) {
|
|
189
188
|
targetPath = babylonAnimationPaths[targetPathIndex];
|
|
190
189
|
}
|
|
191
190
|
// Determine animation type
|
|
192
|
-
|
|
191
|
+
let animationType = Animation.ANIMATIONTYPE_MATRIX;
|
|
193
192
|
if (!isBone) {
|
|
194
193
|
if (targetPath === "rotationQuaternion") {
|
|
195
194
|
animationType = Animation.ANIMATIONTYPE_QUATERNION;
|
|
@@ -200,10 +199,10 @@ var loadAnimations = function (gltfRuntime) {
|
|
|
200
199
|
}
|
|
201
200
|
}
|
|
202
201
|
// Create animation and key frames
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
202
|
+
let babylonAnimation = null;
|
|
203
|
+
const keys = [];
|
|
204
|
+
let arrayOffset = 0;
|
|
205
|
+
let modifyKey = false;
|
|
207
206
|
if (isBone && lastAnimation && lastAnimation.getKeys().length === bufferInput.length) {
|
|
208
207
|
babylonAnimation = lastAnimation;
|
|
209
208
|
modifyKey = true;
|
|
@@ -214,8 +213,8 @@ var loadAnimations = function (gltfRuntime) {
|
|
|
214
213
|
gltfRuntime.scene._blockEntityCollection = false;
|
|
215
214
|
}
|
|
216
215
|
// For each frame
|
|
217
|
-
for (
|
|
218
|
-
|
|
216
|
+
for (let j = 0; j < bufferInput.length; j++) {
|
|
217
|
+
let value = null;
|
|
219
218
|
if (targetPath === "rotationQuaternion") {
|
|
220
219
|
// VEC4
|
|
221
220
|
value = Quaternion.FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2], bufferOutput[arrayOffset + 3]]);
|
|
@@ -227,12 +226,12 @@ var loadAnimations = function (gltfRuntime) {
|
|
|
227
226
|
arrayOffset += 3;
|
|
228
227
|
}
|
|
229
228
|
if (isBone) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
229
|
+
const bone = targetNode;
|
|
230
|
+
let translation = Vector3.Zero();
|
|
231
|
+
let rotationQuaternion = new Quaternion();
|
|
232
|
+
let scaling = Vector3.Zero();
|
|
234
233
|
// Warning on decompose
|
|
235
|
-
|
|
234
|
+
let mat = bone.getBaseMatrix();
|
|
236
235
|
if (modifyKey && lastAnimation) {
|
|
237
236
|
mat = lastAnimation.getKeys()[j].value;
|
|
238
237
|
}
|
|
@@ -273,12 +272,12 @@ var loadAnimations = function (gltfRuntime) {
|
|
|
273
272
|
* Returns the bones transformation matrix
|
|
274
273
|
* @param node
|
|
275
274
|
*/
|
|
276
|
-
|
|
277
|
-
|
|
275
|
+
const configureBoneTransformation = (node) => {
|
|
276
|
+
let mat = null;
|
|
278
277
|
if (node.translation || node.rotation || node.scale) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
278
|
+
const scale = Vector3.FromArray(node.scale || [1, 1, 1]);
|
|
279
|
+
const rotation = Quaternion.FromArray(node.rotation || [0, 0, 0, 1]);
|
|
280
|
+
const position = Vector3.FromArray(node.translation || [0, 0, 0]);
|
|
282
281
|
mat = Matrix.Compose(scale, rotation, position);
|
|
283
282
|
}
|
|
284
283
|
else {
|
|
@@ -293,29 +292,29 @@ var configureBoneTransformation = function (node) {
|
|
|
293
292
|
* @param jointName
|
|
294
293
|
* @param newSkeleton
|
|
295
294
|
*/
|
|
296
|
-
|
|
295
|
+
const getParentBone = (gltfRuntime, skins, jointName, newSkeleton) => {
|
|
297
296
|
// Try to find
|
|
298
|
-
for (
|
|
297
|
+
for (let i = 0; i < newSkeleton.bones.length; i++) {
|
|
299
298
|
if (newSkeleton.bones[i].name === jointName) {
|
|
300
299
|
return newSkeleton.bones[i];
|
|
301
300
|
}
|
|
302
301
|
}
|
|
303
302
|
// Not found, search in gltf nodes
|
|
304
|
-
|
|
305
|
-
for (
|
|
306
|
-
|
|
303
|
+
const nodes = gltfRuntime.nodes;
|
|
304
|
+
for (const nde in nodes) {
|
|
305
|
+
const node = nodes[nde];
|
|
307
306
|
if (!node.jointName) {
|
|
308
307
|
continue;
|
|
309
308
|
}
|
|
310
|
-
|
|
311
|
-
for (
|
|
312
|
-
|
|
309
|
+
const children = node.children;
|
|
310
|
+
for (let i = 0; i < children.length; i++) {
|
|
311
|
+
const child = gltfRuntime.nodes[children[i]];
|
|
313
312
|
if (!child.jointName) {
|
|
314
313
|
continue;
|
|
315
314
|
}
|
|
316
315
|
if (child.jointName === jointName) {
|
|
317
|
-
|
|
318
|
-
|
|
316
|
+
const mat = configureBoneTransformation(node);
|
|
317
|
+
const bone = new Bone(node.name || "", newSkeleton, getParentBone(gltfRuntime, skins, node.jointName, newSkeleton), mat);
|
|
319
318
|
bone.id = nde;
|
|
320
319
|
return bone;
|
|
321
320
|
}
|
|
@@ -328,11 +327,11 @@ var getParentBone = function (gltfRuntime, skins, jointName, newSkeleton) {
|
|
|
328
327
|
* @param nodesToRoot
|
|
329
328
|
* @param id
|
|
330
329
|
*/
|
|
331
|
-
|
|
332
|
-
for (
|
|
333
|
-
|
|
334
|
-
for (
|
|
335
|
-
|
|
330
|
+
const getNodeToRoot = (nodesToRoot, id) => {
|
|
331
|
+
for (let i = 0; i < nodesToRoot.length; i++) {
|
|
332
|
+
const nodeToRoot = nodesToRoot[i];
|
|
333
|
+
for (let j = 0; j < nodeToRoot.node.children.length; j++) {
|
|
334
|
+
const child = nodeToRoot.node.children[j];
|
|
336
335
|
if (child === id) {
|
|
337
336
|
return nodeToRoot.bone;
|
|
338
337
|
}
|
|
@@ -345,16 +344,16 @@ var getNodeToRoot = function (nodesToRoot, id) {
|
|
|
345
344
|
* @param gltfRuntime
|
|
346
345
|
* @param jointName
|
|
347
346
|
*/
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
347
|
+
const getJointNode = (gltfRuntime, jointName) => {
|
|
348
|
+
const nodes = gltfRuntime.nodes;
|
|
349
|
+
let node = nodes[jointName];
|
|
351
350
|
if (node) {
|
|
352
351
|
return {
|
|
353
352
|
node: node,
|
|
354
353
|
id: jointName,
|
|
355
354
|
};
|
|
356
355
|
}
|
|
357
|
-
for (
|
|
356
|
+
for (const nde in nodes) {
|
|
358
357
|
node = nodes[nde];
|
|
359
358
|
if (node.jointName === jointName) {
|
|
360
359
|
return {
|
|
@@ -370,8 +369,8 @@ var getJointNode = function (gltfRuntime, jointName) {
|
|
|
370
369
|
* @param skins
|
|
371
370
|
* @param id
|
|
372
371
|
*/
|
|
373
|
-
|
|
374
|
-
for (
|
|
372
|
+
const nodeIsInJoints = (skins, id) => {
|
|
373
|
+
for (let i = 0; i < skins.jointNames.length; i++) {
|
|
375
374
|
if (skins.jointNames[i] === id) {
|
|
376
375
|
return true;
|
|
377
376
|
}
|
|
@@ -385,27 +384,27 @@ var nodeIsInJoints = function (skins, id) {
|
|
|
385
384
|
* @param skins
|
|
386
385
|
* @param nodesToRoot
|
|
387
386
|
*/
|
|
388
|
-
|
|
387
|
+
const getNodesToRoot = (gltfRuntime, newSkeleton, skins, nodesToRoot) => {
|
|
389
388
|
// Creates nodes for root
|
|
390
|
-
for (
|
|
391
|
-
|
|
392
|
-
|
|
389
|
+
for (const nde in gltfRuntime.nodes) {
|
|
390
|
+
const node = gltfRuntime.nodes[nde];
|
|
391
|
+
const id = nde;
|
|
393
392
|
if (!node.jointName || nodeIsInJoints(skins, node.jointName)) {
|
|
394
393
|
continue;
|
|
395
394
|
}
|
|
396
395
|
// Create node to root bone
|
|
397
|
-
|
|
398
|
-
|
|
396
|
+
const mat = configureBoneTransformation(node);
|
|
397
|
+
const bone = new Bone(node.name || "", newSkeleton, null, mat);
|
|
399
398
|
bone.id = id;
|
|
400
399
|
nodesToRoot.push({ bone: bone, node: node, id: id });
|
|
401
400
|
}
|
|
402
401
|
// Parenting
|
|
403
|
-
for (
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
for (
|
|
407
|
-
|
|
408
|
-
for (
|
|
402
|
+
for (let i = 0; i < nodesToRoot.length; i++) {
|
|
403
|
+
const nodeToRoot = nodesToRoot[i];
|
|
404
|
+
const children = nodeToRoot.node.children;
|
|
405
|
+
for (let j = 0; j < children.length; j++) {
|
|
406
|
+
let child = null;
|
|
407
|
+
for (let k = 0; k < nodesToRoot.length; k++) {
|
|
409
408
|
if (nodesToRoot[k].id === children[j]) {
|
|
410
409
|
child = nodesToRoot[k];
|
|
411
410
|
break;
|
|
@@ -425,7 +424,7 @@ var getNodesToRoot = function (gltfRuntime, newSkeleton, skins, nodesToRoot) {
|
|
|
425
424
|
* @param mesh
|
|
426
425
|
* @param newSkeleton
|
|
427
426
|
*/
|
|
428
|
-
|
|
427
|
+
const importSkeleton = (gltfRuntime, skins, mesh, newSkeleton) => {
|
|
429
428
|
if (!newSkeleton) {
|
|
430
429
|
newSkeleton = new Skeleton(skins.name || "", "", gltfRuntime.scene);
|
|
431
430
|
}
|
|
@@ -433,47 +432,47 @@ var importSkeleton = function (gltfRuntime, skins, mesh, newSkeleton) {
|
|
|
433
432
|
return newSkeleton;
|
|
434
433
|
}
|
|
435
434
|
// Find the root bones
|
|
436
|
-
|
|
437
|
-
|
|
435
|
+
const nodesToRoot = [];
|
|
436
|
+
const nodesToRootToAdd = [];
|
|
438
437
|
getNodesToRoot(gltfRuntime, newSkeleton, skins, nodesToRoot);
|
|
439
438
|
newSkeleton.bones = [];
|
|
440
439
|
// Joints
|
|
441
|
-
for (
|
|
442
|
-
|
|
440
|
+
for (let i = 0; i < skins.jointNames.length; i++) {
|
|
441
|
+
const jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
|
|
443
442
|
if (!jointNode) {
|
|
444
443
|
continue;
|
|
445
444
|
}
|
|
446
|
-
|
|
445
|
+
const node = jointNode.node;
|
|
447
446
|
if (!node) {
|
|
448
447
|
Tools.Warn("Joint named " + skins.jointNames[i] + " does not exist");
|
|
449
448
|
continue;
|
|
450
449
|
}
|
|
451
|
-
|
|
450
|
+
const id = jointNode.id;
|
|
452
451
|
// Optimize, if the bone already exists...
|
|
453
|
-
|
|
452
|
+
const existingBone = gltfRuntime.scene.getBoneById(id);
|
|
454
453
|
if (existingBone) {
|
|
455
454
|
newSkeleton.bones.push(existingBone);
|
|
456
455
|
continue;
|
|
457
456
|
}
|
|
458
457
|
// Search for parent bone
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
for (
|
|
462
|
-
|
|
463
|
-
if (!
|
|
458
|
+
let foundBone = false;
|
|
459
|
+
let parentBone = null;
|
|
460
|
+
for (let j = 0; j < i; j++) {
|
|
461
|
+
const jointNode = getJointNode(gltfRuntime, skins.jointNames[j]);
|
|
462
|
+
if (!jointNode) {
|
|
464
463
|
continue;
|
|
465
464
|
}
|
|
466
|
-
|
|
465
|
+
const joint = jointNode.node;
|
|
467
466
|
if (!joint) {
|
|
468
467
|
Tools.Warn("Joint named " + skins.jointNames[j] + " does not exist when looking for parent");
|
|
469
468
|
continue;
|
|
470
469
|
}
|
|
471
|
-
|
|
470
|
+
const children = joint.children;
|
|
472
471
|
if (!children) {
|
|
473
472
|
continue;
|
|
474
473
|
}
|
|
475
474
|
foundBone = false;
|
|
476
|
-
for (
|
|
475
|
+
for (let k = 0; k < children.length; k++) {
|
|
477
476
|
if (children[k] === id) {
|
|
478
477
|
parentBone = getParentBone(gltfRuntime, skins, skins.jointNames[j], newSkeleton);
|
|
479
478
|
foundBone = true;
|
|
@@ -485,7 +484,7 @@ var importSkeleton = function (gltfRuntime, skins, mesh, newSkeleton) {
|
|
|
485
484
|
}
|
|
486
485
|
}
|
|
487
486
|
// Create bone
|
|
488
|
-
|
|
487
|
+
const mat = configureBoneTransformation(node);
|
|
489
488
|
if (!parentBone && nodesToRoot.length > 0) {
|
|
490
489
|
parentBone = getNodeToRoot(nodesToRoot, id);
|
|
491
490
|
if (parentBone) {
|
|
@@ -494,18 +493,18 @@ var importSkeleton = function (gltfRuntime, skins, mesh, newSkeleton) {
|
|
|
494
493
|
}
|
|
495
494
|
}
|
|
496
495
|
}
|
|
497
|
-
|
|
496
|
+
const bone = new Bone(node.jointName || "", newSkeleton, parentBone, mat);
|
|
498
497
|
bone.id = id;
|
|
499
498
|
}
|
|
500
499
|
// Polish
|
|
501
|
-
|
|
500
|
+
const bones = newSkeleton.bones;
|
|
502
501
|
newSkeleton.bones = [];
|
|
503
|
-
for (
|
|
504
|
-
|
|
502
|
+
for (let i = 0; i < skins.jointNames.length; i++) {
|
|
503
|
+
const jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
|
|
505
504
|
if (!jointNode) {
|
|
506
505
|
continue;
|
|
507
506
|
}
|
|
508
|
-
for (
|
|
507
|
+
for (let j = 0; j < bones.length; j++) {
|
|
509
508
|
if (bones[j].id === jointNode.id) {
|
|
510
509
|
newSkeleton.bones.push(bones[j]);
|
|
511
510
|
break;
|
|
@@ -514,7 +513,7 @@ var importSkeleton = function (gltfRuntime, skins, mesh, newSkeleton) {
|
|
|
514
513
|
}
|
|
515
514
|
newSkeleton.prepare();
|
|
516
515
|
// Finish
|
|
517
|
-
for (
|
|
516
|
+
for (let i = 0; i < nodesToRootToAdd.length; i++) {
|
|
518
517
|
newSkeleton.bones.push(nodesToRootToAdd[i]);
|
|
519
518
|
}
|
|
520
519
|
return newSkeleton;
|
|
@@ -527,7 +526,7 @@ var importSkeleton = function (gltfRuntime, skins, mesh, newSkeleton) {
|
|
|
527
526
|
* @param id
|
|
528
527
|
* @param newMesh
|
|
529
528
|
*/
|
|
530
|
-
|
|
529
|
+
const importMesh = (gltfRuntime, node, meshes, id, newMesh) => {
|
|
531
530
|
if (!newMesh) {
|
|
532
531
|
gltfRuntime.scene._blockEntityCollection = !!gltfRuntime.assetContainer;
|
|
533
532
|
newMesh = new Mesh(node.name || "", gltfRuntime.scene);
|
|
@@ -538,31 +537,31 @@ var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
|
|
|
538
537
|
if (!node.babylonNode) {
|
|
539
538
|
return newMesh;
|
|
540
539
|
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
for (
|
|
548
|
-
|
|
549
|
-
|
|
540
|
+
const subMaterials = [];
|
|
541
|
+
let vertexData = null;
|
|
542
|
+
const verticesStarts = new Array();
|
|
543
|
+
const verticesCounts = new Array();
|
|
544
|
+
const indexStarts = new Array();
|
|
545
|
+
const indexCounts = new Array();
|
|
546
|
+
for (let meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
|
|
547
|
+
const meshId = meshes[meshIndex];
|
|
548
|
+
const mesh = gltfRuntime.meshes[meshId];
|
|
550
549
|
if (!mesh) {
|
|
551
550
|
continue;
|
|
552
551
|
}
|
|
553
552
|
// Positions, normals and UVs
|
|
554
|
-
for (
|
|
553
|
+
for (let i = 0; i < mesh.primitives.length; i++) {
|
|
555
554
|
// Temporary vertex data
|
|
556
|
-
|
|
557
|
-
|
|
555
|
+
const tempVertexData = new VertexData();
|
|
556
|
+
const primitive = mesh.primitives[i];
|
|
558
557
|
if (primitive.mode !== 4) {
|
|
559
558
|
// continue;
|
|
560
559
|
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
560
|
+
const attributes = primitive.attributes;
|
|
561
|
+
let accessor = null;
|
|
562
|
+
let buffer = null;
|
|
564
563
|
// Set positions, normal and uvs
|
|
565
|
-
for (
|
|
564
|
+
for (const semantic in attributes) {
|
|
566
565
|
// Link accessor and buffer view
|
|
567
566
|
accessor = gltfRuntime.accessors[attributes[semantic]];
|
|
568
567
|
buffer = GLTFUtils.GetBufferFromAccessor(gltfRuntime, accessor);
|
|
@@ -573,7 +572,7 @@ var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
|
|
|
573
572
|
else if (semantic === "POSITION") {
|
|
574
573
|
if (GLTFFileLoader.HomogeneousCoordinates) {
|
|
575
574
|
tempVertexData.positions = new Float32Array(buffer.length - buffer.length / 4);
|
|
576
|
-
for (
|
|
575
|
+
for (let j = 0; j < buffer.length; j += 4) {
|
|
577
576
|
tempVertexData.positions[j] = buffer[j];
|
|
578
577
|
tempVertexData.positions[j + 1] = buffer[j + 1];
|
|
579
578
|
tempVertexData.positions[j + 2] = buffer[j + 2];
|
|
@@ -586,9 +585,9 @@ var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
|
|
|
586
585
|
verticesCounts.push(tempVertexData.positions.length);
|
|
587
586
|
}
|
|
588
587
|
else if (semantic.indexOf("TEXCOORD_") !== -1) {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
588
|
+
const channel = Number(semantic.split("_")[1]);
|
|
589
|
+
const uvKind = VertexBuffer.UVKind + (channel === 0 ? "" : channel + 1);
|
|
590
|
+
const uvs = new Float32Array(buffer.length);
|
|
592
591
|
uvs.set(buffer);
|
|
593
592
|
normalizeUVs(uvs);
|
|
594
593
|
tempVertexData.set(uvs, uvKind);
|
|
@@ -616,8 +615,8 @@ var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
|
|
|
616
615
|
}
|
|
617
616
|
else {
|
|
618
617
|
// Set indices on the fly
|
|
619
|
-
|
|
620
|
-
for (
|
|
618
|
+
const indices = [];
|
|
619
|
+
for (let j = 0; j < tempVertexData.positions.length / 3; j++) {
|
|
621
620
|
indices.push(j);
|
|
622
621
|
}
|
|
623
622
|
tempVertexData.indices = new Int32Array(indices);
|
|
@@ -630,14 +629,14 @@ var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
|
|
|
630
629
|
vertexData.merge(tempVertexData);
|
|
631
630
|
}
|
|
632
631
|
// Sub material
|
|
633
|
-
|
|
634
|
-
subMaterials.push(
|
|
632
|
+
const material = gltfRuntime.scene.getMaterialById(primitive.material);
|
|
633
|
+
subMaterials.push(material === null ? GLTFUtils.GetDefaultMaterial(gltfRuntime.scene) : material);
|
|
635
634
|
// Update vertices start and index start
|
|
636
635
|
verticesStarts.push(verticesStarts.length === 0 ? 0 : verticesStarts[verticesStarts.length - 1] + verticesCounts[verticesCounts.length - 2]);
|
|
637
636
|
indexStarts.push(indexStarts.length === 0 ? 0 : indexStarts[indexStarts.length - 1] + indexCounts[indexCounts.length - 2]);
|
|
638
637
|
}
|
|
639
638
|
}
|
|
640
|
-
|
|
639
|
+
let material;
|
|
641
640
|
gltfRuntime.scene._blockEntityCollection = !!gltfRuntime.assetContainer;
|
|
642
641
|
if (subMaterials.length > 1) {
|
|
643
642
|
material = new MultiMaterial("multimat" + id, gltfRuntime.scene);
|
|
@@ -659,14 +658,14 @@ var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
|
|
|
659
658
|
gltfRuntime.scene._blockEntityCollection = false;
|
|
660
659
|
// Apply submeshes
|
|
661
660
|
newMesh.subMeshes = [];
|
|
662
|
-
|
|
663
|
-
for (
|
|
664
|
-
|
|
665
|
-
|
|
661
|
+
let index = 0;
|
|
662
|
+
for (let meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
|
|
663
|
+
const meshId = meshes[meshIndex];
|
|
664
|
+
const mesh = gltfRuntime.meshes[meshId];
|
|
666
665
|
if (!mesh) {
|
|
667
666
|
continue;
|
|
668
667
|
}
|
|
669
|
-
for (
|
|
668
|
+
for (let i = 0; i < mesh.primitives.length; i++) {
|
|
670
669
|
if (mesh.primitives[i].mode !== 4) {
|
|
671
670
|
//continue;
|
|
672
671
|
}
|
|
@@ -684,7 +683,7 @@ var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
|
|
|
684
683
|
* @param rotation
|
|
685
684
|
* @param scaling
|
|
686
685
|
*/
|
|
687
|
-
|
|
686
|
+
const configureNode = (newNode, position, rotation, scaling) => {
|
|
688
687
|
if (newNode.position) {
|
|
689
688
|
newNode.position = position;
|
|
690
689
|
}
|
|
@@ -700,12 +699,12 @@ var configureNode = function (newNode, position, rotation, scaling) {
|
|
|
700
699
|
* @param newNode
|
|
701
700
|
* @param node
|
|
702
701
|
*/
|
|
703
|
-
|
|
702
|
+
const configureNodeFromMatrix = (newNode, node) => {
|
|
704
703
|
if (node.matrix) {
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
704
|
+
const position = new Vector3(0, 0, 0);
|
|
705
|
+
const rotation = new Quaternion();
|
|
706
|
+
const scaling = new Vector3(0, 0, 0);
|
|
707
|
+
const mat = Matrix.FromArray(node.matrix);
|
|
709
708
|
mat.decompose(scaling, rotation, position);
|
|
710
709
|
configureNode(newNode, position, rotation, scaling);
|
|
711
710
|
}
|
|
@@ -720,8 +719,8 @@ var configureNodeFromMatrix = function (newNode, node) {
|
|
|
720
719
|
* @param node
|
|
721
720
|
* @param id
|
|
722
721
|
*/
|
|
723
|
-
|
|
724
|
-
|
|
722
|
+
const importNode = (gltfRuntime, node, id) => {
|
|
723
|
+
let lastNode = null;
|
|
725
724
|
if (gltfRuntime.importOnlyMeshes && (node.skin || node.meshes)) {
|
|
726
725
|
if (gltfRuntime.importMeshesNames && gltfRuntime.importMeshesNames.length > 0 && gltfRuntime.importMeshesNames.indexOf(node.name || "") === -1) {
|
|
727
726
|
return null;
|
|
@@ -730,8 +729,8 @@ var importNode = function (gltfRuntime, node, id) {
|
|
|
730
729
|
// Meshes
|
|
731
730
|
if (node.skin) {
|
|
732
731
|
if (node.meshes) {
|
|
733
|
-
|
|
734
|
-
|
|
732
|
+
const skin = gltfRuntime.skins[node.skin];
|
|
733
|
+
const newMesh = importMesh(gltfRuntime, node, node.meshes, id, node.babylonNode);
|
|
735
734
|
newMesh.skeleton = gltfRuntime.scene.getLastSkeletonById(node.skin);
|
|
736
735
|
if (newMesh.skeleton === null) {
|
|
737
736
|
newMesh.skeleton = importSkeleton(gltfRuntime, skin, newMesh, skin.babylonSkeleton);
|
|
@@ -746,16 +745,16 @@ var importNode = function (gltfRuntime, node, id) {
|
|
|
746
745
|
/**
|
|
747
746
|
* Improve meshes property
|
|
748
747
|
*/
|
|
749
|
-
|
|
748
|
+
const newMesh = importMesh(gltfRuntime, node, node.mesh ? [node.mesh] : node.meshes, id, node.babylonNode);
|
|
750
749
|
lastNode = newMesh;
|
|
751
750
|
}
|
|
752
751
|
// Lights
|
|
753
752
|
else if (node.light && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
|
|
754
|
-
|
|
753
|
+
const light = gltfRuntime.lights[node.light];
|
|
755
754
|
if (light) {
|
|
756
755
|
if (light.type === "ambient") {
|
|
757
|
-
|
|
758
|
-
|
|
756
|
+
const ambienLight = light[light.type];
|
|
757
|
+
const hemiLight = new HemisphericLight(node.light, Vector3.Zero(), gltfRuntime.scene);
|
|
759
758
|
hemiLight.name = node.name || "";
|
|
760
759
|
if (ambienLight.color) {
|
|
761
760
|
hemiLight.diffuse = Color3.FromArray(ambienLight.color);
|
|
@@ -763,8 +762,8 @@ var importNode = function (gltfRuntime, node, id) {
|
|
|
763
762
|
lastNode = hemiLight;
|
|
764
763
|
}
|
|
765
764
|
else if (light.type === "directional") {
|
|
766
|
-
|
|
767
|
-
|
|
765
|
+
const directionalLight = light[light.type];
|
|
766
|
+
const dirLight = new DirectionalLight(node.light, Vector3.Zero(), gltfRuntime.scene);
|
|
768
767
|
dirLight.name = node.name || "";
|
|
769
768
|
if (directionalLight.color) {
|
|
770
769
|
dirLight.diffuse = Color3.FromArray(directionalLight.color);
|
|
@@ -772,8 +771,8 @@ var importNode = function (gltfRuntime, node, id) {
|
|
|
772
771
|
lastNode = dirLight;
|
|
773
772
|
}
|
|
774
773
|
else if (light.type === "point") {
|
|
775
|
-
|
|
776
|
-
|
|
774
|
+
const pointLight = light[light.type];
|
|
775
|
+
const ptLight = new PointLight(node.light, Vector3.Zero(), gltfRuntime.scene);
|
|
777
776
|
ptLight.name = node.name || "";
|
|
778
777
|
if (pointLight.color) {
|
|
779
778
|
ptLight.diffuse = Color3.FromArray(pointLight.color);
|
|
@@ -781,8 +780,8 @@ var importNode = function (gltfRuntime, node, id) {
|
|
|
781
780
|
lastNode = ptLight;
|
|
782
781
|
}
|
|
783
782
|
else if (light.type === "spot") {
|
|
784
|
-
|
|
785
|
-
|
|
783
|
+
const spotLight = light[light.type];
|
|
784
|
+
const spLight = new SpotLight(node.light, Vector3.Zero(), Vector3.Zero(), 0, 0, gltfRuntime.scene);
|
|
786
785
|
spLight.name = node.name || "";
|
|
787
786
|
if (spotLight.color) {
|
|
788
787
|
spLight.diffuse = Color3.FromArray(spotLight.color);
|
|
@@ -799,11 +798,11 @@ var importNode = function (gltfRuntime, node, id) {
|
|
|
799
798
|
}
|
|
800
799
|
// Cameras
|
|
801
800
|
else if (node.camera && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
|
|
802
|
-
|
|
801
|
+
const camera = gltfRuntime.cameras[node.camera];
|
|
803
802
|
if (camera) {
|
|
804
803
|
gltfRuntime.scene._blockEntityCollection = !!gltfRuntime.assetContainer;
|
|
805
804
|
if (camera.type === "orthographic") {
|
|
806
|
-
|
|
805
|
+
const orthoCamera = new FreeCamera(node.camera, Vector3.Zero(), gltfRuntime.scene, false);
|
|
807
806
|
orthoCamera.name = node.name || "";
|
|
808
807
|
orthoCamera.mode = Camera.ORTHOGRAPHIC_CAMERA;
|
|
809
808
|
orthoCamera.attachControl();
|
|
@@ -811,8 +810,8 @@ var importNode = function (gltfRuntime, node, id) {
|
|
|
811
810
|
orthoCamera._parentContainer = gltfRuntime.assetContainer;
|
|
812
811
|
}
|
|
813
812
|
else if (camera.type === "perspective") {
|
|
814
|
-
|
|
815
|
-
|
|
813
|
+
const perspectiveCamera = camera[camera.type];
|
|
814
|
+
const persCamera = new FreeCamera(node.camera, Vector3.Zero(), gltfRuntime.scene, false);
|
|
816
815
|
persCamera.name = node.name || "";
|
|
817
816
|
persCamera.attachControl();
|
|
818
817
|
if (!perspectiveCamera.aspectRatio) {
|
|
@@ -835,7 +834,7 @@ var importNode = function (gltfRuntime, node, id) {
|
|
|
835
834
|
}
|
|
836
835
|
else if (lastNode === null) {
|
|
837
836
|
gltfRuntime.scene._blockEntityCollection = !!gltfRuntime.assetContainer;
|
|
838
|
-
|
|
837
|
+
const dummy = new Mesh(node.name || "", gltfRuntime.scene);
|
|
839
838
|
dummy._parentContainer = gltfRuntime.assetContainer;
|
|
840
839
|
gltfRuntime.scene._blockEntityCollection = false;
|
|
841
840
|
node.babylonNode = dummy;
|
|
@@ -847,9 +846,9 @@ var importNode = function (gltfRuntime, node, id) {
|
|
|
847
846
|
configureNodeFromMatrix(lastNode, node);
|
|
848
847
|
}
|
|
849
848
|
else {
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
849
|
+
const translation = node.translation || [0, 0, 0];
|
|
850
|
+
const rotation = node.rotation || [0, 0, 0, 1];
|
|
851
|
+
const scale = node.scale || [1, 1, 1];
|
|
853
852
|
configureNode(lastNode, Vector3.FromArray(translation), Quaternion.FromArray(rotation), Vector3.FromArray(scale));
|
|
854
853
|
}
|
|
855
854
|
lastNode.updateCache(true);
|
|
@@ -864,10 +863,9 @@ var importNode = function (gltfRuntime, node, id) {
|
|
|
864
863
|
* @param parent
|
|
865
864
|
* @param meshIncluded
|
|
866
865
|
*/
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
var newNode = null;
|
|
866
|
+
const traverseNodes = (gltfRuntime, id, parent, meshIncluded = false) => {
|
|
867
|
+
const node = gltfRuntime.nodes[id];
|
|
868
|
+
let newNode = null;
|
|
871
869
|
if (gltfRuntime.importOnlyMeshes && !meshIncluded && gltfRuntime.importMeshesNames) {
|
|
872
870
|
if (gltfRuntime.importMeshesNames.indexOf(node.name || "") !== -1 || gltfRuntime.importMeshesNames.length === 0) {
|
|
873
871
|
meshIncluded = true;
|
|
@@ -887,7 +885,7 @@ var traverseNodes = function (gltfRuntime, id, parent, meshIncluded) {
|
|
|
887
885
|
}
|
|
888
886
|
}
|
|
889
887
|
if (node.children) {
|
|
890
|
-
for (
|
|
888
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
891
889
|
traverseNodes(gltfRuntime, node.children[i], newNode, meshIncluded);
|
|
892
890
|
}
|
|
893
891
|
}
|
|
@@ -896,26 +894,26 @@ var traverseNodes = function (gltfRuntime, id, parent, meshIncluded) {
|
|
|
896
894
|
* do stuff after buffers, shaders are loaded (e.g. hook up materials, load animations, etc.)
|
|
897
895
|
* @param gltfRuntime
|
|
898
896
|
*/
|
|
899
|
-
|
|
897
|
+
const postLoad = (gltfRuntime) => {
|
|
900
898
|
// Nodes
|
|
901
|
-
|
|
899
|
+
let currentScene = gltfRuntime.currentScene;
|
|
902
900
|
if (currentScene) {
|
|
903
|
-
for (
|
|
901
|
+
for (let i = 0; i < currentScene.nodes.length; i++) {
|
|
904
902
|
traverseNodes(gltfRuntime, currentScene.nodes[i], null);
|
|
905
903
|
}
|
|
906
904
|
}
|
|
907
905
|
else {
|
|
908
|
-
for (
|
|
906
|
+
for (const thing in gltfRuntime.scenes) {
|
|
909
907
|
currentScene = gltfRuntime.scenes[thing];
|
|
910
|
-
for (
|
|
908
|
+
for (let i = 0; i < currentScene.nodes.length; i++) {
|
|
911
909
|
traverseNodes(gltfRuntime, currentScene.nodes[i], null);
|
|
912
910
|
}
|
|
913
911
|
}
|
|
914
912
|
}
|
|
915
913
|
// Set animations
|
|
916
914
|
loadAnimations(gltfRuntime);
|
|
917
|
-
for (
|
|
918
|
-
|
|
915
|
+
for (let i = 0; i < gltfRuntime.scene.skeletons.length; i++) {
|
|
916
|
+
const skeleton = gltfRuntime.scene.skeletons[i];
|
|
919
917
|
gltfRuntime.scene.beginAnimation(skeleton, 0, Number.MAX_VALUE, true, 1.0);
|
|
920
918
|
}
|
|
921
919
|
};
|
|
@@ -929,17 +927,17 @@ var postLoad = function (gltfRuntime) {
|
|
|
929
927
|
* @param material
|
|
930
928
|
* @param onSuccess
|
|
931
929
|
*/
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
for (
|
|
935
|
-
|
|
936
|
-
|
|
930
|
+
const onBindShaderMaterial = (mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess) => {
|
|
931
|
+
const materialValues = material.values || technique.parameters;
|
|
932
|
+
for (const unif in unTreatedUniforms) {
|
|
933
|
+
const uniform = unTreatedUniforms[unif];
|
|
934
|
+
const type = uniform.type;
|
|
937
935
|
if (type === EParameterType.FLOAT_MAT2 || type === EParameterType.FLOAT_MAT3 || type === EParameterType.FLOAT_MAT4) {
|
|
938
936
|
if (uniform.semantic && !uniform.source && !uniform.node) {
|
|
939
937
|
GLTFUtils.SetMatrix(gltfRuntime.scene, mesh, uniform, unif, shaderMaterial.getEffect());
|
|
940
938
|
}
|
|
941
939
|
else if (uniform.semantic && (uniform.source || uniform.node)) {
|
|
942
|
-
|
|
940
|
+
let source = gltfRuntime.scene.getNodeByName(uniform.source || uniform.node || "");
|
|
943
941
|
if (source === null) {
|
|
944
942
|
source = gltfRuntime.scene.getNodeById(uniform.source || uniform.node || "");
|
|
945
943
|
}
|
|
@@ -950,12 +948,12 @@ var onBindShaderMaterial = function (mesh, gltfRuntime, unTreatedUniforms, shade
|
|
|
950
948
|
}
|
|
951
949
|
}
|
|
952
950
|
else {
|
|
953
|
-
|
|
951
|
+
const value = materialValues[technique.uniforms[unif]];
|
|
954
952
|
if (!value) {
|
|
955
953
|
continue;
|
|
956
954
|
}
|
|
957
955
|
if (type === EParameterType.SAMPLER_2D) {
|
|
958
|
-
|
|
956
|
+
const texture = gltfRuntime.textures[material.values ? value : uniform.value].babylonTexture;
|
|
959
957
|
if (texture === null || texture === undefined) {
|
|
960
958
|
continue;
|
|
961
959
|
}
|
|
@@ -976,22 +974,25 @@ var onBindShaderMaterial = function (mesh, gltfRuntime, unTreatedUniforms, shade
|
|
|
976
974
|
* @param technique
|
|
977
975
|
* @param material
|
|
978
976
|
*/
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
977
|
+
const prepareShaderMaterialUniforms = (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms) => {
|
|
978
|
+
const materialValues = material.values || technique.parameters;
|
|
979
|
+
const techniqueUniforms = technique.uniforms;
|
|
980
|
+
/**
|
|
981
|
+
* Prepare values here (not matrices)
|
|
982
|
+
*/
|
|
983
|
+
for (const unif in unTreatedUniforms) {
|
|
984
|
+
const uniform = unTreatedUniforms[unif];
|
|
985
|
+
const type = uniform.type;
|
|
986
|
+
let value = materialValues[techniqueUniforms[unif]];
|
|
986
987
|
if (value === undefined) {
|
|
987
988
|
// In case the value is the same for all materials
|
|
988
989
|
value = uniform.value;
|
|
989
990
|
}
|
|
990
991
|
if (!value) {
|
|
991
|
-
|
|
992
|
+
continue;
|
|
992
993
|
}
|
|
993
|
-
|
|
994
|
-
return
|
|
994
|
+
const onLoadTexture = (uniformName) => {
|
|
995
|
+
return (texture) => {
|
|
995
996
|
if (uniform.value && uniformName) {
|
|
996
997
|
// Static uniform
|
|
997
998
|
shaderMaterial.setTexture(uniformName, texture);
|
|
@@ -1001,7 +1002,7 @@ var prepareShaderMaterialUniforms = function (gltfRuntime, shaderMaterial, techn
|
|
|
1001
1002
|
};
|
|
1002
1003
|
// Texture (sampler2D)
|
|
1003
1004
|
if (type === EParameterType.SAMPLER_2D) {
|
|
1004
|
-
GLTFLoaderExtension.LoadTextureAsync(gltfRuntime, material.values ? value : uniform.value, onLoadTexture(unif),
|
|
1005
|
+
GLTFLoaderExtension.LoadTextureAsync(gltfRuntime, material.values ? value : uniform.value, onLoadTexture(unif), () => onLoadTexture(null));
|
|
1005
1006
|
}
|
|
1006
1007
|
// Others
|
|
1007
1008
|
else {
|
|
@@ -1010,12 +1011,6 @@ var prepareShaderMaterialUniforms = function (gltfRuntime, shaderMaterial, techn
|
|
|
1010
1011
|
delete unTreatedUniforms[unif];
|
|
1011
1012
|
}
|
|
1012
1013
|
}
|
|
1013
|
-
};
|
|
1014
|
-
/**
|
|
1015
|
-
* Prepare values here (not matrices)
|
|
1016
|
-
*/
|
|
1017
|
-
for (var unif in unTreatedUniforms) {
|
|
1018
|
-
_loop_1(unif);
|
|
1019
1014
|
}
|
|
1020
1015
|
};
|
|
1021
1016
|
/**
|
|
@@ -1024,8 +1019,8 @@ var prepareShaderMaterialUniforms = function (gltfRuntime, shaderMaterial, techn
|
|
|
1024
1019
|
* @param shaderMaterial
|
|
1025
1020
|
* @param onError
|
|
1026
1021
|
*/
|
|
1027
|
-
|
|
1028
|
-
return
|
|
1022
|
+
const onShaderCompileError = (program, shaderMaterial, onError) => {
|
|
1023
|
+
return (effect, error) => {
|
|
1029
1024
|
shaderMaterial.dispose(true);
|
|
1030
1025
|
onError("Cannot compile program named " + program.name + ". Error: " + error + ". Default material will be applied");
|
|
1031
1026
|
};
|
|
@@ -1039,10 +1034,10 @@ var onShaderCompileError = function (program, shaderMaterial, onError) {
|
|
|
1039
1034
|
* @param unTreatedUniforms
|
|
1040
1035
|
* @param onSuccess
|
|
1041
1036
|
*/
|
|
1042
|
-
|
|
1043
|
-
return
|
|
1037
|
+
const onShaderCompileSuccess = (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess) => {
|
|
1038
|
+
return (_) => {
|
|
1044
1039
|
prepareShaderMaterialUniforms(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms);
|
|
1045
|
-
shaderMaterial.onBind =
|
|
1040
|
+
shaderMaterial.onBind = (mesh) => {
|
|
1046
1041
|
onBindShaderMaterial(mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess);
|
|
1047
1042
|
};
|
|
1048
1043
|
};
|
|
@@ -1052,13 +1047,13 @@ var onShaderCompileSuccess = function (gltfRuntime, shaderMaterial, technique, m
|
|
|
1052
1047
|
* @param tokenizer
|
|
1053
1048
|
* @param technique
|
|
1054
1049
|
*/
|
|
1055
|
-
|
|
1056
|
-
for (
|
|
1057
|
-
|
|
1058
|
-
|
|
1050
|
+
const parseShaderUniforms = (tokenizer, technique, unTreatedUniforms) => {
|
|
1051
|
+
for (const unif in technique.uniforms) {
|
|
1052
|
+
const uniform = technique.uniforms[unif];
|
|
1053
|
+
const uniformParameter = technique.parameters[uniform];
|
|
1059
1054
|
if (tokenizer.currentIdentifier === unif) {
|
|
1060
1055
|
if (uniformParameter.semantic && !uniformParameter.source && !uniformParameter.node) {
|
|
1061
|
-
|
|
1056
|
+
const transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
|
|
1062
1057
|
if (transformIndex !== -1) {
|
|
1063
1058
|
delete unTreatedUniforms[unif];
|
|
1064
1059
|
return babylonTransforms[transformIndex];
|
|
@@ -1072,21 +1067,19 @@ var parseShaderUniforms = function (tokenizer, technique, unTreatedUniforms) {
|
|
|
1072
1067
|
* All shaders loaded. Create materials one by one
|
|
1073
1068
|
* @param gltfRuntime
|
|
1074
1069
|
*/
|
|
1075
|
-
|
|
1070
|
+
const importMaterials = (gltfRuntime) => {
|
|
1076
1071
|
// Create materials
|
|
1077
|
-
for (
|
|
1078
|
-
GLTFLoaderExtension.LoadMaterialAsync(gltfRuntime, mat,
|
|
1072
|
+
for (const mat in gltfRuntime.materials) {
|
|
1073
|
+
GLTFLoaderExtension.LoadMaterialAsync(gltfRuntime, mat, () => { }, () => { });
|
|
1079
1074
|
}
|
|
1080
1075
|
};
|
|
1081
1076
|
/**
|
|
1082
1077
|
* Implementation of the base glTF spec
|
|
1083
1078
|
* @hidden
|
|
1084
1079
|
*/
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
GLTFLoaderBase.CreateRuntime = function (parsedData, scene, rootUrl) {
|
|
1089
|
-
var gltfRuntime = {
|
|
1080
|
+
export class GLTFLoaderBase {
|
|
1081
|
+
static CreateRuntime(parsedData, scene, rootUrl) {
|
|
1082
|
+
const gltfRuntime = {
|
|
1090
1083
|
extensions: {},
|
|
1091
1084
|
accessors: {},
|
|
1092
1085
|
buffers: {},
|
|
@@ -1179,22 +1172,22 @@ var GLTFLoaderBase = /** @class */ (function () {
|
|
|
1179
1172
|
gltfRuntime.currentScene = parsedData.scenes[parsedData.scene];
|
|
1180
1173
|
}
|
|
1181
1174
|
return gltfRuntime;
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
|
-
|
|
1175
|
+
}
|
|
1176
|
+
static LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress) {
|
|
1177
|
+
const buffer = gltfRuntime.buffers[id];
|
|
1185
1178
|
if (Tools.IsBase64(buffer.uri)) {
|
|
1186
|
-
setTimeout(
|
|
1179
|
+
setTimeout(() => onSuccess(new Uint8Array(Tools.DecodeBase64(buffer.uri))));
|
|
1187
1180
|
}
|
|
1188
1181
|
else {
|
|
1189
|
-
Tools.LoadFile(gltfRuntime.rootUrl + buffer.uri,
|
|
1182
|
+
Tools.LoadFile(gltfRuntime.rootUrl + buffer.uri, (data) => onSuccess(new Uint8Array(data)), onProgress, undefined, true, (request) => {
|
|
1190
1183
|
if (request) {
|
|
1191
1184
|
onError(request.status + " " + request.statusText);
|
|
1192
1185
|
}
|
|
1193
1186
|
});
|
|
1194
1187
|
}
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
|
|
1188
|
+
}
|
|
1189
|
+
static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError) {
|
|
1190
|
+
const texture = gltfRuntime.textures[id];
|
|
1198
1191
|
if (!texture || !texture.source) {
|
|
1199
1192
|
onError("");
|
|
1200
1193
|
return;
|
|
@@ -1203,34 +1196,34 @@ var GLTFLoaderBase = /** @class */ (function () {
|
|
|
1203
1196
|
onSuccess(null);
|
|
1204
1197
|
return;
|
|
1205
1198
|
}
|
|
1206
|
-
|
|
1199
|
+
const source = gltfRuntime.images[texture.source];
|
|
1207
1200
|
if (Tools.IsBase64(source.uri)) {
|
|
1208
|
-
setTimeout(
|
|
1201
|
+
setTimeout(() => onSuccess(new Uint8Array(Tools.DecodeBase64(source.uri))));
|
|
1209
1202
|
}
|
|
1210
1203
|
else {
|
|
1211
|
-
Tools.LoadFile(gltfRuntime.rootUrl + source.uri,
|
|
1204
|
+
Tools.LoadFile(gltfRuntime.rootUrl + source.uri, (data) => onSuccess(new Uint8Array(data)), undefined, undefined, true, (request) => {
|
|
1212
1205
|
if (request) {
|
|
1213
1206
|
onError(request.status + " " + request.statusText);
|
|
1214
1207
|
}
|
|
1215
1208
|
});
|
|
1216
1209
|
}
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
|
|
1210
|
+
}
|
|
1211
|
+
static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess) {
|
|
1212
|
+
const texture = gltfRuntime.textures[id];
|
|
1220
1213
|
if (texture.babylonTexture) {
|
|
1221
1214
|
onSuccess(texture.babylonTexture);
|
|
1222
1215
|
return;
|
|
1223
1216
|
}
|
|
1224
|
-
|
|
1225
|
-
|
|
1217
|
+
const sampler = gltfRuntime.samplers[texture.sampler];
|
|
1218
|
+
const createMipMaps = sampler.minFilter === ETextureFilterType.NEAREST_MIPMAP_NEAREST ||
|
|
1226
1219
|
sampler.minFilter === ETextureFilterType.NEAREST_MIPMAP_LINEAR ||
|
|
1227
1220
|
sampler.minFilter === ETextureFilterType.LINEAR_MIPMAP_NEAREST ||
|
|
1228
1221
|
sampler.minFilter === ETextureFilterType.LINEAR_MIPMAP_LINEAR;
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1222
|
+
const samplingMode = Texture.BILINEAR_SAMPLINGMODE;
|
|
1223
|
+
const blob = buffer == null ? new Blob() : new Blob([buffer]);
|
|
1224
|
+
const blobURL = URL.createObjectURL(blob);
|
|
1225
|
+
const revokeBlobURL = () => URL.revokeObjectURL(blobURL);
|
|
1226
|
+
const newTexture = new Texture(blobURL, gltfRuntime.scene, !createMipMaps, true, samplingMode, revokeBlobURL, revokeBlobURL);
|
|
1234
1227
|
if (sampler.wrapS !== undefined) {
|
|
1235
1228
|
newTexture.wrapU = GLTFUtils.GetWrapMode(sampler.wrapS);
|
|
1236
1229
|
}
|
|
@@ -1240,35 +1233,35 @@ var GLTFLoaderBase = /** @class */ (function () {
|
|
|
1240
1233
|
newTexture.name = id;
|
|
1241
1234
|
texture.babylonTexture = newTexture;
|
|
1242
1235
|
onSuccess(newTexture);
|
|
1243
|
-
}
|
|
1244
|
-
|
|
1245
|
-
|
|
1236
|
+
}
|
|
1237
|
+
static LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError) {
|
|
1238
|
+
const shader = gltfRuntime.shaders[id];
|
|
1246
1239
|
if (Tools.IsBase64(shader.uri)) {
|
|
1247
|
-
|
|
1240
|
+
const shaderString = atob(shader.uri.split(",")[1]);
|
|
1248
1241
|
if (onSuccess) {
|
|
1249
1242
|
onSuccess(shaderString);
|
|
1250
1243
|
}
|
|
1251
1244
|
}
|
|
1252
1245
|
else {
|
|
1253
|
-
Tools.LoadFile(gltfRuntime.rootUrl + shader.uri, onSuccess, undefined, undefined, false,
|
|
1246
|
+
Tools.LoadFile(gltfRuntime.rootUrl + shader.uri, onSuccess, undefined, undefined, false, (request) => {
|
|
1254
1247
|
if (request && onError) {
|
|
1255
1248
|
onError(request.status + " " + request.statusText);
|
|
1256
1249
|
}
|
|
1257
1250
|
});
|
|
1258
1251
|
}
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1252
|
+
}
|
|
1253
|
+
static LoadMaterialAsync(gltfRuntime, id, onSuccess, onError) {
|
|
1254
|
+
const material = gltfRuntime.materials[id];
|
|
1262
1255
|
if (!material.technique) {
|
|
1263
1256
|
if (onError) {
|
|
1264
1257
|
onError("No technique found.");
|
|
1265
1258
|
}
|
|
1266
1259
|
return;
|
|
1267
1260
|
}
|
|
1268
|
-
|
|
1261
|
+
const technique = gltfRuntime.techniques[material.technique];
|
|
1269
1262
|
if (!technique) {
|
|
1270
1263
|
gltfRuntime.scene._blockEntityCollection = !!gltfRuntime.assetContainer;
|
|
1271
|
-
|
|
1264
|
+
const defaultMaterial = new StandardMaterial(id, gltfRuntime.scene);
|
|
1272
1265
|
defaultMaterial._parentContainer = gltfRuntime.assetContainer;
|
|
1273
1266
|
gltfRuntime.scene._blockEntityCollection = false;
|
|
1274
1267
|
defaultMaterial.diffuseColor = new Color3(0.5, 0.5, 0.5);
|
|
@@ -1276,25 +1269,25 @@ var GLTFLoaderBase = /** @class */ (function () {
|
|
|
1276
1269
|
onSuccess(defaultMaterial);
|
|
1277
1270
|
return;
|
|
1278
1271
|
}
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1272
|
+
const program = gltfRuntime.programs[technique.program];
|
|
1273
|
+
const states = technique.states;
|
|
1274
|
+
const vertexShader = Effect.ShadersStore[program.vertexShader + "VertexShader"];
|
|
1275
|
+
const pixelShader = Effect.ShadersStore[program.fragmentShader + "PixelShader"];
|
|
1276
|
+
let newVertexShader = "";
|
|
1277
|
+
let newPixelShader = "";
|
|
1278
|
+
const vertexTokenizer = new Tokenizer(vertexShader);
|
|
1279
|
+
const pixelTokenizer = new Tokenizer(pixelShader);
|
|
1280
|
+
const unTreatedUniforms = {};
|
|
1281
|
+
const uniforms = [];
|
|
1282
|
+
const attributes = [];
|
|
1283
|
+
const samplers = [];
|
|
1291
1284
|
// Fill uniform, sampler2D and attributes
|
|
1292
|
-
for (
|
|
1293
|
-
|
|
1294
|
-
|
|
1285
|
+
for (const unif in technique.uniforms) {
|
|
1286
|
+
const uniform = technique.uniforms[unif];
|
|
1287
|
+
const uniformParameter = technique.parameters[uniform];
|
|
1295
1288
|
unTreatedUniforms[unif] = uniformParameter;
|
|
1296
1289
|
if (uniformParameter.semantic && !uniformParameter.node && !uniformParameter.source) {
|
|
1297
|
-
|
|
1290
|
+
const transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
|
|
1298
1291
|
if (transformIndex !== -1) {
|
|
1299
1292
|
uniforms.push(babylonTransforms[transformIndex]);
|
|
1300
1293
|
delete unTreatedUniforms[unif];
|
|
@@ -1310,27 +1303,27 @@ var GLTFLoaderBase = /** @class */ (function () {
|
|
|
1310
1303
|
uniforms.push(unif);
|
|
1311
1304
|
}
|
|
1312
1305
|
}
|
|
1313
|
-
for (
|
|
1314
|
-
|
|
1315
|
-
|
|
1306
|
+
for (const attr in technique.attributes) {
|
|
1307
|
+
const attribute = technique.attributes[attr];
|
|
1308
|
+
const attributeParameter = technique.parameters[attribute];
|
|
1316
1309
|
if (attributeParameter.semantic) {
|
|
1317
|
-
|
|
1318
|
-
if (
|
|
1319
|
-
attributes.push(
|
|
1310
|
+
const name = getAttribute(attributeParameter);
|
|
1311
|
+
if (name) {
|
|
1312
|
+
attributes.push(name);
|
|
1320
1313
|
}
|
|
1321
1314
|
}
|
|
1322
1315
|
}
|
|
1323
1316
|
// Configure vertex shader
|
|
1324
1317
|
while (!vertexTokenizer.isEnd() && vertexTokenizer.getNextToken()) {
|
|
1325
|
-
|
|
1318
|
+
const tokenType = vertexTokenizer.currentToken;
|
|
1326
1319
|
if (tokenType !== ETokenType.IDENTIFIER) {
|
|
1327
1320
|
newVertexShader += vertexTokenizer.currentString;
|
|
1328
1321
|
continue;
|
|
1329
1322
|
}
|
|
1330
|
-
|
|
1331
|
-
for (
|
|
1332
|
-
|
|
1333
|
-
|
|
1323
|
+
let foundAttribute = false;
|
|
1324
|
+
for (const attr in technique.attributes) {
|
|
1325
|
+
const attribute = technique.attributes[attr];
|
|
1326
|
+
const attributeParameter = technique.parameters[attribute];
|
|
1334
1327
|
if (vertexTokenizer.currentIdentifier === attr && attributeParameter.semantic) {
|
|
1335
1328
|
newVertexShader += getAttribute(attributeParameter);
|
|
1336
1329
|
foundAttribute = true;
|
|
@@ -1344,7 +1337,7 @@ var GLTFLoaderBase = /** @class */ (function () {
|
|
|
1344
1337
|
}
|
|
1345
1338
|
// Configure pixel shader
|
|
1346
1339
|
while (!pixelTokenizer.isEnd() && pixelTokenizer.getNextToken()) {
|
|
1347
|
-
|
|
1340
|
+
const tokenType = pixelTokenizer.currentToken;
|
|
1348
1341
|
if (tokenType !== ETokenType.IDENTIFIER) {
|
|
1349
1342
|
newPixelShader += pixelTokenizer.currentString;
|
|
1350
1343
|
continue;
|
|
@@ -1352,11 +1345,11 @@ var GLTFLoaderBase = /** @class */ (function () {
|
|
|
1352
1345
|
newPixelShader += parseShaderUniforms(pixelTokenizer, technique, unTreatedUniforms);
|
|
1353
1346
|
}
|
|
1354
1347
|
// Create shader material
|
|
1355
|
-
|
|
1348
|
+
const shaderPath = {
|
|
1356
1349
|
vertex: program.vertexShader + id,
|
|
1357
1350
|
fragment: program.fragmentShader + id,
|
|
1358
1351
|
};
|
|
1359
|
-
|
|
1352
|
+
const options = {
|
|
1360
1353
|
attributes: attributes,
|
|
1361
1354
|
uniforms: uniforms,
|
|
1362
1355
|
samplers: samplers,
|
|
@@ -1364,16 +1357,16 @@ var GLTFLoaderBase = /** @class */ (function () {
|
|
|
1364
1357
|
};
|
|
1365
1358
|
Effect.ShadersStore[program.vertexShader + id + "VertexShader"] = newVertexShader;
|
|
1366
1359
|
Effect.ShadersStore[program.fragmentShader + id + "PixelShader"] = newPixelShader;
|
|
1367
|
-
|
|
1360
|
+
const shaderMaterial = new ShaderMaterial(id, gltfRuntime.scene, shaderPath, options);
|
|
1368
1361
|
shaderMaterial.onError = onShaderCompileError(program, shaderMaterial, onError);
|
|
1369
1362
|
shaderMaterial.onCompiled = onShaderCompileSuccess(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess);
|
|
1370
1363
|
shaderMaterial.sideOrientation = Material.CounterClockWiseSideOrientation;
|
|
1371
1364
|
if (states && states.functions) {
|
|
1372
|
-
|
|
1365
|
+
const functions = states.functions;
|
|
1373
1366
|
if (functions.cullFace && functions.cullFace[0] !== ECullingType.BACK) {
|
|
1374
1367
|
shaderMaterial.backFaceCulling = false;
|
|
1375
1368
|
}
|
|
1376
|
-
|
|
1369
|
+
const blendFunc = functions.blendFuncSeparate;
|
|
1377
1370
|
if (blendFunc) {
|
|
1378
1371
|
if (blendFunc[0] === EBlendingFunction.SRC_ALPHA &&
|
|
1379
1372
|
blendFunc[1] === EBlendingFunction.ONE_MINUS_SRC_ALPHA &&
|
|
@@ -1413,32 +1406,27 @@ var GLTFLoaderBase = /** @class */ (function () {
|
|
|
1413
1406
|
}
|
|
1414
1407
|
}
|
|
1415
1408
|
}
|
|
1416
|
-
}
|
|
1417
|
-
|
|
1418
|
-
}());
|
|
1419
|
-
export { GLTFLoaderBase };
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1420
1411
|
/**
|
|
1421
1412
|
* glTF V1 Loader
|
|
1422
1413
|
* @hidden
|
|
1423
1414
|
* @deprecated
|
|
1424
1415
|
*/
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
}
|
|
1428
|
-
GLTFLoader.RegisterExtension = function (extension) {
|
|
1416
|
+
export class GLTFLoader {
|
|
1417
|
+
static RegisterExtension(extension) {
|
|
1429
1418
|
if (GLTFLoader.Extensions[extension.name]) {
|
|
1430
1419
|
Tools.Error('Tool with the same name "' + extension.name + '" already exists');
|
|
1431
1420
|
return;
|
|
1432
1421
|
}
|
|
1433
1422
|
GLTFLoader.Extensions[extension.name] = extension;
|
|
1434
|
-
}
|
|
1435
|
-
|
|
1423
|
+
}
|
|
1424
|
+
dispose() {
|
|
1436
1425
|
// do nothing
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
var _this = this;
|
|
1426
|
+
}
|
|
1427
|
+
_importMeshAsync(meshesNames, scene, data, rootUrl, assetContainer, onSuccess, onProgress, onError) {
|
|
1440
1428
|
scene.useRightHandedSystem = true;
|
|
1441
|
-
GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl,
|
|
1429
|
+
GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, (gltfRuntime) => {
|
|
1442
1430
|
gltfRuntime.assetContainer = assetContainer;
|
|
1443
1431
|
gltfRuntime.importOnlyMeshes = true;
|
|
1444
1432
|
if (meshesNames === "") {
|
|
@@ -1455,25 +1443,25 @@ var GLTFLoader = /** @class */ (function () {
|
|
|
1455
1443
|
Tools.Warn("Argument meshesNames must be of type string or string[]");
|
|
1456
1444
|
}
|
|
1457
1445
|
// Create nodes
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1446
|
+
this._createNodes(gltfRuntime);
|
|
1447
|
+
const meshes = new Array();
|
|
1448
|
+
const skeletons = new Array();
|
|
1461
1449
|
// Fill arrays of meshes and skeletons
|
|
1462
|
-
for (
|
|
1463
|
-
|
|
1450
|
+
for (const nde in gltfRuntime.nodes) {
|
|
1451
|
+
const node = gltfRuntime.nodes[nde];
|
|
1464
1452
|
if (node.babylonNode instanceof AbstractMesh) {
|
|
1465
1453
|
meshes.push(node.babylonNode);
|
|
1466
1454
|
}
|
|
1467
1455
|
}
|
|
1468
|
-
for (
|
|
1469
|
-
|
|
1456
|
+
for (const skl in gltfRuntime.skins) {
|
|
1457
|
+
const skin = gltfRuntime.skins[skl];
|
|
1470
1458
|
if (skin.babylonSkeleton instanceof Skeleton) {
|
|
1471
1459
|
skeletons.push(skin.babylonSkeleton);
|
|
1472
1460
|
}
|
|
1473
1461
|
}
|
|
1474
1462
|
// Load buffers, shaders, materials, etc.
|
|
1475
|
-
|
|
1476
|
-
|
|
1463
|
+
this._loadBuffersAsync(gltfRuntime, () => {
|
|
1464
|
+
this._loadShadersAsync(gltfRuntime, () => {
|
|
1477
1465
|
importMaterials(gltfRuntime);
|
|
1478
1466
|
postLoad(gltfRuntime);
|
|
1479
1467
|
if (!GLTFFileLoader.IncrementalLoading && onSuccess) {
|
|
@@ -1486,7 +1474,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
|
1486
1474
|
}
|
|
1487
1475
|
}, onError);
|
|
1488
1476
|
return true;
|
|
1489
|
-
}
|
|
1477
|
+
}
|
|
1490
1478
|
/**
|
|
1491
1479
|
* Imports one or more meshes from a loaded gltf file and adds them to the scene
|
|
1492
1480
|
* @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
|
|
@@ -1497,10 +1485,9 @@ var GLTFLoader = /** @class */ (function () {
|
|
|
1497
1485
|
* @param onProgress event that fires when loading progress has occured
|
|
1498
1486
|
* @returns a promise containg the loaded meshes, particles, skeletons and animations
|
|
1499
1487
|
*/
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
_this._importMeshAsync(meshesNames, scene, data, rootUrl, assetContainer, function (meshes, skeletons) {
|
|
1488
|
+
importMeshAsync(meshesNames, scene, assetContainer, data, rootUrl, onProgress) {
|
|
1489
|
+
return new Promise((resolve, reject) => {
|
|
1490
|
+
this._importMeshAsync(meshesNames, scene, data, rootUrl, assetContainer, (meshes, skeletons) => {
|
|
1504
1491
|
resolve({
|
|
1505
1492
|
meshes: meshes,
|
|
1506
1493
|
particleSystems: [],
|
|
@@ -1510,22 +1497,21 @@ var GLTFLoader = /** @class */ (function () {
|
|
|
1510
1497
|
transformNodes: [],
|
|
1511
1498
|
geometries: [],
|
|
1512
1499
|
});
|
|
1513
|
-
}, onProgress,
|
|
1500
|
+
}, onProgress, (message) => {
|
|
1514
1501
|
reject(new Error(message));
|
|
1515
1502
|
});
|
|
1516
1503
|
});
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
|
-
var _this = this;
|
|
1504
|
+
}
|
|
1505
|
+
_loadAsync(scene, data, rootUrl, onSuccess, onProgress, onError) {
|
|
1520
1506
|
scene.useRightHandedSystem = true;
|
|
1521
|
-
GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl,
|
|
1507
|
+
GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, (gltfRuntime) => {
|
|
1522
1508
|
// Load runtime extensios
|
|
1523
|
-
GLTFLoaderExtension.LoadRuntimeExtensionsAsync(gltfRuntime,
|
|
1509
|
+
GLTFLoaderExtension.LoadRuntimeExtensionsAsync(gltfRuntime, () => {
|
|
1524
1510
|
// Create nodes
|
|
1525
|
-
|
|
1511
|
+
this._createNodes(gltfRuntime);
|
|
1526
1512
|
// Load buffers, shaders, materials, etc.
|
|
1527
|
-
|
|
1528
|
-
|
|
1513
|
+
this._loadBuffersAsync(gltfRuntime, () => {
|
|
1514
|
+
this._loadShadersAsync(gltfRuntime, () => {
|
|
1529
1515
|
importMaterials(gltfRuntime);
|
|
1530
1516
|
postLoad(gltfRuntime);
|
|
1531
1517
|
if (!GLTFFileLoader.IncrementalLoading) {
|
|
@@ -1538,7 +1524,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
|
1538
1524
|
}
|
|
1539
1525
|
}, onError);
|
|
1540
1526
|
}, onError);
|
|
1541
|
-
}
|
|
1527
|
+
}
|
|
1542
1528
|
/**
|
|
1543
1529
|
* Imports all objects from a loaded gltf file and adds them to the scene
|
|
1544
1530
|
* @param scene the scene the objects should be added to
|
|
@@ -1547,20 +1533,19 @@ var GLTFLoader = /** @class */ (function () {
|
|
|
1547
1533
|
* @param onProgress event that fires when loading progress has occured
|
|
1548
1534
|
* @returns a promise which completes when objects have been loaded to the scene
|
|
1549
1535
|
*/
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
_this._loadAsync(scene, data, rootUrl, function () {
|
|
1536
|
+
loadAsync(scene, data, rootUrl, onProgress) {
|
|
1537
|
+
return new Promise((resolve, reject) => {
|
|
1538
|
+
this._loadAsync(scene, data, rootUrl, () => {
|
|
1554
1539
|
resolve();
|
|
1555
|
-
}, onProgress,
|
|
1540
|
+
}, onProgress, (message) => {
|
|
1556
1541
|
reject(new Error(message));
|
|
1557
1542
|
});
|
|
1558
1543
|
});
|
|
1559
|
-
}
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
GLTFLoaderExtension.LoadShaderStringAsync(gltfRuntime, sha,
|
|
1544
|
+
}
|
|
1545
|
+
_loadShadersAsync(gltfRuntime, onload) {
|
|
1546
|
+
let hasShaders = false;
|
|
1547
|
+
const processShader = (sha, shader) => {
|
|
1548
|
+
GLTFLoaderExtension.LoadShaderStringAsync(gltfRuntime, sha, (shaderString) => {
|
|
1564
1549
|
if (shaderString instanceof ArrayBuffer) {
|
|
1565
1550
|
return;
|
|
1566
1551
|
}
|
|
@@ -1571,13 +1556,13 @@ var GLTFLoader = /** @class */ (function () {
|
|
|
1571
1556
|
if (gltfRuntime.loadedShaderCount === gltfRuntime.shaderscount) {
|
|
1572
1557
|
onload();
|
|
1573
1558
|
}
|
|
1574
|
-
},
|
|
1559
|
+
}, () => {
|
|
1575
1560
|
Tools.Error("Error when loading shader program named " + sha + " located at " + shader.uri);
|
|
1576
1561
|
});
|
|
1577
1562
|
};
|
|
1578
|
-
for (
|
|
1563
|
+
for (const sha in gltfRuntime.shaders) {
|
|
1579
1564
|
hasShaders = true;
|
|
1580
|
-
|
|
1565
|
+
const shader = gltfRuntime.shaders[sha];
|
|
1581
1566
|
if (shader) {
|
|
1582
1567
|
processShader.bind(this, sha, shader)();
|
|
1583
1568
|
}
|
|
@@ -1588,11 +1573,11 @@ var GLTFLoader = /** @class */ (function () {
|
|
|
1588
1573
|
if (!hasShaders) {
|
|
1589
1574
|
onload();
|
|
1590
1575
|
}
|
|
1591
|
-
}
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
GLTFLoaderExtension.LoadBufferAsync(gltfRuntime, buf,
|
|
1576
|
+
}
|
|
1577
|
+
_loadBuffersAsync(gltfRuntime, onLoad) {
|
|
1578
|
+
let hasBuffers = false;
|
|
1579
|
+
const processBuffer = (buf, buffer) => {
|
|
1580
|
+
GLTFLoaderExtension.LoadBufferAsync(gltfRuntime, buf, (bufferView) => {
|
|
1596
1581
|
gltfRuntime.loadedBufferCount++;
|
|
1597
1582
|
if (bufferView) {
|
|
1598
1583
|
if (bufferView.byteLength != gltfRuntime.buffers[buf].byteLength) {
|
|
@@ -1603,13 +1588,13 @@ var GLTFLoader = /** @class */ (function () {
|
|
|
1603
1588
|
if (gltfRuntime.loadedBufferCount === gltfRuntime.buffersCount) {
|
|
1604
1589
|
onLoad();
|
|
1605
1590
|
}
|
|
1606
|
-
},
|
|
1591
|
+
}, () => {
|
|
1607
1592
|
Tools.Error("Error when loading buffer named " + buf + " located at " + buffer.uri);
|
|
1608
1593
|
});
|
|
1609
1594
|
};
|
|
1610
|
-
for (
|
|
1595
|
+
for (const buf in gltfRuntime.buffers) {
|
|
1611
1596
|
hasBuffers = true;
|
|
1612
|
-
|
|
1597
|
+
const buffer = gltfRuntime.buffers[buf];
|
|
1613
1598
|
if (buffer) {
|
|
1614
1599
|
processBuffer.bind(this, buf, buffer)();
|
|
1615
1600
|
}
|
|
@@ -1620,41 +1605,35 @@ var GLTFLoader = /** @class */ (function () {
|
|
|
1620
1605
|
if (!hasBuffers) {
|
|
1621
1606
|
onLoad();
|
|
1622
1607
|
}
|
|
1623
|
-
}
|
|
1624
|
-
|
|
1625
|
-
|
|
1608
|
+
}
|
|
1609
|
+
_createNodes(gltfRuntime) {
|
|
1610
|
+
let currentScene = gltfRuntime.currentScene;
|
|
1626
1611
|
if (currentScene) {
|
|
1627
1612
|
// Only one scene even if multiple scenes are defined
|
|
1628
|
-
for (
|
|
1613
|
+
for (let i = 0; i < currentScene.nodes.length; i++) {
|
|
1629
1614
|
traverseNodes(gltfRuntime, currentScene.nodes[i], null);
|
|
1630
1615
|
}
|
|
1631
1616
|
}
|
|
1632
1617
|
else {
|
|
1633
1618
|
// Load all scenes
|
|
1634
|
-
for (
|
|
1619
|
+
for (const thing in gltfRuntime.scenes) {
|
|
1635
1620
|
currentScene = gltfRuntime.scenes[thing];
|
|
1636
|
-
for (
|
|
1621
|
+
for (let i = 0; i < currentScene.nodes.length; i++) {
|
|
1637
1622
|
traverseNodes(gltfRuntime, currentScene.nodes[i], null);
|
|
1638
1623
|
}
|
|
1639
1624
|
}
|
|
1640
1625
|
}
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
}());
|
|
1645
|
-
export { GLTFLoader };
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
GLTFLoader.Extensions = {};
|
|
1646
1629
|
/** @hidden */
|
|
1647
|
-
|
|
1648
|
-
|
|
1630
|
+
export class GLTFLoaderExtension {
|
|
1631
|
+
constructor(name) {
|
|
1649
1632
|
this._name = name;
|
|
1650
1633
|
}
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
},
|
|
1655
|
-
enumerable: false,
|
|
1656
|
-
configurable: true
|
|
1657
|
-
});
|
|
1634
|
+
get name() {
|
|
1635
|
+
return this._name;
|
|
1636
|
+
}
|
|
1658
1637
|
/**
|
|
1659
1638
|
* Defines an override for loading the runtime
|
|
1660
1639
|
* Return true to stop further extensions from loading the runtime
|
|
@@ -1664,9 +1643,9 @@ var GLTFLoaderExtension = /** @class */ (function () {
|
|
|
1664
1643
|
* @param onSuccess
|
|
1665
1644
|
* @param onError
|
|
1666
1645
|
*/
|
|
1667
|
-
|
|
1646
|
+
loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError) {
|
|
1668
1647
|
return false;
|
|
1669
|
-
}
|
|
1648
|
+
}
|
|
1670
1649
|
/**
|
|
1671
1650
|
* Defines an onverride for creating gltf runtime
|
|
1672
1651
|
* Return true to stop further extensions from creating the runtime
|
|
@@ -1674,9 +1653,9 @@ var GLTFLoaderExtension = /** @class */ (function () {
|
|
|
1674
1653
|
* @param onSuccess
|
|
1675
1654
|
* @param onError
|
|
1676
1655
|
*/
|
|
1677
|
-
|
|
1656
|
+
loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError) {
|
|
1678
1657
|
return false;
|
|
1679
|
-
}
|
|
1658
|
+
}
|
|
1680
1659
|
/**
|
|
1681
1660
|
* Defines an override for loading buffers
|
|
1682
1661
|
* Return true to stop further extensions from loading this buffer
|
|
@@ -1686,9 +1665,9 @@ var GLTFLoaderExtension = /** @class */ (function () {
|
|
|
1686
1665
|
* @param onError
|
|
1687
1666
|
* @param onProgress
|
|
1688
1667
|
*/
|
|
1689
|
-
|
|
1668
|
+
loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress) {
|
|
1690
1669
|
return false;
|
|
1691
|
-
}
|
|
1670
|
+
}
|
|
1692
1671
|
/**
|
|
1693
1672
|
* Defines an override for loading texture buffers
|
|
1694
1673
|
* Return true to stop further extensions from loading this texture data
|
|
@@ -1697,9 +1676,9 @@ var GLTFLoaderExtension = /** @class */ (function () {
|
|
|
1697
1676
|
* @param onSuccess
|
|
1698
1677
|
* @param onError
|
|
1699
1678
|
*/
|
|
1700
|
-
|
|
1679
|
+
loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError) {
|
|
1701
1680
|
return false;
|
|
1702
|
-
}
|
|
1681
|
+
}
|
|
1703
1682
|
/**
|
|
1704
1683
|
* Defines an override for creating textures
|
|
1705
1684
|
* Return true to stop further extensions from loading this texture
|
|
@@ -1709,9 +1688,9 @@ var GLTFLoaderExtension = /** @class */ (function () {
|
|
|
1709
1688
|
* @param onSuccess
|
|
1710
1689
|
* @param onError
|
|
1711
1690
|
*/
|
|
1712
|
-
|
|
1691
|
+
createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError) {
|
|
1713
1692
|
return false;
|
|
1714
|
-
}
|
|
1693
|
+
}
|
|
1715
1694
|
/**
|
|
1716
1695
|
* Defines an override for loading shader strings
|
|
1717
1696
|
* Return true to stop further extensions from loading this shader data
|
|
@@ -1720,9 +1699,9 @@ var GLTFLoaderExtension = /** @class */ (function () {
|
|
|
1720
1699
|
* @param onSuccess
|
|
1721
1700
|
* @param onError
|
|
1722
1701
|
*/
|
|
1723
|
-
|
|
1702
|
+
loadShaderStringAsync(gltfRuntime, id, onSuccess, onError) {
|
|
1724
1703
|
return false;
|
|
1725
|
-
}
|
|
1704
|
+
}
|
|
1726
1705
|
/**
|
|
1727
1706
|
* Defines an override for loading materials
|
|
1728
1707
|
* Return true to stop further extensions from loading this material
|
|
@@ -1731,86 +1710,84 @@ var GLTFLoaderExtension = /** @class */ (function () {
|
|
|
1731
1710
|
* @param onSuccess
|
|
1732
1711
|
* @param onError
|
|
1733
1712
|
*/
|
|
1734
|
-
|
|
1713
|
+
loadMaterialAsync(gltfRuntime, id, onSuccess, onError) {
|
|
1735
1714
|
return false;
|
|
1736
|
-
}
|
|
1715
|
+
}
|
|
1737
1716
|
// ---------
|
|
1738
1717
|
// Utilities
|
|
1739
1718
|
// ---------
|
|
1740
|
-
|
|
1741
|
-
GLTFLoaderExtension._ApplyExtensions(
|
|
1719
|
+
static LoadRuntimeAsync(scene, data, rootUrl, onSuccess, onError) {
|
|
1720
|
+
GLTFLoaderExtension._ApplyExtensions((loaderExtension) => {
|
|
1742
1721
|
return loaderExtension.loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError);
|
|
1743
|
-
},
|
|
1744
|
-
setTimeout(
|
|
1722
|
+
}, () => {
|
|
1723
|
+
setTimeout(() => {
|
|
1745
1724
|
if (!onSuccess) {
|
|
1746
1725
|
return;
|
|
1747
1726
|
}
|
|
1748
1727
|
onSuccess(GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
|
|
1749
1728
|
});
|
|
1750
1729
|
});
|
|
1751
|
-
}
|
|
1752
|
-
|
|
1753
|
-
GLTFLoaderExtension._ApplyExtensions(
|
|
1730
|
+
}
|
|
1731
|
+
static LoadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError) {
|
|
1732
|
+
GLTFLoaderExtension._ApplyExtensions((loaderExtension) => {
|
|
1754
1733
|
return loaderExtension.loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError);
|
|
1755
|
-
},
|
|
1756
|
-
setTimeout(
|
|
1734
|
+
}, () => {
|
|
1735
|
+
setTimeout(() => {
|
|
1757
1736
|
onSuccess();
|
|
1758
1737
|
});
|
|
1759
1738
|
});
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1762
|
-
GLTFLoaderExtension._ApplyExtensions(
|
|
1739
|
+
}
|
|
1740
|
+
static LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress) {
|
|
1741
|
+
GLTFLoaderExtension._ApplyExtensions((loaderExtension) => {
|
|
1763
1742
|
return loaderExtension.loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
|
|
1764
|
-
},
|
|
1743
|
+
}, () => {
|
|
1765
1744
|
GLTFLoaderBase.LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
|
|
1766
1745
|
});
|
|
1767
|
-
}
|
|
1768
|
-
|
|
1769
|
-
GLTFLoaderExtension._LoadTextureBufferAsync(gltfRuntime, id,
|
|
1746
|
+
}
|
|
1747
|
+
static LoadTextureAsync(gltfRuntime, id, onSuccess, onError) {
|
|
1748
|
+
GLTFLoaderExtension._LoadTextureBufferAsync(gltfRuntime, id, (buffer) => {
|
|
1770
1749
|
if (buffer) {
|
|
1771
1750
|
GLTFLoaderExtension._CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
|
|
1772
1751
|
}
|
|
1773
1752
|
}, onError);
|
|
1774
|
-
}
|
|
1775
|
-
|
|
1776
|
-
GLTFLoaderExtension._ApplyExtensions(
|
|
1753
|
+
}
|
|
1754
|
+
static LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError) {
|
|
1755
|
+
GLTFLoaderExtension._ApplyExtensions((loaderExtension) => {
|
|
1777
1756
|
return loaderExtension.loadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
|
|
1778
|
-
},
|
|
1757
|
+
}, () => {
|
|
1779
1758
|
GLTFLoaderBase.LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
|
|
1780
1759
|
});
|
|
1781
|
-
}
|
|
1782
|
-
|
|
1783
|
-
GLTFLoaderExtension._ApplyExtensions(
|
|
1760
|
+
}
|
|
1761
|
+
static LoadMaterialAsync(gltfRuntime, id, onSuccess, onError) {
|
|
1762
|
+
GLTFLoaderExtension._ApplyExtensions((loaderExtension) => {
|
|
1784
1763
|
return loaderExtension.loadMaterialAsync(gltfRuntime, id, onSuccess, onError);
|
|
1785
|
-
},
|
|
1764
|
+
}, () => {
|
|
1786
1765
|
GLTFLoaderBase.LoadMaterialAsync(gltfRuntime, id, onSuccess, onError);
|
|
1787
1766
|
});
|
|
1788
|
-
}
|
|
1789
|
-
|
|
1790
|
-
GLTFLoaderExtension._ApplyExtensions(
|
|
1767
|
+
}
|
|
1768
|
+
static _LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError) {
|
|
1769
|
+
GLTFLoaderExtension._ApplyExtensions((loaderExtension) => {
|
|
1791
1770
|
return loaderExtension.loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
|
|
1792
|
-
},
|
|
1771
|
+
}, () => {
|
|
1793
1772
|
GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
|
|
1794
1773
|
});
|
|
1795
|
-
}
|
|
1796
|
-
|
|
1797
|
-
GLTFLoaderExtension._ApplyExtensions(
|
|
1774
|
+
}
|
|
1775
|
+
static _CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError) {
|
|
1776
|
+
GLTFLoaderExtension._ApplyExtensions((loaderExtension) => {
|
|
1798
1777
|
return loaderExtension.createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
|
|
1799
|
-
},
|
|
1778
|
+
}, () => {
|
|
1800
1779
|
GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess);
|
|
1801
1780
|
});
|
|
1802
|
-
}
|
|
1803
|
-
|
|
1804
|
-
for (
|
|
1805
|
-
|
|
1781
|
+
}
|
|
1782
|
+
static _ApplyExtensions(func, defaultFunc) {
|
|
1783
|
+
for (const extensionName in GLTFLoader.Extensions) {
|
|
1784
|
+
const loaderExtension = GLTFLoader.Extensions[extensionName];
|
|
1806
1785
|
if (func(loaderExtension)) {
|
|
1807
1786
|
return;
|
|
1808
1787
|
}
|
|
1809
1788
|
}
|
|
1810
1789
|
defaultFunc();
|
|
1811
|
-
}
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
export { GLTFLoaderExtension };
|
|
1815
|
-
GLTFFileLoader._CreateGLTF1Loader = function () { return new GLTFLoader(); };
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
GLTFFileLoader._CreateGLTF1Loader = () => new GLTFLoader();
|
|
1816
1793
|
//# sourceMappingURL=glTFLoader.js.map
|