Sunday, October 26, 2014

Create a Nurbs Circle Shaped Control Script.

 So, this is usually my first method of getting folks' feet wet with scripting while they are learning rigging, then by the time they get to scripting they are at least familiar with what the Python language looks like, examples of how it works, and some of the logic that can be used to accomplish a small scripting tool.  This example is used to create a nurbs circle control with a few various useful options for the tool.  I typically throw this in just after they have rigged their first character, nothing is more frustrating than creating 30 FK controls for fingers by hand every time you need a rig.  This code is using Python in Maya running with the PyMel libraries.  The code is below...



import pymel.core as pm


def create_circle_control( i_sJoint='', 
                            i_vNormal=[1,0,0], 
                            i_bOrientToJoint=True, 
                            i_sRigConstraintType='parent', 
                            i_bCreateAnimGrp=False,
                            i_iColor=17 ):
                                
    """
    Function to create a simple nurbs shaped control
    
    Args:
        i_sJoint (string) : name of joint to create the control at
        i_vNormal (vector) : direction of the circle to draw
        i_bOrientToJoint (bool) : determine if the control should be oriented to joint
        i_sRigConstraintType (sting) : type of rig constraint to create if any
        i_bCreateAnimGrp (bool) : determine if an anim/sdk group needs to be created
        i_iColor (int) : color value for the circle shape override color attribute    
    
    """
    
    # create the circle control
    control = pm.circle( name=i_sJoint + "_Ctrl",
                        radius=0.25,
                        normal=i_vNormal, 
                        constructionHistory=False )
                        
    # create the pad group
    pad = pm.group( name=i_sJoint + "_Pad",
                    empty=True )
    
    # parent the control to the pad
    pm.parent( control, pad )
    
    # If createAnim, create the anim group and parent
    if i_bCreateAnimGrp:
        anim = pm.group( name=i_sJoint + "_Anim", empty=True )
        pm.parent( control, anim )
        pm.parent( anim, pad )
    
    # if you want the control oriented to the joint, use parentConstraint
    if i_bOrientToJoint:
        pm.delete( pm.parentConstraint( i_sJoint,
                                        pad,
                                        maintainOffset=False, 
                                        weight=1.0 ) )
    else:
        pm.delete( pm.pointConstraint( i_sJoint, 
                                       pad, 
                                       maintainOffset=False, 
                                       weight=1.0 ) )
    
    # if rigConstraint is a parent constraint
    if i_sRigConstraintType == 'parent':
        pm.parentConstraint( control, 
                            i_sJoint, 
                            maintainOffset=True, 
                            weight=1.0 )
               
    # if rigConstraint is a point constraint             
    elif i_sRigConstraintType == 'point':
        pm.pointConstraint( control, 
                            i_sJoint, 
                            maintainOffset=True, 
                            weight=1.0 )

    # if rigConstraint is a orient constraint  
    elif i_sRigConstraintType == 'orient':
        pm.orientConstraint( control, 
                            i_sJoint, 
                            maintainOffset=True, 
                            weight=1.0 )
    
    # Set override color
    control[0].getShape().setAttr( 'overrideEnabled', True )
    control[0].getShape().setAttr( 'overrideColor', i_iColor )
    
    # Get the joint parent
    sJointParent = i_sJoint.getParent()
    
    # if the joint parent's ctrl exists, parent this new pad to it
    if sJointParent:
        if pm.objExists( sJointParent + "_Ctrl" ):
            pm.parent( pad, sJointParent + "_Ctrl" )


# Loop through the selection and create controls
for item in pm.ls( selection=True ):
    create_circle_control( item )\


Adding a Simple Automated Forearm Setup to the Marine Rig


  The earlier post finished up with a very simple ( and common ) 3 joint setup for the arm.  The downside to this setup is you get really poor twisting rotation in the Forearm and also the upper arm area ( this pictorial covers the lower arm ).  So some new things covered in this little rig mod:

 Add Influence - Allows adding new influences to an existing SkinCluster.
Multiply Divide Node - A Math utility node in Maya that can handle Multiplication/Division/Pow
Start by duplicating the Export Skeleton's Elbow joint, parent it under the Elbow.  Then offset translateX down to halfway distance between the Wrist/Elbow.  With the joint selected, add the mesh to the selection and navigate to Skin->Edit Smooth Skin - > Add Influence.

Start weighting the Forearm joint, from Elbow to mid way down the forearm should be just Elbow and Forearm influence.  Then from halfway down the forearm to the wrist should be NO Elbow, just Forearm and Wrist.


Open the Node Editor, right click and hold to open the Marking Menu that has "Create Node" as the North Option.  Create a new Multiply Divide node, named "md_LForearm_twist".  The graph shows some of Maya's unitConversion nodes that are automatically created, so just ignore them in the Image.  Plug the .rotateX value of the Wrist into the input1X of md_LForearm_twist", then send the outputX of md_LForearm_twist to the .rotateX of the LForearm.  Open the Attribute Editor and set the Input2X value to 0.5.  This setup takes half of the rotateX ( twist  value ) and applies it to the Forearm joint.


Polish the weighting.

Friday, October 17, 2014

Your first full character rig - Video series

US Marine rig video 1 - Joint Placement

US Marine rig video 2 - Arms

US Marine rig video 3 - Legs

US Marine rig video 4 - Torso

US Marine rig video 5 - Skinning 1

US Marine rig video 6 - Skinning 2


  I recently decided to start recording tutorials for my students in my introduction to Rigging class, so that they can reference and learn at home.  So far we've worked through rigging setups separated from each other, this is the first full character they are working on.  So I started a video series that goes through a basic game resolution biped rig from scratch.

  It was definitely an interesting experience, I haven't done too many video tutorials on the basics of rigging so talking during the process of weight painting or joint placement really was difficult for me to do - but worth it.  I also haven't been able to time myself during a manually built rig in a while so that was also quite interesting.

  Some of the videos ended up being quite long, but I tried to take plenty of time as this is a follow up implementation of the rigging fundamentals for beginners.  I may upload the fundamentals videos at some point.

  Most of the rig building refers to previous class rigging examples or terms, here's a few of the terms...

Pad - a group on top of the control used to orient and/or position the control to a specific joint or point.

Anim Group - an optional group that lives between a pad and a control with no offset transformation information.   Its used for set driven keyframe animation or direct connections.   Example, useful to have an sdk for a finger curl start on a group above the animator control but still start at rotation value of zero and be oriented because the group inherits thePad orientation.

RP - rotate plane ik solver.  Used when you would like a twisting control of an ik setup, think directing the knee while the leg is planted.

Ambulation controls - controls for the animator to manipulate the character as a whole, think of scene placement.