I have a mesh object and i want to add spheres on the mesh. I can add mesh in it by enabling the Add Sphere checkbox and click on the mesh surface. Now the issue is i can drag and move that sphere anywhere in the mesh as per pointer move. If i view from a corner and try to move that sphere the z axis not recognized as per the spheres position it is determined the mouse pointer position. So the sphere goes out of the mesh. I dont want to move the sphere out side of the mesh. I want to keep it within the mesh, is there any solution for that? Here is my PG link https://playground.babylonjs.com/#S0KJUA#8
Let me take a look
You can check if the sphere is inside the bounding box or use a point inside mesh algorithm? Check When a Point is Inside a Mesh | Babylon.js Documentation (babylonjs.com)
I’m wondering why nto setting the current position directly with the picking point like this:
With out the diff it is working fine. Is there any way to calculate the boundingInfo and Using pointerDraggable to validate that?
Which boundingInfo do you want to compute? you only need 2 vertex positions to compute one.
You have the currentMesh.position and its potential destination, so, it looks like it’s easy to do some computation to check if you can change its position or not.
What kind of check do you want to do?
I want to compute between currentMesh.position (sphere) and root_mesh. If we add a PointerDragBehavior to the sphere and validate it’s position using PointerDragBehavior.validateDrag, validateDrag gives the current target position. If we get the root_mesh boundingInfo and validate it with the current sphere position then it might work properly. With out the pointerDragBehaviour if we select the sphere from a angle where the root_mesh is not available it is not moving.
Not sure if I understand correctly but you want to pick the sphere and keep it moving until mouse is over the rootmesh. this can be done by changing a few things in your code. Not sure a need a behavior for that.
Is it working by changing code?
You should be able to change the state in your code. Basically, only allow camera rotation when no sphere is picked, or when the rootmesh is not picked (add sphere mode).
Then, it’s a matter of allowing picked sphere to move to destination.
Hello @imarabinda just checking in if you need any more help with this
I need help on that, i have done something picking using ray, but it works but not that good. https://playground.babylonjs.com/#S0KJUA#35
I tried it and it looks ok to me. what do you mean by not that good?