Display model in the center

Here is the working playground (to be honest, I just copy pasted everything from the existing Playground I posted in the above mentioned thread). The reason why your playground is not working is because you didn’t implement anything that I mentioned in the comment and in the existing playground (fully commented on each step). :smiley:

Basically the logic is, you use the provided method totalBoundingInfo, which basically loops through every mesh in the scene, looks at the boundingBox values and defining the most minimum and most maximum point of whole scene (meshes only).

Once you have that info, you set that bounding box to any of the meshes in the scene (meshes[0] lets say). And now you have bounding box for your object.

Next step is to create a parentBox that will act as parent of every mesh in the scene, the size of the parentBox is the size of the biggest dimension of the newly created boundingBox.

You can position the box at (0,0,0), meaning that no matter what object you load the position will always be at (0, 0, 0), where you camera already looks at.

After that you call normalizeToUnitCube which will resize your object to 1x1x1 space.

Thats it.

What you achieve with this is. Your object will always be at (0,0,0) and your object will always have same size relative to camera. So no matter how big your object is or where in space it is positioned, it will always behave the same, so you dont need to worry about the incoming mesh at all.

3 Likes