Scale parent mesh without scaling its child

I’m developing a configurator with loaded .gltf objects. It’ll be necessary to have some meshes set as parent of others (because they have to move together). But it’s important that the scaling of the parent doesn’t affect the scaling of the child, since it’ll be a fixed object in dimensions.

In Blender there’s the constraint “Child of” feature, in which you can relate two objects and set which transformation won’t have an impact on the child (for example X ax of scaling property).
I tried to export it but it seems that babylon doesn’t keep the relationship.
I searched in the mesh documentation but i couldn’t find any properties / methods related to this goal.
When looking up online I found this trick of setting the child’s scaling to be the inverse of the parent → babylonjs - Babylon Js children that follow parent withouth the scaling - Stack Overflow

childMesh.parent = parentMesh;

childMesh.scaling = Vector3.One().divide(parentMesh.absoluteScaling);

but it’s lowering the performance a lot and it still doesn’t calculate correctly the position.

Another topic of stack overflow says that (as of 2016) they couldn’t find a way to export ChildOf constraint from blender model. – blender - parent-child linking between meshes in Babylon.js - Stack Overflow

I wondered if there’s a feature in babylon api to achieve this, or if someone has suggestions on how to proceed.

Otherwise I thought about creating for each parent mesh an empty object on the edge of the mesh, to which the child will always snap to for every transformation. So they would be fake parent - child, only related to that pos x, y, z of the empty object.

But idk, i wanted to see before starting this new procedure, if there was something easier.

Thank you very much and have a great day!

1 Like

Certainly one way to go

Box and sphere can be moved together via their root and box can be scaled on its own.

No, there’s nothing in Babylon.js that would let you freeze some transformations that would not be inherited by the children.

Ah okay, good to know. Thank you!

Smart thinking. This ‘twist’ should work I believe.

I thought it could work too, but i’m encountering a new problem, which i didn’t think about.
I made this playground as an example:

The red mesh will actually be my “empty objects” that will be used just as snapping points.
They are child of the variable part, so that when the parent scales, also their position changes.
While the fixed part, after the scaling of the variable, will be repositioned according to the empty object.
The only obstacle is that, when i scale the variable mesh, even though the red cubes move as expected, their x, y, z value remains equal to the starting one.

So I need to understand if there’s a way to have an updated location of those mesh.
(The behaviour is the same also in blender, i have to do some research)

Thank you very much for your example.
Unfortunately I think this could not work though, cause in my situation there is more interaction between the parts:
(When i scale the yellow part, the blue / fixed ones have to be repositioned in the extremes of the yellow )

Hello again and sry for late reply (I had to attend to a weekend of flight sim in the Swiss alps;)
Just need to get my feets back on the ground. This must work (may be not just this way), but using parented empty meshes for defining inner and outer exclusion zones you can snap to (or collide with) is something I have used for creating customer environments and dealer dev tools for scene building in unity and this approach in 3D with meshes works. Did you have a chance to investigate it a little further during the WE or are you still stuck?

Hei @mawa, i’m late too with this reply, i don’t know how i missed it. I hope everything was great in the Swiss alps!
The configurator i’m building had to do a jump back on the flow analysis and bureaucracy stuff, but in the meanwhile i’ve used another approach:

I’m scaling the variable pieces and at the same time, multiplying the original position of the fixed mesh * the scaling factor.
I don’t think it’s the most performing solution but it’s the only one that i found that suits my situation.

When the configurator will be (finally) done, i’ll share it with you guys :slight_smile:

Well, we had some s**t weather, but else it’s always good to breathe;)

This is among the pillars of BJS and why I love it: There’s nearly always an alternate path. One you can explore or eventually discover.

Yes, please do. I’d luv to see it in action :smiley:

GL with your project && have an awesome day,