[Closed] from maxscript utility to free floating window
Ih,
I d like to modify the wonderful Bret Kroll script to create simple a drag n drop *.ms to open the window on max viewport. I don’t like the maxscript utility use.
anyone could do that for me? thx!!
the link:
http://www.scriptspot.com/3ds-max/mirrorverts
or
the script:
– Script by: Bret Kroll (bk@brekroll.com)
– copyright © 2004– Script updated on: September 05, 2004
– Description: mirror vertices from left to right side or vice versa for one model or across two models
– Requirements:
– 1. Max 5 or Max 6
– 2. models must be either editable mesh or editable poly
– 3. source, base & target model must all have their symmetry plane at x=0– Instructions:
– 1. run mirrorVerts.ms
– 2. select mirrorVerts from Utilities dropdown list
– 3. in the front view, select all vertices from the source model whose x-position < 0.0 and be careful not to select any
– vertices that lie on x = 0.0 because a pair will be calculated
– 4. within the mirrorVerts rollout window, use the selectSourceModel pickbutton to select the source model which has perfect symmetry
– 5. click the recordVertPairs button which will prompt you to select or create a .dat file to store the vertex pair data
– 6. after selecting the file and clicking Save, the progress bar will display the progress in calculating the vertex pair data
– 7. after all the data has been calculated and saved, click the loadVertPairs to load the vertex pair data into the interface
– 8. use the selectBaseModel pickbutton to select the base model which will pass the updated vertex data
– 9. use the selectTargetModel pickbutton to select the target model which will receive the updated vertex data
– 10. select the appropriate mirror option and click the mirrorVerts button to transfer the vertex data– Extras:
– 1. since the vertex pair data file is saved externally, you can close the Max file and reuse the data later
– 2. for the mirror options, L corresponds to the vertices to the left of the symmetry plane in the front view and thus
– R corresponds to the vertices to the right of the symmetry plane in the front view
– 3. the base and target model can be the same model
– 4. this is a great tool for creating morph targets with movements isolated to one side of the model
– 5. since every model must have symmetry plane at x=0, after clicking any of the pickbuttons, press the “h” key to easily
– select the model from the Select Objects Dialog– Errors: please report any bugs to http://forums.cgsociety.org/bk@bretkroll.co m” data-bbcode=”true”>bk@bretkroll.com
– Suggestions / Comments: please email me at http://forums.cgsociety.org/bk@bretkroll.co m” data-bbcode=”true”>bk@bretkroll.com
– location of file which will store vert pair data
global outputFileName
– file handle which will store all vert pair data
global outputFile
– array which will store the recorded vertex pairs
global objVertPairs = #()
– make rollout global in order to gain access to any of its controls
global mv– purpose: finds the distance between two passed vertices
fn calcDisVerts position1 position2 = (distanceX = (position1.x - position2.x) * (position1.x - position2.x) distanceY = (position1.y - position2.y) * (position1.y - position2.y) distanceZ = (position1.z - position2.z) * (position1.z - position2.z) hypotenuseDistanceXYZ = sqrt(distanceX + distanceY + distanceZ) as float return hypotenuseDistanceXYZ
)
– purpose: update progress bar / percentage
fn updateProgressBar val =
(
mv.pb_vertPairs.value = val
mv.lb_vertPairs.text = ((val as integer) as string) + “%”
)– purpose: main function that handles recording vertex pairs
fn recordVertPairs meshObj =
(
– all verts for model object
local objVertsAll = #()
– selected verts for model object
local objVertsSel = #()
– all verts minus selected verts for model object
local objVertsQuery = #()-- find total num of verts numVertsAll = meshObj.numVerts -- fill objVertsAll with just index number for i=1 to numVertsAll do ( append objVertsAll i ) -- find num of selected verts numVertsSel = meshObj.selectedVerts.count -- output number of selected vertices format "%
” numVertsSel to:outputFile
-- fill objVertsSel with just index number of selected verts for i=1 to numVertsSel do ( vertIndex = meshObj.selectedVerts[i].index append objVertsSel vertIndex ) -- create a new array that we will use to test against -- the selected verts, it will contain all the verts minus -- the selected verts for i=1 to objVertsAll.count do ( if (findItem objVertsSel i) == 0 then ( append objVertsQuery i ) ) -- for each selected verts, test all the non-selected verts to find which one is its -- mirror vert -- take the absolute value of x because we will assume the model's origin is at x=0 for i=1 to numVertsSel do ( mirrorVertPos = meshObj.verts[objVertsSel[i]].pos mirrorVertPos.x = abs(mirrorVertPos.x) shortDis = calcDisVerts mirrorVertPos meshObj.verts[objVertsQuery[1]].pos mirrorVertIndex = objVertsQuery[1] for j=2 to objVertsQuery.count do ( testDis = calcDisVerts mirrorVertPos meshObj.verts[objVertsQuery[j]].pos if testDis < shortDis then ( shortDis = testDis mirrorVertIndex = objVertsQuery[j] ) ) -- create mirror verts pair vertPair = #() append vertPair objVertsSel[i] append vertPair mirrorVertIndex -- output vertex pair format "%
” vertPair to:outputFile
-- remove mirrorVertIndex from stack so it will not be tested again vertIndex = findItem objVertsQuery mirrorVertIndex deleteItem objVertsQuery vertIndex -- update progress bar updateProgressBar (((i as float) / (numVertsSel as float) ) * 100) ) subobjectLevel = 0 clearSelection()
)
– purpose: parse outputFile and store contents in global variable
fn parseOutputFile =
(-- first line in outputFile will be the number of vertex pairs local numVertPairs = (readline outputFile) as integer local vertPair -- loop through each vertex pair and record it for i=1 to numVertPairs do ( vertPair = execute((readline outputFile)) -- store vertPair append objVertPairs vertPair -- update progress bar updateProgressBar (((i as float) / (numVertPairs as float) ) * 100) )
)
– purpose: main function for mirroring verts pairs
fn mirrorVertPairs baseObj targetObj mirrorOption =
(local baseObjVertPos if ((classof baseObj as string) == "Editable_Poly" or (classof baseObj as string) == "Editable_mesh") and ((classof targetObj as string) == "Editable_Poly" or (classof targetObj as string) == "Editable_mesh") then ( -- mirror vert pairs if mirrorOption == 1 then ( -- (L -> L) for i=1 to objVertPairs.count do ( -- pull vertex position for base object baseObjVertPos = baseObj.verts[objVertPairs[i][1]].pos -- set vertex position for base object (use proper call) if (classof targetObj as string) == "Editable_Poly" then ( polyOp.setVert targetObj objVertPairs[i][1] baseObjVertPos ) else ( meshOp.setVert targetObj objVertPairs[i][1] baseObjVertPos ) ) ) else if mirrorOption == 2 then ( -- (R -> R) for i=1 to objVertPairs.count do ( -- pull vertex position for base object baseObjVertPos = baseObj.verts[objVertPairs[i][2]].pos -- set vertex position for base object (use proper call) if (classof targetObj as string) == "Editable_Poly" then ( polyOp.setVert targetObj objVertPairs[i][2] baseObjVertPos ) else ( meshOp.setVert targetObj objVertPairs[i][2] baseObjVertPos ) ) ) else if mirrorOption == 3 then ( -- (L -> R) for i=1 to objVertPairs.count do ( -- pull vertex position for base object baseObjVertPos = baseObj.verts[objVertPairs[i][1]].pos -- need to multiply -1 to x-position baseObjVertPos.x = -1 * baseObjVertPos.x -- set vertex position for base object (use proper call) if (classof targetObj as string) == "Editable_Poly" then ( polyOp.setVert targetObj objVertPairs[i][2] baseObjVertPos ) else ( meshOp.setVert targetObj objVertPairs[i][2] baseObjVertPos ) ) ) else( for i=1 to objVertPairs.count do ( -- (R -> L) -- pull vertex position for base object baseObjVertPos = baseObj.verts[objVertPairs[i][2]].pos -- need to multiply -1 to x-position baseObjVertPos.x = -1 * baseObjVertPos.x -- set vertex position for base object (use proper call) if (classof targetObj as string) == "Editable_Poly" then ( polyOp.setVert targetObj objVertPairs[i][1] baseObjVertPos ) else ( meshOp.setVert targetObj objVertPairs[i][1] baseObjVertPos ) ) ) ) else( messageBox "base / target model both must be either an editable poly or editable mesh!" )
)
– create mirrorVerts interface
rollout mv “mirrorVerts”
(
– create selectSourceModel pickButton
pickButton pn_selectSourceModel ” selectSourceModel ” pos:[5,15] width:105
– create sourceModelName editText label
editText et_sourceModelName “” pos:[110,15] width:105 text:” source model ” enabled:false
– create recordVertPairs button
button bn_recordVertPairs ” recordVertPairs ” pos:[5,40] width:105 enabled:false
– create loadVertPairs button
button bn_loadVertPairs ” loadVertPairs ” pos:[111,40] width:105
– create progress bar
progressBar pb_vertPairs pos:[5,70] value:0 width:165 height:15 across:2
– create progress label
label lb_vertPairs “0%” offset:[0,5] align:#right
– create selectBaseModel pickButton
pickButton pn_selectBaseModel ” selectBaseModel ” pos:[5,100] width:105
– create baseModelName editText label
editText et_baseModelName “” pos:[110,100] width:105 text:” base model ” enabled:false
– create selectTargetModel pickButton
pickButton pn_selectTargetModel ” selectTargetModel ” pos:[5,125] width:105
– create targetModelName editText label
editText et_targetModelName “” pos:[110,125] width:105 text:” target model ” enabled:false
– create mirrorOptions label
label lb_mirrorOptions “mirror options (base -> target)” pos:[7,155]
– create mirrorOptions radiobutton
radioButtons rb_mirrorOptions labels:#(“L -> L”,“R -> R”, “L -> R”, “R -> L”) columns:1 pos:[7,175]
– create mirrorVerts button
button bn_mirrorVerts ” mirrorVerts ” pos:[95,195] width:105 enabled:false
– create copyright label
label lb_copyright ” copyright © 2004 – Bret Kroll ” pos:[40,245] enabled:false-- store name of chosen model local sourceModelObj, baseModelObj, targetModelObj on pn_selectSourceModel picked obj do ( -- set sourceModelObj to selected model sourceModelObj = obj -- set et_sourceModelName with name of selected model et_sourceModelName.text = sourceModelObj.name -- enable bn_recordVertPairs button bn_recordVertPairs.enabled = true ) on pn_selectBaseModel picked obj do ( -- set baseModelObj to selected model baseModelObj = obj -- set et_baseModelName with name of selected model et_baseModelName.text = baseModelObj.name -- enable mirrorVerts button if target model has been picked and vertPairs has been loaded if et_targetModelName.text != " target model " and objVertPairs.count != 0 then ( bn_mirrorVerts.enabled = true ) ) on pn_selectTargetModel picked obj do ( -- set targetModelObj to selected model targetModelObj = obj -- set et_targetModelName with name of selected model et_targetModelName.text = targetModelObj.name -- enable mirrorVerts button if base model has been picked and vertPairs has been loaded if et_baseModelName.text != " base model " and objVertPairs.count != 0 then ( bn_mirrorVerts.enabled = true ) ) -- run recordVertPairs function on bn_recordVertPairs pressed do ( -- choose output file location outputFileName = getSaveFileName types:"Data(*.dat)|*.dat|" -- create output file which will store vert pairs data \ outputFile = createFile outputFileName -- reset progressBar value / percentage mv.pb_vertPairs.value = 0.0 mv.lb_vertPairs.text = "0%" -- run record procedure recordVertPairs sourceModelObj -- close output file close outputFile -- make sure mirrorVerts button is disabled because they need to be loaded bn_mirrorVerts.enabled = false ) -- run loadVertPairs function on bn_loadVertPairs pressed do ( -- reset variable objVertPairs = #() -- find output file location outputFileName = getOpenFileName types:"Data(*.dat)|*.dat|" -- open output file which contains all skinning data outputfile = openFile outputFileName -- reset progressBar value / percentage mv.pb_vertPairs.value = 0.0 mv.lb_vertPairs.text = "0%" -- parse output file parseOutputFile() -- close input file close outputfile -- enable mirrorVerts button if both base/target model has been picked if et_baseModelName.text != " base model " and et_targetModelName.text != " target model " then ( bn_mirrorVerts.enabled = true ) ) -- run mirrorVerts function on bn_mirrorVerts pressed do ( -- get mirrorOptions state local mirrorOptionsState = rb_mirrorOptions.state -- run mirrorVertPairs procedure mirrorVertPairs baseModelObj targetModelObj mirrorOptionsState -- redraw all views redrawViews() )
)
– create mirrorVerts window
utility mirrorVerts “mirrorVerts”
(
on mirrorVerts open do
(
mirrorVerts_window = newRolloutFloater “mirrorVerts” 235 295 200 200
addrollout mv mirrorVerts_windowformat "
******* mirrorVerts interface sucessfully loaded *******
“
))
Hi,
Replace the create mirrorVerts window part with this:
mirrorVerts_window = newRolloutFloater “mirrorVerts” 235 295 200 200
addrollout mv mirrorVerts_window
Light