Home Technical Talk

any way to do contiguous smoothing group + material ID selection in max ?

polycount sponsor
Offline / Send Message
Joost polycount sponsor
Does anyone know of a way to select all connected polys with the same material ID or smoothing group? Would be a pretty cool scripts I reckon. I'd attempt to script it myself but that's way beyond my limited scripting skills. Maybe one of the Maxscript wizards out there can have a go at it?

Replies

  • FelixL
    Options
    Offline / Send Message
    FelixL polycounter lvl 4
    Not sure why you'd need this. But you can select an element first (for continuity), hide unselected, then use select by SG, select your smoothing group, and voila.
  • Joost
    Options
    Offline / Send Message
    Joost polycount sponsor
    Not quite what I mean. I would like something where it's like select by element mode but instead of selecting the entire element it would only select one contiguous Material ID or smoothing group depending on the setting. So if you have multiple groups of faces with the same smoothing group or material IDs it will only select the ones that are contiguous with your selected face(s)

    I.e.

    this

    Y9yC9mbm.png

    instead of this

    QNOJ9m9m.png
  • FelixL
    Options
    Offline / Send Message
    FelixL polycounter lvl 4
    I see. It could be quite useful.
    As a workaround, you can select by ID, hide unselected, select one face, then hit "grow" under edit poly. It will only grow the selected area on visible faces, not invisible ones.

    I still don't see how you would need this so often that you require a hotkey/macro for it. Have you looked into selection sets? Also available through the ribbon UI.

    You could also just detach it to an element or seperate it into a UV shell, select it through unwrap UVW and collapse it back to edit poly.
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    macroscript selectFacesBySmoothingGroup category:"Polycount Tech Talk" ButtonText:"Tooltip Description for button" toolTip:"Insert Description Here"
    (
    	finalArray = #()
    
    	fn getOutEdgesUsingFace oPoly baFace =
    	(
    	    if ( ((classOf oPoly) == Editable_Poly) and ((classOf baFace) == BitArray) ) then
    	    (
    	        if (baFace.isEmpty == true) then ( return #{} )
    
    	        local baEdgeSet01 = polyOp.getEdgesUsingFace oPoly baFace
    	        local baFaceSet01 = #{1..(polyOp.getNumFaces oPoly)} - baFace
    	        local baEdgeSet02 = polyOp.getEdgesUsingFace oPoly baFaceSet01
    
    	        return (baEdgeSet01 * baEdgeSet02)
    	    )
    	)
    
    	fn getSmoothingGroupFaces sel faceArray smoothingGroups = (
    		faceWalkMatches = #()
    		edges = getOutEdgesUsingFace sel faceArray
    		for edge in edges do 
    		(
    			faceListFromEdge = (polyop.getFacesUsingEdge sel #{edge}) - (finalArray as BitArray)
    			for faceList in faceListFromEdge do 
    			(
    				faceSmoothGrp = polyOp.getFaceSmoothGroup sel faceList
    				for smoothGroup in smoothingGroups do (
    					if faceSmoothGrp == smoothGroup then 
    					(
    						appendIfUnique faceWalkMatches faceList 
    					)
    				)
    			)
    		)
    		if faceWalkMatches.count > 0 then 
    		(
    			for faceMatch in faceWalkMatches do 
    			(
    				appendIfUnique finalArray faceMatch
    			)
    		)
    		return #(finalArray,faceWalkMatches)
    	)
    
    	fn main sel faceSel smoothingGroups= 
    	(			
    		for face in faceSel do 
    		(
    			faceSelSmoothingGrp = polyOp.getFaceSmoothGroup selection[1] face
    			appendIfUnique smoothingGroups faceSelSmoothingGrp
    			appendIfUnique finalArray face
    		)
    		result = getSmoothingGroupFaces selection[1] faceSel smoothingGroups
    		while result[2].count > 0 do
    		(
    			result = getSmoothingGroupFaces selection[1] (result[1] as BitArray) smoothingGroups
    		)
    		sel.EditablePoly.SetSelection #Face (result[1] as BitArray)
    	)
    
    	fn userCheck = 
    	(
    		sel = selection[1]
    		result = #(False)
    		if ((classOf sel) == Editable_Poly) then 
    		(
    			faceSel = polyop.getFaceSelection selection[1]
    			if faceSel.isEmpty then 
    			(
    				messageBox "No Faces selected"
    			)
    			else 
    			(
    				result = #(True,faceSel)  
    			)
    		)
    		if  ((classOf sel) == Editable_Mesh) then
    		(
    			userInput = queryBox ("This mesh is an Editable Mesh. Would you like to convert it to Editable Poly?") title:"Editable Mesh found!"
    			if userInput then 
    			(
    				faceSel = getFaceSelection sel
    				convertToPoly sel
    				macros.run "Modifier Stack" "SubObject_4"
    				faceSel = polyop.getFaceSelection selection[1]
    				if faceSel.isEmpty then 
    				(
    					messageBox "No Faces selected"
    				)
    				else 
    				(
    					result = #(True,faceSel)  
    				) 
    			)
    			if not userInput then 
    			(
    				messageBox "Script needs the object to be as an Editable Poly."
    			)
    		)
    		return result
    	)
    	userCheckTest = userCheck()
    	if userCheckTest[1] == True then 
    	(
    		smoothingGroups = #()
    		sel = selection[1]
    		faceSel = userCheckTest[2]
    		main sel faceSel smoothingGroups
    	)	
    )
    

    Lemme know if that works. Wrote this a while back for an artist. Needs to be an edit poly but can modify for edit mesh would just need to make other functions aware of that. Also had a walkthrough grow selection by smoothing group.
  • kary
    Options
    Offline / Send Message
    kary polycounter lvl 18
    Lemme know if that works. Wrote this a while back for an artist. Needs to be an edit poly but can modify for edit mesh would just need to make other functions aware of that. Also had a walkthrough grow selection by smoothing group.

    And I'd be that artist. This works very well for my workflow. In combination w/ a hotkey for poly select by angle (5, 45, etc) it can get very fast to setup big areas for a Meshsmooth + by smoothing groups setup.
  • Joost
    Options
    Offline / Send Message
    Joost polycount sponsor
    FelixL wrote: »
    I see. It could be quite useful.
    As a workaround, you can select by ID, hide unselected, select one face, then hit "grow" under edit poly. It will only grow the selected area on visible faces, not invisible ones.

    I still don't see how you would need this so often that you require a hotkey/macro for it. Have you looked into selection sets? Also available through the ribbon UI.

    You could also just detach it to an element or seperate it into a UV shell, select it through unwrap UVW and collapse it back to edit poly.

    I'm doing a lot of mid poly stuff atm with loads of cut in panels that have different material IDS and I'm using support loops+ 1 smoothing group for the smoothing. Which results in a lot of geo and makes it a real pain to select stuff. I guess if you're doing conventional low/high poly work it's not that useful. That workaround works pretty well. Just a bit annoying when you have to do it several times.
    Selection sets tend to disappear when you change the geo so I avoid using them.

    @haiddasalami: Thanks a lot man! That's exactly what I was looking for, for smoothing groups. Works great so far.
  • FelixL
    Options
    Offline / Send Message
    FelixL polycounter lvl 4
    Works fine! Thanks, I might start using that.
  • monster
    Options
    Offline / Send Message
    monster polycounter
    https://dl.dropboxusercontent.com/u/2904948/MaxScript/Martinez_Macro_GrowByMaterialID.mcr

    Here is my attempt to grow/expand by material ID. You can even select more than one face/matID to start.
  • Joost
    Options
    Offline / Send Message
    Joost polycount sponsor
    Thanks monster, that works great!
    Really appreciate it. Thanks guys!
  • Neox
    Options
    Online / Send Message
    Neox veteran polycounter
    msshtools has this function since i dunno 10 years ^^
Sign In or Register to comment.