.glb file fails with SceneLoader.ImportMeshAsync

i’m trying to load a mesh from a .glb file with:


export default async function gruntScene(engine: Engine): Promise<Scene> {
    const scene = new Scene(engine);
    new HemisphericLight("light", new Vector3(0, 1, 0), scene);
    await SceneLoader.ImportMeshAsync(undefined, "/assets/", "grunt.glb", scene);
    return scene;
}

on

“babylonjs”: “^5.23.0”,

This throws an error:

1. RuntimeError: Unable to load from /assets/grunt.glb: importMesh of undefined from undefined version: undefined, exporter version: undefinedimportMesh has failed JSON parse at t2 [as constructor] (http://localhost:8000/js/index.js:3865:38) at new t2 (http://localhost:8000/js/index.js:3872:25) at d2 (http://localhost:8000/js/index.js:19434:31) at Object.importMesh (http://localhost:8000/js/index.js:45438:13) at http://localhost:8000/js/index.js:19453:25 at p2 (http://localhost:8000/js/index.js:19369:63) at http://localhost:8000/js/index.js:6489:13 at XMLHttpRequest.e3 (http://localhost:8000/js/index.js:6521:31)

1. Local

  1. this: undefined
  2. value: RuntimeError: Unable to load from /assets/grunt.glb: importMesh of undefined from undefined version: undefined, exporter version: undefinedimportMesh has failed JSON parse at t2 [as constructor] (http://localhost:8000/js/index.js:3865:38) at new t2 (http://localhost:8000/js/index.js:3872:25) at d2 (http://localhost:8000/js/index.js:19434:31) at Object.importMesh (http://localhost:8000/js/index.js:45438:13) at http://localhost:8000/js/index.js:19453:25 at p2 (http://localhost:8000/js/index.js:19369:63) at http://localhost:8000/js/index.js:6489:13 at XMLHttpRequest.e3 (http://localhost:8000/js/index.js:6521:31)

    1. errorCode: 3000
    2. innerError: SyntaxError: Unexpected token 'g', "glTF� "... is not valid JSON at JSON.parse (<anonymous>) at Object.importMesh (http://localhost:8000/js/index.js:45303:27) at http://localhost:8000/js/index.js:19453:25 at p2 (http://localhost:8000/js/index.js:19369:63) at http://localhost:8000/js/index.js:6489:13 at XMLHttpRequest.e3 (http://localhost:8000/js/index.js:6521:31)

      1. message: "Unexpected token 'g', \"glTF\u0002\u0000\u0000\u0000�\n\"... is not valid JSON"
      2. stack: "SyntaxError: Unexpected token 'g', \"glTF\u0002\u0000\u0000\u0000�\n\"... is not valid JSON\n at JSON.parse (<anonymous>)\n at Object.importMesh (http://localhost:8000/js/index.js:45303:27)\n at http://localhost:8000/js/index.js:19453:25\n at p2 (http://localhost:8000/js/index.js:19369:63)\n at http://localhost:8000/js/index.js:6489:13\n at XMLHttpRequest.e3 (http://localhost:8000/js/index.js:6521:31)"
      3. [[Prototype]]: Error

    3. name: "RuntimeError"
    4. message: "Unable to load from /assets/grunt.glb: importMesh of undefined from undefined version: undefined, exporter version: undefinedimportMesh has failed JSON parse"
    5. stack: "RuntimeError: Unable to load from /assets/grunt.glb: importMesh of undefined from undefined version: undefined, exporter version: undefinedimportMesh has failed JSON parse\n at t2 [as constructor] (http://localhost:8000/js/index.js:3865:38)\n at new t2 (http://localhost:8000/js/index.js:3872:25)\n at d2 (http://localhost:8000/js/index.js:19434:31)\n at Object.importMesh (http://localhost:8000/js/index.js:45438:13)\n at http://localhost:8000/js/index.js:19453:25\n at p2 (http://localhost:8000/js/index.js:19369:63)\n at http://localhost:8000/js/index.js:6489:13\n at XMLHttpRequest.e3 (http://localhost:8000/js/index.js:6521:31)"
    6. [[Prototype]]: t2

Seems its trying to parse it as JSON?
The request for the asset is successful with 200

The asset also renders in the babylon sandbox…
Asset available at: Dropbox - grunt.glb - Simplify your life

Hi @kevzettler - Here is a playground example with your asset and SceneLoader.ImportMeshAsync: Babylon.js Playground. Looping in @sebavan

1 Like

Hi,

You are missing the babylonjs-loaders package (if using the UMD packages). This is why the glb is parsed as a json (since without loaders every file loaded is considered a .babylon file:

4 Likes