Tim_Rosskamp Posted September 21, 2017 Share Posted September 21, 2017 Hey, I have a problem with the function Project function inside the Vector3 class. This is my code: var screenXY = BABYLON.Vector3.Project( new BABYLON.Vector3(10, 10, 10), BABYLON.Matrix.Identity(), scene.getTransformMatrix(), camera.viewport.toGlobal(engine.getRenderWidth(true), engine.getRenderHeight(true)) ); What I want to do is get the 2d screen x/y position from a 3d vector. And this is what gets returned from the function: Vector3 {x: NaN, y: NaN, z: NaN} How can I fix this? Quote Link to comment Share on other sites More sharing options...
RaananW Posted September 22, 2017 Share Posted September 22, 2017 Howdy @Tim_Rosskamp, is it by anc chance the first frame of the scene? In this case - just wait for the second one Simple example here - https://www.babylonjs-playground.com/#6XQZ4P The first frame is nan, probably because of the transformation matrix, but after everything is set, it is calculated correctly. Tim_Rosskamp 1 Quote Link to comment Share on other sites More sharing options...
Tim_Rosskamp Posted September 22, 2017 Author Share Posted September 22, 2017 Dude, thanks a lot! This was indeed the problem! I only used the function once when the component mounts and didn't tested it in the render loop. RaananW 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.