Przeglądaj źródła

Use JSON pointer in glTF loader error messages

Gary Hsu 7 lat temu
rodzic
commit
1bf44e3757
1 zmienionych plików z 26 dodań i 26 usunięć
  1. 26 26
      loaders/src/glTF/2.0/babylon.glTFLoader.ts

+ 26 - 26
loaders/src/glTF/2.0/babylon.glTFLoader.ts

@@ -263,7 +263,7 @@ module BABYLON.GLTF2 {
                 throw new Error("Failed to find scene " + (this._gltf.scene || 0));
             }
 
-            this._loadScene("scenes[" + scene.index + "]", scene, nodeNames);
+            this._loadScene("#/scenes/" + scene.index, scene, nodeNames);
         }
 
         private _loadScene(context: string, scene: IGLTFScene, nodeNames: any): void {
@@ -318,7 +318,7 @@ module BABYLON.GLTF2 {
                     throw new Error(context + ": Failed to find node " + nodeIndices[i]);
                 }
 
-                this._loadNode("nodes[" + nodeIndices[i] + "]", node);
+                this._loadNode("#/nodes/" + nodeIndices[i], node);
             }
 
             // Disable the root mesh until the asset is ready to render.
@@ -340,7 +340,7 @@ module BABYLON.GLTF2 {
                     throw new Error(context + ": Failed to find mesh " + node.mesh);
                 }
 
-                this._loadMesh("meshes[" + node.mesh + "]", node, mesh);
+                this._loadMesh("#/meshes/" + node.mesh, node, mesh);
             }
 
             node.babylonMesh.parent = node.parent ? node.parent.babylonMesh : null;
@@ -354,7 +354,7 @@ module BABYLON.GLTF2 {
                     throw new Error(context + ": Failed to find skin " + node.skin);
                 }
 
-                node.babylonMesh.skeleton = this._loadSkin("skins[" + node.skin + "]", skin);
+                node.babylonMesh.skeleton = this._loadSkin("#/skins/" + node.skin, skin);
             }
 
             if (node.camera != null) {
@@ -368,7 +368,7 @@ module BABYLON.GLTF2 {
                         throw new Error(context + ": Failed to find child node " + node.children[i]);
                     }
 
-                    this._loadNode("nodes[" + node.children[i] + "]", childNode);
+                    this._loadNode("#/nodes/" + node.children[i], childNode);
                 }
             }
         }
@@ -389,7 +389,7 @@ module BABYLON.GLTF2 {
 
             for (var index = 0; index < mesh.primitives.length; index++) {
                 var primitive = mesh.primitives[index];
-                this._loadPrimitive(context + "/primitives[" + index + "]", node, mesh, primitive, (subVertexData, loadMaterial) => {
+                this._loadPrimitive(context + "/primitives/" + index, node, mesh, primitive, (subVertexData, loadMaterial) => {
                     subMeshInfos.push({
                         verticesStart: vertexData.positions.length,
                         verticesCount: subVertexData.positions.length,
@@ -440,7 +440,7 @@ module BABYLON.GLTF2 {
                             throw new Error(context + ": Failed to find material " + primitive.material);
                         }
 
-                        this._loadMaterial("materials[" + material.index + "]", material, (babylonMaterial, isNew) => {
+                        this._loadMaterial("#/materials/" + material.index, material, (babylonMaterial, isNew) => {
                             if (isNew && this._parent.onMaterialLoaded) {
                                 this._parent.onMaterialLoaded(babylonMaterial);
                             }
@@ -477,7 +477,7 @@ module BABYLON.GLTF2 {
                     throw new Error(context + ": Failed to find attribute '" + attribute + "' accessor " + attributes[attribute]);
                 }
 
-                this._loadAccessorAsync("accessors[" + accessor.index + "]", accessor, data => {
+                this._loadAccessorAsync("#/accessors/" + accessor.index, accessor, data => {
                     switch (attribute) {
                         case "NORMAL":
                             vertexData.normals = <Float32Array>data;
@@ -520,7 +520,7 @@ module BABYLON.GLTF2 {
                                 throw new Error(context + ": Failed to find indices accessor " + primitive.indices);
                             }
 
-                            this._loadAccessorAsync("accessors[" + indicesAccessor.index + "]", indicesAccessor, data => {
+                            this._loadAccessorAsync("#/accessors/" + indicesAccessor.index, indicesAccessor, data => {
                                 vertexData.indices = <IndicesArray>data;
                                 onSuccess(vertexData);
                             });
@@ -558,10 +558,10 @@ module BABYLON.GLTF2 {
                 for (let attribute in attributes) {
                     var accessor = GLTFUtils.GetArrayItem(this._gltf.accessors, attributes[attribute]);
                     if (!accessor) {
-                        throw new Error(context + "/targets[" + index + "]: Failed to find attribute '" + attribute + "' accessor " + attributes[attribute]);
+                        throw new Error(context + "/targets/" + index + ": Failed to find attribute '" + attribute + "' accessor " + attributes[attribute]);
                     }
 
-                    this._loadAccessorAsync("accessors[" + accessor.index + "]", accessor, data => {
+                    this._loadAccessorAsync("#/accessors/" + accessor.index, accessor, data => {
                         if (accessor.name) {
                             babylonMorphTarget.name = accessor.name;
                         }
@@ -632,7 +632,7 @@ module BABYLON.GLTF2 {
                     throw new Error(context + ": Failed to find inverse bind matrices attribute " + skin.inverseBindMatrices);
                 }
 
-                this._loadAccessorAsync("accessors[" + accessor.index + "]", accessor, data => {
+                this._loadAccessorAsync("#/accessors/" + accessor.index, accessor, data => {
                     this._loadBones(context, skin, <Float32Array>data);
                 });
             }
@@ -731,7 +731,7 @@ module BABYLON.GLTF2 {
 
             for (var animationIndex = 0; animationIndex < animations.length; animationIndex++) {
                 var animation = animations[animationIndex];
-                var context = "animations[" + animationIndex + "]";
+                var context = "#/animations/" + animationIndex;
                 for (var channelIndex = 0; channelIndex < animation.channels.length; channelIndex++) {
                     var channel = GLTFUtils.GetArrayItem(animation.channels, channelIndex);
                     if (!channel) {
@@ -744,8 +744,8 @@ module BABYLON.GLTF2 {
                     }
 
                     this._loadAnimationChannel(animation,
-                        context + "/channels[" + channelIndex + "]", channel,
-                        context + "/samplers[" + channel.sampler + "]", sampler);
+                        context + "/channels/" + channelIndex, channel,
+                        context + "/samplers/" + channel.sampler, sampler);
                 }
             }
         }
@@ -873,7 +873,7 @@ module BABYLON.GLTF2 {
                 throw new Error(samplerContext + ": Failed to find input accessor " + sampler.input);
             }
 
-            this._loadAccessorAsync("accessors[" + inputAccessor.index + "]", inputAccessor, data => {
+            this._loadAccessorAsync("#/accessors/" + inputAccessor.index, inputAccessor, data => {
                 inputData = <Float32Array>data;
                 checkSuccess();
             });
@@ -883,7 +883,7 @@ module BABYLON.GLTF2 {
                 throw new Error(samplerContext + ": Failed to find output accessor " + sampler.output);
             }
 
-            this._loadAccessorAsync("accessors[" + outputAccessor.index + "]", outputAccessor, data => {
+            this._loadAccessorAsync("#/accessors/" + outputAccessor.index, outputAccessor, data => {
                 outputData = <Float32Array>data;
                 checkSuccess();
             });
@@ -949,7 +949,7 @@ module BABYLON.GLTF2 {
                 throw new Error(context + ": Failed to find buffer " + bufferView.buffer);
             }
 
-            this._loadBufferAsync("buffers[" + buffer.index + "]", buffer, bufferData => {
+            this._loadBufferAsync("#/buffers/" + buffer.index, buffer, bufferData => {
                 if (this._disposed) {
                     return;
                 }
@@ -979,7 +979,7 @@ module BABYLON.GLTF2 {
                 throw new Error(context + ": Failed to find buffer view " + accessor.bufferView);
             }
 
-            this._loadBufferViewAsync("bufferViews[" + bufferView.index + "]", bufferView, bufferViewData => {
+            this._loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView, bufferViewData => {
                 var numComponents = this._getNumComponentsOfType(accessor.type);
                 if (numComponents === 0) {
                     throw new Error(context + ": Invalid type (" + accessor.type + ")");
@@ -1144,7 +1144,7 @@ module BABYLON.GLTF2 {
                     throw new Error(context + ": Failed to find base color texture " + properties.baseColorTexture.index);
                 }
 
-                babylonMaterial.albedoTexture = this._loadTexture("textures[" + texture.index + "]", texture, properties.baseColorTexture.texCoord);
+                babylonMaterial.albedoTexture = this._loadTexture("#/textures/" + texture.index, texture, properties.baseColorTexture.texCoord);
             }
 
             if (properties.metallicRoughnessTexture) {
@@ -1153,7 +1153,7 @@ module BABYLON.GLTF2 {
                     throw new Error(context + ": Failed to find metallic roughness texture " + properties.metallicRoughnessTexture.index);
                 }
 
-                babylonMaterial.metallicTexture = this._loadTexture("textures[" + texture.index + "]", texture, properties.metallicRoughnessTexture.texCoord);
+                babylonMaterial.metallicTexture = this._loadTexture("#/textures/" + texture.index, texture, properties.metallicRoughnessTexture.texCoord);
                 babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
                 babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
                 babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
@@ -1199,7 +1199,7 @@ module BABYLON.GLTF2 {
                     throw new Error(context + ": Failed to find normal texture " + material.normalTexture.index);
                 }
 
-                babylonMaterial.bumpTexture = this._loadTexture("textures[" + texture.index + "]", texture, material.normalTexture.texCoord);
+                babylonMaterial.bumpTexture = this._loadTexture("#/textures/" + texture.index, texture, material.normalTexture.texCoord);
                 babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
                 babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
                 if (material.normalTexture.scale != null) {
@@ -1213,7 +1213,7 @@ module BABYLON.GLTF2 {
                     throw new Error(context + ": Failed to find occlusion texture " + material.occlusionTexture.index);
                 }
 
-                babylonMaterial.ambientTexture = this._loadTexture("textures[" + texture.index + "]", texture, material.occlusionTexture.texCoord);
+                babylonMaterial.ambientTexture = this._loadTexture("#/textures/" + texture.index, texture, material.occlusionTexture.texCoord);
                 babylonMaterial.useAmbientInGrayScale = true;
                 if (material.occlusionTexture.strength != null) {
                     babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
@@ -1226,7 +1226,7 @@ module BABYLON.GLTF2 {
                     throw new Error(context + ": Failed to find emissive texture " + material.emissiveTexture.index);
                 }
 
-                babylonMaterial.emissiveTexture = this._loadTexture("textures[" + texture.index + "]", texture, material.emissiveTexture.texCoord);
+                babylonMaterial.emissiveTexture = this._loadTexture("#/textures/" + texture.index, texture, material.emissiveTexture.texCoord);
             }
         }
 
@@ -1308,7 +1308,7 @@ module BABYLON.GLTF2 {
                     throw new Error(context + ": Failed to find source " + texture.source);
                 }
 
-                this._loadImage("images[" + image.index + "]", image, data => {
+                this._loadImage("#/images/" + image.index, image, data => {
                     texture.url = URL.createObjectURL(new Blob([data], { type: image.mimeType }));
                     texture.dataReadyObservable.notifyObservers(texture);
                 });
@@ -1357,7 +1357,7 @@ module BABYLON.GLTF2 {
                     throw new Error(context + ": Failed to find buffer view " + image.bufferView);
                 }
 
-                this._loadBufferViewAsync("bufferViews[" + bufferView.index + "]", bufferView, onSuccess);
+                this._loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView, onSuccess);
             }
         }