Sunday, December 01, 2013

recent projects

hi

just to keep the blog flowing and up to date, here is the trailer of the upcoming robocop, where i did a bit a work a few months ago:



regards



Tuesday, October 08, 2013

couple of breakdowns

hi

this was made public recently although the film was released quite a while ago.
still interesting:


and this other one in case you missed it:

Thursday, July 11, 2013

cool python comprehension and maya.cmds

hi

here is a cool and simple way of combining python comprehension and maya.cmds. comprehension is an concise way of populating lists, which means that in a few lines you can run loops and gather elements from, in this case, a few maya commands.

in this example i needed to find all the skinned objects whose weights where not normalised as 'interactive'. therefore, after gathering all objects in the scene, i need to: -find all skinClusters. -check normalizeWeights. -return the transform linked to the skinCluster.

import maya.cmds as mc

def findOddNomalizedSkin():
        
    # get all shapes
    allshapes = mc.ls(typ= ['mesh','nurbsSurface','nurbsCurve','lattice'])

    # get all skinClusters
    history = [a for a in mc.listHistory(allshapes, pruneDagObjects=True)]
    sCluster = [h for h in history if mc.nodeType(h) == 'skinCluster']
    # check all normalizeWeights
    oddSkinned = [s for s in sCluster if mc.getAttr(s+'.normalizeWeights') != 1]
    # get all transforms if oddSkinned is not empty
    try:
        oddSkinnedTransforms = [o for o in mc.listConnections(oddSkinned, type='mesh')]
        return oddSkinnedTransforms
    except:
        return None

with what is essentially 4 lines of code i have run a bunch of loops in one-liners via list-returning cmds. this is an example that can be applied to loads of stuff.

keep in mind that for the sake of the example i have avoided doing this to gather my skinClusters:
sCluster = mc.ls(typ='skinCluster')
in the grand scheme of things one might have separate functions that gather all skinClusters, related shapes, transforms and so on, as they are quite recurrent things, but say this, can be used as series of shell buttoned stuff for checking and pruning.

regards

Wednesday, May 15, 2013

Thursday, April 11, 2013

breakdowns

hey

here are a couple of breakdowns of projects i worked in. had the pleasure of working with a very cool rigging team. in these projects: remi, viktor, sam, tom, jimmy and ruth!
you can see a few of my rigs or rigs i collaborated with:

prometheus:




(edit) the dark shadows breakdown has been replaced by the man of steel trailer. so here is their latest vfx reel with other interesting stuff:



(edit) the dark shadows breakdown is back up!:



regards

Thursday, March 21, 2013

test string type

hi

i have not found a way to create a field in a maya window, that will read the contents as something other than text.
when querying a field it will be returned as unicode, therefore here is a simple way to check if that text can be interpreted as a string, float, integer, or some type of list.

this can be useful for windows or many other cases (python only):

def testStringType(string):
    
    '''
    given a string, test if it can be interpreted as a differen type.
    useful for reading text.
    
    @string = str: string to be tested

    @return = list['this', 'is', 'a', 'tuple']: if string type = this, is, a, tuple
    @return = float(1.0): if string type = 1.0
    @return = int(5): if string type = 5
    @return = str(a123): if string type = a123
    '''
    
    #var is not a list, test type
    def testType(var):
        
        #var contains numbers, test type
        def numTest(n):
            try:
                print 'i am a float!'
                return float(n)
            except:
                print 'no! i am actually a str!'
                return str(n)
        
        #test type                        
        if var.isdigit():
            print 'i am an integer!'
            return int(var)
        elif  entry == 'True' or entry == 'False':
            print 'i am a bool!'
            return bool(entry)  
        elif var.isalpha():
            print 'i am a str!'
            return str(var)
        else:
            print 'i look complicated...'
            return numTest(var)
    
    #test if var is a type of list
    cleanList=[]
    if ',' in var:
        print 'i am a some sort of list!'
        clean = var.replace(' ', '')
        cleanList = clean.split(',')
        return cleanList
    else:
        print 'let\'s see what am i...'
        single = testType(var)
        return single     

because we are assuming that we are reading text, the function checks if the text contains comas ',' and if so it will be converted into a list. lists shall be presented in the form: a,b,c,d,1,2,3. additionally we could remove '(', ')', '[', ']' if necessary.

otherwise, we would use the 'types.ListType' and  'types.TupleType', or 'is list' and 'is tuple', but both would return false whilst reading text.

now in maya, used in a practical example, we can create a window, that given a function will create a UI for it. this function needs to return the exact type read from the window and with the above method it is tested and returned correctly.

import maya.cmds as mc

def jc_makeDefWin(myDef):

    '''
    creates a window to run given function
    enter function name and run
    
    @myDef = function: 
    '''
    
    # inspect my function, get arguments and name    
    funArgs = inspect.getargspec(myDef)
    myArgs = funArgs[0]
    name = myDef.__name__+'_win'
    
    # create window  
    window = mc.window(title=name, iconName=name, widthHeight=(200, 200))
    mc.columnLayout(adjustableColumn=True)
    slots = []
    
    # create slots for function arguments    
    for i in range(len(myArgs)):
        slot = mc.textFieldGrp(label='arg: '+myArgs[i])
        slots.append(slot)
    
    # read input text and run function
    def run(*args):
        
        entries = []    
        
        #read entries
        for i in range(len(slots)):
            entry = mc.textFieldGrp(slots[i], q=True, text=True)
            
            # func test data type and pass correct (str, int, float)
            def testType(entry):
                            
                def numTest(n):
                    try:
                        return float(n)                        
                    except:
                        return str(n)
                                
                if entry.isdigit():
                    return int(entry)
                elif  entry == 'True' or entry == 'False':
                    return bool(entry)
                elif entry.isalpha():
                    return str(entry)
                else:
                   return numTest(entry)
            
            #test if entry is a tuple, add as tuple or type
            if ',' in entry:
                clean = entry.replace(' ', '')
                cleanList = clean.split(',')
                entries.append(cleanList)
            else:
                entry = testType(entry)  
                entries.append(entry)
 
        myDef(*entries)
                
    # run button, calls run def    
    mc.button(label='Run', command=run)
    mc.button(label='Close', command=('maya.cmds.deleteUI(\"' + window + '\", window=True)'))
    mc.setParent('..')
    mc.showWindow(window)

    mm.eval("print \"type jc_makeDefWin(your function!)\"")

python variables into mel.eval

hi

this is rather simple, but not necessarily easy to find.

when calling mel commands you might want to pass variables declared in python, without having to do so in the mel environment first.

the documentation suggests that you might be working on both and might to communicate in-between them (and you can do so only via global variables). in activities such as mine, this is rarely the case.
using the eval function is 99% of the time given by the need to call a mel only command or script not available in python.

to solve this one can use the python() function when opening a "mel statement" via eval, one can call python again.
 
import maya.cmds as mc
import maya.mel as mm   
collideMainGrp = mc.group(n= 'ColisMain_grp', em=1)  
kONode, kOShape, kODrivenGrp = mm.eval('cMuscle_rigKeepOut(python("collideMainGrp"))')

easy! in this case cMuscle_rigKeepOut uses a python variable, instead of having to do stuff like using selection based commands such as cMuscle_rigKeepOutSel whilst selecting stuff in your script, which is a rather unclean alternative.

unfortunately because of the explained above, mel will not read the variable unless it is global. therefore if one where to pass it to a function: 

loc = 'locator1'
makeKeepOut(loc)

def makeKeepOut(obj):
    global keepOut
    keepOut = obj
    kONode, kOShape, kODrivenGrp = mm.eval('cMuscle_rigKeepOut(python("keepOut"))')
    del keepOut
    return kONode, kOShape, kODrivenGrp

this as you can see is not the cleanest way to call mel commands... but! thanks to python formatting we can avoid the variable smuggling and we can just pass stuff as strings. this will not only make for a cleaner and more pythonic code, but shorter too.

we can either use the old %s formatting or str.format(), like so:

collideMainGrp = mc.group(n= 'ColisMain_grp', em=1)

mm.eval('cMuscle_rigKeepOut("{0}")'.format(collideMainGrp))
# or 
#mm.eval('cMuscle_rigKeepOut("%s")' % collideMainGrp )

when in a function:

def makeKeepOut(obj):

    kONode, kOShape, kODrivenGrp = mm.eval('cMuscle_rigKeepOut("%s")' % obj)
    # or
    #kONode, kOShape, kODrivenGrp = mm.eval('cMuscle_rigKeepOut("{0}")'.format(obj))

    return kONode, kOShape, kODrivenGrp

no need for globals or other fluff... neat and easier to read. (cheers to jakub for suggesting a couple of things)

cMuscle_rigKeepOut, by the way is a maya muscle un-documented command. you can find it in /***/autodesk/maya2012sp1/scripts/muscle/cMuscle.mel , it creates a collision node with a collision vector. needs a muscle object to interact with. handy stuff!

for more information on python formatting and the old %.

regards