Browse Source

Merge pull request #9838 from bghgary/sceneloader-fix

Fix a bug in scene loader and add some unit tests
Raanan Weber 4 years ago
parent
commit
f2e3c8b030

BIN
Playground/scenes/Box/Box.bin


+ 142 - 0
Playground/scenes/Box/Box.gltf

@@ -0,0 +1,142 @@
+{
+    "asset": {
+        "generator": "COLLADA2GLTF",
+        "version": "2.0"
+    },
+    "scene": 0,
+    "scenes": [
+        {
+            "nodes": [
+                0
+            ]
+        }
+    ],
+    "nodes": [
+        {
+            "children": [
+                1
+            ],
+            "matrix": [
+                1.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                -1.0,
+                0.0,
+                0.0,
+                1.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                1.0
+            ]
+        },
+        {
+            "mesh": 0
+        }
+    ],
+    "meshes": [
+        {
+            "primitives": [
+                {
+                    "attributes": {
+                        "NORMAL": 1,
+                        "POSITION": 2
+                    },
+                    "indices": 0,
+                    "mode": 4,
+                    "material": 0
+                }
+            ],
+            "name": "Mesh"
+        }
+    ],
+    "accessors": [
+        {
+            "bufferView": 0,
+            "byteOffset": 0,
+            "componentType": 5123,
+            "count": 36,
+            "max": [
+                23
+            ],
+            "min": [
+                0
+            ],
+            "type": "SCALAR"
+        },
+        {
+            "bufferView": 1,
+            "byteOffset": 0,
+            "componentType": 5126,
+            "count": 24,
+            "max": [
+                1.0,
+                1.0,
+                1.0
+            ],
+            "min": [
+                -1.0,
+                -1.0,
+                -1.0
+            ],
+            "type": "VEC3"
+        },
+        {
+            "bufferView": 1,
+            "byteOffset": 288,
+            "componentType": 5126,
+            "count": 24,
+            "max": [
+                0.5,
+                0.5,
+                0.5
+            ],
+            "min": [
+                -0.5,
+                -0.5,
+                -0.5
+            ],
+            "type": "VEC3"
+        }
+    ],
+    "materials": [
+        {
+            "pbrMetallicRoughness": {
+                "baseColorFactor": [
+                    0.800000011920929,
+                    0.0,
+                    0.0,
+                    1.0
+                ],
+                "metallicFactor": 0.0
+            },
+            "name": "Red"
+        }
+    ],
+    "bufferViews": [
+        {
+            "buffer": 0,
+            "byteOffset": 576,
+            "byteLength": 72,
+            "target": 34963
+        },
+        {
+            "buffer": 0,
+            "byteOffset": 0,
+            "byteLength": 576,
+            "byteStride": 12,
+            "target": 34962
+        }
+    ],
+    "buffers": [
+        {
+            "byteLength": 648,
+            "uri": "Box.bin"
+        }
+    ]
+}

+ 2 - 2
src/Loading/sceneLoader.ts

@@ -600,8 +600,8 @@ export class SceneLoader {
             name = sceneFile.name;
             file = sceneFile;
         }
-        else if (typeof sceneFilename === "string" && Tools.IsBase64(sceneFilename)) {
-            url = rootUrl + sceneFilename;
+        else if (typeof sceneFilename === "string" && StringTools.StartsWith(sceneFilename, "data:")) {
+            url = sceneFilename;
             name = "";
         }
         else {

+ 34 - 0
tests/unit/babylon/src/Loading/babylon.sceneLoader.tests.ts

@@ -687,4 +687,38 @@ describe('Babylon Scene Loader', function() {
             expect(scene.lights.length).to.eq(0);
         });
     });
+
+    describe('#ArgumentPermutations', () => {
+        it('Typical', () => {
+            return BABYLON.SceneLoader.LoadAsync("/Playground/scenes/Box/", "Box.gltf");
+        });
+
+        it('Single url', () => {
+            return BABYLON.SceneLoader.LoadAsync("/Playground/scenes/Box/Box.gltf");
+        });
+
+        it('Direct load', () => {
+            return BABYLON.Tools.LoadFileAsync("/Playground/scenes/Box/Box.gltf", false).then((gltf) => {
+                return BABYLON.SceneLoader.LoadAsync("/Playground/scenes/Box/", `data:${gltf}`);
+            });
+        });
+
+        it('File object', () => {
+            BABYLON.Tools.LoadFileAsync("/Playground/scenes/Box/Box.gltf").then((gltf) => {
+                return BABYLON.SceneLoader.LoadAsync("/Playground/scenes/Box/", new File([gltf], "Box.gltf"));
+            });
+        });
+
+        it('Files input', () => {
+            return Promise.all([
+                BABYLON.Tools.LoadFileAsync("/Playground/scenes/Box/Box.gltf", true),
+                BABYLON.Tools.LoadFileAsync("/Playground/scenes/Box/Box.bin", true)
+            ]).then(([gltf, bin]: [ArrayBuffer, ArrayBuffer]) => {
+                BABYLON.FilesInput.FilesToLoad["box.gltf"] = new File([gltf], "Box.gltf");
+                BABYLON.FilesInput.FilesToLoad["box.bin"] = new File([bin], "Box.bin");
+                return BABYLON.SceneLoader.LoadAsync("file:", "Box.gltf");
+            });
+        });
+
+    });
 });