Cannot Create Shadow Map with Point Light in Node on Server

I am trying to create a model on a server using node with a shadow map.

const light = new BABYLON.PointLight("PointLight", new BABYLON.Vector3(1,1,1), scene);
const shadowGenerator = new BABYLON.ShadowGenerator(1024, light);

When I call this code, I get an exception thrown: “Cannot read property ‘TEXTURE_CUBE_MAP’ of undefined”

Any suggestions?

Thanks,
Michael

Welcome aboard!

I think you can only use use the null engine on the server side: it seems you are using the regular Engine class as TEXTURE_CUBE_MAP is a gl identifier.

Using Node on the server, this code fails to construct the ShadowGenerator with the error:

TypeError: Cannot read properties of undefined (reading ‘TEXTURE_CUBE_MAP’)

run node .\start.js

start.js:

try{
    const BABYLON = require("babylonjs");

    const engine = new BABYLON.NullEngine();
    const scene = new BABYLON.Scene(engine);
    const light = new BABYLON.PointLight("Point", new BABYLON.Vector3(1,1,1), scene);

    const generator = new BABYLON.ShadowGenerator(1024, light);
} catch(error){
    console.error(error);
}

It is probably cause NullEngine does not have a shim for createRenderTargetCubeTexture like it does for https://github.com/sebavan/Babylon.js/blob/master/packages/dev/core/src/Engines/nullEngine.ts#L714

Would you like to make a PR for it ?

I don’t know the fix to suggest here. I will create an issue.

3 Likes