0

I am trying to load Draco-compressed meshes, processed server-side with glTF-Transform, in BabylonJS retrieving them on the fly via REST calls. Due to this, the mesh to load doesn’t have an extension, because it is a blob in memory and the method URL.createObjectURL() (which is being used to have a URL for such blob) doesn’t allow to specify an extension or a custom URL. If one tries to import the blob as it is, SceneLoader.ImportMeshAsync() seems to not know how to load it and gives

createModelRenderable.ts:520 Error during loading meshes, try again RuntimeError: Unable to load from blob:http://127.0.0.1:5173/b3b55baa-4ede-41fd-a66e-304460969a7f: importMesh of undefined from undefined version: undefined, exporter version: undefinedimportMesh has failed JSON parse
    at A (sceneLoader.js:343:46)
    at Object.importMesh (babylonFileLoader.js:797:17)
    at sceneLoader.js:382:35
    at A (sceneLoader.js:182:13)
    at fileTools.js:375:9
    at XMLHttpRequest.A (fileTools.js:489:33)

without being even able to load a classic .glb. That’s why you have to specify “.glb” as the pluginExtension parameter of ImportMeshAsync to make it work. By doing so, the classic glb will load, but the draco-compressed one won't because (maybe? I suppose) its schema definition doesn't specify any extension mesh.primitive.KHR_draco_mesh_compression.schema.json

createModelRenderable.ts:519 Error during loading meshes, try again RuntimeError: Unable to load from blob:http://127.0.0.1:5173/07f9e64c-2c58-4c64-81c0-54f7d3bbb586: (this.dracoCompression || E8.Default)._decodeMeshToGeometryForGltfAsync is not a function
    at A (sceneLoader.js:343:46)
    at sceneLoader.js:397:21

By the way, the KHR_draco_mesh_compression is loaded because trying to add it again will raise a warning saying that “there’s no need to add the KHR_draco_mesh_compression extension because it’s already present”. I have already checked that draco’s configuration was ok, and the default one points to a valid CDN

wasmUrl: “https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js”
wasmBinaryUrl: “https://preview.babylonjs.com/draco_decoder_gltf.wasm”
fallbackUrl: “https://preview.babylonjs.com/draco_decoder_gltf.js”

the decoder wasm is downloaded correctly. I have anyway tried to use local files, but the result was the same.

I'm also sure that the mesh is a valid Draco compressed GLB file, because it loads correctly on https://sandbox.babylonjs.com/

I also tried loading the mesh as a file with something classic like

const loadFileAsync = function (url) {
  return new Promise(function (resolve, reject) {
    LoadFile(
      url,
      function (data) {
        resolve(data);
      },
      undefined,
      undefined,
      true,
      function (_request, exception) {
        reject(exception);
      }
    );
  });
};

and then decode its Draco-compressed part with new DracoCompression().decodeMeshAsync() to mix it then with texture and the rest but no luck again getting "Not a Draco file." in response.

Seems the same issue is faced in this post on BabylonJS forum, still without any working solution.

4
  • Your error message undefinedimportMesh has failed JSON parse seems to suggest that it's a browser issue reading from a BLOB or something, not related to the glTF itself. Can you investigate DevTools network panel and see if you're getting a 403 or some other error? Commented Jan 31, 2024 at 15:08
  • Just checked, I get a 200 OK in response Commented Jan 31, 2024 at 16:18
  • In that case I think you have to trap the text being fed into JSON.parse that's giving you the parse failure. Is it trying to parse the binary contents of the GLB? Or is it trying to parse some non-JSON error message? Clearly it's not parsing the JSON payload from the glTF file, given the glTF file works fine in other viewers. Commented Feb 1, 2024 at 19:45
  • good catch, effectively not specifying the plugin extension, Babylon was using a loader with extension .babylon which was trying to parse the whole file as a json, instead of extracting the json header and then load the binary data. By specifying .glb instead, the loader being used is correct, but it seems to not have the draco plugin. even though adding it manually says it's already loaded! Commented Feb 13, 2024 at 14:18

2 Answers 2

0

Here is the PG example with Draco mesh loading from blob - https://playground.babylonjs.com/#FIWM5X#45

Sign up to request clarification or add additional context in comments.

1 Comment

Even though it works in there, with the same exact lines it doesn't in my project. I'm starting to wonder if it might be caused by any incompatibility with other libraries I have. I double-checked BabylonJS version and is 6.18, so it should work.
0

After debugging BabylonJS' core I discovered that using “.glb” was right and it was using the correct loader (glTFLoader), but there was a version mismatch in babylon’s imports causing a function not to be found, namely, _decodeMeshToGeometryForGltfAsync()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.