How to point the camera to a specific Mesh from a Group

Hello there.

I have this 3d model that is quite complex, it has several nested groups and I is kind of big so I want to be able to point the camera to an specific Mesh or Group, so I can show that specific part in more detail. My two main questions here are,

  1. How to determine the target to point the camera? For this I was told to use Box3 but is not really accurate, I guess I’m doing something wrong because when I add a Box3Helper is not aligned with the mesh/group.
  2. How to tell the PerspectiveCamera or the OrbitControls where to look at.

Some screenshots of the model:


image

Thanks in advance :slight_smile:

You can try this
https://threejs.org/docs/index.html#api/en/core/Object3D.lookAt

1 Like

If computing the bounding box does not provide the expected result, consider to just hard-code your focus points.

Is not a scalable solution. I must be doing something wrong, check this image, those are the boxes of the body and the neck.

Why are they in a totally different position?

They seem to be correct. Are the boxes placed within the mesh (as children), or directly in your scene object? Do you use box3 calculation via geometry or Box3.setFromObject() ?

Are the boxes placed within the mesh (as children), or directly in your scene object?

Directly to the scene, here’s the code I’m using

getObjectCenter(mesh, addHelper) {
      const { scene } = this.options;
      const box3 = new Box3().setFromObject(mesh);
      const position = new Vector3();
      box3.getCenter(position);

      if (addHelper) {
        const helper = new Box3Helper(box3, '#000000');
        scene.add(helper);
      }

      return position;
    }

Nevermind, I found out I was rotating the scene:
scene.rotation.y = Math.degToRad(rotation);