-- ScaleRiggs.ms /* Scale all Hierarchies and skinned meshes in scene. Note: Skin modifiers only (not Physique). Works with Biped Systems or Bone Riggs Scale center at [x, y] of Hierarchy Root and z: 0.0 Thanks to fooFunctions from www.footools.com. version 0.12 correct amount of riggs and bones in skins scale all riggs in scene (being selected or not) version 0.11 original */ ( struct ScaleRiggs_struct ( rootNodes = #(), boneObjs = #(), ScaleRigg_rollout, ScaleFloater ) ScaleRiggs_str = ScaleRiggs_struct() /* parentObjs = #() parentMeshes = #() Skinnedmeshes = #() */ fn GetChildren parent depth:-1 objArray:undefined = ( if objArray == undefined then objArray = #() if depth == 0 then return() else depth -= 1 for child in parent.children do ( append objArray child getChildren child objArray:objArray depth:depth ) return objArray ) fn GetHierarchyRoot obj = ( local theParent = obj while theParent.parent != undefined do theParent = theParent.parent theParent ) fn GetHierarchy obj = ( local rootObj = getHierarchyRoot obj local kids = getChildren rootObj (#(rootObj) + kids) ) fn bonesInSkinMods objsArray = ( -- collect all objects in the scene included in a Skin modifier as a bone local objInSkinMod = #() local skinMods for obj in objsArray where obj != undefined do ( local inSkinMod = false for each in refs.dependentNodes obj where each != undefined and classof each == Editable_mesh do ( skinMods = for mod in each.modifiers where getClassName mod == "Skin" collect mod if skinMods.count > 0 do inSkinMod = true ) if inSkinMod do append objInSkinMod obj ) objInSkinMod ) fn skinedWithThisBones bonesArray = ( -- collect all meshes in the scene with a skin modifier local objsWithSkinMod = #() for boneInRigg in bonesArray where boneInRigg != undefined do ( for each in refs.dependentNodes boneInRigg where each != undefined and classof each == Editable_mesh do ( skinMods = for mod in each.modifiers where getClassName mod == "Skin" collect mod if skinMods.count > 0 do appendIfUnique objsWithSkinMod each ) ) if objsWithSkinMod.count > 0 then objsWithSkinMod else #() ) fn scaleRigg rootN bObjs SkinM scaleFactor = ( parentMeshes = #() figureMode = false alwaysDeformWasOn = false if classof rootN == Biped_Object do ( -- Set Figure Mode to Bipeds if rootN.controller.figureMode == false do ( rootN.controller.figureMode = true figureMode = true ) ) parentObjs = for obj in bObjs collect obj.parent parentMeshes = for obj in SkinM collect obj.parent groundPos = [rootN.transform.pos.x, rootN.transform.pos.y, 0.0] tempPt = point pos:groundPos -- create a temporal point to use as master scale for i in 1 to bObjs.count do bObjs[i].parent = tempPt skinDataMeshes = #() for i=1 to SkinM.count do ( -- parent all meshes with a skin modifier to the temporal point skinMods = for mod in SkinM[i].modifiers where getClassName mod == "Skin" collect mod for skinS in skinMods do ( -- turn off skin modifiers if skinS.always_deform == true do alwaysDeformWasOn = true skinS.always_deform = false -- turn off skin modifier ) -- create a mesh with skin data temp = if (skinUtils.ExtractSkinData SkinM[i]) == OK then (execute ("$'SkinData_" +SkinM[i].name + "'")) else undefined append skinDataMeshes temp SkinM[i].parent = tempPt skinDataMeshes[i].parent = tempPt ) tm = tempPt.transform scale tm [scaleFactor, scaleFactor, scaleFactor] tempPt.transform = tm delete tempPt --for o in boneNodes do print o.name resetScale bObjs resetScale SkinM if classof rootN == Biped_Object do ( rootN.controller.height *= scaleFactor if figureMode do rootN.controller.figureMode = false -- Reset Figure Mode to Bipeds ) for i in 1 to bObjs.count do if parentObjs[i] != undefined do bObjs[i].parent = parentObjs[i] -- Relink everything for i = 1 to SkinM.count do ( -- paste skin data select SkinM[i] selectMore (execute ("$'SkinData_" + SkinM[i].name + "'")) if selection.count == 2 and skinDataMeshes[i] != undefined do ( temp = skinUtils.ImportSkinDataNoDialog true false false false false 1.0 0 -- match by vertex if temp != OK then format "Cannot copy Skin data from $'%'\n" SkinM[i].name else delete skinDataMeshes[i] ) if alwaysDeformWasOn do ( -- turn on skin modifier skinMods = for mod in SkinM[i].modifiers where getClassName mod == "Skin" collect mod for skinS in skinMods do SkinS.always_deform = true ) ) ) for obj in objects do ( if classof obj == Biped_Object then appendIfUnique ScaleRiggs_str.rootNodes obj.controller.rootnode -- collect biped COMs else appendIfUnique ScaleRiggs_str.rootNodes (GetHierarchyRoot obj) -- collect root hierarchies in bone riggs -- collect all childrens of the Hierarchy, provided they are not part of a biped system (not extra bones, Nub dummies, etc.) for child in (getChildren obj) where classof child.controller != BipSlave_Control and classof child.controller != Footsteps do appendIfUnique ScaleRiggs_str.boneObjs child ) fn scaleAllRiggs SkinM scaleFactor = ( disableSceneRedraw() for i = 1 to ScaleRiggs_str.rootNodes.count do ( -- for any hierarchy root ScaleRiggs_str.boneObjs = #(ScaleRiggs_str.rootNodes[i]) + (for obj in getChildren ScaleRiggs_str.rootNodes[i] collect obj) -- collects the complete hierarchy if classof ScaleRiggs_str.rootNodes[i] == Biped_Object do ( -- for Bipeds we need to scale just the COM and extra bones linked to it. Not any other biped limb. for i = ScaleRiggs_str.boneObjs.count to 1 by -1 where classof ScaleRiggs_str.boneObjs[i] == Biped_Object or (classof ScaleRiggs_str.boneObjs[i] == Dummy and (substring ScaleRiggs_str.boneObjs[i].name (ScaleRiggs_str.boneObjs[i].name.count-2) 3) == "Nub") do deleteItem ScaleRiggs_str.boneObjs i ) -- Skinnedmeshes = skinedWithThisBones ScaleRiggs_str.boneObjs -- collects all meshes skinned with these hierarchies scaleRigg ScaleRiggs_str.rootNodes[i] ScaleRiggs_str.boneObjs SkinM scaleFactor ) enableSceneRedraw() ) tempBonesInSkins = #() for obj in ScaleRiggs_str.rootNodes do ( tempBonesInSkins += (GetChildren obj) ) tempBonesInSkins += ScaleRiggs_str.rootNodes Skinnedmeshes = skinedWithThisBones tempBonesInSkins for obj in Skinnedmeshes do ( if (tempItem = findItem ScaleRiggs_str.rootNodes obj) != 0 do deleteItem ScaleRiggs_str.rootNodes tempItem ) tempItems = #("Inches", "Feet", "Miles", "Millimeters", "Centimeters", "Meters", "Kilometers") temp = units.SystemType as string temp = toUpper (substring temp 1 1) + substring temp 2 (temp.count-1) tempSel = findItem tempItems temp tempVal = units.SystemScale as string rollout ScaleRigg_rollout "Scale Riggs and Skinned Meshes" width:244 height:100 ( fn unitFactor val sel = ( case tempItems[sel] of ( "Inches" : temp = "\"" "Feet" : temp = "'" "Miles" : temp = "FL" "Millimeters" : temp = "mm" "Centimeters" : temp = "cm" "Meters" : temp = "m" "Kilometers" : temp = "km" ) units.decodeValue (val+temp) ) GroupBox unitFrom "Units from" pos:[3,0] width:230 height:50 label lbl1 "1 Unit = " pos:[14,23] width:49 height:21 edittext valFrom "" pos:[63,23] width:64 height:17 fieldwidth:70 labelOnTop:false text:"1.0" dropdownList typeFrom "" pos:[137,21] width:90 height:23 items:tempItems selection:1 GroupBox unitTo "Scaled to" pos:[3,52] width:230 height:50 label lbl2 "1 Unit = " pos:[14,74] width:49 height:21 edittext valTo "" pos:[63,74] width:64 height:17 fieldwidth:70 labelOnTop:false text:tempVal dropdownList typeTo "" pos:[137,72] width:90 height:23 items:tempItems selection:tempSel label lbl4 "Riggs:" pos:[14,110] width:146 height:18 label Riggs_label "0" pos:[60,110] width:57 height:15 label lbl6 "Bones In Skins:" pos:[124,110] width:146 height:18 label Bones_label "0" pos:[216,110] width:57 height:15 label lbl7 "Skinned Meshes:" pos:[14,130] width:146 height:18 label skinned_label "0" pos:[110,130] width:57 height:15 label lbl8 "Scale Factor (to / from):" pos:[14,150] width:146 height:18 label scale_label "0.00" pos:[194,150] width:57 height:15 button start_convert "GO!" pos:[5,170] width:226 height:22 toolTip:"to Scale Riggs" fn scaleTxt = ( temp = (unitFactor valFrom.text typeFrom.selection) as string temp += " / " + (unitFactor valTo.text typeTo.selection) as string ) on ScaleRigg_rollout open do ( Riggs_label.text = ScaleRiggs_str.rootNodes.count as string Bones_label.text = ScaleRiggs_str.boneObjs.count as string skinned_label.text = Skinnedmeshes.count as string scale_label.text = execute (scaleTxt()) as string ) on typeTo selected val do scale_label.text = execute (scaleTxt()) as string on typeFrom selected val do scale_label.text = execute (scaleTxt()) as string on valFrom entered val do ( valFrom.text = if val as float != undefined then val else "1.0" scale_label.text = execute (scaleTxt()) as string ) on valTo entered val do ( valTo.text = if val as float != undefined then val else "1.0" scale_label.text = execute (scaleTxt()) as string ) on start_convert pressed do ( scaleFactor = execute (scaleTxt()) scaleAllRiggs Skinnedmeshes scaleFactor closeRolloutFloater ScaleRiggs_str.ScaleFloater ) ) rollout about_rollout "About" width:244 height:100 ( label lbl20 "Created by Fernando Ferro" pos:[50,6] width:226 height:30 align:#center label lbl22 "Email: fferro@hotmail.com " pos:[52,24] width:226 height:17 label lbl17 "Version:" pos:[80,40] width:41 height:14 label lbl18 "0.10" pos:[130,40] width:35 height:16 ) try(destroyDialog ScaleRigg_rollout) catch() function MakerolloutFloat = ( if undefined != ScaleRiggs_str.ScaleFloater then closeRolloutFloater ScaleRiggs_str.ScaleFloater ScaleRiggs_str.ScaleFloater = newRolloutFloater "Scale Characters" 250 268 addRollout ScaleRigg_rollout ScaleRiggs_str.ScaleFloater rolledup:false addRollout About_rollout ScaleRiggs_str.ScaleFloater rolledup:true ) MakerolloutFloat() )