0

I want to draw room polygons onto a DWG background plan using the Autodesk forge viewer. As I learned in this post, I can get the transformation matrix "pageToModel" like this:

model.getPageToModelTransform(viewportId)

In the post linked above, the viewport ID is extracted in a quite complicated fashion using a 2D geometry and the vertex buffer reader. Running the proposed code with different DWG files, I realized, that the returned viewport ID was always "1".

Can I rely on the fact, that the current viewport ID is "1" in all cases? If not, is there a simpler approach to get the viewport ID? I want to draw the rooms right after the geometry is loaded and I don't want to force the user to click on a 2D geometry first...

I already tried to use the viewport extension, but as someone else already stated here, I also encountered the problem, that no viewport was returned.

1 Answers1

0

The viewports extension only works for Revit models, unfortunately. The extension read viewport data from AEC Model Data, not the 2D drawings.

To make GeometryCallback work for multiple models loaded in the same viewer instance, you need to change the model object passed to the getRenderProxy funciton. Here is the modified code snippet for your reference:

var viewportId = null;
function GeometryCallback(viewer) {
    this.viewer = viewer;
}

GeometryCallback.prototype.onLineSegment = function(x1, y1, x2, y2, vpId) {
    viewportId = vpId;
}

var model = viewer.getAllModels()[0]; //!<<< change the index to switch to other models loaded in the same scene.
var fragId = 0;
var m = viewer.impl.getRenderProxy(model, fragId);
var vbr = new Autodesk.Viewing.Private.VertexBufferReader(m.geometry, viewer.impl.use2dInstancing);
vbr.enumGeomsForObject(dbId, new GeometryCallback());
Eason Kang
  • 6,155
  • 1
  • 7
  • 24