Close

Relief for ODA Team in Ukraine

Learn more
ODA Facet Modeler
Create Basic Objects

This chapter provides information on how to create basic objects in Facet Modeler.

Facet Modeler enables you to create several body primitives. All functions are declared in the <KERNEL_DIR>/FacetModeler/include/Modeler/FMMdlBody.h header file.

Create a Box

To create a box, use the box() constructor:

static Body box(const OdGePoint3d& ptOrigin, const OdGeVector3d& vSizes);

The following code snippet creates a cube with side length of edgeLen:


Body createCube(double edgeLen)
{
  // Create dimensions vector
  OdGeVector3d dimensions(edgeLen, edgeLen, edgeLen);
   // Move the origin point to the center of the cube base
  OdGeVector3d shift(edgeLen / 2, edgeLen / 2, 0.0);
   return Body::box(OdGePoint3d::kOrigin - shift, dimensions);
}

Create a Pyramid

To create a pyramid, use the pyramid() constructor:

static Body pyramid(const Profile2D& rBase, const OdGePoint3d& ptApex, const DeviationParams& deviation = FMGeGbl::gDefDev);

The following code snippet creates a pyramid based on a polygon with sidesCnt edges inscribed into a circle with a radius dRradius, and with height dHeight:


Body createPyramid(const DeviationParams& devDeviation, double dRadius, double dHeight, unsigned int sidesCnt)
{
  // Create circle for polygon inscribing
  OdGeCircArc2d circle(OdGePoint3d::kOrigin.convert2d(), dRadius);
  OdGePoint2dArray points;
   // Inscribe a polygon in a circle and get vertices
  circle.getSamplePoints(sidesCnt, points);
   // Create base profile
  Profile2D cBase;
   // Only with one contour
  cBase.resize(1);
   // Fill contour with vertices
  cBase.front().appendVertices(points);
   // Close profile
  cBase.front().setClosed();
   // Make contour outer
  cBase.front().makeCCW();
   // Create apex
  OdGePoint3d apex(
    OdGePoint3d::kOrigin.x,
    OdGePoint3d::kOrigin.y,
    OdGePoint3d::kOrigin.z + dHeight
  );
   // Create pyramid
  return Body::pyramid(cBase, apex, devDeviation);
}

Create a Cone

In Facet Modeler a cone is a special type of pyramid. To create a cone, create a circle and use the pyramid() constructor with the circle as rBase:

static Body pyramid(const Profile2D& rBase, const OdGePoint3d& ptApex, const DeviationParams& deviation = FMGeGbl::gDefDev);

The following code snippet creates a cone with a radius dRadius and height dHeight:


Body createCone(const DeviationParams& devDeviation, double dRadius, double dHeight)
{
  // Create base profile
  Profile2D cBase;
   // With one contour
  cBase.resize(1);
   // Add vertices with bulge == 1 (so that they form an arc)
  cBase.front().appendVertex(OdGePoint2d::kOrigin - OdGeVector2d::kXAxis * dRadius, 1);
  cBase.front().appendVertex(OdGePoint2d::kOrigin + OdGeVector2d::kXAxis * dRadius, 1);
   cBase.front().setOrientationAt(0, efoFront);
  cBase.front().setOrientationAt(1, efoFront);
   // Close profile
  cBase.front().setClosed();
   // Make contour outer
  cBase.front().makeCCW();
   // Create apex point
  OdGePoint3d apex(
    OdGePoint3d::kOrigin.x,
    OdGePoint3d::kOrigin.y,
    OdGePoint3d::kOrigin.z + dHeight
  );
   return Body::pyramid(cBase, apex, devDeviation);
}

Create a Mesh Body

In Facet Modeler it is also possible to create a body from a given mesh. To do so, use the createFromMesh() method:

static Body createFromMesh(
  const std::vector& aVertices, 
  const std::vector& aFaceData, 
  const std::vector* aFaceFlags = NULL, 
  const std::vector* aEdgeFlags = NULL, 
  const std::vector* aVertexFlags = NULL, 
  const std::vector* pFaceColors = NULL, 
  const std::vector* pEdgeColors = NULL);

The code snippet below creates a cube from a mesh given in the aFaceData vecotr. As you can see, for convenience, this vector was split into lines. Each line follows this template "n P1 P2 ... Pn", where n represents the number of points that form a face and must be greater than or equal to 3. Index of a point used here is equal to the point's index in aVertices vector. Also it's important to mention that points in aFaceData's line should form a counterclockwise direction.


Body createMeshCube(const DeviationParams& devDeviation)
{
  // Create array of vertices
  OdGePoint3d aVertices[] = {
    OdGePoint3d(0.0, 0.0, 0.0),
    OdGePoint3d(1.0, 0.0, 0.0),
    OdGePoint3d(1.0, 1.0, 0.0),
    OdGePoint3d(0.0, 1.0, 0.0),
    OdGePoint3d(0.0, 0.0, 1.0),
    OdGePoint3d(1.0, 0.0, 1.0),
    OdGePoint3d(1.0, 1.0, 1.0),
    OdGePoint3d(0.0, 1.0, 1.0),
  };
   // Create array with face data
  OdInt32 aFaceData[] = {
    4, 3, 2, 1, 0,
    4, 4, 5, 6, 7,
    4, 2, 3, 7, 6,
    4, 1, 2, 6, 5,
    4, 0, 1, 5, 4,
    4, 3, 0, 4, 7
  };
   Body body = Body::createFromMesh(
    makeVector(aVertices), makeVector(aFaceData)
  );
   return body;
}

Here, makeVector() function is implemented as follows:


template< typename T, size_t N >
std::vector<T> makeVector(const T(&data)[N])
{
  return std::vector<T>(data, data + N);
}

See Also

Work With B-Rep Data in Facet Modeler
Create Objects via Revolution
Create Objects via Extrusion
Create Basic 2D Objects
Iterate throught Entities
Perform Boolean Operations
Calculate Area and Volume
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.