Notifications
Clear all

[Closed] SDK: How do I collect and store vertex normals?

I’ve got the following:

Mesh mesh;
// ... (get Mesh to work with)

Tab<Point3> VertNormals;

for (int p=0; p<vnum; p++) {
  //VertNormals[p] = mesh->getNormal(p); // crashes, try something else
  Point3 &vn = mesh->getNormal(p); // so far so good
  VertNormals[p] = vn; // back to crashing, but what should I be doing here instead?
}

What is the right way of doing this?

5 Replies

Your Point3Tab has no members, so trying to access a location in the array by index will crash, of course. You can do that with maxscript, but only because maxscript allows all kinds of cheating.

Append the new members to your tab instead.

Actually, my mistake in posting, and I can see where that would be the case, but I left a few things out when I posted for the sake of simplicity, including one I should have left in. I actually do have a line

VertNormals->SetCount(vnum);

prior to my for loop. So I don’t think that’s the problem.

and what happens if you do foll ?


 VertNormals.SetCount(0)
 ..
 {
   ..
   VertNormals.Append(1, &vn);
 }
 

btw: did you BuildNormals() ?

You also need to check for explicit normals (i.e., Edit Normals Modifier).

Turns out it I was missing BuildNormals()

Thanks for all the help!