ImportAsyncMesh on server side without scene

I’m not sure. It depends on how WebAssembly works in node. Typically, the loaded JavaScript for the WebAssembly loads the WASM part or can take the payload directly. If it still works this way in node environment, then it should be possible. I’m a bit worried we have too many code paths that do similar things, but maybe we can factor a pattern that we can use for these scenarios.

Node has a webassembly runtime that needs to be used to load the wasm file ( Node.js with WebAssembly (nodejs.dev)) .

Yes, this is my fear as well. We will need to find the best way to achieve that. for now we can say that we don’t support webassembly on node. I’ll add an issue for this future work

1 Like

Allow loading WebAssembly scripts when in node environment · Issue #13422 · BabylonJS/Babylon.js (github.com)

3 Likes

Appreciate that serverside importing of draco compressed GLBs have been added as a Future milestone. Do you have an approximation for when the team may be able to complete this? Having this feature would help unlock interesting serverside use cases that aren’t feasible with the limitations of the client browser.

That will not be implemented for version 6.0 for sure, as we have a lot on our TODO list. We will add that to future tasks when 6.0 is released and ready.
No real time estimation, I know. Sorry…

2 Likes

nodejsBABYLON.zip (196.7 KB)

I have also encountered this issue, and I have uploaded an example to demonstrate it, hoping to accelerate the resolution of this issue. @bghgary

1 Like

I think maybe some of the changes @RaananW made recently with the script loading may help. It also looks like we have something working for Havok (as noted in the issue) based on this?

i’ll download the demo project later today. We’ll get to the bottom of this :slight_smile:

Ok!

I know what the issue is. This requires a small change to the way the framework consumes Draco, but it is solvable. I will keep this open, as this is, in general, a larger issue we need to tackle. Using your project, i managed to get this output after making a few modifications to the framework:

image

To your specific project - you start scene and server concurrently, so it’s not deterministic. Sometimes the scene will start before the server starts and it will fail due to that. But this is not the reason it doesn’t work.

Again - I know what the issue is, and will work on a proper solution.

3 Likes

Coming back to this topic - after this PR is merged - Allow Draco in NullEngine on node by RaananW · Pull Request #14887 · BabylonJS/Babylon.js (github.com) you will be able to use draco compression on node. Tested with your demo project (and the current version locally linked).

Code looks like this:

const BABYLON = require("babylonjs");
const fs = require("fs");
const xhr = require("xhr2");
require("babylonjs-loaders");

const Draco = require("./draco/draco_decoder_gltf.js");
const wasm = fs.readFileSync(process.cwd() + "/draco/draco_decoder_gltf.wasm");

BABYLON.DracoCompression.Configuration.decoder.wasmBinary = wasm;
BABYLON.DracoCompression.Configuration.decoder.jsModule = Draco;

globalThis.XMLHttpRequest = xhr.XMLHttpRequest;
let engine = new BABYLON.NullEngine();
let scene = createScene();
BABYLON.SceneLoader.ImportMesh(
  "",
  "http://localhost:5656/public/meshes/1/",
  "123.glb",
  scene,
  () => {
    console.log("success! no draco");
  },
  null,
  () => {
    console.log("failed! no draco");
  },
  ".glb"
);
BABYLON.SceneLoader.ImportMesh(
  "",
  "http://localhost:5656/public/meshes/1/",
  "123_draco.glb",
  scene,
  () => {
    console.log("success! draco ");
  },
  null,
  () => {
    console.log("failed! draco ");
  },
  ".glb"
);
function createScene() {
  let scene = new BABYLON.Scene(engine);
  scene.createDefaultLight();
  // scene.createDefaultSkybox();
  scene.createDefaultCamera(true);
  scene.clearColor = new BABYLON.Color4(0, 0, 0, 0);
  return scene;
}

4 Likes