如何将查看器坐标转换回CAD坐标? [英] How to convert viewer coordinates back to CAD coordinates?

查看:109
本文介绍了如何将查看器坐标转换回CAD坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将查看器(场景)坐标转换回原始CAD坐标.我见过有人提到全局偏移量,但是每当尝试检索此偏移量时,我都无法定义.我认为这意味着没有偏移量.但是,当我在查看器中比较两个坐标而在CAD中比较两个坐标时,它们肯定是不相等的.我碰到了功能NOP_VIEWER.model.getUnitScale();但是,将此数字应用于坐标时似乎没有任何意义.

I am trying to convert from the viewer (scene) coordinates back to the original CAD coordinates. I have seen people mentioning the global offset, but whenever I try to retrieve this, I get undefined. I assumed this means there is no offset. But when I compare two coordinates one in the viewer and one in CAD, they are definitely not equal. I came across the function NOP_VIEWER.model.getUnitScale(); however, this number did not seem to mean anything when applying it to the coordinates.

话虽如此,我该如何从查看者坐标转换回CAD坐标?

That being said, how can I convert back to the CAD coordinates from the viewer coordinates?

推荐答案

根据我的经验,globalOffset通常用于3D模型,您可以将PageToModelTransform应用于查看者点以将其转换回CAD.以下代码段摘自名为 viewer-dwgoffset .

The globalOffset is for 3D model commonly with my experience, you can apply the PageToModelTransform to your viewer points to transform them back to CAD. The following code snippet is extracted from a demo called viewer-dwgoffset written by our colleague.

其关键概念是使用VertexBufferReader读取Forge Viewer 2D模型的顶点,并获取相应的变换矩阵,以将Viewer的点投影回DWG坐标系.

Its key concept is using the VertexBufferReader to read vertices of a Forge Viewer 2D model, and get the corresponding transformation matrix to project points of the Viewer back to DWG coordinate system.

function GeometryCallback(viewer) {
    this.viewer = viewer;
}

GeometryCallback.prototype.onLineSegment = function(x1, y1, x2, y2, vpId) {
    var vpXform = this.viewer.model.getPageToModelTransform(vpId);

    var pt1 = new THREE.Vector3().set(x1, y1, 0).applyMatrix4(vpXform);
    var pt2 = new THREE.Vector3().set(x2, y2, 0).applyMatrix4(vpXform);

    console.log('Line segment vertices in CAD coordinate system', {
        pointX1: pt1.x,
        pointY1: pt1.y,
        pointX2: pt2.x,
        pointY2: pt2.y
    });
}

GeometryCallback.prototype.onCircularArc = function(cx, cy, start, end, radius, vpId) {
};

GeometryCallback.prototype.onEllipticalArc = function(cx, cy, start, end, major, minor, tilt, vpId) {

};

var it = viewer.model.getData().instanceTree;
it.enumNodeFragments( dbId, function( fragId ) {
    var m = viewer.impl.getRenderProxy(viewer.model, fragId);
    var vbr = new Autodesk.Viewing.Private.VertexBufferReader(m.geometry, viewer.impl.use2dInstancing);
    vbr.enumGeomsForObject(dbId, new GeometryCallback());
});

希望有帮助.

这篇关于如何将查看器坐标转换回CAD坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆