How can I ‘mate’ 2 meshes ? The term ‘mate’ comes from the CAD world and I mean a coincident mate.
I would like to attach 2 meshes together, so if I move one also the other one is moved and viceversa.
I found ‘setParent’, but if I move the parent the position of the root is not updated.
So if M1 is ‘mated’ with M2 they behave like they are merged, but the scaling and the rotation are possible ( with some rules ).
I feel like .parent is what you want. This playground has one box parented to the other. When the red box moves, the other follows suit. Granted, now if you change something on the red box, the other will follow (scale/rotation). What you might want is a blank parent, and then add the boxes to that, so now you can move that top level parent, and each child can gave it’s own scale/rotation/positioning within the parent.
I just watched a video on coincident mate, I think my previous reply is close. As far as positioning meshes together automatically, I think that becomes a bit tougher of a problem.
Thank you for your answer.
It has been the first test I made when I approached the problem, but I had strange results with the gizmo.
See this playground .
‘parent’ attaches the the 2 cubes. This could be fine, but if you try drag the 2 cubes, one is attached to the other, the other is free to move.
What I’m expecting is that both are equally attached.
attach both boxes to same parent transformNode
https://www.babylonjs-playground.com/#TF8DSZ#1
when, in your code, moving a box, check if(mesh.parent) and move parent, else move mesh.
very smart solution.
However in my case the problem is that the gizmo is on the node. For the end user it would be not acceptable.
I have to find a solution where the gizmo goes in both the boxes.
Moreover in the real case I could have more than 2 ‘mated’ meshes like:
M1|M2|M3|M4 ( where the ‘|’ is the mate ) If I drag M3 for example, all the block should move.
If you’re open to a hacky solution, you could do as i did in my previous post, but attach to box instead of box parent, then hijack the gizmo move/position code and apply move to box.parent.position
I think I just did what @aWeirdo suggested, though it took a bit of tinkering.
https://www.babylonjs-playground.com/#TF8DSZ#2
I think this gets you pretty close to what you would want. And you can go ahead and add as many items to the parentBox (which is an abstractMesh) as you want.
Thank you. You pointed me in the right direction.
I did not think to use ‘scene.onBeforeRenderObservable’ to update the position of the Meshes based on my rules
Here’s one simply replacing the onDragObservable
https://www.babylonjs-playground.com/#TF8DSZ#3