Drag (move) vertices of mesh

Hi, my goal is select a point of vertice and drag (or move) to manipulate the mesh: Sample Select Vertices

Also i tried to add one box by point of vertice to be more easy drag the point (could be heavy :-/ ), but not working.

Is possible drag the vertices with this approach ?

Thank you!

I would say that first, you could ray cast and found the closest vertices. once done you could create a box with our drag behavior and then keep in sync the chose vertex position with the box one. Would that not work for you ?

Hi @Sebavan , thank you for your reply. I think your sugestion could be a good approach to do what i want :wink: If is possible you can help me implement in pratice this approach ?
First: I started to add a event to pick the ray but i want ā€œisolateā€ the mesh on pick, basically i want pick only if iĀ“m ā€œinsideā€ cat mesh(in this case), but until now not working.
Second: how can i get the closest vertices arround the ray?

Start with creating a playground and use the picking or raycast to find what triangles your in. Then compute the distance to all the 3 vertices and keep the closest one. This gives you a position in local space. You can then convert in world space using the world matrix of the object and place a cube at this position. Once done attach a drag behavior to the cube so that you can move it. and on each frame transform back the cube position in object space using the inverse of the world matrix and update the position buffer of the object accordingly.

2 Likes

Thank you very much @sebavan ! I will try this approach and i will sharing how iĀ“m doing :wink:

2 Likes

Hi @sebavan if iĀ“m not wrong, i think this is the approach we spoke :slight_smile: i have this sample https://playground.babylonjs.com/#I0TSSC#6 where i add a point(yellow box) in mesh with picking ray (mouse right click) and we get the position, but now my doubt is, how i can attach the vertice or vertices closest to a point(yellow box) to be drag ?

Thank you !

Here is a PG to place yellow box at vertex points https://playground.babylonjs.com/#I0TSSC#7

Note Lines

17 ---- Cat has been loaded with non- zero position and has been scaled, so any positioning of a yellow box will need to take this into account. Remember that positions are stored as with zero origin and a unit scaling.
47 ----- stored positions transformed before use to position yellow box.

Note as you drag the yellow box the actual change in a vertex position may need scaling.

4 Likes

https://playground.babylonjs.com/#8QGENL#1
(Right-click to select)

5 Likes

I love this community every day more !!! amazing samples from @JohnK and @Raggar !!!

And @Helder_Oliveira, the playground is always the best way :slight_smile:

1 Like

:wink: Excelent !!

@JohnK and @Raggar thanks a lot for your PG!!

@sebavan you are right, definitely share the PG is the best way :wink:

Thank you all

2 Likes

Thank you all for this amazing community
I have adapted this pg in case someone needs it for building terrains manually with mouse pointer events

I hope you enjoy it

3 Likes