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.
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());
});
Hope it helps.