Using this code to write e mesh object ( really its called many times so maybe the name
is the problem ?)
when I read in Rhino I get a object instance with the mesh inside instead of a mesh object
What to do ?
gd
void DB_RhinoWriter::AddMeshobject(ON_3dPointArray &pArray)
{
int vertex_count =pArray.Count();
int face_count=vertex_count/3;
if( ! face_count ) return;
ON_Mesh *mesh = new ON_Mesh( face_count, vertex_count, false, false );
for(int i=0;i< vertex_count;i++ )
mesh->SetVertex(i,pArray[i] );
int cnt=0;
for(int i=0;i< vertex_count ; i+=3 )
{
mesh->SetTriangle( cnt , i ,i+1, i+2 );
cnt++;
}
mesh->CombineIdenticalVertices(true,true);
if ( mesh->IsValid() )
{
mesh->ComputeVertexNormals();
ON_3dmObjectAttributes attributes;
attributes.m_name = "IxMesh";
attributes.m_layer_index = CurrLayer;
bool bResolveIdAndNameConflicts = true;
Model()->AddModelGeometryComponent(mesh, &attributes, bResolveIdAndNameConflicts);
}
}
dale
(Dale Fugier)
May 5, 2021, 4:28pm
2
Hi @gerryark ,
Nothing in your code snippet stands out as being incorrect. We might need a small sample that we can run here.
Here are two other mesh writing samples if you need some reference.
}
}
model.AddModelGeometryComponent(&nurbs_surface, nullptr);
// model.AddDefaultLayer(L"NURBS surface", ON_Color::UnsetColor);
return Internal_WriteExampleModel(model, filename, error_log);
}
static bool write_mesh_example( const wchar_t* filename, ON_TextLog& error_log )
{
// example demonstrates how to create and write a mesh
ONX_Model model;
INTERNAL_INITIALIZE_MODEL(model);
model.AddDefaultLayer(L"mesh", ON_Color::Black);
// create a mesh to write
// The mesh is a pyramid with 4 triangular sides and a quadranglar
// base. The mesh has 5 vertices and 5 faces.
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
// Avoid copying the mesh - useful technique for large objects
model.AddModelGeometryComponentForExperts(false, &mesh, false, nullptr, true);
return Internal_WriteExampleModel(model, filename, error_log);
}
static bool write_mesh_with_material_example( const wchar_t* filename, ON_TextLog& error_log )
{
// example demonstrates how to create and write a mesh
ONX_Model model;
INTERNAL_INITIALIZE_MODEL(model);
model.AddDefaultLayer(L"mesh", ON_Color::Black);
const bool bResolveIdAndNameConflicts = true;
// example demonstrates how to create and write a mesh that uses
– Dale