Create Mesh without scene to access computeworldmatrix

So I’m using NodeJS in a client server model with some client-side prediction. The client is a separate application that connects using sockets to the client, thats just to say that I don’t have to do any rendering on the server. However, in order to accurately emulate the inputs from the client on the server I need to replicate the mesh from the client on the server.

The problem is that I can’t create a mesh on the server unless I have a scene, can’t make the scene without the engine, and can’t make the engine without using some dom and canvas npm’s.

For my use’s these are not needed because they would only be used to create meshes that aren’t ever going to be rendered, I just need access to the internal methods of the meshes, specifically computeWorldMatrix so that my forward right and up orientations are updated based on the changes in rotation of the object.

I could send the orientation from the client but I’m running a rewind setup so I really need to be duplicating the calculations for this on the server.

Is there anyway I can create a mesh that has access to the inner methods without having to create the engine and the scene?

I tried creating VertexData and then applying that to a mesh but when I do that I get getUniqueId error, not even sure that this approach will achieve my goal, found that solution here. Creating a Mesh without adding to the scene - Questions - Babylon.js (babylonjs.com)

When I try to create a new mesh with new BABYLON.Mesh() I get the below error, I assume it has something to do with the fact that I’m trying to create an instance without an engine being created or a scene but I’m not sure.

Also I’m not sure this will even give me what I need.

TypeError: Cannot read properties of null (reading 'getUniqueId')
    at t.e (E:\Coding\Game Dev\AR_Server\node_modules\babylonjs\babylon.js:16:391441)
    at t [as constructor] (E:\Coding\Game Dev\AR_Server\node_modules\babylonjs\babylon.js:16:548677)
    at t [as constructor] (E:\Coding\Game Dev\AR_Server\node_modules\babylonjs\babylon.js:16:461962)
    at new t (E:\Coding\Game Dev\AR_Server\node_modules\babylonjs\babylon.js:16:39206)
    at new Graphics (E:\Coding\Game Dev\AR_Server\src\engine\graphics.js:7:17)
    at Object.<anonymous> (E:\Coding\Game Dev\AR_Server\src\main.js:9:18)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)

Any assistance would be great. Thanks in advance

1 Like

Seems that you may try Babylon Null.Engine - Running Babylon.js On A Server | Babylon.js Documentation
I tested recently one of the implementations from Github and it works with no hassle - GitHub - aeon0/multiplayer-babylon-js-game: Multiplayer BabylonJS game with Server and Client-Side physics engine synchronization

3 Likes

OMG so simple, thank you so much, and thank you for the documentation on that I’ll go over it thoroughly.

Appreciate it.

And yea I just tested it I have access to all the functions I was looking for.

2 Likes