MacroScript PaintFaceSelection category:"Piranha-Bytes" tooltip:"PaintFaceSelection" buttonText:"PaintFaces" ( /********************************************************************************************/ /* */ /* PaintFaceSelection (c) 2004 by Andre Hotz, Piranha-Bytes */ /* */ /* Options: */ /* */ /* "Paint Selection" : Start/Stop Painting */ /* "Faces/Polys" : Choose between Face and Polygon Selection */ /* "Single/Brush" : This is the PaintMode, "Single" selects only the face at the current */ /* mouseposition, "Brush" will select all faces inside the brush area */ /* "BrushSize" : The size of the brush */ /* "ClearSelection" : Clears the current selection */ /* */ /* You can map the "Paint Selection" button to a hotkey, use the "PaintFaceSelectionKey" */ /* and assign it to a key. */ /* */ /* Use at your own risk! */ /* */ /* mailto:andre@piranha-bytes.com */ /* www.gothic2.com */ /* http://mitglied.lycos.de/bogi1976/ */ /********************************************************************************************/ global PaintFaceSelection_Running global ro_PaintFaceSelection global ro_PaintFaceSelection_WinPos rollout ro_PaintFaceSelection "pb PaintFaces" ( checkbutton ui_Paint "Paint Selection" pos:[10,5] width:100 height:20 tooltip:"Start Painting! LMB to select, ALT-LMB to deselect." radioButtons ui_PaintType labels:#("Faces" , "Polys") pos:[10,30] default:2 columns:2 checkbutton ui_BrushMode_Single "Single" pos:[10,50] width:50 height:20 checked:true tooltip:"Only select faces under mousepointer" checkbutton ui_BrushMode_Brush "Brush" pos:[60,50] width:50 height:20 tooltip:"Use brush for selection" spinner ui_BrushSize "Brush Size: " range:[0,9999,10] type:#float scale:0.1 fieldwidth:32 pos:[10,75] button ui_ClearSelection "Clear Selection" pos:[10,100] width:100 height:20 local curObj = undefined local curFaceSel = #{} local oldHitList = #{} local paintType = 2 local objectType = 0 local brushMode = 1 function startStroke = ( if objectType == 1 then paintType = ui_PaintType.state else ui_PaintType.state = 2 oldHitList = #{} ) function paintStroke = ( if (brushMode == 1) do ( hit = thePainterInterface.getTestHit mouse.pos if hit do ( bcoords = [0,0,0] pface = 0 thePainterInterface.getCustomHitFaceData &bcoords &pface curObj if paintType == 1 then newfaces = #{pface} if paintType == 2 do ( newfaces = meshop.getPolysUsingFace curObj.mesh #{pface} threshhold:360 faceVerts = meshop.getVertsUsingFace curObj.mesh newFaces if objectType == 2 do ( newFaces = #{} newPolys = (polyop.getFacesUsingVert curObj faceVerts) as array for p=1 to newPolys.count do ( polyVerts = polyop.getVertsUsingFace curObj newPolys[p] if (polyVerts as array).count == (faceVerts as array).count do ( if ((polyVerts + faceVerts) as array).count == (faceVerts as array).count then newFaces[newPolys[p]] = true ) ) ) ) curFaceSel = curFaceSel + newFaces if keyboard.altPressed then curFaceSel = curFaceSel - newFaces setFaceSelection curObj curFaceSel ) ) if (brushMode == 2) do ( hitList = thePainterInterface.GetPointGatherHits curObj newHits = hitlist - oldHitList oldhitList = oldHitlist + newHits if objectType == 1 then vertFaces = meshop.getFacesUsingVert curObj newHits if objectType == 2 then vertFaces = polyop.getFacesUsingVert curObj newHits curFaceSel = curFaceSel + vertFaces if keyboard.altPressed then curFaceSel = curFaceSel - vertFaces setFaceSelection curObj curFaceSel ) ) function abortSelection = ( thePainterInterface.endPaintSession() curObj = undefined ui_Paint.state = false curFaceSel = #{} ) function dummyFunc = () on ui_BrushMode_Single changed state do ( ui_BrushMode_Brush.state = false ui_BrushMode_Single.state = true brushMode = 1 ) on ui_BrushMode_Brush changed state do ( ui_BrushMode_Brush.state = true ui_BrushMode_Single.state = false brushMode = 2 ) on ui_BrushSize changed val do thePainterInterface.maxSize = val on ui_ClearSelection pressed do ( curFaceSel = #{} curObj = (getCurrentSelection())[1] ot = classof curObj if ((ot == editable_Mesh) or (ot == editable_Poly)) then setFaceSelection curObj curFaceSel ) on ui_Paint changed state do ( if state == true do ( curObj = (getCurrentSelection())[1] objectType = 0 if ((classof curObj) == editable_Mesh) then objectType = 1 if ((classof curObj) == editable_Poly) then objectType = 2 if ((curObj != undefined) and (ObjectType == 0)) do ( ask = queryBox "Object must be an EditMesh or EditPoly, apply EditMesh?" if ask == true do ( addModifier curObj (Edit_Mesh()) objectType = 1 ) ) ui_Paint.state = false if ObjectType != 0 do ( max modify mode ui_Paint.state = true paintType = ui_PaintType.state if objectType == 2 then ui_PaintType.state = paintType = 2 if subobjectLevel != (paintType + 2) then subobjectLevel = paintType + 2 curFaceSel = getFaceSelection curObj oldHitList = #{} thePainterInterface.ScriptFunctions startStroke paintStroke dummyFunc abortSelection abortSelection thePainterInterface.initializeNodes 0 curObj thePainterInterface.updateonMouseUp = false thePainterInterface.pointGatherEnable = true thePainterInterface.drawRing = true thePainterInterface.markerEnable = false thePainterInterface.drawNormal = false thePainterInterface.drawTrace = false thePainterInterface.maxsize = ui_BrushSize.value thePainterInterface.maxstr = 1 thePainterInterface.treeDepth = 2 thePainterInterface.PressureEnable = false thePainterInterface.MirrorEnable = false thePainterInterFace.startPaintSession() ) ) if state == false do ( thePainterInterface.endPaintSession() curObj = undefined curFaceSel = #{} oldHitList = #{} ) ) on ro_PaintFaceSelection open do PaintFaceSelection_Running = true on ro_PaintFaceSelection close do ( if thePainterInterface.inPaintMode() then thePainterInterface.endPaintSession() curObj = undefined curFaceSel = undefined PaintFaceSelection_Running = false ro_PaintFaceSelection_WinPos = getDialogPos ro_PaintFaceSelection ro_PaintFaceSelection = undefined gc() ) ) if PaintFaceSelection_Running == undefined then PaintFaceSelection_Running = false if ro_PaintFaceSelection_WinPos == undefined then ro_PaintFaceSelection_WinPos = [300,300] if not PaintFaceSelection_Running then createDialog ro_PaintFaceSelection width:120 pos:ro_PaintFaceSelection_WinPos style:#(#style_sysmenu, #style_toolwindow) ) MacroScript PaintFaceSelectionKey category:"Piranha-Bytes" tooltip:"PaintFaceSelectionKey" ( global ro_PaintFaceSelection global PaintFaceSelection_Running if PaintFaceSelection_Running == undefined then PaintFaceSelection_Running = false if not PaintFaceSelection_Running then macros.run "Piranha-Bytes" "PaintFaceSelection" if PaintFaceSelection_Running do ( currentMode = ro_PaintFaceSelection.ui_Paint.state if currentMode == true do ( ro_PaintFaceSelection.ui_Paint.state = false ro_PaintFaceSelection.ui_Paint.changed false ) if currentMode == false do ( ro_PaintFaceSelection.ui_Paint.state = true ro_PaintFaceSelection.ui_Paint.changed true ) ) )