I've been maintaining a model export script for a few weeks now, and I've reached an impass in improving it. At present, the exporter has loops to export polygon, vertex, vertex normal, and texture vertex data, each to separate files. This also meant that if the user wanted to make a model with more than one texture, they had to split the model manually through a rather laborious process. I need a way to get the total number of material ID's in a mesh, in a similar manner to selection.numFaces or selection.numVerts. I searched through the documentation a great many times and cannot find a member of the mesh class that seems to hold this information. And as for trying to use the MeshSelect modifier to select by material ID, I cannot seem to get this to work either in maxscript.
Any assistance is greatly appreciated.
Replies
I am a noob in Maxscript, dont know the exact answer to your query.But i use Meshtools and it has a function called Select by Material ID Surface.You could look at that script.
the node has a .material property. If the node.material is a multi-sub object class material then you can infer what is needed from the material, and while looping throuhg your mesh data handle the material ID per face in whichever way suits you best, and even bung in some error checking if you need it.
Or just loop the faces, get material IDs per face as you go - you can collect them into buckets as you go along or if you just need them irrespective of the material or the sets of ids just grab that number per face and include it in your data.
I guess I mean it all depends how you are handling the data really, but it is definitely doable. If you have more gnarly questions feel free to pm me or email.
I've been experimenting with this technique... I don't need to detatch the faces in question. In fact, all I need to know is how many sub-materials the particular model is using, not how many the material has. I tried this:
However, _faceSel doesn't return NULL when there is no selection present so this method isn't producing the correct number of hits.