OnPolymesh Method


IExport Context On Polymesh Method

This method is called when a tessellated polymesh of a 3d face is being output.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 27.0.4.0 (27.0.4.0)
Syntax
void OnPolymesh(
	PolymeshTopology node
)

Parameters

node PolymeshTopology
A node representing topology of the polymesh
Example
C#
/// <summary>
/// This method is called up for every face that was processed and tessellated
/// </summary>
/// <remarks>
/// The node provides all information about geometric topology if the mesh.
/// It is assumed that a concrete exporter would consume the part it can 
/// understand and/or support (vertices, normals, UVs, etc.) and convert
/// them into the final, export format.
/// </remarks>
public void OnPolymesh(PolymeshTopology node)
{
   // Note: the current material will get applied to the polymesh.

   // If a stack of transformation is maintained by the context object,
   // the current combined transform will be applied to the points.
   Transform currentTransform = m_TransformationStack.Peek();

   // basic properties of the mesh

   int numberOfFacet = node.NumberOfFacets;
   int numberOfPoints = node.NumberOfPoints;
   int numberOfUVs = node.NumberOfUVs;
   int numberOfNormal = node.NumberOfNormals;

   // Note: Normals are associated with either points or facets of the polymesh
   // The export code must account for different processing of these two cases.

   // A) process points of the polymesh

   if( node.DistributionOfNormals == DistributionOfNormals.AtEachPoint )
   {
      ExportMeshPoints(node.GetPoints(), currentTransform, node.GetNormals() );
   }
   else if( node.DistributionOfNormals == DistributionOfNormals.OnePerFace )
   {
      ExportMeshPoints(node.GetPoints(), currentTransform, node.GetNormal(0) );
   }
   else  // DistributionOfNormals.OnEachFacet
   {
      // In this case, there is normal vector associated with each facet
      // Depending on the export, our format either support this case,
      // of we would have to determine what normals to apply at each 
      // point by a way of combining normal of the surrounding facets.
      ExportMeshPoints(node.GetPoints(), currentTransform );
   }

   // B Process facets of the polymesh

   if( node.DistributionOfNormals == DistributionOfNormals.OnEachFacet )
   {
      ExportMeshFacets(node.GetFacets(), node.GetNormals() );
   }
   else
   {
      ExportMeshFacets(node.GetFacets(), null );
   }

   // B) Process UV coordinates if available (and applicable)

   if( node.NumberOfUVs > 0 )
   {
      ExportMeshUVs( node.GetUVs() );
   }
}

private void ExportMeshPoints(IList<XYZ> points, Transform trf, IList<XYZ> normals)
{
   // process points with normals
}

private void ExportMeshPoints(IList<XYZ> points, Transform trf, XYZ normal)
{
   // process points with only one normal vector (a planar face)
}

private void ExportMeshPoints(IList<XYZ> points, Transform trf)
{
   // process points without normal (assuming normals are associated with facets instead)
}

private void ExportMeshFacets(IList<PolymeshFacet> facets, IList<XYZ> normals)
{
   if (normals == null)
   {
      // process facets without normals  (assuming normals are associated with points instead)
   }
   else
   {
      // process facets with normals
   }
}

private void ExportMeshUVs(IList<UV> UVs)
{
   // process UVs
}
See Also
ArchiLabs Desktop

Put AI to work inside Revit.

Give Desktop your instructions and project files to build Revit families, update model elements, and create views and schedules. Works directly in Revit and AutoCAD.

Explore Desktop →