As promised I have returned with some Maxscript to share with you my loyal readers. You should know that I am no Maxscripting guru. In fact, I have only spent about 12 hours writing Maxscript so far. Luckily I find Maxscript to be similar to Python in many ways, so the transition is tough, but not too bad.
I would like to start off by giving some background into what I am trying to accomplish at this stage of my project. If you have been following along, then you have seen the rig I built by hand as a template for what I want to construct using Maxscript. There are many ways to go about scripting that rig, but I prefer to keep my rigging systems modular enough that I can build a rig for any type of creature that comes down the pipe. To that end I intend to use layout templates for each rigging component. To facilitate identifying one template from another in my scene, I have decided to leverage the user defined object properties of the root template object in my scene. If you don’t know what user defined object properties are, then right click on any object in your Max scene and look for “object properties”. You will then find a tab titled “user defined”. When you click this tab you will find a blank text field where you can type in anything you like. In my case, I will define things like “Layout Type”. Once I get the spine done, I will upload my Max file so you can see what I am doing here. So the idea is to use a layout object. In the case of the spine, I will be using a simple chain of helper objects to define the position of my spine Bones.
I can then import that template into the file with the character I intend to rig. With the template imported, I run a script and presto! I have a spine rig.
Thus far I have written some simple code that will find the children of the root template object. I have hard coded the name of my root object for testing purposes, but later on I will identify the root by looking for it’s object properties. I then find the child of each template object, and create pairs of parent and child object which are then stored in an array. Using that array I can build sets of helper objects that are later used as the start and end joints for ik chains. At this stage my code is messy and full of notes and comments, but I am ok with that. In my time as a Technical Artist I have learned several important lessons, but I think these two lessons are of paramount importance when it comes to any endeavor.
- Show your work often.
- Quickly make your mistakes so you can get them out of the way.
Thanks again for reading my ramblings. Before I log out, I leave you with my code.
--struct bp_info (bp_name, bpChild_name, bp_xform) -- Function to get all the children of a defined object fn addChildren obj hierarchy = ( -- add object to the array append hierarchy obj -- loop over children and recursively add their children for child in obj.children do addChildren child hierarchy hierarchy ) fn addSubChild = ( bpData = #() c = addChildren $BP_SplineRoot #() for i in c where i.children[1] != undefined do append bpData #(i, i.children[1]) return bpData ) fn drawBone = ( local bpBones = #() stuff = addSubChild() for item in stuff do( parentBP = item[1] childBP = item[2] parentBoneName = substitutestring parentBP.name "BP" "Bone" childBoneName = substitutestring childBP.name "BP" "CapBone" parentPos = parentBP.transform childPos = childBP.transform new_ParentBone = point name:parentBoneName size:10 box:on cross:off new_ChildBone = point name:childBoneName size:5 box:on cross:off new_ChildBone.parent = new_ParentBone new_ParentBone.transform = parentPos new_ChildBone.transform = childPos new_ParentBone.wirecolor = color 140 88 225 new_ChildBone.wirecolor = color 196 88 225 append bpBones #(new_ParentBone, new_ChildBone) ) return bpBones ) fn drawIKSpline bpBoneData = ( -- Draw an HIK between each parent / child grp for ikBone in bpBoneData do( solverName = substitutestring ikBone[1].name "Bone" "IK" IKChain = IKSys.ikChain ikBone[1] ikBone[2] "IKHISolver" IKChain.name = solverName ) -- Question: What is .count for? ) fn mainFunction = ( local bpBoneData = drawBone () local ikInfo = drawIKSpline bpBoneData ) mainFunction() -- These are some new concepts I got. I will save them here for later. --data = #() --for node in helpers while data.count == 0 where node.children[1] != undefined do append data #(node, node.children[1]) --for node in helpers collect #(node, node.children[1])


