Match Scale of Parent

I’m trying to figure out how I can keep consistent scale with mesh objects. In my project I have a variety of meshes that have differing scales that all read “1” for the x,y,z scale values but are vastly differently in scale between each other.

For this reason I’m trying to utilize a single parent mesh and have those meshes scaled to fit within the bounds of that box. I wanted to provide context in case there is a better way to achieve this.

Here is a basic playground where I added the sphere as a child of the box:

How could I resize the sphere to fit the bounds of the box? Is there a simple way to achieve this? The only thought I have at the moment is to include some sort of loop that continually increases the scale of the sphere up until it makes contact with the bounds of the parent box. What are my options here?

Probably you may use mesh.normalizeToUnitCube() function - Babylon.js docs

normalizeToUnitCube(includeDescendants?: boolean, ignoreRotation?: boolean, predicate?: Nullable<((node: AbstractMesh) => boolean)>): AbstractMesh

The includeDescendants parameter let’s to use the hierarchy’s bounding box instead of the mesh’s bounding box. Default is false.


Looks like just what I need, thanks! I included some simple snippets here to see how it works for anyone who wants a demo: