1

Three.js: a loaded glb model has center different with it's bounding box center. How can I translate all it's mesh geometries to have same center with its bounding box?

For clearance: when I set position of bounding box = position of model. The bounding box will not cover the model anymore (picture below).

Because I will use bounding box for creating canon rigid body, so that position of model will be updated by rigid body. So I need to translate mesh position in model to have center = bounding box center.

In the picture: 3 models, 3 bounding boxes and 3 boxHelper(red).

bounding box illustration

2
  • 1
    Can you please share the glb model in this thread? Commented Aug 22, 2019 at 9:20
  • @Mugen87 I uploaded a runable project for reference here: drive.google.com/open?id=1kPvxMgAmmrST2XJvDHvO6DUnjLPVqTf1 . You can find the model name model.glb inside models folder. Commented Aug 22, 2019 at 14:13

1 Answer 1

2

The bounding box is computed correctly. The problem is that your blockBounding mesh is not positioned at the right place.

You have to position blockBounding at the center point of the bounding box (not at the model's position). Besides, it is also not necessary to apply a rotation to blockBounding. An instance of Box3 is an axis-aligned bounding box (AABB). So it's totally sufficient to do this:

blockBounding.position.copy( center ); // "center" is the center point of the model's AABB

The result looks like so:

enter image description here

three.js R107

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.