BABYLON.SceneSerializer.Serialize() fails when running on server

Running BABYON on a server using Node,
BABYLON.SceneSerializer.Serialize() fails with an exception

TypeError: c.asArray is not a function
at Function.e.Serialize (D:\Source\Repos\gallery\web\node_modules\babylonjs\babylon.js:16:9595)
at t.serialize (D:\Source\Repos\gallery\web\node_modules\babylonjs\babylon.js:16:451812)
at Function.e.Serialize (D:\Source\Repos\gallery\web\node_modules\babylonjs\babylon.js:16:3109875)

Any suggestions?
Thanks,
Michael

The stacktrace doesn’t give us a lot to play with other than the fact that it fails in the asArray function, which is implemented in our math lib.

This is probably due to the fact that one of the nodes that is being rendered doesn’t have one of the elements that needs to be serialized, but that’s a very abstract explanation :slight_smile: I doubt it has directly something to do with the fact that it is done on the server (but it is hard to tell, honestly). Can you try reproducing this, with the same scene, outside of the server environment? does it work there?

Is there a way to enable the .max bablyonjs file in the node app? The code runs fine outside the server. I’m in the process of trying to get it to run on the server now that I know it runs on the client.

I figured out the issue. On the server, I want to assign a texture to a material and have the URL resolve when the model is downloaded to the browser. Is that possible, or do I need to load the full texture when on the server?

    let texture = new BABYLON.Texture("/images/canvas.jpg", scene);
    texture.uScale = 10;
    texture.vScale = 10;
    material.diffuseTexture = texture;

That’s a good question.

You don’t have to download the texture directly, but you will need to initialize the scene fully, otherwise it will not be serialized correctly.

I just tried serializing a scene with a missing image (404), and it serialized without an issue ( Babylon.js Playground (babylonjs.com)), would this kind of approach help you?

Just wondering, since this is the server it is probably easier to have the assets closer to the scene. Why not define the texture?