Autodesk Forge Viewer : f2d get frag from dbid

岁酱吖の 提交于 2019-12-12 02:46:54

问题


I am trying to fill in room with color on a revit converted file's 2d viewer.

I have a Revit file that has "rooms" defined. The Revit file also has sheets defined "Floor one", "Floor two". When I convert it using the Forge API

I get a svf for the Revit 3D view and f2d files for "Floor one" and "Floor Two" sheets.

For the svf I was able to get fragid from dbids other post

Now Im trying to do the same for the f2d files.

I am able to change the color of the room walls if I know the wall shapes dbid by using

viewer.setThemingColor(dbid, new THREE.Vector4(0, 1, 1,1));

What I want to do now is be able to get the fragid of the shape on 2d so that I can get the start and stop vertices of the lines it uses. I want to know these vertices so I can build a custom mesh and fill it in with color for room "hatching".

My problem is that I do not know the f2d format. It seems it is all one mesh and lets the shader control the color of the lines. Can anyone give me any pointers on how to the the fragment list of the room?

This is what I used for the 3d svf

function getFragIdFromDbId(viewer, dbid) {
 var returnValue;
 var it = viewer.model.getData().instanceTree;
 it.enumNodeFragments(dbid, function (fragId) {
   //console.log("dbId: " + dbid + " FragId : " + fragId);
   returnValue = fragId;
 }, false);
  return returnValue;
}

What can I use for f2d to do the same when the f2d has viewer.model.getData().instanceTree = undefined?


回答1:


Fragments can have geometry for multiple dbids and the geometry for a dbid can be in multiple fragments. It is possible to extract with Autodesk.Viewing.Private.VertexBufferReader, used by the 2D snapper that helps. You could do something like this:

  1. FragmentList.dbid2fragId[dbid] will return the fragment id or an array of fragment ids that contain geometry for the dbid.
  2. Loop through the fragments and get the geometry for each fragment.
  3. Create a VertexBufferReader using the geometry.
  4. Use the VertexBufferReader to find the geometry for a dbid.

The best way to find the geometry is to use VertexBufferReader.enumGeomsForObject(dbid, callback). It uses a callback object to enumerate geometry for a dbid. The callback object needs these optional functions:

  • onLineSegment(x0, y0, x1, y1, viewport_id)
  • onCircularArc(centerX, centerY, startAngle, endAngle, radius, viewport_id)
  • onEllipticalArccenterX, centerY, startAngle, endAngle, major, minor, tilt, viewport_id)
  • onTriangleVertex(x, y, viewport_id)

This is OK if you just need the primitives and not where they are in the buffer.

You can also use the VertexBufferReader to loop through the geometry in the buffer looking for the dbid. This requires you to know the a primitive in the vertex buffer is 4 vertices if .useInstancing() is false and 1 vertex if .useInstancing() is true. And you need to decode the primitive type from .getVertexFlagsAt(vertexIndex) but we don’t any public values or methods for decoding the flags.



来源:https://stackoverflow.com/questions/39861563/autodesk-forge-viewer-f2d-get-frag-from-dbid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!