This article will describe the methodology that should be used to determine part and face appearances correctly.
As an application developer, you want the graphical representation of imported parts to match their appearance in the authoring software as closely as possible. Appearance can be specified on a per B-Rep face basis, and furthermore, the particular path through the assembly hierarchy can impart parent/child overrides on visual appearance.
Exchange captures data about the appearance of objects coming from a variety of formats, each with different levels of available information.
Reading Color and Material Data
There are two parts to obtaining correct appearance data. The first is to compute the effect style of a face given a specific path through the product structure.
The second is to interpret and adapt to your graphical display tools.
The chart below depicts the steps you need to take in order to obtain the available appearance information.
Computing the effective style for a face
To determine how a particular face should be displayed, you must first determine the effective style. This can be done by using the functionality provided in the Miscellaneous Cascaded Attributes module of the Exchange API.
Since a general implementation should account for part instancing, the final style for the graphical representation of a particular B-Rep face is determined by the path taken through the product hierarchy. Create, then Push Miscellaneous Cascaded Attribute objects for each instance of the hierarchy leading to the tessellated face (
A3DTessFaceData). The final call to Push varies from each of the previous calls.
If you are using the Exchange Toolkit, the process of determining the effective style is implemented in the class ts3d::RepresentationItemInstance. Specifically, the member function ts3d::RepresentationItemInstance::getNetStyle can be used for each face index. If you aren’t using this helper toolkit, you can refer to its implementation to better understand how to use Cascaded Attributes.
Interpreting the style data
Once you’ve computed the effective style, you must interpret the information conveyed therein. The style provides information on how lines and faces should be displayed.
The face appearance falls into two main categories based on if it is a material.
If the style does not indicate a material, your job is simple. Use the API A3DGlobalGetGraphRgbColorData to obtain the A3DGraphRgbColorData. This is the most basic appearance data available.
If the style indicates a material, you must next check to see if there is texture application data available. If so, use this API to retrieve the texture application data. The A3DGraphTextureApplicationData structure provides indexes for material data as well as texture definition data. Furthermore, PBR attributes are obtained using
A3DMiscPointerFromIndexGet along with
A3DMiscAttribute functionality. Please refer to this page for more information on PBR attributes. Be aware that the texture application data structure contains an index for additional texture application data. All texture channels combined must be used to compose the final appearance.
To correctly display lines, you must interpret the style data properly. The attribute A3DGraphStyleData::m_bVPicture is used to indicate that vector-based data is used to define the line style.
If the line style indicates a vector picture, use the API A3DGlobalGetGraphVPicturePatternData to obtain the data required to correctly render.
If the line style does not indicate a vector picture, instead use A3DGlobalGetGraphLinePatternData.
Summary and Additional Resources
Determining the correct display parameters for your CAD geometry is an essential capability in your software application. By following the steps outlined above, you can be sure you are using Exchange’s complete set of capabilities to achieve this.
For a sample implementation of reading and dumping all color and material information to JSON, please refer to this example in the Exchange Toolkit.