【问题标题】:How to find the position(x,y,z coordinates) in the 3D model using autodesk forge viewer如何使用 Autodesk Forge 查看器在 3D 模型中查找位置(x、y、z 坐标)
【发布时间】:2020-10-04 21:28:30
【问题描述】:

我尝试使用repo 在 3D 模型中找到一个表面的位置(x、y、z 坐标)。我尝试在整个模型上单击,但每次单击都会获得相同的位置(x、y、z 值)。 Click here to see the position when i click on a surface 当我尝试在模型中单击 (somewhere else) 时,我也得到了相同的位置(x、y、z 值)。我已经尝试了在这个模型的 repo 链接中给出的完全相同的东西(urn:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6YXBwdGVzdGJ1Y2tldG5pc2hhbnQyL2dhdGVob3VzZSUyMDEubndk)。如何在模型中找到位置(x,y,z 坐标)?提前致谢。

【问题讨论】:

    标签: autodesk-forge autodesk-viewer


    【解决方案1】:

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

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

       $('#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));
            }
        });
    

    【讨论】:

      猜你喜欢
      • 2019-02-17
      • 2021-12-24
      • 2019-05-02
      • 2018-11-08
      • 2017-03-28
      • 2018-06-16
      • 2020-06-07
      • 2018-10-03
      • 2019-05-02
      相关资源
      最近更新 更多