How do I apply an InstanceObject’s transform to the meshes it contains?

Hey all!

I am having an issue with correctly applying the position of a mesh according to the block instance it belongs to.

So, as the question says, how do I exactly apply the transform data of a CRhinoInstanceObject into an mesh of type currentONMesh. (I am using the C++ API, btw)

I have tried multiple approaches like :

a) Using the Transform() method :

			ON_Mesh* currentONMesh = currentRhinoMesh.m_mesh;

			const CRhinoInstanceObject* currentMeshInstaceObj = currentRhinoMesh.m_iref_object;

			ON_Xform instanceTransform = currentMeshInstaceObj->InstanceXform();


b) Individually changing the mesh’s vertices as:

            const CRhinoInstanceObject* currentMeshInstaceObj = currentRhinoMesh.m_iref_object;
			ON_3dPoint instancePoint = ON_3dPoint::Origin;

In this approach, after I get the instancePoint, I use it’s x, y, z values as the values for the vertices of the mesh.

Both of these approaches are not working for me.

So, what would be the correct way to achieve this?

Need help.

From the two methods the first one should be correct. How are you determining this doesn’t work for you? I am assuming you are using Rhino 6.

1 Like

Hi @binigya,

Keep in mind that an instance object’s transformation is based from the world origin. So before applying the instance object’s transformation matrix on the mesh, you will first want to transform the mesh to the world origin.

Just curious, what you trying to do and why? If you need to obtain the render mesh from an instance object, there are better ways to approach this.

– Dale

Yeah, I am using Rhino 6. Well, I am determining it’s not working as I am writing an 3dm conversion software for a 3d viewer.

So, whenever I use the first method, the 3d viewer software crashes.

I am in talks with the 3d viewer software’s developers but we are yet to come to anything conclusive.

Hey @dale how would do I do that?

Well, I am still writing a 3dm converter to another 3d model format. So, I would need the details of an object and which mesh does it have.

I am curious about that. How would I get about doing that? I am currently using RhinoMeshObjects to get the meshes.

Since you are working on an exporter based on meshes you may be interested in the discussion here

Basically I’m trying to push for the mentioned changequeue mechanism for exporters so that we have a central place where handling conversion to meshes is done, including handling of block instances…

1 Like

Oh, thank you! I was looking for alternative approaches for that. Will be taking a swipe at implementing the changequeue mechanism as you mentioned!

Hi @binigya,

RhinoMeshObjects creates meshes from some meshing parameters that you provide.

If all you want is an object’s standard render meshes, then use RhinoGetRenderMeshes.

Both of these functions will accept CRhinoInstanceObject objects and generate/return the correct meshes and in the correct transformed location. There is no need to perform any post- get mesh transformation after you’ve called either of these functions. This is why I am confused why you are transforming the meshes.

So, perhaps you can un-confuse me as to why either of these two functions don’t just work for you?

– Dale