Notifications
Clear all

[Closed] SDK: Push modifier class ID, and class IDs in general?

Alternately, does anyone have code that does the same thing? I’m struggling with trying to understand something. I have one case where using

for (int v=0; v<vnum; v++) {
  // ...
  mesh.setVert(v, p); // i.e. (vertex id, point3 value);
}
ip->RedrawViews(t);

does what I want it to (i.e. moves the vertices of the mesh). But I am trying to replicate this for another function and it does NOTHING. I have checked and the point3 values I am getting are what I want – it’s just that the mesh.setVert statement is being completely ignored by Max.

I was hoping I could take a look at the code for the Push modifier for some tips (the function having the problem does almost exactly the same thing) and maybe get some idea what I’m missing, but that doesn’t seem to be an option.

Push modifier is incredibly simple, and just moves verts along vertex normals.

Are you forgetting to set channel validity and reset cache after changing the mesh?


  mesh.InvalidateGeomCache();
  os->obj->SetChannelValidity(GEOM_CHAN_NUM, valid); 
  
  

Also in case you do your mesh changing stuff in another function, make sure you pass the mesh by reference or pass a pointer to it, instead of passing by value.

What would be the proper way to do this?

  1. Get vert

  2. Get normal

  3. Get push amount

  4. Set vert = vert + normal * push amount

Okay, I’m obviously doing something wrong.


 //INode *Node = ... // first node
 //INode *Node2 = ... // second node (copy of the first node)
 //float dist = ... // push distance
 
 // First mesh
 TriObject *TriObj = (TriObject *)Node->GetObjectRef();
 Mesh &mesh = TriObj->GetMesh();
 int vnum = TriObj->NumPoints();
 
 // Second mesh
 TriObject *TriObj2 = (TriObject *)Node2->GetObjectRef();
 Mesh &mesh2 = TriObj2->GetMesh();
 mesh2.buildNormals();
 
 // Get vert positions of first mesh
 Tab<Point3> VertPoints;
 VertPoints.SetCount(vnum);
 for (int i=0; i<vnum; i++) VertPoints[i] = TriObj->GetPoint(i);
 
 // Get vert normals of first mesh
 Tab<Point3> Normals;
 Normals.SetCount(vnum);
 for (int p=0; p<vnum; p++) theImpressObjects.VertNormalsA[p] = mesh.getNormal(p);
 
 // Set vert positions of second mesh
 for (int i=0; i<Normals.Count(); i++) mesh2.setVert(i, VertPoints[i] + Normals[i] * dist);

The results I’m getting look like this

And that’s with a push distance of 20,000, which is odd because that mesh only has a radius of 35. What am I missing?

First thing that stands out is that you’re building the normals of the second mesh, but trying to take them from the first mesh. You have to build normals on the first mesh before you can access them. You don’t need to build normals for the second mesh since you’re neither getting or setting the second mesh’s normals.

//...
Mesh &mesh = TriObj->GetMesh();
mesh.buildNormals();
//...

Getting literally identical results.

I don’t know if it matters, but you are taking verts of first object from trimesh, not from mesh.
Just in case…

Well, then you need to step through your code and find out what’s going on.

99% of SDK problems can be easily solved just by setting breakpoints and examining variables in realtime as your code executes.

Set a breakpoint where you grab the normals and make sure they’re coming off the mesh properly. Then set a breakpoint when you set the new vertex position and make sure the mesh is taking the changes properly, etc. Do all this on a simpler mesh than a sphere so you’re not having to check the math on thousands of verts.

Page 2 / 2