-- Pair_Vertex_Collapser.ms -- v 2.6 -- By Nikolay Litvinov (gniklit@gmail.com) -- Created On: 17/07/15 -- Modified: 22/08/15 -- tested using Max 2012 messageBox "Category: \"#Scripts\"" MacroScript Pair_Vertex_Collapser category:"#Scripts" toolTip:"Pair Vertex Collapser" icon:#("UVWUnwrapTools",4) ( escapeEnable = true global arV = #() global sortVset = #() global DISTANCE_direct global fn_GizmoSphere global fn_sortVsetMaker global aGizm global ColorSet = [255,0,255] global stateOp fn fn_ScA fco = ( for i = 1 to sortVset.count do ( fco.setselection #vertex #{} node: selection[1] fco.setselection #vertex #{} node: selection[2] fco.select #vertex #{sortVset[i][2]} node: selection[2] aPos = (fco.GetVertex sortVset[i][1] node: selection[1]) fco.SetOperation #Transform fco.scaleSelection [1e-005,1e-005,1e-005] axis:(transMatrix aPos) fco.Commit() ) ) fn fn_ScMid fco = ( for i = 1 to sortVset.count do ( fco.setselection #vertex #{} node: selection[1] fco.setselection #vertex #{} node: selection[2] fco.select #vertex #{sortVset[i][1]} node: selection[1] fco.select #vertex #{sortVset[i][2]} node: selection[2] a = (fco.GetVertex sortVset[i][1] node: selection[1]) b = (fco.GetVertex sortVset[i][2] node: selection[2]) midPos = (a + b) / 2 fco.SetOperation #Transform fco.scaleSelection [1e-005,1e-005,1e-005] axis:(transMatrix midPos) fco.Commit() ) ) fn fn_ScB fco = ( for i = 1 to sortVset.count do ( fco.setselection #vertex #{} node: selection[1] fco.setselection #vertex #{} node: selection[2] fco.select #vertex #{sortVset[i][1]} node: selection[1] bPos = (fco.GetVertex sortVset[i][2] node: selection[2]) fco.SetOperation #Transform fco.scaleSelection [1e-005,1e-005,1e-005] axis:(transMatrix bPos) fco.Commit() ) ) fn fn_setVert fco = ( ba_arV1 = arV[1] as BitArray ba_arV2 = arV[2] as BitArray for i = 1 to arV[1].count do ( fco.select #vertex ba_arV1 node: selection[1] fco.select #vertex ba_arV2 node: selection[2] ) ) fn fn_getAttachVertID fco = ( local Result = "" append Result (Selection[1].name + "\t" + Selection[2].name + "\n") for i = 1 to sortVset.count do append Result ((sortVset[i][1]-1) as string + "\t" + (sortVset[i][2]-1) as string + "\n") if sortVset[1][1] != undefined do format Result ) fn fn_initialVert fco = (arV = for i = 1 to 2 collect (fco.getSelection #Vertex node: selection[i]) as array) fn fn_PairV_Collapse = ( toolMode.coordsys #view fco = modPanel.getCurrentObject() if selection.count != 2 or classof fco != Edit_Poly then messageBox "Please select 2 objects and assigne Edit Poly modifier" else if ((fco.getselection #vertex node: selection[1]).numberset == 0 or (fco.getselection #vertex node: selection[2]).numberset == 0) then messageBox "Expected selected vertices of both objects" else ( fn_initialVert fco if arV[1].count != arV[2].count do messageBox ( "First object" + "\t" + Selection[2].name + ":" + "\t" + arV[2].count as string + " vertex selected" + "\n" + \ "Second object " + "\t" + Selection[1].name + ":" + "\t" + arV[1].count as string + " vertex selected" ) fn_sortVsetMaker fco if sortVset.count != 0 do ( fn_getAttachVertID fco case stateOp of ( 1: fn_ScA fco 2: fn_ScMid fco 3: fn_ScB fco ) fn_setVert fco PushPrompt ((sortVset.count*2) as string + " vertex write to Listener (F11)") ) ) ) gco = modPanel.getCurrentObject() if selection.count != 2 or classof gco != Edit_Poly then messageBox "Please select 2 objects and assigne Edit Poly modifier" else if ((gco.getselection #vertex node: selection[1]).numberset == 0 or (gco.getselection #vertex node: selection[2]).numberset == 0) then messageBox "Expected selected vertices of both objects" else ( fn_initialVert gco try DestroyDialog PVC_Rollout catch() rollout PVC_Rollout "PVC" width:154 height:90 ( spinner DISTANCE_direct "Distance: " pos:[14,2] width:107 height:16 range:[0,100,1.5] scale: 0.01 button btn1 "Collapse to object A" pos:[2,20] width:150 height:22 button btn2 "Collapse to MidPos" pos:[2,43] width:150 height:22 button btn3 "Collapse to object B" pos:[2,67] width:150 height:22 button btn4 "\x95" pos:[137,2] width:16 height:16 toolTip: "Recreate helper point" colorpicker theColor "" color:[255,0,255] pos:[120,2] width:16 height:16 modal:false on btn1 pressed do ( stateOp = 1 try (fn_PairV_Collapse()) catch() ) on btn2 pressed do ( stateOp = 2 try (fn_PairV_Collapse()) catch() ) on btn3 pressed do ( stateOp = 3 try (fn_PairV_Collapse()) catch() ) on PVC_Rollout open do ( btn1.caption = ("Move to " + selection[1].name) btn3.caption = ("Move to " + selection[2].name) btn1.toolTip = selection[1].name btn3.toolTip = selection[2].name fn fn_sortVsetMaker fco = ( Count1 = arV[1].count Count2 = arV[2].count sortVset = #() i = 1 while (i <= Count1) do ( j = 1 while (j <= Count2) do ( a = (fco.GetVertex arV[1][i] node: selection[1]) b = (fco.GetVertex arV[2][j] node: selection[2]) if (distance a b) < DISTANCE_direct.Value do ( append sortVset #(arV[1][i], arV[2][j]) deleteItem arV[1] i; Count1 -= 1 deleteItem arV[2] j; Count2 -= 1 i -= 1 j -= 1 exit() ) j += 1 ) i += 1 ) ) fn fn_GizmoSphere fco = ( with redraw off ( aGizm = VolumeHelper pos:(fco.GetVertex arV[1][1] node: selection[1]) size: DISTANCE_direct.Value wirecolor: ColorSet volumeType: 1 name:"Gizmo Sphere" aGizm.showFrozenInGray = off freeze aGizm ) ) fn_GizmoSphere gco ) on theColor changed new_col do ( aGizm.wirecolor = ColorSet = new_col ) on DISTANCE_direct changed arg do aGizm.size = arg on btn4 pressed do ( try delete aGizm catch() gco = modPanel.getCurrentObject() if ((gco.getselection #vertex node: selection[1]).numberset == 0 or (gco.getselection #vertex node: selection[2]).numberset == 0) then messageBox "Expected selected vertices of both objects" else ( fn_initialVert gco fn_GizmoSphere gco ) ) on PVC_Rollout close do ( try delete aGizm catch() escapeEnable = false ) -- Обработка нажатия Esc on PVC_Rollout escape do ( try delete aGizm catch() DestroyDialog PVC_Rollout ) ) createDialog PVC_Rollout escapeEnable:true ) )