Thursday, September 17, 2015

Alembic color from Houdini to maya

So I end up doing this over and over again, so I thought I'd write it here so I won't forget it. 
You can export color out of Houdini into an alembic as a regular point attribute using Cd. Then in maya import the alembic using a command like this one:
AbcImport -mode import -rcs "test.abc"

It won't make any color sets, it just brings the colors straight into the vertex as rgb  attributes. 

Other attributes come in as arrays on the shape node. Easiest way for me to access to those is with the great SOuP suite. 

If you're using vray, on your poly mesh that comes from alembic, add a name to your empty current color set node (in the shape node under the Mesh Controls tab -- just type it in there). I usually call it colorSet1 which is what Maya usually calls it.  
Then use a VRayVertexColors node (found under 2D textures in the hypershade), change the type to Set Name and type in your color set name (colorSet1 if you do what I suggested). 
That's it, you can now use that VRayVertexColors node to pipe those colors into whatever you like!  

Saturday, December 27, 2014

Falconry

I went out hunting with a local falconer in Southold today.

It was amazing.  Although the birds didn't catch any prey, seeing the birds (he had two Harris's Hawk's) and they way they hunted as a team, was incredible.  So glad people still carry on this tradition.

Monday, February 3, 2014

find all instanced nodes in your Maya scene and make them unique

I ran across another great little uninstancer script, this one for uninstancing transforms and shapes, not the actual instancer node.  It uses the isInstanced API call and creates unique transform and shapes for all instanced nodes (again, nothing to do with the instancer node).
This comes from www.akeric.com/blog/?p=1087 if you want a more thorough explanation (edit, the script originates from the great mayamel.tiddlyspot.com.)


Here's the code.  Run uninstance() after sourcing these two functions:

import maya.cmds as mc
import maya.OpenMaya as om

def getInstances():
    instances = []
    iterDag = om.MItDag(om.MItDag.kBreadthFirst)
    while not iterDag.isDone():
        instanced = om.MItDag.isInstanced(iterDag)
        if instanced:
            instances.append(iterDag.fullPathName())
            print iterDag.fullPathName()
        iterDag.next()
    return instances
    
    
def uninstance():
    instances = getInstances()
    while len(instances):
        parent = mc.listRelatives(instances[0], parent=True, fullPath=True)[0]
        mc.duplicate(parent, renameChildren=True)
        mc.delete(parent)
        instances = getInstances()



Wednesday, August 14, 2013

create curve from transform in maya

This has been done a million times, but the versions I've seen have been done using mel and rather slow.
This one uses python and isloate's the selected object(s) to speed up the curve creation.



import maya.cmds as mc
def curveFromXform():
    obj = mc.ls(sl=1)[0]
    #try to get current modeling pane if possible to isloate select and speed xform aquisition
    currentPanel = mc.getPanel(withFocus=1)
    panelType = mc.getPanel(to=currentPanel)
    visPanels = mc.getPanel(vis=1)
    for each in visPanels:
        if "modelPanel" in each and currentPanel != each:
            print "Switching focus to " + each
            mc.setFocus(each)
            currentPanel = each
            if len(mc.ls(sl=1)) > 0:
                mc.isolateSelect(currentPanel,state=1)
        elif "modelPanel" in each and currentPanel == each:
            print "isolate panel " + each
            if len(mc.ls(sl=1)) > 0:
                mc.isolateSelect(currentPanel,state=1)
    if mc.nodeType(obj) == "transform":
        #get start and end frames from playback
        start = mc.playbackOptions(q=1,min=1)
        end = mc.playbackOptions(q=1,max=1)
        curvePoints = []
        #query pivot per frame and store in list
        for i in range(start,end):
            mc.currentTime(i)
            pos = mc.xform(obj,q=1,ws=1,t=1)
            curvePoints.append(pos)
   
        #create curve from point data
        mc.curve(n=obj + "_bakedPivot",p=curvePoints )
        mc.isolateSelect(currentPanel,state=0)
        mc.select(obj,r=1)

Friday, April 5, 2013

Uninstancer for maya

There are a few uninstancer scripts and plugins around, but I stumbled upon a bit of python that Peter Shipkov (developer of the SOuP toolset) which works great.  Here's a link to the page:
http://soup-dev.websitetoolbox.com/post/Uninstancer-5887571

Here's the bit of code just in case the link or web site is somehow taken down at some point:
 # save the code below in file named uninstancer.py  
 # select at least one instancer node in the maya scene and run the next command:  
 # import imp; uninstancer = imp.load_source('uninstancer','/path/to/uninstancer.py'); uninstancer.uninstancer().main()  
 import maya.cmds as mc  
 import maya.OpenMaya as om  
 import maya.OpenMayaFX as omfx  
 class uninstancer():  
   def main(self):  
     li = []  
     l = mc.ls(sl=True) or []  
     for n in l:  
       if mc.nodeType(n) != "instancer": continue  
       li.append(n)  
     if len(li) == 0: raise Exception('Select at least one instancer node.')  
     l = []  
     m = om.MMatrix()  
     dp = om.MDagPath()  
     dpa = om.MDagPathArray()  
     sa = om.MScriptUtil()  
     sa.createFromList([0.0, 0.0, 0.0], 3)  
     sp = sa.asDoublePtr()  
     sf = int(mc.playbackOptions(q=True, min=True))-1  
     ef = int(mc.playbackOptions(q=True, max=True))+2  
     for i in range(sf, ef):  
       mc.currentTime(i)  
       for inst in li:  
         g = inst+"_objects"  
         if i == sf:  
           if mc.objExists(g) == True: mc.delete(g)  
           mc.createNode("transform", n=g)  
           l.append(g)  
         sl = om.MSelectionList()  
         sl.add(inst)  
         sl.getDagPath(0, dp)  
         fni = omfx.MFnInstancer(dp)  
         for j in range(fni.particleCount()):  
           fni.instancesForParticle(j, dpa, m)  
           for k in range(dpa.length()):  
             n = inst+"_"+str(j)+"_"+dpa[k].partialPathName()  
             if mc.objExists(n) == False:  
               n2 = mc.duplicate(dpa[k].partialPathName())[0]  
               n = mc.rename(n2, n)  
               if mc.listRelatives(n, p=True) != g:  
                 n = mc.parent(n, g)[0]  
               mc.setKeyframe(n+".v", t=i-1, v=False)  
             tm = om.MTransformationMatrix(m)  
             t = tm.getTranslation(om.MSpace.kWorld)  
             mc.setAttr(n+".t", t[0], t[1], t[2])  
             mc.setKeyframe(n+".t")  
             r = tm.eulerRotation().asVector()  
             mc.setAttr(n+".r", r[0]*57.2957795, r[1]*57.2957795, r[2]*57.2957795)  
             mc.setKeyframe(n+".r")  
             tm.getScale(sp, om.MSpace.kWorld)  
             sx = om.MScriptUtil().getDoubleArrayItem(sp, 0)  
             sy = om.MScriptUtil().getDoubleArrayItem(sp, 1)  
             sz = om.MScriptUtil().getDoubleArrayItem(sp, 2)  
             s = om.MTransformationMatrix(dpa[k].inclusiveMatrix()).getScale(sp, om.MSpace.kWorld)  
             sx2 = om.MScriptUtil().getDoubleArrayItem(sp, 0)  
             sy2 = om.MScriptUtil().getDoubleArrayItem(sp, 1)  
             sz2 = om.MScriptUtil().getDoubleArrayItem(sp, 2)  
             mc.setAttr(n+".s", sx*sx2, sy*sy2, sz*sz2)  
             mc.setKeyframe(n+".s")  
             mc.setAttr(n+".v", True)  
             mc.setKeyframe(n+".v")  
             mc.setKeyframe(n+".v", t=i+1, v=False)  
     return l  
"This code will create animated individual copies of the base instanced objects. It supports point clouds with varying number of points - for instance - dying or newly created particles, or meshes with changning number of points over time.
Looking now at it before posting - i think it will not not accommodate for the case where the base objects have non-zeroed out TR channels."

Wednesday, April 3, 2013

My family was captured this weekend in a potate sack race by  Brandon Stanton of humansofnewyork.com fame.

Here's the shot:
the-head-start


The funny thing is, I never intended to bring out the potate sacks; I happened upon them by accident as I was looking for a pump to fill up our soccer balls.  Leftover from last summer and never used.  Seemed like a fun thing to do on Easter Sunday, and it was!

Thursday, March 28, 2013

Splitting out a file name in an image sequence from a directory path using tcl in Nuke

I'm writing this down, mostly so I won't have to dig around different nuke comps the next time I need it.  Using tcl to write little scripts in Nuke is very helpful, but it's a bit of an old language (just a few years younger than Perl), so it's got an interesting nomenclature.

Anyways I use this bit of tcl in my nuke text nodes to get the name of an image sequence:
 
[split [lindex [split [lindex [split [knob [topnode].file] "/"] 10] "."] 0] "_"]

It first splits the whole path (which in this case has 10 tokens) using a "/"
The last token is returned and split again based on "."
And finally it splits out the last token if there's any underscores

so a path like this:
/job/thingny/dev/sandbox/sandbox_iguerrer/work/iguerrer/maya/images/skinTestSmooth_backLeft.####.iff

ends up being displayed as this:
skinTestSmooth backLeft

This assumes you have a read node as the top most node in the tree with the text node in the flow.

I'd like to figure (using tcl --- python is a bit easier for me when it comes to text manipulation) how to get the total number of tokens in the first directory split where I'm using "/", and then feed the number to the rest of the expression.

Further explorations!


addenum --  check out this web site for lots of nuke tcl tips:
http://thoughtvfx.blogspot.com/2012/12/nuke-tcl-tips.html