【问题标题】: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
【问题描述】:
【问题讨论】:
标签:
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));
}
});