Whether there is a method to calculate the world coordinate XYZ to the screen point XY coordinate in Babylon. For example, U3D’s camera.WorldToScreenPoint (obj.transform.position);
1 Like
may be this will help
var coordinates = BABYLON.Vector3.Project(vector3,
BABYLON.Matrix.Identity(),
scene.getTransformMatrix(),
camera.viewport.toGlobal(
engine.getRenderWidth(),
engine.getRenderHeight(),
));
7 Likes
So this is supposed WorldToScreenPoint
Yo @Atul_Sharma … What about ScreenToWorldPoint … How we we do that ?
1 Like
I think i found the answer: If world to screen to point is Vector3.Project … then Screen To World point must be Vecter2.Unproject
From @Deltakosh
var vector= BABYLON.Vector3.Unproject(
mousePosition,
engine.getRenderWidth(),
engine.getRenderHeight(),
BABYLON.Matrix.Identity(), scene.getViewMatrix(),
scene.getProjectionMatrix());
where mousePosition is the Vector2 with the screen X/Y coord you want to convert to world space
Right ???
1 Like
Yes that is the right function but the first parameter is a vec3: you also need to provide a z value in screen space (value between 0 and 1).