-- Pair_Vertex_Collapser.ms
-- By Nikolay Litvinov (gniklit@gmail.com)
-- Created On: 2015-07-17
-- Modified: 2016-03-14
-- tested using Max 2012
messageBox "Category: \"Niklit Scripts\""
MacroScript Pair_Vertex_Collapser category:"Niklit Scripts" toolTip:"Pair Vertex Collapser" icon:#("UVWUnwrapTools",4)
(
escapeEnable=true
global arV =#()
global sortVset=#()
global DISTANCE_direct, sel0
global GizmoSphere_fn()
global fn_sortVsetMaker()
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][1]} node: selection[1]
setVertSelection selection[2] fco #{sortVset[i][2]} keep:on
aPos=(fco.GetVertex 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 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]
setVertSelection selection[1] fco #{sortVset[i][1]} keep:on
setVertSelection selection[2] fco #{sortVset[i][2]} keep:on
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]
setVertSelection selection[1] fco #{sortVset[i][1]} keep:on
--fco.select #vertex #{sortVset[i][2]} node: selection[2]
--aPos=(fco.GetVertex 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
(
setVertSelection selection[1] fco ba_arV1 keep:on
setVertSelection selection[2] fco ba_arV1 keep:on
)
)
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 (clearlistener(); format Result)
)
fn fn_initialVert=(arV=For i=1 to 2 collect (getvertselection selection[i].mesh)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 (getvertselection selection[1].mesh).numberset==0 or (getvertselection selection[2].mesh).numberset==0 then messageBox "Expected selected vertices of both objects" else
(
fn_initialVert()
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 (getvertselection selection[1].mesh).numberset==0 or (getvertselection selection[2].mesh).numberset==0 then messageBox "Expected selected vertices of both objects" else
(fn_initialVert()
(
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,0.04] scale: 0.005
button btn1 "Collapse to object A" pos:[2,20] width:150 height:22
button btn2 "Move 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"
on btn1 pressed do
with undo on
(
stateOp=1
fn_PairV_Collapse()
)--fn_ScA
on btn2 pressed do
with undo on
(
stateOp=2
fn_PairV_Collapse()
)--fn_ScMid
on btn3 pressed do
with undo on
(
stateOp=3
fn_PairV_Collapse()
)--fn_ScB
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
)
)
sel0=selection as array
fn GizmoSphere_fn fco=(SphereGizmo radius:DISTANCE_direct.Value pos:(fco.GetVertex ((getvertselection selection[1].mesh)as array)[1]) isSelected:off name: "SphereGizmo_PVC"; select sel0; subobjectlevel=1)
GizmoSphere_fn gco
)
on DISTANCE_direct changed arg do $SphereGizmo_PVC.radius=arg
on btn4 pressed do
(
try delete $SphereGizmo_PVC catch()
gco=modPanel.getCurrentObject()
if (getvertselection selection[1].mesh).numberset==0 or (getvertselection selection[2].mesh).numberset==0 then messageBox "Expected selected vertices of both objects" else
(fn_initialVert()
GizmoSphere_fn gco)
)
on PVC_Rollout close do try delete $SphereGizmo_PVC catch()
)--End Rollout
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
createDialog PVC_Rollout
)
)
)