Can i get the geometry out of a MeshInstance?

I am working on creating a custom renderer which receives the geometry in the format of triangle meshes:

    {    0.0f,    0.0f,    0.0f  },
    {    0.0f,    0.0f,  559.2f },
    {  556.0f,    0.0f,  559.2f }
...

Working on the change queue I realize that the result of the class will be of class MeshInstance like it is shown in ApplyMeshInstanceChanges in SampleChangeQueue rhino sample:

	m_pImpl->m_iInstanceCount += deleted.Count() + added.Count();
	for (int aidx = 0; aidx < added.Count(); aidx++) {
		const MeshInstance* mi = added[aidx];
		// now you can access the material id, retrieve a render material with it:
		const CRhRdkMaterial* rm = MaterialFromId(mi->MaterialId());
		// know what mesh parts at what indices 'belong' to an object
		const ON_UUID& obid = mi->MeshId();
		// the mesh index of the part in ChangeQueue::Mesh::Meshes()
		const int idx = mi->MeshIndex();
		// the mesh instance id can be used to identify the object.
		const int instanceidx = mi->InstanceId();

Is it possible to get the total triangle meshes of the scene out f the MeshInstance objects?
Thanks!

any suggestions on this?

@nathanletwory - is this something you can help with?

MeshInstances don’t contain mesh data themselves. Instead they point to meshes through a combination of mesh ids and mesh indices.

With these mesh instances you can instantiate mesh data into your renderer scene graph. Multiple MeshInstances can reference the same mesh data.

Mesh data you’ll receive in the ApplyMeshChanges method

So to get the polygon count you have to tally up the face counts in ApplyMeshChanges, then potentially adjust for instances if you need to for your engine.

The .NET RhinoCommon library works in the same way, you should check the RhinoCycles implementations how ApplyMeshChanges and ApplyMeshInstanceChanges can be used to get and combine the data.

See

and

Thanks for your reply, I think I have implemented the ApplyMeshChanges in the ChangeQueue and at the exit of the function I have the meshes in a map:

std::map<ON_UUID, std::vector<Mesh> > meshes;

Consider the following simple scenario:

  • Create a box
  • Create a block instance of this box
  • Insert 1 out of this block instance.

Now I have 2 boxes in the viewport.

Exiting the ApplyMeshChanges my meshes map has size of 1.

Entering the

	void ChangeQueue::ApplyMeshInstanceChanges(
		const ON_SimpleArray<ON__UINT32>& deleted,
		const ON_SimpleArray<const MeshInstance*>& addedOrChanged) const

The addedOrChanged has size of 2 as expected.

for (int i = 0; i < addedOrChanged.Count(); ++i)
{
const auto instance = addedOrChanged[i];
const auto instanceID = instance->InstanceId();
ON_UUID mid = instance->MeshId();
int meshindex = instance->MeshIndex();
ON_Xform xform = instance->InstanceXform();
ON_3dPoint p = ON_3dPoint::Origin;
ON_3dVector zup = ON_3dVector::ZAxis;
}

You mention

MeshInstances don’t contain mesh data themselves. Instead they point to meshes through a combination of mesh ids and mesh indices.

With these mesh instances you can instantiate mesh data into your renderer scene graph. Multiple MeshInstances can reference the same mesh data.

What confuses me here is how I can get all the triangle mesh data of the scene out of these mesh instances. Should I get the mesh of each instance out of the std::map<ON_UUID, std::vector<Mesh> > meshes (using the mid) and then apply the transformation on the geometry of this mesh?