I am using C++ API, and would like to know how would I properly get the details regarding the mesh of a block instance in Rhino?
Hi @alexian007,
I am not I understand what you want. Are you looking for the render meshes attached to instance definition geometry?
Any additional details you can provide might help.
– Dale
Hi @dale
Yes, I am looking for the render meshes attached to the instance definition geometry.
Right now, I am following the similar approach to this extremely helpful sample mesh export code that has been provided to us:
So, the approach I have taken is as follows:
-
Used
RhinoMeshObjects()
to get all the meshes into a single array of meshes i.eON_ClassArray<CRhinoObjectMesh> meshes(objects.Count());
. -
Now that I have the meshes, I have to associate it with the objects on the document. I do so by, using the object iterator as:
CRhinoObjectIterator objectIterator(CRhinoObjectIterator::undeleted_objects, CRhinoObjectIterator::active_objects);
-
Then as I iterate through the obtained objects, I check if it has a mesh or not, by traversing through the meshes array, which I had created before and compare the mesh’s parent object’s UUID to that of the current object’s UUID. If they match, I have written a code that stores the reference of the mesh from the meshes array into the object definition. (What I am doing is storing the rhino object information into another custom data structure, which will be saved into a JSON file and then be readable by another 3D viewer software.)
I do so by:
for (int k = 0; k < allMeshes.Count(); k++)
{
if (allMeshes[k].m_parent_object->Attributes().m_uuid == currentObjID)
{
// code to store the mesh reference to the object
}
}
-
This works fine and well for normal objects, but in the case of block instances, as the block object itself doesn’t have a mesh, I had problem getting mesh reference for them. So, I used
GetSubObjects()
to store the subobjects of a block into an array. -
So, now I wrote a special case for an object having sub-object (i.e a block instance) as:
int subCount = rhino_object->GetSubObjects(allSubObjects, NULL);
if (subCount > 0)
{
hasSubObj = true;
for (int i = 0; i < subCount; i++)
{
CRhinoObject* currentSubObject = allSubObjects[i];
ON_UUID currentSubObjUUID = currentSubObject->Attributes().m_uuid;
for (int k = 0; k < allMeshes.Count(); k++)
{
if (allMeshes[k].m_parent_object->Attributes().m_uuid == currentSubObjUUID)
{
// Code to handle reference to the mesh
}
}
}
}
- And that should have done it. But, even doing this gives me some weird results. I found out that, if a block object was duplicated i.e if there is a block object “block1”, and then duplicate it in the document as “block2”, the code above will get the meshes for the block2 too, but the meshes will be in the same position as the original object.
And, when I debugged the sub-object’s UUID in case of both the objects’ sub-objects, they were the same.
So, the meshes that were referred by both the object’s sub-objects were the same. Ideally, the references should’ve been different. I just dont get it why this is happening. How do I handle this case?
@dale, this was all that’s happening. Please give me some feedback upon how do I improve this situation. I apologize if the details I have provided were ambiguous or not clear. Let me know if I can do a better job at explaining.
Thank you Dale, and hope to get your helpful reply.
Hi @alexian007,
The CRhinoObjectMesh
objects, returned by RhinoMeshObjects
contains the mesh and a pointer to the object the mesh came from. Is this all you need?
– Dale
Hey @dale, yes that is helpful and I can get the object the mesh came from through the m_parent_object
, but that is not kinda helpful to me as I need to get the block instance from the mesh.
I need it because I would like to apply the block transform to the mesh to correctly set the mesh’s position.
So, if given a mesh from RhinoMeshObjects
how would I set its position (vertices) correctly with regards to the block instance it belongs? I need help on that.
Just use RhinoGetRenderMeshes
. See rhinoSdkMeshObject.h for details.
– Dale