-- cometWeightTable.ms - Michael B. Comet - comet@comet-cartoons.com -- http://www.comet-cartoons.com -------------------------------------------------------------------------------- -- Copyright ©2001 Michael B. Comet All Rights Reserved -------------------------------------------------------------------------------- -- There are no warranties as to the usability, functionality or safety of -- this tool. The author is not responsible for any loss of work, data, -- or money caused by using this tool. Use at your own risk. -------------------------------------------------------------------------------- -- -- DESCRIPTION: -- -- This script does a Maya like Component editor, in that for the selected -- object, this will show the vertex "skin weights" for each bone in a -- table, for the top most skin modifier. And through editing the table, -- it allows you to easily set vertex weights for multiple vertices at once. -- Works in MAX 4.0 with objects that have a Skin modifier on them. -- -------------------------------------------------------------------------------- -- -- VERSIONS: -- -- Version 1.0 - 07/26/01 - Michael B. Comet - comet@comet-cartoons.com -- First pass at getting the script made. -- -- Version 1.01 - 07/27/01 - Michael B. Comet - comet@comet-cartoons.com -- Fixed errors where first time it was run, the data was not put into -- the dialog box or it gave errors. -- -------------------------------------------------------------------------------- -- -- USAGE: -- -- Take an object and apply the skin modifier, with some bones, like you are -- doing a regular skin. Then select some vertices inside the skin -- modifier's subobject mode. Run the script. Hit refresh to show the -- weights for the selected vertices. -- If you change the vertex selection, hit refresh again to show the -- weights for the newly selected vertices -- If you wish to show ALL vertices, not selected ones, check the "List All -- Vertices" button. NOTE: There is a limit of maxWtVERTS (defaults to -- 100) of verts shown in the list. Higher numbers may crash max. -- Use the "<<" and ">>" to scroll through pages of each bone left and right -- as needed if there are more bones than fit on screen at once -- Change weights by adjusting values in the spinner. -- The extra top row of spinners will adjust ALL selected vertices below it -- in the column for that bone. -- Selecting the Bone name buttons on top will select that bone in the skin -- modifier itself if it is up. -- Selecting the vertex # labels on the left has no effect. -- -------------------------------------------------------------------------------- ( /* * SETTINGS... */ global maxWtVERTS = 100; -- THis is the max # of verts the UI will display -- if it is too high, MAX may crash your system! /* * global vars */ --definition for the Vertex Weight Info struct struct VWI ( bidx, -- bone index array wt, -- weight array for each bone vi); -- the index of this vertex global vselidx=#(); global vdata = #(); -- the main data of VWI's... global skmod = undefined; global skObj = undefined; global listAll = false; global updateRowWT; -- function global ro_setupWT; -- rollout global ro_weightsWT global curpage=0; global printpage=1; global maxBonesPerPage = 5; global ro_wt_floater; -------------------------------------------------------------------------------- -- Functions -------------------------------------------------------------------------------- /* * readSkinData() - reads in the data used for the table */ fn readSkinData = ( obj = selection[1]; -- get first selected object skObj = obj; if (obj == undefined) then return(); try ( skmod = obj.skin; -- get topmost skin modifier ) catch ( skmod = undefined; ) if (skmod == undefined) then return(); vselidx = #(); vdata = #(); gc(); -- cleanup old memory -- Get a list of which verts are selected for i = 1 to obj.numverts do ( if (vselidx.count >= maxWtVERTS) then ( -- cap selected vert count messageBox ("Warning: Selected vert count too high\nLimiting to the first "+(maxWtVERTS as string)+" selected vertices") title:"cometWeightTable Warning" beep:true; exit; ) if (listAll == true or (skinops.isvertexselected skmod i) == 1) then ( vi = vselidx.count + 1; vselidx[vi] = i ) ) -- Now get data for the selected verts for i = 1 to vselidx.count do ( vi = vselidx[i]; numBones = skinops.getvertexweightcount skmod vi; vertD = VWI bidx:#() wt:#() vi:vi; for bli = 1 to numBones do ( bid = skinops.getvertexweightboneid skmod vi bli; vertD.bidx[bli] = bid; -- store true boneID idx # vertD.wt[bli] = skinops.getvertexweight skmod vi bli; ) vdata [ (vdata.count + 1) ] = vertD; ) ) /* * dumpSkinData() - does a Debug dump of all the skin data that was read in */ fn dumpSkinData = ( for d = 1 to vdata.count do ( format "DEBUG: vdata[%] bidx=% wt=% vi=% \n" d vdata[d].bidx vdata[d].wt vdata[d].vi; ) ) /* * updateRow() - refresh's a Row in the UI given a vdata index #. */ fn updateRowWT d = ( if (skmod == undefined) then ( return(); ) str = ""; -- Re-obtain the bone id's and weights for them. vi = vdata[d].vi; numBones = skinops.getvertexweightcount skmod vi; vdata[d].bidx=#(); vdata[d].wt=#(); for bli = 1 to numBones do ( bid = skinops.getvertexweightboneid skmod vi bli; vdata[d].bidx[bli] = bid; -- store true boneID idx # vdata[d].wt[bli] = skinops.getvertexweight skmod vi bli; ) totalBones = skinOps.GetNumberBones skmod; bnum = vdata[d].bidx.count; startbone = 1+curpage; endbone = startbone + maxBonesPerPage - 1; if (endbone > totalBones) then endbone = totalBones; for i in startbone to endbone do ( wt = 0.0; for b = 1 to bnum do ( if (vdata[d].bidx[b] == i) then ( -- does an assigned bone idx match the bone we are on table wise? wt = vdata[d].wt[b]; exit; ) ) str += "ro_weightsWT.vertWt"+(d as string)+"_"+(i as string)+".value = "+(wt as string)+";\n"; ) execute str; ) /* * refreshWT() - rebuilds the weight table rollout with new info */ fn refreshWT = ( if (skmod == undefined) then ( return(); ) -- remove old rollout if it exists execute( "removeRollout ro_weightsWT ro_wt_floater;" ); str=""; dostr="\n\n"; str += "rollout ro_weightsWT \"Weights: "+(skObj.name)+"\"\n";; str += "(\n"; str += "\n"; totalBones = skinOps.GetNumberBones skmod; /* -- resize it size = ro_wt_floater.size; size[1] = (140*(totalBones+1)) ro_wt_floater.size = size; */ startbone = 1+curpage; endbone = startbone + maxBonesPerPage - 1; if (endbone > totalBones) then endbone = totalBones; acrossBone = maxBonesPerPage; if (acrossBone > totalBones) then acrossBone = totalBones; -- First make Button label row str += "button boneAllBut \"Bone Selection >>\" width:120 enabled:false tooltip:\"This row selects bones\" offset:[0,0]; across:"+((acrossBone+1) as string)+"\n"; for i in startbone to endbone do ( bname = skinOps.GetBoneName skmod i 1; str += "button boneBut"+(i as string)+" \""+bname+"\" width:120 tooltip:\"Selects the bone\" offset:[0,0];\n"; dostr += "on boneBut"+(i as string)+" pressed do (\n"; dostr += " try ( skinops.selectbone skmod "+(i as string)+" ) \n"; dostr += " catch( format \"OOPS!: You must have the skin modifier selected in the modify panel!\\n\")\n"; dostr += " )\n"; ) -- Then do master weight row str += "button weightAllBut \"Column Weighting >>\" width:120 enabled:false tooltip:\"This row will weight an entire column\" offset:[0,0]; across:"+((acrossBone+1) as string)+"\n"; for i in startbone to endbone do ( bname = skinOps.GetBoneName skmod i 1; str += "spinner masterVertWt"+(i as string)+" \"\" range:[0.0,1.0,0.0] scale:0.01 type:#float fieldwidth:110 tooltip:\"Set weights in column\" align:#center offset:[0,0];\n"; dostr += "on masterVertWt"+(i as string)+" changed val do (\n"; dostr += " wt = val;\n"; dostr += " setWaitCursor();\n"; dostr += " for d in 1 to vdata.count do (\n"; dostr += " skinops.SetVertexWeights skmod vdata[d].vi "+(i as string)+" wt;\n"; dostr += " updateRowWT d;\n"; dostr += " )\n"; dostr += " masterVertWt"+(i as string)+".value = 0.0;\n"; dostr += " setArrowCursor();\n"; dostr += " )\n"; ) -- Then do each vertex for d = 1 to vdata.count do ( str += "button vertBut"+(d as string)+" \"Vtx "+(vdata[d].vi as string)+"\" width:120 enabled:true tooltip:\"Does nothing\" offset:[0,0]; across:"+((acrossBone+1) as string)+"\n"; for i in startbone to endbone do ( bnum = vdata[d].bidx.count; wt = 0.0; for b = 1 to bnum do ( if (vdata[d].bidx[b] == i) then ( -- does an assigned bone idx match the bone we are on table wise? wt = vdata[d].wt[b]; exit; ) ) str += "spinner vertWt"+(d as string)+"_"+(i as string)+" \"\" range:[0.0,1.0,"+(wt as string)+"] scale:0.01 type:#float fieldwidth:110 tooltip:\"Set weight\" align:#center offset:[0,0];\n"; dostr += "on vertWt"+(d as string)+"_"+(i as string)+" changed val do (\n"; dostr += " wt = val;\n"; dostr += " setWaitCursor();\n"; dostr += " skinops.SetVertexWeights skmod "+(vdata[d].vi as string)+" "+(i as string)+" wt;\n"; dostr += " updateRowWT "+(d as string)+";\n"; dostr += " setArrowCursor();\n"; dostr += " )\n"; ) ) str += dostr+"\n"; str += ")\n\n"; execute str; -- now make the weights Rollout str = "addRollout ro_weightsWT ro_wt_floater;"; execute str; -- do this via execute too in case 1st time. str = "ro_setupWT.but_prev.enabled = true;\n"; -- enable it! str += "ro_setupWT.but_next.enabled = true;\n"; -- enable it! execute str; ) -------------------------------------------------------------------------------- -- UI Rollouts -------------------------------------------------------------------------------- -- The weights rollout...since it's built on the fly...here it's just empty for now. rollout ro_weightsWT "Weights" ( ) -- Setup rollout rollout ro_setupWT "Setup" ( button but_refresh "Refresh" width:100 align:#left tooltip:"Refresh's/Rebuilds the weight table below." across:5; checkbox cbox_listAll "List All Vertices" width:100 checked:false align:#left tooltip:"When off, only selected verts are listed" offset:[-40,3]; button but_prev "<<" width:35 align:#left enabled:false tooltip:"Scroll Left" offset:[-5,0]; label lbl_page "1" width:36 tooltip:"Current Page" offset:[-135,0]; button but_next ">>" width:35 align:#left enabled:false tooltip:"Scroll Right" offset:[-180,0]; on but_refresh pressed do ( curpage = 0; printpage = 1; setWaitCursor(); readSkinData(); -- dumpSkinData(); refreshWT(); setArrowCursor(); ) on cbox_listAll changed state do ( listAll = state; ) on but_prev pressed do ( if (curpage > 0) then ( curpage -= maxBonesPerPage; if (curpage < 0) then curpage = 0; printpage -= 1; lbl_page.text = printpage as string; setWaitCursor(); refreshWT(); setArrowCursor(); ) ) on but_next pressed do ( totalBones = skinOps.GetNumberBones skmod; if (curpage + maxBonesPerPage < totalBones ) then ( curpage += maxBonesPerPage; if (curpage + maxBonesPerPage > totalBones ) then ( curpage = totalBones - maxBonesPerPage; ) printpage += 1; lbl_page.text = printpage as string; setWaitCursor(); refreshWT(); setArrowCursor(); ) ) ) -- The about rollout rollout ro_aboutWT "About" ( label abt_lbl1 "Version 1.01" label abt_lbl2 "Jul 26, 2001" label abt_lbl3 "" label abt_lbl4 "by Michael B. Comet" label abt_lbl5 "comet@comet-cartoons.com" label abt_lbl6 "http://www.comet-cartoons.com/" ) ro_wt_floater = (newRolloutFloater "Comet WeightTable 1.01" 800 450) addRollout ro_aboutWT ro_wt_floater rolledUp:true addRollout ro_setupWT ro_wt_floater addRollout ro_weightsWT ro_wt_floater rolledUp:true )