In this forum post, we’ll discuss CAD access and mesh processing using HOOPS Exchange and Polygonica and the bridge between them.
Basics of HOOPS Exchange
To get started, let’s briefly go over HOOPS Exchange. HOOPS Exchange is a data access SDK with a C++ interface that supports importing over 30 CAD file formats, including BRep (boundary representation) and tessellated (triangulated) data. Tech Soft 3D reverse engineers these CAD formats enabling users to access this data without depending on any CAD system. We import this data into one data model, PRC or Product Representation Compact. The PRC data model contains model trees, BRep, mesh, visualization, PMI, and views. You only need to integrate your application with the PRC data to import data from all these formats.
The CAD Product Structure and Model Geometry
When a CAD model is imported into HOOPS Exchange it is represented by a hierarchical data structure. At the top is the ModelFile and under that a hierarchy of Product Occurrences. The Product Occurrence is essentially an assembly node. As it is hierarchical, you can have product occurrences that reference other occurrences and represent a complex assembly.
Below a Product Occurrence is the part definition. This typically represents a single part within a CAD file. That part is also represented by something we call a representation item. A part may have more than one representation item. The main representation items we are interested in are the BRepModel and PolyBrepModel. Both these can reference tessellated data.
Not all models have tessellation; if a model does not don’t, it can be generated from the Brep model utilizing HOOPS Exchange tessellators, whichare part of the toolkit. This tessellated data is the basis of the Polygonica bridge.
Basics of Polygonica
Polygonica is a mesh modeling toolkit provided as an SDK. Most people using Polygonica are developing CAD, CAE or CAM applications, especially in Additive Manufacturing. Polygonica capabilities include, but are not limited to:
Healing Models: Closing open solids. Fixing non-manifold geometry, badly oriented faces, precision issues, self-intersecting geometry, and fold overs.
Additive preparation: Generating printing supports and lattices. Compensating for deformation.
Remeshing: Adapting existing geometry for later processes by shrink wrapping, remeshing, denoising or smoothing.
2D Operations: Polygonica provides 2D profiles for a wide variety of analysis and construction including mesh slicing and medial axis applications. The 2D Boolean engine is as sophisticated and reliable as the 3D Boolean engine.
Point Clouds : Typically used for scanning tasks, point cloud functionality includes registration, triangulation, sampling, and working with normals.
Analysis: A wide variety of geometric analysis techniques are provided such as mesh comparison, gap and thickness analysis, feature detection, and surface detection.
Boolean Operations: Polygonica uses much of the same underlying code as MachineWorks, so it should be no surprise that one of its strengths is high quality Boolean operations on both open and closed solids.
Mesh Creation and Alteration: It’s good with minor modifications such as imprinting & embossing or offsetting surfaces. As part of working with tool paths, sweeping solids and profiles is also available.
Polygonica Internal Representation
PTSolid: This is Polygonica’s principal representation of a 3d model, consisting of planar polygonal data.
PTWorldEntity: A scene or assembly in Polygonica is represented by world entities. Each PTWorldEntity specifies a PTSolid with a position and orientation, along with additional metadata where necessary. To support instanced data sets, the same PTSolid can be mapped to multiple world entities. If an assembly has multiple identical bolts, for example, then each of those bolts would have a separate PTWorldEntity referencing the same bolt model PTSolid.
PTFace: The polygon faces that make up a PTSolid. The corresponding edges and vertices can be queried and manipulated.
PTAppSurface: Connects to the surface of the original CAD object
PTEntityList: A collection of Polygonica objects. Typically used for defining regions of faces for further operations.
Polygonica PTWorldEntity objects have no hierarchical information. Unlike HOOPS Exchange, which has a recursive structure, it is not possible to make one PTWorldEntity the child of another. Luckily that’s where the HOOPS Exchange and Polygonica Bridge come into play.
What is the Bridge for?
Polygonica can only load a few file types; its own PGS format, STL and (through example code available on request) AMF. However, HOOPS Exchange gives access to many more. HOOPS also supports a much richer data model than Polygonica, as mentioned previously, such as a complex assembly hierarchy. The bridge creates a mapping between the CAD data structure and that of Polygonica. This allows a developer to import many different CAD formats while maintaining a correspondence between the attributes and B-Rep data read by Exchange and the tessellated data held in Polygonica.
Structure of the HOOPS Polygonica Bridge
The Exchange Bridge is a C++ header-only file called “ExchangePolygonicaBridge.h." It is incorporated in an application by including this header file in the code. The Polygonica library should be linked within the application, whereas the HOOPS Exchange library will be loaded at runtime.
The Exchange Bridge acts as the communication interface between the application logic and both Polygonica and HOOPS Exchange. HOOPS Exchange brings data from CAD files into the application. The data then passes through the bridge and ends up in Polygonica, where it can be accessed from the application logic.
After loading a HOOPS model file, calling the A3DModelCreatePGWorld function from the header populates a set of return values in the pgOpts parameter. It also adds the resulting PTSolid and PTWorldEntity objects to the world.
The A3DAsmPartDefinition objects in HOOPS Exchange are mapped to PTSolids in Polygonica. The A3DAsmProductOccurence items, which position the objects with 3D space, map to corresponding PTWorldEntitys. If there are instances of identical parts, each instance will be a separate PTWorldEntity sharing a single PTSolid.
The information about these entities and solids is communicated through the m_entities field of the options, which is a map. The surfaces from the CAD models can be extracted in two ways: either through a map of entity groups for each solid, where each group represents a CAD surface or by using the PTAppSurface property set on individual polygons (PTFace objects) in Polygonica.
The assembly path is mapped for each PTWorldEntity, connecting it to a chain of objects (A3DAsmPartDefinition and A3DAsmProductOccurrence) from the top of the tree to the leaf node corresponding to that specific PTWorldEntity. Material colors are transformed into Polygonica materials (render styles), resulting in a map for this transformation.
Overall, this mapping process allows for efficient communication between HOOPS Exchange, Polygonica, and the application, enabling effective handling of 3D CAD models and their data.
Demo and Code
Where to find the bridge
To use the bridge, the header can be found hosted on the Tech Soft 3D GitHub Repo here: GitHub - techsoft3d/ExchangePolygonicaBridge. This is being provided as an open-source tool, which means it is not officially maintained, but bug reports are still welcome.