簡體   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

當使用這個repo單擊它時,我試圖在 3D model 中找到表面的位置(x,y,z 坐標)。 我嘗試在 model 上單擊,但每次單擊都會得到相同的 position(x、y、z 值)。 單擊此處查看 position 當我單擊表面時,當我嘗試單擊 model 中的(其他位置)時,我也得到了相同的位置(x、y、z 值)。 對於這個 model(urn:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6YXBwdGVzdGJ1Y2tldG5pc2hhbnQyL2dhdGVob3VzZSUyMDEubndk),我已經嘗試了在 repo 鏈接中給出的完全相同的東西。 如何在 model 中找到位置(x、y、z 坐標)? 提前致謝。

這通常是計算 cursor 坐標時相對於托管 Forge 查看器的 canvas 的問題,因此首先要確保這些坐標是正確的。 例如,單擊 canvas 的左上角附近應該會為您提供接近 (0,0) 的相對 cursor 坐標。 然后將這些相對坐標傳遞給 Viewer API 以進行光線投射和命中測試。

這是另一個執行相同操作的示例代碼(單擊畫布后查找最近命中的世界坐標):

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