Scene.pointer to Vector3

Hi @Snekmel and welcome to the forum

In order to spawn a mesh in the scene at a 3D position, you first have to convert the 2D coordinates (scene.pointer) to 3D. This can be done with a raycast where the ray hits a plane and the hit point becomes the spawning position.
If you don’t have a plane to do the raycasting, you can call

var pickResult = scene.pick(scene.pointerX, scene.pointerY);

and the ray corresponding to the mouse pointer is:

pickResult.ray.origin 
pickResult.ray.direction

then you have to choose an arbitrary distance between the origin and your destination so you can compute a 3D position:

position = pickResult.ray.origin + pickResult.ray.direction * distance

Some documentation here : Raycasts - Babylon.js Documentation

4 Likes