Skip to content

Instantly share code, notes, and snippets.

@icavalheiro
Created June 7, 2020 14:51
Show Gist options
  • Save icavalheiro/e708615d613da94e841c9ae9bd3dd5d2 to your computer and use it in GitHub Desktop.
Save icavalheiro/e708615d613da94e841c9ae9bd3dd5d2 to your computer and use it in GitHub Desktop.
Snipped to convert a Mesh position to the viewport position in Babylonjs
const mesh: Mesh // the mesh I want to know the size and position of
const worldMatrix = mesh.getWorldMatrix()
const transformMatrix = scene.getTransformMatrix()
const position = mesh.position
const viewport = scene.activeCamera!.viewport
const coordinates = Vector3.Project(position, worldMatrix, transformMatrix, viewport)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment