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?
Use viewer.model.getData().globalOffset
Related
My current use case is to align a 2d image to a 3d model inside the forge viewer allowing zoom as well as panning functionalities. I have tried the following implementations -
Adding the 2d image as an overlay scene on the forge viewer but the problem there is that I can't position the model on the image precisely even though i have tried translating, rotating and scaling the model programatically.
Loading two different viewers on top of each other and then using viewer.getState() and viewer.restoreState() to sync the state between the two viewers on Autodesk.Viewing.CAMERA_CHANGE_EVENT.
Placing the image inside the HTML beneath the forge viewer and then disabling the pointer events on the viewer and using Javascript to zoom both the viewer and the image in sync. But the problem there is that the measure tool doesn't seem to work right.
What am i missing?
I assume that you simply want to insert a 2D raster image into the viewer scene. That can certainly be done using the 1st approach you suggested. Use an overlay scene or the SceneBuilder extension to add a custom three.js mesh into the scene, and then apply your image as a texture to the mesh.
Regarding the placement of the mesh in the viewer scene, that really depends on your use case and the type of models you're working with. For example, if you wanted to place the image under the 3D model (perhaps the picture contains some satellite imagery), you could find the bounding box of the model using the viewer APIs (viewer.model.getBoundingBox()), and place the three.js object with your image at the bottom side of it.
Is there a method from Autodesk Forge to find out the location of each point from the corner of the building like the picture I attached?
In the context of Forge Model Derivative & Viewer, the geometries have been translated to mesh (triangles). It does not contain the information of face/edge, which means it does not tell which is corner of the shape. you may have to calculate which is the furthest vertex. This is a blog about how to get vertex
https://forge.autodesk.com/blog/show-mesh-triangles-data-hittest
I want to show X,Y,Z axes in forge viewer at the bottom-left corner like Navisworks. I can create the axes lines (described here) in a certain position of the viewer. But, as expected, whenever I navigate to somewhere the axes also moves. I want it to be placed at the bottom-left corner every time and syncing with the viewer X,Y,Z axes. The Navisworks axes in HUD is like below -
Please share some good idea!
Forge Viewer doesn't offer this feature out-of-the-box but it should be pretty straightforward to implement something similar yourself.
I'd recommend using the approach used by the viewer's "view cube" (in the top-right corner). That cube is actually rendered in its own <canvas> element, and overlaid on top of the viewer canvas. You could create your own <canvas> element in the bottom-right corner, use standard three.js (specifically version 71 that's included in Forge Viewer) to render your axes there, and update their orientation based on the viewer's Autodesk.Viewing.CAMERA_CHANGE_EVENT.
I am using Forge's viewer.setCutPlanes() function to set the cutplanes along with levels, so it will apply the cutplanes horizontally to cut the model level wise. I have two Vector4, as planes, I pass these two planes to the setCutPlanes() function. Now I want to get all elements those are inside the cutplanes, which means, only those elements which are visible in viewer after applying the cutplanes. How can I achieve that?
You could use the Viewer APIs to iterate through the geometry fragments of all objects in your design, get their bounding boxes, and check whether they're between your clipping planes. The process of obtaining the geometry bounds is explained in this blog post: https://forge.autodesk.com/blog/working-2d-and-3d-scenes-and-geometry-forge-viewer.
You can also re-use the 'window selection' example (https://forge.autodesk.com/blog/custom-window-selection-forge-viewer-part-iii) and switch the 8 frustum points to the section plane points.
Is it possible to get the real world coordinates form the original model in the Forge viewer? It looks like when a model is loaded into the Viewer it is placed with the center of the model in the origin of the Viewer.
viewer.model.getData().globalOffset is what you are looking for:
Aligning Coordinate Systems in Autodesk Forge Viewer
Afaik, the Forge viewer centres the model. In other words, the origin of the viewer coordinate system is the centroid of the model. The scale of the model remains unchanged. As a result, you can transform the original model coordinates to Forge viewer and vice versa simply by adding or subtracting the model centroid.