如何使用 Autodesk Forge 查看器在 3D 模型中查找位置(x、y、z 坐标)

How to find the position(x,y,z coordinates) in the 3D model using autodesk forge viewer

我试图在模型中使用此 repo. I tried clicking all over the model, but I am getting the same position (x,y,z value) for every click. Click here to see the position when i click on a surface and when I try clicking (somewhere else) 在 3D 模型中找到表面的位置(x、y、z 坐标),我得到了相同的位置(x ,y,z 值)。我已经为这个模型尝试了在 repo link 中给出的完全相同的东西(urn:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6YXBwdGVzdGJ1Y2tldG5pc2hhbnQyL2dhdGVob3VzZSUyMDEubndk)。如何找到模型中的位置(x、y、z 坐标)?提前致谢。

这通常是计算相对于 canvas 托管 Forge Viewer 的光标坐标的问题,因此首先要确保这些是正确的。例如,单击 canvas 的左上角附近应该会给您接近 (0,0) 的相对光标坐标。然后将这些相对坐标传递给查看器 API 以进行光线投射和命中测试。

这是另一个做同样事情的 sample code(点击 canvas 后找到最近命中的世界坐标):

   $('#viewer').on('click', function(ev) {
        let intersections = [];
        const bounds = document.getElementById('viewer').getBoundingClientRect();
        mainViewer.impl.castRayViewport(mainViewer.impl.clientToViewport(ev.clientX - bounds.left, ev.clientY - bounds.top), false, null, null, intersections);
        if (intersections.length > 0) {
            const intersection = intersections[0];
            $('#issue-part').val(intersection.dbId);
            $('#issue-position-x').val(intersection.point.x.toFixed(2));
            $('#issue-position-y').val(intersection.point.y.toFixed(2));
            $('#issue-position-z').val(intersection.point.z.toFixed(2));
        }
    });