0

I am trying to display a point on model displayed in the Autodesk forge viewer. However I am unable to figure out how to transform the point. I found the next question that seems to resolve this question:

Transform point from DWG model coordinates to autodesk forge viewer coordinates

When I try to use the function of this question:

var vpXform = viewer.model.getPageToModelTransform(viewportId).clone();
var invVpXform = new WGS.LmvMatrix4(true);

invVpXform.getInverse(vpXform, true);

var ptInCadX = ...;
var ptInCadY = ...;
var verticesInViewer = new THREE.Vector3().set(ptInCadX, ptInCadY, 0).applyMatrix4(invVpXform);

It shows the next error: Uncaught ReferenceError: WGS is not defined

And if I try it without the WGS.LmvMatrix4, it shows the following error: Uncaught ReferenceError: new LmvMatrix4 is not defined

I'm using the latest version of the Forge Viewer, v7.Can someone help me finding what am I doing wrong?

Thank you very much.

Clara
  • 13
  • 3

1 Answers1

0

Here's an updated version of the snippet:

// Start by getting a list of all viewports in your model
let viewports = viewer.model.getData().viewports;
// Choose a viewport you want to use for the design-to-viewer coordinate mapping (it must include a `transform` property);
// in my case I'll just pick the first one
let viewport = viewports[0];
// Load the viewport transform into a three.js matrix
let xform = new THREE.Matrix4().fromArray(viewport.transform);
// Compute the inverse transxform
let inverse = new THREE.Matrix4().getInverse(xform, true);
// Use the inverse transform to convert design coordinates to paper coordinates
let someX = 0, someY = 0;
let viewerCoords = new THREE.Vector3().set(someX, someY, 0).applyMatrix4(inverse);
Petr Broz
  • 8,891
  • 2
  • 15
  • 24
  • Hi, thank you very much. But unfortunately it doesn't work this transformation for me. The result is not the coordinates I was expecting. – Clara Nov 16 '22 at 09:58