MacroScript SelMatEdge category:"Piranha-Bytes" tooltip:"Select Material Edge" buttonText:"SelMatEdge" ( rollout ro_MatEdgeSelect "pb Select Material Edge" ( pickbutton ui_SelectObj "Select Obj" pos:[5,5] width:140 height:20 tooltip:"Select Object" multiListBox ui_MatList "Select Materials:" pos:[5,30] items:#() width:240 height:10 checkbutton ui_ShareAll "Share All" pos:[5,190] width:70 height:20 checked:true tooltip:"Select Material Edges sharing ALL materials" checkbutton ui_ShareTwo "Share Two" pos:[75,190] width:70 height:20 tooltip:"Select Material Edges sharing AT LEAST TWO materials" button ui_SelectFirst "First" pos:[145,190] width:50 height:20 enabled:false button ui_SelectSecond "Second" pos:[195,190] width:50 height:20 enabled:false label lbl_numFaces "Selected Faces: 0" pos:[10,220] button ui_grow "Grow Selection" pos:[5,250] width:140 height:20 visible:false groupBox grp_G1 "Edit Vertex Colors" pos:[5,240] width:140 height:90 button ui_ApplyVertColor "Apply Vertex Colors" pos:[10,260] width:130 height:20 tooltip:"Apply smooth Vertex Color transition (black -> white)" spinner ui_SmoothSteps "Smoothing: " pos:[10,285] fieldwidth:25 range:[0,10,2] scale:1 type:#integer checkbutton ui_Swap "Swap" pos:[105,285] width:35 height:16 tooltip:"Swap Black & White Vertex Colors" spinner ui_RandomFactor "Random Color:" pos:[10,307] fieldwidth:47 range:[0,127,50] scale:1 type:#integer button ui_ToggleShow "Show/Hide Selection" pos:[5,340] width:140 height:20 tooltip:"Show / Hide Vertex Color Face-Selection" materialButton ui_ApplyMaterial "Apply new Material" pos:[5,360] width:140 height:20 tooltip:"Apply new Material to selected faces" local theObj local objType = 0 --- 1:EditMesh, 2:EditPoly local firstList, secondList on ui_ToggleShow pressed do ( if ((theObj != undefined) and (objType == 2)) do ( os = subobjectLevel if os == 0 then subobjectLevel = 4 if os == 4 then subobjectLevel = 0 ) ) function getMats = ( ui_matList.items = #() if theObj.Material != undefined then ( matList = #() if ((classof theObj.material) == MultiMaterial) then for m=1 to theObj.Material.count do append matList theObj.Material[m].name if ((classof theObj.material) == StandardMaterial) then append matList theObj.Material.name ui_matList.items = matList ) else messageBox "Object has no materials!!" title:"Warning!" ) function setFaceCount cn = ( lbl_numfaces.caption = "Selected Faces: " + (cn as string) lbl_numFaces.pos = [10,220] ) function selectMaterialEdge = ( if theObj != undefined do ( selMat = ui_MatList.selection as array if selMat.count >= 2 do ( if (getCurrentSelection())[1] != theObj then select theObj max modify mode if objType == 1 do ----- EDIT MESH MODE ( subobjectLevel = 3 faceList = #() for m=1 to selMat.count do ( matFaceList = #{} for f=1 to theObj.numFaces do if (getFaceMatID theObj f) == selMat[m] then matFaceList[f] = true append faceList matFaceList ) edgeList = #() for m=1 to selMat.count do append edgeList (meshop.getVertsUsingFace theObj faceList[m]) if ui_ShareAll.state == true do ( edges = edgeList[1] for m=1 to selMat.count do edges = edges * edgeList[m] newFaceArray = meshop.getFacesUsingVert theObj edges newFaceSelection = newFaceArray as Array for f=1 to newFaceSelection.count do ( fID = (getFaceMatID theObj newFaceSelection[f]) if (findItem selMat FID) == 0 then newFaceArray[newFaceSelection[f]] = false ) ) if ui_ShareTwo.state == true do ( multiEdges = #{} for e=1 to selMat.count do ( for m=1 to selMat.count do ( edges = edgeList[e] if m != e do ( edges = edges * edgeList[m] multiEdges = multiEdges + edges ) ) ) newFaceArray = meshop.getFacesUsingVert theObj multiEdges newFaceSelection = newFaceArray as Array for f=1 to newFaceSelection.count do ( fID = (getFaceMatID theObj newFaceSelection[f]) if (findItem selMat FID) == 0 then newFaceArray[newFaceSelection[f]] = false ) ) setFaceSelection theObj newFaceArray setFaceCount (newFaceArray as array).count -- get first / second List: firstList = #() secondList = #() listFaceArray = newFaceArray as array for f=1 to listFaceArray .count do ( fID = (getFaceMatID theObj listFaceArray[f]) if fID == selMat[1] then append firstList listFaceArray[f] if fID == selMat[2] then append secondList listFaceArray[f] ) firstList = firstList as bitArray secondList = secondList as bitArray ) --- if objType == 2 do ---- EDIT POLY MODE ( subobjectLevel = 4 faceList = #() for m=1 to selMat.count do ( matFaceList = #{} for f=1 to theObj.numFaces do if (polyOp.getFaceMatID theObj f) == selMat[m] then matFaceList[f] = true append faceList matFaceList ) edgeList = #() for m=1 to selMat.count do append edgeList (polyop.getVertsUsingFace theObj faceList[m]) if ui_ShareAll.state == true do ( edges = edgeList[1] for m=1 to selMat.count do edges = edges * edgeList[m] newFaceArray = polyop.getFacesUsingVert theObj edges newFaceSelection = newFaceArray as Array for f=1 to newFaceSelection.count do ( fID = (polyop.getFaceMatID theObj newFaceSelection[f]) if (findItem selMat FID) == 0 then newFaceArray[newFaceSelection[f]] = false ) ) if ui_ShareTwo.state == true do ( multiEdges = #{} for e=1 to selMat.count do ( for m=1 to selMat.count do ( edges = edgeList[e] if m != e do ( edges = edges * edgeList[m] multiEdges = multiEdges + edges ) ) ) newFaceArray = polyop.getFacesUsingVert theObj multiEdges newFaceSelection = newFaceArray as Array for f=1 to newFaceSelection.count do ( fID = (polyop.getFaceMatID theObj newFaceSelection[f]) if (findItem selMat FID) == 0 then newFaceArray[newFaceSelection[f]] = false ) ) polyop.setFaceSelection theObj newFaceArray setFaceCount (newFaceArray as array).count -- get first / second List: firstList = #() secondList = #() listFaceArray = newFaceArray as array for f=1 to listFaceArray .count do ( fID = (polyOp.getFaceMatID theObj listFaceArray[f]) if fID == selMat[1] then append firstList listFaceArray[f] if fID == selMat[2] then append secondList listFaceArray[f] ) firstList = firstList as bitArray secondList = secondList as bitArray ) ) ) forceCompleteRedraw() ) on ui_ShareAll changed state do ( ui_ShareTwo.state = false ui_ShareAll.state = true selectMaterialEdge() ) on ui_ShareTwo changed state do ( ui_ShareAll.state = false ui_ShareTwo.state = true selectMaterialEdge() ) on ui_Grow pressed do ( selMats = ui_MatList.selection as array if ((objType == 2) and (selmats.count == 2)) do ( theObj.growSelection selLevel:#face curSel = (polyop.getFaceSelection theObj) curSelArray = curSel as array for f=1 to curselArray.count do ( fID = (polyop.getFaceMatID theObj curselArray[f]) if (findItem selMats FID) == 0 then curSel[curselArray[f]] = false ) polyop.setFaceSelection theObj curSel setFaceCount (curSel as array).count ) ) on ui_Swap changed state do ui_applyVertColor.pressed() on ui_ApplyVertColor pressed do ( selMats = ui_MatList.selection as array if ((theObj != undefined) and (objType != 2)) do ( ask = queryBox "Works only on Editable Poly, convert?" if ask == true do ( convertTo theObj PolyMeshObject objType = 2 ) ) if selMats.count != 2 then messageBox "Select TWO materials first!!" if ((theObj != undefined) and (objType == 2) and (selMats.count == 2)) do ( --- clean vert colors if ui_swap.checked == true do ( cc1 = white cc2 = black ccf = 1 ) if ui_swap.checked == false do ( cc1 = black cc2 = white ccf = -1 ) subobjectLevel = 4 newFaceSel = #{} for f = 1 to theObj.numFaces do if (polyop.getFaceMatID theObj f) == selmats[1] then newFaceSel[f] = true polyop.setFaceSelection theObj newFaceSel theObj.ConvertSelection #face #vertex cleanVerts = polyop.getVertSelection theObj polyOp.setVertColor theObj 0 cleanVerts cc1 print "*** Material 1 cleaned!" newFaceSel = #{} for f = 1 to theObj.numFaces do if (polyop.getFaceMatID theObj f) == selmats[2] then newFaceSel[f] = true polyop.setFaceSelection theObj newFaceSel theObj.ConvertSelection #face #vertex cleanVerts = polyop.getVertSelection theObj polyOp.setVertColor theObj 0 cleanVerts cc2 print "*** Material 2 cleaned!" --- selectMaterialEdge() orgFaces = polyOp.getFaceSelection theObj for s=1 to ui_SmoothSteps.value do ui_grow.pressed() AllorgFaces = polyOp.getFaceSelection theObj selMats = ui_MatList.selection as array theObj.ConvertSelection #face #vertex subobjectLevel = 1 allVertices = polyop.getVertSelection theObj allFaces = polyop.getFacesUsingVert theObj allVertices allFacesArray = allFaces as array faceList1 = #{} faceList2 = #{} for f=1 to allFacesArray.count do ( fID = polyop.getFaceMatID theObj allFacesArray[f] if fID == selMats[1] then faceList1[allFacesArray[f]] = true if fID == selMats[2] then faceList2[allFacesArray[f]] = true ) subobjectLevel = 4 polyop.setFaceSelection theObj faceList1 theObj.ConvertSelection #face #vertex subobjectLevel = 1 VertList1 = polyop.getVertSelection theObj subobjectLevel = 4 polyop.setFaceSelection theObj faceList2 theObj.ConvertSelection #face #vertex subobjectLevel = 1 VertList2 = polyop.getVertSelection theObj shareVerts = vertList1 * vertList2 vertList1 = vertList1 - shareVerts vertList2 = vertList2 - shareVerts polyop.setVertSelection theObj shareVerts polyOp.setVertColor theObj 0 vertList1 cc1 polyOp.setVertColor theObj 0 vertList2 cc2 polyOp.setVertColor theObj 0 shareVerts (color 127 127 127) currentColorVerts = shareVerts as array currentColorVerts = currentColorVerts as bitarray cf = 127.0 / ui_SmoothSteps.value rf = ui_RandomFactor.value print "*** Vertex Lists gathered!" for s=1 to ui_SmoothSteps.value do ( theObj.growSelection selLevel:#vertex grownVerts = polyop.getVertSelection theObj vertsCopy = grownVerts as array grownVerts = grownVerts - currentColorVerts matVertList1 = grownVerts * vertList1 matVertList2 = grownVerts * vertList2 if ccf == -1 do ( colorFak = (s * cf) c1 = amax (127 - colorFak) 0 c2 = amin (127 + colorFak) 255 polyOp.setVertColor theObj 0 matVertList2 (color c2 c2 c2) polyOp.setVertColor theObj 0 matVertList1 (color c1 c1 c1) ma1 = matVertList1 as array randomList = #{} for m=1 to ma1.count do ( r = random 0 1 if r == 1 then randomList[ma1[m]] = true ) colorFak = (s * cf) + (random 0 rf) c1 = amax (127 - colorFak) 0 polyOp.setVertColor theObj 0 randomList (color c1 c1 c1) ma2 = matVertList2 as array randomList = #{} for m=1 to ma2.count do ( r = random 0 1 if r == 1 then randomList[ma2[m]] = true ) colorFak = (s * cf) + (random 0 rf) c2 = amin (127 + colorFak) 255 polyOp.setVertColor theObj 0 randomList (color c2 c2 c2) ) if ccf == 1 do ( colorFak = (s * cf) c2 = amax (127 - colorFak) 0 c1 = amin (127 + colorFak) 255 polyOp.setVertColor theObj 0 matVertList2 (color c2 c2 c2) polyOp.setVertColor theObj 0 matVertList1 (color c1 c1 c1) ma2 = matVertList2 as array randomList = #{} for m=1 to ma2.count do ( r = random 0 1 if r == 1 then randomList[ma2[m]] = true ) colorFak = (s * cf) + (random 0 rf) c1 = amax (127 - colorFak) 0 polyOp.setVertColor theObj 0 randomList (color c1 c1 c1) ma1 = matVertList1 as array randomList = #{} for m=1 to ma1.count do ( r = random 0 1 if r == 1 then randomList[ma1[m]] = true ) colorFak = (s * cf) + (random 0 rf) c2 = amin (127 + colorFak) 255 polyOp.setVertColor theObj 0 randomList (color c2 c2 c2) ) currentColorVerts = vertsCopy as bitarray ) subobjectLevel = 4 polyop.setFaceSelection theObj AllOrgFaces subobjectLevel = 0 print "*** Vertex colors applied!" gc() ) ) on ui_ApplyMaterial picked newMaterial do ( if (theObj != undefined) do ( select theObj max modify mode subobjectlevel = 4 $.material = newMaterial getMats() ) ) on ro_MatEdgeSelect open do ( curSel = getCurrentSelection() if curSel.count >= 1 do ( theObj = curSel[1] objType = 0 if ((classof theObj) == Editable_mesh) then objType = 1 if ((classof theObj) == Editable_Poly) then objType = 2 if objType == 0 then theObj = undefined else ( ui_SelectObj.caption = theObj.name getMats() ) ) ) on ui_SelectObj picked obj do ( theObj = obj objType = 0 if ((classof theObj) == Editable_mesh) then objType = 1 if ((classof theObj) == Editable_Poly) then objType = 2 if objType == 0 then ( theObj = undefined setFaceCount 0 ui_MatList.items = #() messageBox "Invalid Object, must be EditMesh or EditPoly" title:"Error!" ui_SelectObj.caption = "Select Object" ) else ( ui_SelectObj.caption = theObj.name getMats() setFaceCount 0 select theObj ) ) on ui_SelectFirst pressed do ( if objType == 2 then polyop.setFaceSelection theObj firstList if objType == 1 then setFaceSelection theObj firstList ) on ui_SelectSecond pressed do ( if objType == 2 then polyop.setFaceSelection theObj secondList if objType == 1 then setFaceSelection theObj secondList ) on ui_MatList selected sel do ( if theObj != undefined do ( selMat = ui_MatList.selection as array if selMat.count == 1 do ( sel = selMat[1] if (getCurrentSelection())[1] != theObj then select theObj max modify mode newFaceSel = #{} if objType == 1 do ( subobjectLevel = 3 for f = 1 to theObj.numFaces do if (getFaceMatID theObj f) == sel then newFaceSel[f] = true setFaceSelection theObj newFaceSel setFaceCount (newFaceSel as array).count ) if objType == 2 do ( subobjectLevel = 4 for f = 1 to theObj.numFaces do if (polyop.getFaceMatID theObj f) == sel then newFaceSel[f] = true polyop.setFaceSelection theObj newFaceSel setFaceCount (newFaceSel as array).count ) ) ui_SelectFirst.enabled = false ui_SelectSecond.enabled = false if selMat.count == 2 do ( ui_SelectFirst.enabled = true ui_SelectSecond.enabled = true ) ) ) on ui_matList selectionEnd do selectMaterialEdge() ) createDialog ro_MatEdgeSelect width:250 style:#(#style_sysmenu, #style_toolwindow) )