简体   繁体   English

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

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

I tried to find the position(x,y,z coordinates) of a surface in the 3D model when it is clicked using this repo .当使用这个repo单击它时,我试图在 3D model 中找到表面的位置(x,y,z 坐标)。 I tried clicking all over the model, but I am getting the same position (x,y,z value) for every click.我尝试在 model 上单击,但每次单击都会得到相同的 position(x、y、z 值)。 Click here to see the position when i click on a surface and when I try clicking ( somewhere else ) in the model, I am getting the same position(x,y,z value) for that too.单击此处查看 position 当我单击表面时,当我尝试单击 model 中的(其他位置)时,我也得到了相同的位置(x、y、z 值)。 I have tried exactly the same thing given in the repo link for this model (urn:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6YXBwdGVzdGJ1Y2tldG5pc2hhbnQyL2dhdGVob3VzZSUyMDEubndk).对于这个 model(urn:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6YXBwdGVzdGJ1Y2tldG5pc2hhbnQyL2dhdGVob3VzZSUyMDEubndk),我已经尝试了在 repo 链接中给出的完全相同的东西。 How to find the position(x,y,z coordinates) in the model?如何在 model 中找到位置(x、y、z 坐标)? Thanks in advance.提前致谢。

This is often an issue with computing the cursor coordinates relative to the canvas hosting the Forge Viewer, so make sure that these are correct in the first place.这通常是计算 cursor 坐标时相对于托管 Forge 查看器的 canvas 的问题,因此首先要确保这些坐标是正确的。 For example, clicking close to the top-left corner of the canvas should give you relative cursor coordinates close to (0,0).例如,单击 canvas 的左上角附近应该会为您提供接近 (0,0) 的相对 cursor 坐标。 These relative coordinates are then passed to the Viewer APIs to do the ray casting and hit testing.然后将这些相对坐标传递给 Viewer API 以进行光线投射和命中测试。

Here's another sample code that's doing the same thing (finding the world coordinates of the closest hit after clicking on the 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));
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM