3

I would like to display some reference lines in the viewer that are not shown by default when a drawing is uploaded to Forge.

I know the exact end points of the lines as they were defined in the model, however, it seems that the model in the viewer is translated so that 0,0 is in the center of the bounds.

Is there a way to get the transformation matrix that was applied to the model, so I can align the coordinates of my reference lines with the coordinates of the model in the viewer?

JGeerWM
  • 810
  • 10
  • 16

1 Answers1

7

Use viewer.model.getData().globalOffset

Felipe
  • 4,325
  • 1
  • 14
  • 19
  • 1
    What is this offset? the difference between (0,0,0) and where the model was placed originally? – shinzou Apr 09 '17 at 10:35
  • 1
    Correct. The viewer will load the model by placing the center of its bounding box at the origin, so depending on the original file, this may add an offset which is returned by the property discussed above. – Felipe Apr 11 '17 at 13:02
  • How can I use it to map THREE Js coordinates to the original cad coordinates? For example I want the camera to look at pos x,y,z that I know from the original cad? – Pola Edward Sep 06 '17 at 22:16
  • 3
    Let's say your CAD model is centered around (100, 100, 100). In the viewer it will be centered around (0,0,0) and globalOffset should be (100, 100, 100). Your camera target should be (x-100, y-100, z-100), ie cadPos - globalOffset – Felipe Sep 07 '17 at 05:58
  • @PhilippeLeefsma Thank you so much for your reply! Unfortunately I don't know the center of the original CAD, All what I have is a Coordinate of a point in the file, that I want to find in threejs. So I'm sure I need something like a mapping function, but don't know how. – Pola Edward Sep 07 '17 at 10:42
  • You don't need to know the CAD model center, only thing you need to know is globalOffset, that's why your point in the viewer is (x-globalOffset.x, y-globalOffset.y, z-globalOffset.z) where (x,y,z) is the point in CAD coordinates that you know and globalOffset that you get from the viewer API. There is no mapping function as far as I know ... – Felipe Sep 08 '17 at 14:24
  • Let's say that i'm bringing two models together in the viewer and one should be rotated about some point not at the center of that model. How should the global offset be factored into the transformation of the second model so it rotates correctly? – JGeerWM Aug 09 '18 at 20:15