Changing the model size

Hello. My task in the game is to dynamically substitute heads and bodies for the character. I have positioned and scaled entities on the scene to which I add a model element after loading. The problem is that with the same scale, the size of the model itself is different and the female head is smaller than the male, and when substituting they are not always displayed correctly. Is there a parameter inside the model that shows the actual length, width, and height, so that I can create a constant size and change the size of the model to constant size each time I load it.

Hi @sergey_ch,

You can iterate through the mesh instances of each pc.Model and check the aabb property. That is a pc.BoundingBox instance that contains a property that can help you find the maximum size on each side of the model:

const meshInstances = this.entity.model.meshInstances;

meshInstances.forEach( meshInstance => {
   const aabb = meshInstance.aabb;
   const maxX = aabb.halfExtents.x * 2.0;
}); 

If you have more than one mesh instances in a model, you will have to add them first, to find the sum bounding box.

You can check the model viewer project template (orbit-camera.js) on how it uses that method to find the best frame for the camera.

2 Likes

Thanks. An interesting method. Tell me, do I understand the algorithm of my further work correctly? I take one head and pull out aabb. halfExtents from it. This head I position and scale, this is the reference. When I get a new head I get aabb. halfExtents from it and divide the reference with the current value and get a coefficient by which I multiply the scale

Yes, I think that will work for you, having a reference aabb and the new aabb, you can match them by calculating that coefficient.

2 Likes

It worked, thank you so much!

1 Like