Figure out (x, y) position of mesh in 2D canvas space

Is there a way to figure out the 2D canvas position of a mesh, with a given scene and camera position?

this should work:

Hey sebavan, thanks for creating this PG!

To clarify my question, my particular use case was - I was mainly wondering if it was possible to render HP bars with HTML/CSS, but positioned correctly over certain entities in the game. So I was more looking for a way to figure it out without relying on any pointer events. Now that I’m thinking a little more about it, I’d expect that would be possible with some linear algebra, is that right? (I’ve forgotten all the linear algebra I learnt in uni :sweat_smile:)

You do not need the pointer event, just the project function:

var p = BABYLON.Vector3.Project(point, 
                BABYLON.Matrix.Identity(), 
                scene.getTransformMatrix(), 
                freeCamera.viewport.toGlobal(engine));
1 Like