• Blog
  • Work
  • Resources
    • Rigs
  • Resume
  • Contact
I do technical things...

Pose space deformer - Vector Angle node, whatever it's called.

2/20/2012

0 Comments

 
I wrote another custom node, again beholden somewhat to this post, that basically calculates the angle between to vectors.

It takes in two world space matrices and compares specified axis (x,y or z) of the nodes. It returns a ranged, 0-1, value based on user set bounds (actually the node outputs a ranged angle, full angle and dot product). Its really pretty simple but should come in handy.

I have tried to make this setup before, using Maya utility nodes and some elbow grease, but It was always quite cumbersome and I was a bit off with the math, So I thought an api node would be a better bet. So I created a nice self contained node that does it all for you and gave the user a nice display.

Here it is in action. I piped the output into the scale of the cube for visual cue of the output. 
I think i can take this a bit further, I'm thinking of trying to make this calculate a u-v space bounds of a sphere, so i can cut a more complex piece of a sphere to calculate if the vector is inside. We'll see how far i get with that!
0 Comments

Draw on top Maya control node

2/20/2012

2 Comments

 
I wrote a custom locator node for use in my rigs a while back, thought I'd show it off.

As many other have, I'm sure, I read through this post and started playing about with the methods outlined.  It's a great tutorial for anyone looking to get into the python api, so check it out now! Yes, stop reading this and go there if you haven't already,

I took it a little further and wrote a node that could be used as an all purpose controller for rig setups. One of the main pluses of this node is that it can be set to 'draw on top', which is very nice for making aesthetically easy to understand rigs. Credit needs to go to Christopher Lewis also for help on the openGL depth methods for that.

I also wrote in the ability to change the draw shape, rescale the drawn shape, edit transparency and other settings.

I've been using it for a while now and its working great!

2 Comments

Python Api Close Window CallBack

12/1/2011

1 Comment

 
Post Post Edit! I found a much easier way to do this. :D
    scriptJob -uiDeleted "uiName" "someFunction";
Ah well, I learned something anyway!
----------------------------------------------------------------------------------------------------------

Add a callback when a window is closed.

Can come in really handy when you have heavy ui usage and require post tool cleanup or whatever.

from maya import OpenMaya
from maya import OpenMayaUI
import maya.cmds as cmds

def makeTestWindow():
    window = cmds.window( 'TEST_WIN', title="Long Name", iconName='Short Name', widthHeight=(200, 55) )
    cmds.columnLayout( adjustableColumn=True )
    cmds.button( label='Do Nothing' )
    cmds.button( label='Close', command=('cmds.deleteUI(\"' + window + '\", window=True)') )
    cmds.setParent( '..' )
    cmds.showWindow( window )
    return window
 
def uiDeleteCallback( *args ):
    """
    This is the function that will be called whenever the ui, passed to the MUiMessage.addUiDeletedCallback( window, uiDeleteCallback )
    is deleted
    """
    cmds.confirmDialog(-message "The Window Was Closed!!!") 


# make a test window
win = makeTestWindow()

# create the callback to run when the ui is deleted
uiCallBack = OpenMayaUI.MUiMessage.addUiDeletedCallback( win, uiDeleteCallback )

# removes the callback from memory
#OpenMaya.MMessage.removeCallback( uiCallBack )

apideleteuicallback.py
File Size: 1 kb
File Type: py
Download File

1 Comment

Simple Api Vert Iterator

12/1/2011

0 Comments

 
I used some nice api code in a script recently, so thought i'd share it. I used it to calculate vertex positions. 

import maya.OpenMaya as OpenMaya
import maya.mel as mel
import pymel.core as pm
import os

def getMeshPositions( ):

    # get selection
    selection = OpenMaya.MSelectionList()
    OpenMaya.MGlobal.getActiveSelectionList( selection );
   
    # create an iterator for selection... we use the constant tyer id MFn.kGeometric to filter anything but poly mesh objects
    selIter = OpenMaya.MItSelectionList ( selection, OpenMaya.MFn.kGeometric );
   
    # intiialize a list in this scope... to return
    distanceArr = []
   
    # iterate/loop over the selection
    while not selIter.isDone():

        # intialize a MObject class type
        mObj = OpenMaya.MObject()
        # convert the emtpy MObject into the actual scene node
        selIter.getDependNode( mObj )
       
        # create another iterator for the mesh vertecies
        meshVertIT = OpenMaya.MItMeshVertex ( mObj )
       
        # iterate/loop over the vertecies
        while not meshVertIT.isDone():
            # get the current vert index
            indx = meshVertIT.index()
           
            # get the position of the current vert
            pos = meshVertIT.position (OpenMaya.MSpace.kObject)       
           
            # Store the position in the list to return later
            distanceArr.append( [pos.x, pos.y, pos.z]  )         
           
            # move iterator to next vert on mesh
            meshVertIT.next()
           
        # move iterator to next item in MSelectionList
        selIter.next()
       
    return distanceArr

The code above isn't exactly the code I used, but I wrapped it here for ease of use.

I can't take total credit, I used some exaples on Ryan Trowbridge's and Chad Vernon's site as guidelines. 

here's some links if you've never been to them... excellent resources
    http://www.rtrowbridge.com/blog/
    http://www.chadvernon.com/blog/

This isn't hooked up to a plug-in of course so it's not 'un-doable'. It works really well, and was MUCH faster than using basic commands to get the data.

Sweet.
0 Comments

    Andy T.

    I do Tech things for Artist.

    Archives

    July 2014
    February 2014
    January 2014
    April 2013
    August 2012
    March 2012
    February 2012
    December 2011
    July 2010

    Categories

    All
    3ds Max C#
    3ds Max .net Api
    Animation
    Api
    Face Rig
    Maxscript
    Maya
    Mel
    Python
    Python Api
    Rigging
    Scripting
    Ui
    Work

    Links To Cool Folks

    Mic Marvin
    Alex Utting
    Rick Vicens
    Gary Talbot
    Richie Prado
    Felipe Nogueira

    RSS Feed