Notifications
Clear all

[Closed] Get mesh of instanced GeomObject

How can I get the mesh from an instanced GeomObject?

In maxscript I do:


gsphere = createInstance geosphere radius:1 segs:4 
 gsphere_mesh = gsphere.mesh

Here is the first line of the maxscript translated into C++:


GeomObject *GSphere = (GeomObject*)ip->CreateInstance(GEOMOBJECT_CLASS_ID, GSPHERE_CLASS_ID);
  GSphere->GetParamBlockByID(2)->SetValue(0, 0, 1);
  GSphere->GetParamBlockByID(2)->SetValue(1, 0, 4);

Now, I need to get the mesh, but I cannot figure out how.

I tried:


TriObject *tObj = (TriObject*)GSphere;
Mesh &mesh= tObj->GetMesh();

However that doesn’t seem to work. What am I doing wrong?

Thanks for any help.

3 Replies

try it like this, GSphere doesn’t inherit from TriObject so can’t be cast to it,


 
 #include <simpobj.h> 
 
  enum { geo_radius, geo_segs, geo_type, geo_hemi, geo_smooth, geo_basepivot, geo_mapping, };
  
  
  SimpleObject2* GSphere = (SimpleObject2*)ip->CreateInstance(GEOMOBJECT_CLASS_ID, GSPHERE_CLASS_ID);
    
   if(GSphere)
   {
   	GSphere->pblock2->SetValue(geo_radius, 0, 1);
       GSphere->pblock2->SetValue(geo_segs, 0, 4);
       Mesh& mesh = GSphere->mesh;	
   }

Thank you for replying. However, I am still having trouble. GetNumVerts() and GetNumFaces() are returning 0. The mesh never gets created within Max.

Here is my complete code.


 	SimpleObject2* GSphere = (SimpleObject2*)CreateInstance(GEOMOBJECT_CLASS_ID, GSPHERE_CLASS_ID);
  
 	if(GSphere)
 	{
 		GSphere->pblock2->SetValue(0, 0, 1);
 		GSphere->pblock2->SetValue(1, 0, 4);
 		Mesh& gmesh = GSphere->mesh;
 
 		int numVerts = gmesh.getNumVerts();
 		int numFaces = gmesh.getNumFaces();
 
 		mesh.setNumVerts(numVerts);
 		mesh.setNumFaces(numFaces);
 		
 		int i;
 		for (i=0;i<numVerts;++i){
 			Point3 v = gmesh.getVert(i);
 			mesh.setVert(i, v[0], v[1], v[2]);
 		}
 		for (i=0;i<numFaces;++i){
 			Face f = gmesh.faces[i];
 			mesh.faces[i].setVerts(f.getVert(0), f.getVert(1), f.getVert(2));
 		}
 
 		mesh.InvalidateGeomCache();
 		mesh.InvalidateTopologyCache();
 	}
 

As you can see, I want to modify the mesh before creating it.

Thanks for the help!

not sure you could try calling…


 void BuildMesh(TimeValue t);

before accessing the mesh.