To create an ON_Mesh:
You are now ready to add this mesh object to the document. The opennurbs_mesh.h header file is well documented. It's worth reading through at least once.
CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
{
int face_count = 6;
int vertex_count = 12;
BOOL bVertexNormals = FALSE;
BOOL bTextureCoordinates = FALSE;
ON_Mesh mesh( face_count, vertex_count, bVertexNormals, bTextureCoordinates );
mesh.SetVertex( 0, ON_3fPoint(0.0f, 0.0f, 1.0f) );
mesh.SetVertex( 1, ON_3fPoint(1.0f, 0.0f, 1.0f) );
mesh.SetVertex( 2, ON_3fPoint(2.0f, 0.0f, 1.0f) );
mesh.SetVertex( 3, ON_3fPoint(3.0f, 0.0f, 0.0f) );
mesh.SetVertex( 4, ON_3fPoint(0.0f, 1.0f, 1.0f) );
mesh.SetVertex( 5, ON_3fPoint(1.0f, 1.0f, 2.0f) );
mesh.SetVertex( 6, ON_3fPoint(2.0f, 1.0f, 1.0f) );
mesh.SetVertex( 7, ON_3fPoint(3.0f, 1.0f, 0.0f) );
mesh.SetVertex( 8, ON_3fPoint(0.0f, 2.0f, 1.0f) );
mesh.SetVertex( 9, ON_3fPoint(1.0f, 2.0f, 1.0f) );
mesh.SetVertex( 10, ON_3fPoint(2.0f, 2.0f, 1.0f) );
mesh.SetVertex( 11, ON_3fPoint(3.0f, 2.0f, 1.0f) );
mesh.SetQuad( 0, 0, 1, 5, 4 );
mesh.SetQuad( 1, 1, 2, 6, 5 );
mesh.SetQuad( 2, 2, 3, 7, 6 );
mesh.SetQuad( 3, 4, 5, 9, 8 );
mesh.SetQuad( 4, 5, 6, 10, 9 );
mesh.SetQuad( 5, 6, 7, 11, 10 );
mesh.ComputeVertexNormals();
mesh.Compact();
context.m_doc.AddMeshObject( mesh );
context.m_doc.Redraw();
return CRhinoCommand::success;
}
Public Overrides Function RunCommand(ByVal context As IRhinoCommandContext) As IRhinoCommand.result
Dim face_count As Integer = 6
Dim vertex_count As Integer = 12
Dim bVertexNormals As Boolean = False
Dim bTextureCoordinates As Boolean = False
Dim mesh As New OnMesh(face_count, vertex_count, bVertexNormals, bTextureCoordinates)
mesh.SetVertex(0, New On3fPoint(0.0F, 0.0F, 1.0F))
mesh.SetVertex(1, New On3fPoint(1.0F, 0.0F, 1.0F))
mesh.SetVertex(2, New On3fPoint(2.0F, 0.0F, 1.0F))
mesh.SetVertex(3, New On3fPoint(3.0F, 0.0F, 0.0F))
mesh.SetVertex(4, New On3fPoint(0.0F, 1.0F, 1.0F))
mesh.SetVertex(5, New On3fPoint(1.0F, 1.0F, 2.0F))
mesh.SetVertex(6, New On3fPoint(2.0F, 1.0F, 1.0F))
mesh.SetVertex(7, New On3fPoint(3.0F, 1.0F, 0.0F))
mesh.SetVertex(8, New On3fPoint(0.0F, 2.0F, 1.0F))
mesh.SetVertex(9, New On3fPoint(1.0F, 2.0F, 1.0F))
mesh.SetVertex(10, New On3fPoint(2.0F, 2.0F, 1.0F))
mesh.SetVertex(11, New On3fPoint(3.0F, 2.0F, 1.0F))
mesh.SetQuad(0, 0, 1, 5, 4)
mesh.SetQuad(1, 1, 2, 6, 5)
mesh.SetQuad(2, 2, 3, 7, 6)
mesh.SetQuad(3, 4, 5, 9, 8)
mesh.SetQuad(4, 5, 6, 10, 9)
mesh.SetQuad(5, 6, 7, 11, 10)
mesh.ComputeVertexNormals()
mesh.Compact()
context.m_doc.AddMeshObject(mesh)
context.m_doc.Redraw()
Return IRhinoCommand.result.success
End Function
public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
{
int face_count = 6;
int vertex_count = 12;
bool bVertexNormals = false ;
bool bTextureCoordinates = false;
OnMesh mesh = new OnMesh(face_count, vertex_count, bVertexNormals, bTextureCoordinates);
mesh.SetVertex( 0, new On3fPoint(0.0f, 0.0f, 1.0f) );
mesh.SetVertex( 1, new On3fPoint(1.0f, 0.0f, 1.0f) );
mesh.SetVertex( 2, new On3fPoint(2.0f, 0.0f, 1.0f) );
mesh.SetVertex( 3, new On3fPoint(3.0f, 0.0f, 0.0f) );
mesh.SetVertex( 4, new On3fPoint(0.0f, 1.0f, 1.0f) );
mesh.SetVertex( 5, new On3fPoint(1.0f, 1.0f, 2.0f) );
mesh.SetVertex( 6, new On3fPoint(2.0f, 1.0f, 1.0f) );
mesh.SetVertex( 7, new On3fPoint(3.0f, 1.0f, 0.0f) );
mesh.SetVertex( 8, new On3fPoint(0.0f, 2.0f, 1.0f) );
mesh.SetVertex( 9, new On3fPoint(1.0f, 2.0f, 1.0f) );
mesh.SetVertex( 10, new On3fPoint(2.0f, 2.0f, 1.0f) );
mesh.SetVertex( 11, new On3fPoint(3.0f, 2.0f, 1.0f) );
mesh.SetQuad( 0, 0, 1, 5, 4 );
mesh.SetQuad( 1, 1, 2, 6, 5 );
mesh.SetQuad( 2, 2, 3, 7, 6 );
mesh.SetQuad( 3, 4, 5, 9, 8 );
mesh.SetQuad( 4, 5, 6, 10, 9 );
mesh.SetQuad( 5, 6, 7, 11, 10 );
mesh.ComputeVertexNormals();
mesh.Compact();
context.m_doc.AddMeshObject( mesh );
context.m_doc.Redraw();
return IRhinoCommand.result.success;
}