Sunday, March 20, 2011



My first update for the Ik arm rig script:

Having made sure my buttons work...it was time to put them to work...collecting information and doing stuff with that information...

The first actions should be creating the shapes for the wrist controller and the elbow pole vector controller...for now they are both boxes and have a set size...in later versions the size will be scalable by the user before the script runs..center their pivots...move the positions and orient the shapes to the bones...then align their pivots accordingly...and freeze their transformations...

To freeze transformations on an object I took a section of code provided by Max, since the tools provided by Max are macro's in themselves, and pasted it inside a function.

fn FreezeTransform item =
(
local CurObj = item

if classof CurObj.rotation.controller != Rotation_Layer do
(

-- freeze rotation
CurObj.rotation.controller = Euler_Xyz()
CurObj.rotation.controller = Rotation_list()
CurObj.rotation.controller.available.controller = Euler_xyz()
/* "Localization on" */
CurObj.rotation.controller.setname 1 "Frozen Rotation"
CurObj.rotation.controller.setname 2 "Zero Euler XYZ"
/* "Localization off" */
CurObj.rotation.controller.SetActive 2
)
if classof CurObj.position.controller != Position_Layer do
(

-- freeze position
CurObj.position.controller = Bezier_Position()
CurObj.position.controller = position_list()
CurObj.position.controller.available.controller = Position_XYZ()

/* "Localization on" */
CurObj.position.controller.setname 1 "Frozen Position"
CurObj.position.controller.setname 2 "Zero Pos XYZ"
/* "Localization off" */
CurObj.position.controller.SetActive 2

-- position to zero
CurObj.Position.controller[2].x_Position = 0
CurObj.Position.controller[2].y_Position = 0
CurObj.Position.controller[2].z_Position = 0
)

The next section of code is my own. Going step by step commenting as I go making things less confusing. Adding the Ikhandle, setting the preferred angle and adding the constraints is the point I'm at now. Currently I have explicit names for these functions. I would like to refer back to the local variables assigned earlier in the script, but for now to get things moving I have given them specific names of scene objects.

)
--next update Add selectable controller shapes
Box lengthsegs:1 widthsegs:1 heightsegs:1 length:4 width:4 height:4 mapcoords:on name: "ik_arm_ctrl" color: blue
wCtrl = $ik_arm_ctrl --wrist Control
wCtrl.pivot = [0, 0, 2] --NEEDto change on next update to centerPivot of any object
parent $ik_arm_ctrl $Bip01_L_Hand
AlignToParent--alignpivot to wrist bone
wBone = wristobj --wrist Bone
wCtrl.rotation = wBone.rotation --match rotations
wCtrl.pos = wBone.transform.position --match positions
freezeTransform wCtrl --freezeTransformations
--Ik stuff
IKSys.ikChain bicepobj wristobj "arm_ikh"--add ik handle
iksys.ikchain $Bip01_L_UpperArm $Bip01_L_Hand "IKHISolver"
select $arm_ikh
IKChainControl.setPrefAngles() --assume preferred angle
--add position constraint
--add rotation constraint
box lengthsegs:1 widthsegs:1 heightsegs:1 length:2 width:2 height:2 mapcoords:on name: "elbow_pv" color: blue
eCtrl = $elbow_pv --wrist Control
eCtrl.pivot = [0, 0, 1] --NEEDto change on next update to centerPivot of any object
eBone = elbowobj --wrist Bone
eCtrl.rotation = eBone.rotation --match rotations
eCtrl.pos = eBone.transform.position --match positions
)
The next update will be a completed script for rigging an Arm with IK. Future updates will include...right or left arm capability, the FK arm Rig and an option for both IK and FK plus switching.


No comments:

Post a Comment