Friday, September 29, 2017

Zero-out Rotation Axis in Maya

Recently while working on some rigs, I was needed to strictly move the current skinned finger joints position to match a newly given set of finger joints by another TD. Usually, we should receive nicely oriented joints but it was not the case. Not only the rotations and joint orient values are messy, but there is also rotation axis value. If I were to directly snap to the new joints (following its translation + rotation), my joints will be messed up too.

It has been awhile since I last dealt with such a problem, so I forgot I solved it. Thanks to Goggle Search, someone has shared their solution, so I thought more people can benefits from it.

Basically, it is a short script to zero-out Rotation Axis in the joint without affecting the rest of the children joints. Pretty need and simple. Just select the joints that you would like to zero out the rotation axis values, and run this:

joint -e -zso;

Voila! It worked flawlessly. I think my old method required a bunch of calculations but this is magical. Hope it helps.

Thank you to Oana Jones for this sharing at :

http://oanajones.blogspot.my/2013/08/zero-out-rotation-axis-in-maya.html

Saturday, June 25, 2011

Weight Painting - Maya 2011

I was using Maya 2011 and could not get used to the new weight painting system. To weight paint like how we used to in the previous Maya (2009 and before), just go into the Paint Skin Weights Tool options, change the "Normalize Weights" from "Post" (default) to "Interactive". A message box will pop up and ask if you want to normalize the weights, in which I prefer to pick 'No'. Normalize Weights is accessible from "Edit Smooth Skins option" if I need it later.

Friday, February 4, 2011

joint Zero-ing

Here's a simple Python script that is used to zero-out selected joints' or given joint's rotation value and joint orient value. 

INSTRUCTION:
For the first argument, 'jointName' is used to specify a given joint name. If you intend to run the script for selected joints instead, give a 'None' or do not use this argument at all. It is defaulted as 'None' though. Second and third argument is 'rot' and 'jo'. Give it a 1 to 'rot' to zero-out rotation values or a 1 to 'jo' to zero-out joint orient values. Otherwise, give them a 0 to do nothing on that particular arguments.

EXAMPLE:
1) This will zero-out rotation values for joint1, but its joint orient will not be affected:
 
jointZero (jointName='joint1', rot=1, jo=0)

2) This will zero-out rotation values and joint orient values for all selected joints:

jointZero (rot=1,jo=1)

FULL SCRIPTS (to run before hand):


def jointZero (jointName=None, rot=1, jo=1):

    if jointName == None:
    
        sel = cmds.ls(sl=True)
        for joint in sel:
            if rot == 1:
                cmds.setAttr ('%s.rx'%joint, 0)
                cmds.setAttr ('%s.ry'%joint, 0)
                cmds.setAttr ('%s.rz'%joint, 0)    
                
            if jo == 1:
                cmds.setAttr ('%s.jointOrientX'%joint, 0)
                cmds.setAttr ('%s.jointOrientY'%joint, 0)
                cmds.setAttr ('%s.jointOrientZ'%joint, 0)                    
        
    else:
        
        if rot == 1:
            cmds.setAttr ('%s.rx'%jointName, 0)
            cmds.setAttr ('%s.ry'%jointName, 0)
            cmds.setAttr ('%s.rz'%jointName, 0)    
            
        if jo == 1:
            cmds.setAttr ('%s.jointOrientX'%jointName, 0)
            cmds.setAttr ('%s.jointOrientY'%jointName, 0)
            cmds.setAttr ('%s.jointOrientZ'%jointName, 0) 



Note that this is a very simple script. Fail-proof procedures are not added. So make sure your selection type is 'joint' and no rotation or joint orient attributes are locked or non-keyable. 


That is all for now. Hope this sheds some lights to the blog's viewers.

Tuesday, January 11, 2011

Animation Transfer Script

A friend of mine was asking me if it is possible to have a script that can save the animation data into a text file and load the saved animation data text file into another object. So I wrote a simple Python script that could perform such operation. It saves the keys as well as its animation curves and tangents.

The GUI is pretty simple to navigate. There are two tabs, LOAD and SAVE. To save out animation data into a text file, first select the object with the animation that you like to save out. Then click 'Browse' to browse to a directory where you want to save the text file containing the animation data. You can specify the start frame and end frame, as well as choosing the channels you like to save such as translate, rotate, scale and visibility. I made an additional custom attribute if you ever need one. The 'Save Data' button executes the saving data script. And to load the animation data, all you need to do is to choose your object, click 'Browse' to select your saved animation data text file, and decide whether if you like to remove the current keys on the selected object by ticking the checkbox. A click on 'Load Data' will executes the loading data script.

That is all.


Download link: Python File : jwAnimTransfer.py

** Note that this script is very simple. It can only save 1 object's animation at one time. Not that great, I know! Well, if you have any suggestions to make it more useful, let me know. Thanks!

Tuesday, January 4, 2011

Joint Labeling

I developed this script about a year ago. It is used to rename the joint labeling and set the 'side' of the selected joints according to their prefix. In my case, I used 'cc' for center, 'll' for left side and 'rr' for right side. You may modify that to suit your preference. It is important to make sure the name on both sides of the selected joints are the same except its prefix. The script is as below:


# Import Maya functions

import maya.cmds as cmds

# Prefixes change here

leftSide = 'll'
rightSide = 'rr'
center = 'cc'

def jointLabeling ():

    sel = []
    sel = cmds.ls (sl=True, fl=True)

    for i in sel:

        afterName=i.split ('_', 1)[0] # take the starting prefix and check
        afterNameTwo=i.split ('_', 1)[1] # take the obj's name and check

        if afterName ==
leftSide:
            cmds.setAttr ('%s.side'%i, 1)
            cmds.setAttr ('%s.type'%i, 18)
            cmds.setAttr ('%s.otherType'%i, '%s'%afterNameTwo, type= "string")
            print 'Labeled %s prefix called %s' %(afterName, afterNameTwo)

        if afterName == rightSide:
            cmds.setAttr ('%s.side'%i, 2)
            cmds.setAttr ('%s.type'%i, 18)
            cmds.setAttr ('%s.otherType'%i, '%s'%afterNameTwo, type= "string")
            print 'Labeled %s prefix called %s' %(afterName, afterNameTwo)

        if afterName == center:
            cmds.setAttr ('%s.side'%i, 0)
            cmds.setAttr ('%s.type'%i, 18)
            cmds.setAttr ('%s.otherType'%i, '%s'%afterNameTwo, type= "string")
            print 'Labeled %s prefix called %s' %(afterName, afterNameTwo)



Wednesday, December 15, 2010

IK Spring Solver

IK Spring Solver is useful when posing and animating limbs that have numerous joints such as insect legs. The most prominent function is the ability to adjust the spring angle bias to keep the joint angles to be evenly distributed. To use this IK solver, it has to be activated through an easy MEL script:

ikSpringSolver

Through the Internet, there are many people who bumps into problems while using this IK Solver, especially when performing world rotation that seems not to affect the joints rigged with IK Spring Solver. This problem has been a plague since Maya 7.0 and no rectification is being done up till Maya 2009 (which I am using) to make it behave properly.

The only available fix to it, is to have the first joint of a series of joints bounded to an IK Spring Solver not to be parented to its whatever parent. That joint shall be parent constrained to whatever parent it supposed to be, instead of directly parented underneath them. 

Note that IK Spring Solver will also break if you choose to parent the joints under a transform node and choose that transform node to perform the required parent-constraining. It is okay if you parent constrain the joints to whatever parents it supposed to be as described above, and group the joints in an empty transform node for clarity purposes. 

I guess that is as much as I could explain. Please do drop a message if the problem persists, or my instructions being unclear.

Monday, February 22, 2010

Returning multiple values from a Python function

I was working on my Python scripts. Then I came to a point where I require more than 1 value to be returned from a function that I wrote. Usually, functions in Python can only return one thing, but the one thing can be a collection of items - tuple. The returned values can be broken down into a bunch of variables:

# Create a function as below, with three returns:
def addme(num):
v1 = num + 15
v2 = num - 10
v3 = num * 2
return v1,v2,v3;

# Running the function:

main = addme (15)
sA, sB, sC = addme (15)

#By printing main, main will be equal to (30,5,30):

 
print main
 

#By printing main[0], main[1] and main[2], you'll get individual values of 30, 5 and 30 respectively:
 print main[0]
print main[1]
print main[2]

#Or, another way would be printing sA, sB and sC; you'll get 30, 5 and 30 respectively as well:

 
print sA
print sB
print sC