Stability in screen coordinates computation

Hello,

I am using BABYLON.Vector3.Project to convert 3D points to screen coordinates on the camera movement. For some reason, I am getting NaN for first couple of times when I attempt the conversion, but then I start to get correct results

Function calls to convert are on lines 43 and 51

Try to rotate the view, you should see something similar on your console
initial call: controlPos = NaN NaN
0 '. controlPos = ’ NaN NaN
1 '. controlPos = ’ NaN NaN
2 '. controlPos = ’ 0.42325827540309724 0.49999999999999994
3 '. controlPos = ’ 0.42325827540309724 0.49999999999999994
4 '. controlPos = ’ 0.42327171941972747 0.49965581839418377

Let me know what I am doing wrong,
thank you

Hi!
I believe this is caused by some of the necessary matrixes not being ready yet during scene creation, if you move the calls to inside a onSceneReadyObservable then we don’t get the NaNs: Project Mesh Position Screen Optimization | Babylon.js Playground (babylonjs.com)

1 Like

@carolhmj Thank you That’s perfect.