Hi All,
I’m working on an app which involves people uploading glb models and scale them to a specific size so that they fit in a show room environment where they can be viewed by potential buyers.
I’m using the threejs example models to test the various formats that can be imported. Almost all are scaling correct apart from the Xbot.glb file used in this example: three.js examples
The first step I’m taking using to scale the object is to use the following code to get the original size of the model:
meshBounds = new THREE.Box3().setFromObject( obj3D );
let lengthMeshBounds = {
x: Math.abs(meshBounds.max.x - meshBounds.min.x),
y: Math.abs(meshBounds.max.y - meshBounds.min.y),
z: Math.abs(meshBounds.max.z - meshBounds.min.z)
};
I use this to create a bounding boxmesh and to check it works correctly I add the model and the transparent bounding boxmesh to the scene.
For obj3D I have tried using:
- The Group which is at the top level of the object heirarchy and immediately within the Scene.
- The first child of the group which is called “Armature” and I belive is the root of the skeleton.
Using either method the box created is tiny and certainly does not contain the whole model. (see image).
A designer that is testing the system also had the same issue with another similar model created with blender and mixamo which also uses a skeleton.
Could anyone please advise me as to why the xbot.glb file produces this strange result and let me know if there is another way to scale the model that I could try?
Many thanks in advance.
[Update]
After reading this post ([HELP] FBXLoader SkinnedMesh does not scale with the model? - #2 by ViniciusFranciscoXavier) I tried setting the scale of the group after I had created the bounding box:
obj3D.scale.set(.01, .01, .01);
This now matches the size of the bounding box:
I also have a similar model with this issue and used obj3D.scale.set(.01, .01, .01);
The dimensions of the second model also matched the bounding box when I scaled it down like this, however it’s orientation did not match.
So it seems that however xbot.glb was produced, the scale does not match of the Box3 size.
Does anyone know the reason for this? It cant be a coincidence that the two models are incorrectly scaled by the same amount.
Ideally I’m looking for:
- the reason behind this issue
- a method to detect it
- a method to automatically re-align / re-scale
I could even ask our users to manually scale and reorient the object and resave it in our UI but if if anyone else has an idea for an automated solution I’d be very grateful for any pointers.