Scale all meshes to same scale

Here is my playground https://playground.babylonjs.com/#S0KJUA#1 , all i want to achive is to fit all type meshes in same scaling, there is one mesh is commented out, you can uncomment it and can see that it is smaller than previous one. I tried to make it scaling to 1 , but it goes too big acording to previous one.

You could use normalizeToUnitCube on your root meshes.

3 Likes

By doing that if i zoom into the mesh, it gets cut-off randomly. Without normalizeToUnitCube i can zoom in properly.

Yeah, that’s because your scene becomes really small (1x1x1), ergo “unitCube”.

I don’t know what’s your use case, but by setting camera limits and minZ you can avoid these things. Also, depending on your needs, you might need to adjust panningSensibility, mousePrecision, pinchPrecision and so on.

Or if you want to control scaling a bit, as this is scaled to 1x1x1, you can multiply every root mesh by same constant number and keep their size the same.

3 Likes

Hi and welcome to the Community,
@nogalo (nearly) said it all :smiley: except may be, that this mesh is not ‘cut-off randomly’ (and is also not because of the normalizeToUnitCube function which works perfectly fine for what it’s supposed to do.
What happens here is that your arcRotateCamera radius is going through and beyond your mesh when you use the mouse-wheel to (what you likely believe to be) a ‘zoom-in’. Though, it is not really ‘a zoom’. The way it works with an arcRotateCamera and the mouse-wheel in its default behavior is that the mouse-wheel changes the ‘radius’ to the target, without limits (by default).

To avoid and control this, you have a number of options: You can prevent the camera from going through the mesh (any or all meshes). You can limit the minZ on the camera (radius/depth). You can add colision to camera and objects.

Beyond this, to really make a ‘zoom-in’ effect you can use the ‘zoomIn’ function. You can also create your own custom zoom effect (accounting the lensSize) by changing the camera FOV (eventually changing the camera position and/or lensSize at the same time, to better simulate the zoom depending on the camera lens and distance).

Though, for whatever you do and as @nogalo spotted, your scene objects are really just the tiny-mini and every change you will bring to the camera, lights or anything in the scene will have a strong/nearly uncontrollable effect. I would also recom that you would start with scaling-up your objects.

Meanwhile, have a great day :sunglasses:

5 Likes

You are the best one! I searched for hours and now it is working. +rep

2 Likes