Hi all !
So, I am making an exporter plugin to export a 3dm object into another file format.
And, I am exporting the materials using the material table and getting the material id, through the following code, which I discovered on this thread.
So, this is what I am doing to get the material index:
int GetMaterialIndex(CRhinoDoc& doc, const CRhinoObjectMesh& object_mesh)
{
::RhinoApp().Print("\nGetting the material index");
int material_index = -1;
int layer_index = -1;
switch (object_mesh.m_mesh_attributes.MaterialSource())
{
case ON::material_from_object:
::RhinoApp().Print("\nMaterial is from - OBJECT");
material_index = object_mesh.m_mesh_attributes.m_material_index;
break;
case ON::material_from_layer:
::RhinoApp().Print("\nMaterial is from - LAYER");
layer_index = object_mesh.m_mesh_attributes.m_layer_index;
material_index = doc.m_layer_table[layer_index].m_material_index;
break;
case ON::material_from_parent:
{
::RhinoApp().Print("\nMaterial is from - PARENT");
const CRhinoInstanceObject* iref_object = object_mesh.m_iref_object;
if (iref_object)
{
switch (iref_object->Attributes().MaterialSource())
{
case ON::material_from_object:
material_index = iref_object->Attributes().m_material_index;
break;
case ON::material_from_layer:
layer_index = iref_object->Attributes().m_layer_index;
material_index = doc.m_layer_table[layer_index].m_material_index;
break;
}
}
}
break;
default:
::RhinoApp().Print("\n****NO MATERIAL IS FOUND FOR THIS OBJECT !!!!****");
break;
}
return material_index;
}
What I’m having issues with is that, whenever an object has a material assigned to it by the layer (the Default material, to be precise), the material data doesn’t show up on my exported file and also I get the material index for it as -1.
This can be seen as,
This is an object in a rendered view in Rhino:
And, when I export the same object, its material is gone, like this:
So, this has raised some questions from me:
-
Is the layer material not stored on the material table, especially the Default material, that has been assigned to this object, as seen in the screenshot?
-
If the layer material is not in the material table, how do I get it?
-
Also, an unrelated but a related question, how do I get the total count of materials that are present in the current document. (Is using the MaterialTable’s MaterialCount() the way to go?)
Thanks, and happy holidays to anyone who is reading this