Autodesk Platform Services - Viewer: How do I make the camera normal to a selected face on the part?

45 Views Asked by At

I am trying to create a feature where the user can click the face of a model in the viewer and the camera will orient itself normal to the selected face.

The approach I followed was was capturing the details of the normal of the face from the viewer.hitTest(), the setting the camera at a point along this normal targeted at the original clicked point using the setPosition() method. I noticed however this was not working with some models. On further inspection I noticed that the face normal reported by the hitTest() was in a different coordinate system compared to the camera. I am trying to create a feature where the user can click the face of a model in the viewer and the camera will orient itself normal to the selected face. The approach I followed was was capturing the details of the normal of the face from the viewer.hitTest(), the setting the camera at a point along this normal targeted at the original clicked point using the setPosition() method. I noticed however this was not working with some models. On further inspection I noticed that the face normal reported by the hitTest() was in a different coordinate system compared to the camera. For the same direction camera and face normal report in different coordinate systems The models source is a .dwfx file generated from an inventor .iam file Is there another approach I could try that would work regardless if the coordinate systems line up or not? Or is there a way to find out the difference in rotations of the coordinate systems programmatically?

1

There are 1 best solutions below

0
On

From these 2 answers(1,2), i got the cameraview to face the fragid.

function getApproximatePosition(model, fragid) {
    const frags = model.getFragmentList();
    let bbox = new THREE.Box3();
    frags.getWorldBounds(fragid, bbox);
    return bbox.getCenter();
}
let pos = getApproximatePosition(viewer.model,fragid)
let t = new THREE.Vector3(0,0,1)
viewer.navigation.setView (pos, t)