[SOLVED] NullEngine and screen space calculation


#1

Hi,
enforced issue with my screen space calculation inside NullEngine.

const engine = scene.getEngine();
const scaling = engine.getHardwareScalingLevel();

const pos = Vector3.Project(
            new Vector(5, 10, 3),
            Matrix.IdentityReadOnly,
            scene.getTransformMatrix(),
            scene.activeCamera.viewport.toGlobal(
                engine.getRenderWidth(),
                engine.getRenderHeight(),
            ),
        );
        pos.x *= scaling;
        pos.y *= scaling;
        pos.z *= scaling;
        return pos;

works well in browser but in NullEngine always returns Vector3(x: NaN, y: NaN, z: NaN).
Doing something wrong or its by design so?
Thank You


#2

My camera settings

this.scene.activeCamera = new ArcRotateCamera(
      "camera", 0, 0, 100, Vector3.Zero(), this.scene,
);

#3

I’ll have a look


#4

The scene.getTransformMatrix() must return an empty matrix I guess as the camera was not activated (probably).

You can replace scene.getTransformMatrix() by camera.getTransformMatrix()


#5

@Deltakosh Thank you for answer, yes you were right, called this.scene.render(true); after creation so works well now