# ImportAsyncMesh on server side without scene

**URL:** <https://forum.babylonjs.com/t/importasyncmesh-on-server-side-without-scene/34151>\
**Category:** Questions\
**Created:** [September 22, 2022, 1:43pm UTC](https://forum.babylonjs.com/t/importasyncmesh-on-server-side-without-scene/34151 "2022-09-22T13:43:50Z")\
**Posts on this page:** 12\
**Page:** 3

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [January 6, 2023, 7:32pm UTC](https://forum.babylonjs.com/t/importasyncmesh-on-server-side-without-scene/34151/41 "2023-01-06T19:32:11Z")

</div>

> [@RaananW](#):
>
> For example - when in node.js, the dev will use fs (or require?) to load both the .js and the wasm file (which should be loaded a little differently) and babylon will use those?

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.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [January 9, 2023, 10:56am UTC](https://forum.babylonjs.com/t/importasyncmesh-on-server-side-without-scene/34151/42 "2023-01-09T10:56:19Z")

</div>

Node has a webassembly runtime that needs to be used to load the wasm file ( [Node.js with WebAssembly (nodejs.dev)](https://nodejs.dev/en/learn/nodejs-with-webassembly/)) .

> [@bghgary](#):
>
> I’m a bit worried we have too many code paths that do similar things

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

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [January 9, 2023, 11:47am UTC](https://forum.babylonjs.com/t/importasyncmesh-on-server-side-without-scene/34151/43 "2023-01-09T11:47:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Coffiend](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/coffiend/32/8785_2.png) [@Coffiend](https://forum.babylonjs.com/u/Coffiend)\
**Post date:** [January 18, 2023, 3:01pm UTC](https://forum.babylonjs.com/t/importasyncmesh-on-server-side-without-scene/34151/44 "2023-01-18T15:01:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [January 18, 2023, 3:20pm UTC](https://forum.babylonjs.com/t/importasyncmesh-on-server-side-without-scene/34151/45 "2023-01-18T15:20:23Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Happy0Ending](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/happy0ending/32/26835_2.png) [@Happy0Ending](https://forum.babylonjs.com/u/Happy0Ending)\
**Post date:** [November 17, 2023, 10:54am UTC](https://forum.babylonjs.com/t/importasyncmesh-on-server-side-without-scene/34151/46 "2023-11-17T10:54:24Z")

</div>

[nodejsBABYLON.zip](https://forum.babylonjs.com/uploads/short-url/n5uYNE2k4Vjwc8BCei19ECkbTKi.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

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [November 27, 2023, 11:01pm UTC](https://forum.babylonjs.com/t/importasyncmesh-on-server-side-without-scene/34151/47 "2023-11-27T23:01:45Z")

</div>

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](https://github.com/BabylonJS/Babylon.js/issues/13422)) based on [this](https://forum.babylonjs.com/t/running-nullengine-in-node-js-to-leverage-the-havok-physics-engine/41424)?

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [November 28, 2023, 10:25am UTC](https://forum.babylonjs.com/t/importasyncmesh-on-server-side-without-scene/34151/48 "2023-11-28T10:25:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [November 28, 2023, 10:25am UTC](https://forum.babylonjs.com/t/importasyncmesh-on-server-side-without-scene/34151/49 "2023-11-28T10:25:21Z")

</div>

Assigned @RaananW on November 28, 2023, 10:25am UTC



---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [November 28, 2023, 4:00pm UTC](https://forum.babylonjs.com/t/importasyncmesh-on-server-side-without-scene/34151/50 "2023-11-28T16:00:25Z")

</div>

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](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/5/d/5df4dfbb0519c8991811769e9fff807b9c45148d.png)

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.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [March 20, 2024, 3:16pm UTC](https://forum.babylonjs.com/t/importasyncmesh-on-server-side-without-scene/34151/51 "2024-03-20T15:16:30Z")

</div>

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)](https://github.com/BabylonJS/Babylon.js/pull/14887) you will be able to use draco compression on node. Tested with your demo project (and the current version locally linked).

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/d/3d2cbfd28fd242f3419e4c102813159f84c8404e.png)

Code looks like this:

```javascript
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;
}

```

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [March 20, 2024, 3:16pm UTC](https://forum.babylonjs.com/t/importasyncmesh-on-server-side-without-scene/34151/52 "2024-03-20T15:16:33Z")

</div>

Unassigned @RaananW on March 20, 2024, 3:16pm UTC



[Previous page](https://forum.babylonjs.com/t/importasyncmesh-on-server-side-without-scene/34151.md?page=2)
