Convert an Object to a Faceted Mesh

Taras Khalimanenko

June 25, 2020
convertion example

 

Sometimes you may need to convert an object to a faceted mesh, for example, to get rid of complex surfaces or to export to another format. You can use the OdDbSubDMesh class and the function oddbGetObjectMesh to convert OdDb3dSolid, OdDbSurface, OdDbRegion, OdDbPolyline objects into facet mesh data.

OdResult oddbGetObjectMesh( 
  OdDbObject *pObj, 
  const OdDbFaceterSettings *faceter, 
  OdGePoint3dArray& vertexArray, 
  OdInt32Array& faceArray, 
  OdGiFaceData*& faceData);

The input parameters for this method are:

  • A pointer to the object.
  • A pointer to the parameters of the partition on the face.

The output contains the vertexArray, faceArray, and faceData arrays.

Objects can contain faces and edges that are smooth or large. To control how these objects are converted, there is a parameter that influences the result. Here are brief descriptions:

struct MeshFaceterSettings 
{
 /** Maximum surface deviation. */
 double faceterDevSurface;
 /** Maximum normal deviation. */
 double faceterDevNormal;
 /** Grid ratio. */
 double faceterGridRatio;
 /** Maximum edge length. */
 double faceterMaxEdgeLength;
 /** Maximum aspect ratio for the grid quads. */
 OdUInt16 faceterMaxGrid;
 /** Minimum number of U parameter grid lines. */
 OdUInt16 faceterMinUGrid;
 /** Minimum number of V parameter grid lines. */
 OdUInt16 faceterMinVGrid;
 /** Facet mesh type.
 * 0 - quad type,
 * 1 - hybrid (triangle & quad) type,
 * 2 - triangle type. */
 OdInt16 faceterMeshType;
};

It is important to note that the result of this function depends on the current modeler and how it uses faceter settings. To quickly start testing this functionality or experimenting on your own, you can use the CONVTOMESH command from the ExCommands module, which is located in the Drawing/Examples installation folder. The CONVTOMESH command converts selected objects into OdDbSubDMesh objects if possible.

 

conver to mesh example