PG examples on creating lines on click?

Hi, I want to create a “tool” that connects lines between clicked spheres, and I was wondering if someone had some PG examples of anything related with creating lines on mouse click.


to get 3D coordinates from click is quite easy: Mesh Picking | Babylon.js Documentation

you can use the pickInfo.pickedPoint to get the coordinates of the pick

Then from there you can create lineMesh: Creating Lines | Babylon.js Documentation

1 Like

Nice evening Babylon exercise :slight_smile:
One can add some counter to limit the number of meshes picked, or highlight them etc.

1 Like

This is great, just what I needed. However I need an additional functionality: when another button is pressed (let’s say RMB) I want the drawing to stop, and the user can pick the next starting point. I’m not sure how I would do this, I imagine that linePoints would be an array of arrays, and when the button is pressed the points would be stored in the next row, and lines would be created for every row of linePoints, is that right?

In this example linePoints is array of instances/objects from Vector3 Class, used to store (x,y,z) vector representation. A Vector3 is the main object used in 3D geometry. It can represent etiher the coordinates of a point in the space, either a direction.
It is up to you what to do with this array; Vector3 instance holds not only positions but also another properties (see console).