Home Technical Talk

MAXScript select by Material ID (ish)

Dude
polycounter lvl 18
Offline / Send Message
Dude polycounter lvl 18
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

  • animax
    Offline / Send Message
    animax polycounter lvl 15
    Hey dude,

    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.
  • akramparvez
    Offline / Send Message
    akramparvez polycounter lvl 8
    You could use this
    ids = $.material.materialIDList [COLOR="Yellow"]--Go through the material ids[/COLOR]
    for id in ids do
    	(
    		$.selectbymaterial id [COLOR="yellow"]--Select by material id[/COLOR]
    		_faceSel = polyOp.getFaceSelection $ [COLOR="yellow"]-- Get the selection[/COLOR]
    		polyOp.detachFaces $ _faceSel delete:true asNode:true [COLOR="yellow"]-- Detach as separate object[/COLOR]
    	)
    
  • cw
    Offline / Send Message
    cw polycounter lvl 17
    Dude wrote: »
    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.

    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. :)
  • Dude
    Offline / Send Message
    Dude polycounter lvl 18
    You could use this
    ids = $.material.materialIDList [COLOR="Yellow"]--Go through the material ids[/COLOR]
    for id in ids do
    	(
    		$.selectbymaterial id [COLOR="yellow"]--Select by material id[/COLOR]
    		_faceSel = polyOp.getFaceSelection $ [COLOR="yellow"]-- Get the selection[/COLOR]
    		polyOp.detachFaces $ _faceSel delete:true asNode:true [COLOR="yellow"]-- Detach as separate object[/COLOR]
    	)
    

    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:
    	ids = selection[1].material.materialIDList --Go through the material ids
    	mesh_total = 0
    		for id in ids do
    		(
    			selection[1].selectbymaterial id --Select by material id
    			_faceSel = polyOp.getFaceSelection selection[1] -- Get the selection
    			if _faceSel != NULL do
    			(
    				mesh_total = mesh_total + 1
    			)
    		)
    		messagebox (mesh_total as string)
    	)
    

    However, _faceSel doesn't return NULL when there is no selection present so this method isn't producing the correct number of hits.
  • akramparvez
    Offline / Send Message
    akramparvez polycounter lvl 8
    The getFaceSelection returns a bitarray, to check whether there are faces selected or not use this
    if (not _faceSel.isEmpty) then mesh_total = mesh_total + 1
    
  • Dude
    Offline / Send Message
    Dude polycounter lvl 18
    Nevermind I got it... watch this space, more failures are bound to ensue
Sign In or Register to comment.