maya tool: get speed from animated object live

i’ve wrote 2 handy tools in maya for getting a speed value from animated Objects.  it works on everything, which have a transform node. Locators, Geo etc…

this script add an extra attribute call Speed. its updates live, even when change keyframes. its very hand if you have to animate your force field based on speed /animation of other Objects. you can simply refer this attribude inside other expression.

this second script is pretty much the same, except it display the speed live in Maya’s HUB display. (inside a viewport)

when you activate the script again it will turn off the HUD display.

link to script

link to script 2

Python script:

import maya.cmds as cmds
import math

Psel = cmds.ls( selection=True )
try:

nodeT = cmds.nodeType( Psel[0] )
print nodeT
if nodeT == ‘transform’:
checkAttr = cmds.objExists(Psel[0]+’.speed’)
print checkAttr
if checkAttr == True:
listexpr = cmds.listConnections(Psel[0]+’.speed’)
if listexpr == None :
ex1 = ‘float $lastPosX = getAttr -t (frame-1) '+Psel[0]+'.tx;’
ex2 = ‘float $lastPosY = getAttr -t (frame-1) '+Psel[0]+'.ty;’
ex3 = ‘float $lastPosZ = getAttr -t (frame-1) '+Psel[0]+'.tz;’
ex4 = Psel[0]+’.speed = abs (mag (<<‘+Psel[0]+’.translateX,’+Psel[0]+’.translateY,’+Psel[0]+’.translateZ>>)- mag (<<$lastPosX,$lastPosY,$lastPosZ>>) );’
exAll = ex1+ex2+ex3+ex4
cmds.expression( o=Psel[0], s=exAll)
else:
cmds.delete(listexpr[0])
ex1 = ‘float $lastPosX = getAttr -t (frame-1) '+Psel[0]+'.tx;’
ex2 = ‘float $lastPosY = getAttr -t (frame-1) '+Psel[0]+'.ty;’
ex3 = ‘float $lastPosZ = getAttr -t (frame-1) '+Psel[0]+'.tz;’
ex4 = Psel[0]+’.speed = abs (mag (<<‘+Psel[0]+’.translateX,’+Psel[0]+’.translateY,’+Psel[0]+’.translateZ>>)- mag (<<$lastPosX,$lastPosY,$lastPosZ>>) );’
exAll = ex1+ex2+ex3+ex4
cmds.expression( o=Psel[0], s=exAll)

else:
print “test”
cmds.addAttr( Psel[0],longName=’speed’ )
ex1 = ‘float $lastPosX = getAttr -t (frame-1) '+Psel[0]+'.tx;’
ex2 = ‘float $lastPosY = getAttr -t (frame-1) '+Psel[0]+'.ty;’
ex3 = ‘float $lastPosZ = getAttr -t (frame-1) '+Psel[0]+'.tz;’
ex4 = Psel[0]+’.speed = abs (mag (<<‘+Psel[0]+’.translateX,’+Psel[0]+’.translateY,’+Psel[0]+’.translateZ>>)- mag (<<$lastPosX,$lastPosY,$lastPosZ>>) );’
exAll = ex1+ex2+ex3+ex4
print exAll
cmds.expression( o=Psel[0], s=exAll)

else:
print ‘—> select transform !’

except TypeError :
print ‘—> select transform !’

 

 

 Script 2:


import maya.cmds as cmds
import math

def getSpeed(*args):

res = 0
Psel = cmds.ls( selection=True )
try:

nodeT = cmds.nodeType( Psel[0] )
print nodeT
if nodeT == ‘transform’:
checkAttr = cmds.objExists(Psel[0]+’.speed’)
print checkAttr
if checkAttr == True:
listexpr = cmds.listConnections(Psel[0]+’.speed’)
if listexpr == None :
ex1 = ‘float $lastPosX = getAttr -t (frame-1) '+Psel[0]+'.tx;’
ex2 = ‘float $lastPosY = getAttr -t (frame-1) '+Psel[0]+'.ty;’
ex3 = ‘float $lastPosZ = getAttr -t (frame-1) '+Psel[0]+'.tz;’
ex4 = Psel[0]+’.speed = abs (mag (<<‘+Psel[0]+’.translateXA,’+Psel[0]+’.translateY,’+Psel[0]+’.translateZ>>)- mag (<<$lastPosX,$lastPosY,$lastPosZ>>) );’
exAll = ex1+ex2+ex3+ex4
cmds.expression( o=Psel[0], s=exAll)
else:
cmds.delete(listexpr[0])
ex1 = ‘float $lastPosX = getAttr -t (frame-1) '+Psel[0]+'.tx;’
ex2 = ‘float $lastPosY = getAttr -t (frame-1) '+Psel[0]+'.ty;’
ex3 = ‘float $lastPosZ = getAttr -t (frame-1) '+Psel[0]+'.tz;’
ex4 = Psel[0]+’.speed = abs (mag (<<‘+Psel[0]+’.translateX,’+Psel[0]+’.translateY,’+Psel[0]+’.translateZ>>)- mag (<<$lastPosX,$lastPosY,$lastPosZ>>) );’
exAll = ex1+ex2+ex3+ex4
cmds.expression( o=Psel[0], s=exAll)

else:
print “test”
cmds.addAttr( Psel[0],longName=’speed’ )
ex1 = ‘float $lastPosX = getAttr -t (frame-1) '+Psel[0]+'.tx;’
ex2 = ‘float $lastPosY = getAttr -t (frame-1) '+Psel[0]+'.ty;’
ex3 = ‘float $lastPosZ = getAttr -t (frame-1) '+Psel[0]+'.tz;’
ex4 = Psel[0]+’.speed = abs (mag (<<‘+Psel[0]+’.translateX,’+Psel[0]+’.translateY,’+Psel[0]+’.translateZ>>)- mag (<<$lastPosX,$lastPosY,$lastPosZ>>) );’
exAll = ex1+ex2+ex3+ex4
print exAll
cmds.expression( o=Psel[0], s=exAll)

else:
print ‘—> select transform !’

except TypeError :
print ‘—> select transform !’
res = cmds.getAttr(Psel[0]+’.speed’)
return res
try:
cmds.headsUpDisplay( ‘voxelsHUD’, section=1, block=0, blockSize=’small’, label=’Speed’, command=getSpeed, event=’timeChanged’, nodeChanges=’attributeChange’ )
except RuntimeError:
cmds.headsUpDisplay(‘voxelsHUD’, remove=True)

 

Advertisements

Maya Speed Attribute Python Script

this script add a speed attribute to the selected object and calculates it in realtime. Very handy for setup effects, animating vehicles etc.. github link

import maya.cmds as cmds
import math

Psel = cmds.ls( selection=True )
try:

nodeT = cmds.nodeType( Psel[0] )
print nodeT
if nodeT == ‘transform’:
checkAttr = cmds.objExists(Psel[0]+’.speed’)
print checkAttr
if checkAttr == True:
listexpr = cmds.listConnections(Psel[0]+’.speed’)
if listexpr == None :
ex1 = ‘float $lastPosX = `getAttr -t (frame-1) ‘+Psel[0]+’.tx`;’
ex2 = ‘float $lastPosY = `getAttr -t (frame-1) ‘+Psel[0]+’.ty`;’
ex3 = ‘float $lastPosZ = `getAttr -t (frame-1) ‘+Psel[0]+’.tz`;’
ex4 = Psel[0]+’.speed = abs (mag (<<‘+Psel[0]+’.translateX,’+Psel[0]+’.translateY,’+Psel[0]+’.translateZ>>)- mag (<<$lastPosX,$lastPosY,$lastPosZ>>) );’
exAll = ex1+ex2+ex3+ex4
cmds.expression( o=Psel[0], s=exAll)
else:
cmds.delete(listexpr[0])
ex1 = ‘float $lastPosX = `getAttr -t (frame-1) ‘+Psel[0]+’.tx`;’
ex2 = ‘float $lastPosY = `getAttr -t (frame-1) ‘+Psel[0]+’.ty`;’
ex3 = ‘float $lastPosZ = `getAttr -t (frame-1) ‘+Psel[0]+’.tz`;’
ex4 = Psel[0]+’.speed = abs (mag (<<‘+Psel[0]+’.translateX,’+Psel[0]+’.translateY,’+Psel[0]+’.translateZ>>)- mag (<<$lastPosX,$lastPosY,$lastPosZ>>) );’
exAll = ex1+ex2+ex3+ex4
cmds.expression( o=Psel[0], s=exAll)

else:
print “test”
cmds.addAttr( Psel[0],longName=’speed’ )
ex1 = ‘float $lastPosX = `getAttr -t (frame-1) ‘+Psel[0]+’.tx`;’
ex2 = ‘float $lastPosY = `getAttr -t (frame-1) ‘+Psel[0]+’.ty`;’
ex3 = ‘float $lastPosZ = `getAttr -t (frame-1) ‘+Psel[0]+’.tz`;’
ex4 = Psel[0]+’.speed = abs (mag (<<‘+Psel[0]+’.translateX,’+Psel[0]+’.translateY,’+Psel[0]+’.translateZ>>)- mag (<<$lastPosX,$lastPosY,$lastPosZ>>) );’
exAll = ex1+ex2+ex3+ex4
print exAll
cmds.expression( o=Psel[0], s=exAll)

else:
print ‘—> select transform !’

except TypeError :
print ‘—> select transform !’

this script adds apeed attribute to selected object and display it in maya opengl view. When you select different object you have change the frame to get the update. gitbhub link

import maya.cmds as cmds
import math

def getSpeed(*args):

res = 0
Psel = cmds.ls( selection=True )
try:

nodeT = cmds.nodeType( Psel[0] )
print nodeT
if nodeT == ‘transform’:
checkAttr = cmds.objExists(Psel[0]+’.speed’)
print checkAttr
if checkAttr == True:
listexpr = cmds.listConnections(Psel[0]+’.speed’)
if listexpr == None :
ex1 = ‘float $lastPosX = `getAttr -t (frame-1) ‘+Psel[0]+’.tx`;’
ex2 = ‘float $lastPosY = `getAttr -t (frame-1) ‘+Psel[0]+’.ty`;’
ex3 = ‘float $lastPosZ = `getAttr -t (frame-1) ‘+Psel[0]+’.tz`;’
ex4 = Psel[0]+’.speed = abs (mag (<<‘+Psel[0]+’.translateX,’+Psel[0]+’.translateY,’+Psel[0]+’.translateZ>>)- mag (<<$lastPosX,$lastPosY,$lastPosZ>>) );’
exAll = ex1+ex2+ex3+ex4
cmds.expression( o=Psel[0], s=exAll)
else:
cmds.delete(listexpr[0])
ex1 = ‘float $lastPosX = `getAttr -t (frame-1) ‘+Psel[0]+’.tx`;’
ex2 = ‘float $lastPosY = `getAttr -t (frame-1) ‘+Psel[0]+’.ty`;’
ex3 = ‘float $lastPosZ = `getAttr -t (frame-1) ‘+Psel[0]+’.tz`;’
ex4 = Psel[0]+’.speed = abs (mag (<<‘+Psel[0]+’.translateX,’+Psel[0]+’.translateY,’+Psel[0]+’.translateZ>>)- mag (<<$lastPosX,$lastPosY,$lastPosZ>>) );’
exAll = ex1+ex2+ex3+ex4
cmds.expression( o=Psel[0], s=exAll)

else:
print “test”
cmds.addAttr( Psel[0],longName=’speed’ )
ex1 = ‘float $lastPosX = `getAttr -t (frame-1) ‘+Psel[0]+’.tx`;’
ex2 = ‘float $lastPosY = `getAttr -t (frame-1) ‘+Psel[0]+’.ty`;’
ex3 = ‘float $lastPosZ = `getAttr -t (frame-1) ‘+Psel[0]+’.tz`;’
ex4 = Psel[0]+’.speed = abs (mag (<<‘+Psel[0]+’.translateX,’+Psel[0]+’.translateY,’+Psel[0]+’.translateZ>>)- mag (<<$lastPosX,$lastPosY,$lastPosZ>>) );’
exAll = ex1+ex2+ex3+ex4
print exAll
cmds.expression( o=Psel[0], s=exAll)

else:
print ‘—> select transform !’

except TypeError :
print ‘—> select transform !’
res = cmds.getAttr(Psel[0]+’.speed’)
return res
try:
cmds.headsUpDisplay( ‘SpeedHUD’, section=1, block=0, blockSize=’small’, label=’Speed’, command=getSpeed, event=’timeChanged’, nodeChanges=’attributeChange’ )
except RuntimeError:
cmds.headsUpDisplay(‘SpeedHUD’, remove=True)

 

Maya playblast tool2

here is an improved version of the playblast script. Jean Denis pointed out the playblasting of more cameras is sequential and parallel. (thanks for that!) which would extreme slow in heavy scene with complex characters or large cache file. the new version of the script capture all cameras on each frame at the same time.  this way, maya have evaluate once on each frame and not do extra evaluation for each camera.  this way you can playblast simulations with different camera without caching.

i am using the active viewport for each camera to keep resolution constant. (and it avoid maya viewport issues).

* just made a little update to free maya after player is showing up

** another update: i added 2 more botton’s for houdini “mplay” tool. if you have houdini installed (even the demo version) it will bring up a mplay app and play until 4 cameras simultaneity in one window. (row or quas view)
tip: with shortcut “s” you link all view together and zoom synchronously

*** you use rv tile option (menu tools–>tile) to view all cameras side by side. i set it to default in the script

**** bugfix with timerange

Screenshot
download it here

// written ny Heribert Raab heribertraab@gmail.com
// the tool create outliner with contain just cameras
// clicking on each camera switches through camera on your active viewport
// playblast botton will playblast all selected camera with aktiv viewport and load them into fcheck or rv

global proc playB(string $player)
{
string $select[] = `ls -sl`;

// setup playblast dir
//string $path = “/tmp/test/”;
string $frames2[] ;
string $fl[] = `renderSettings -firstImageName -fullPathTemp`;
string $f2[] = `renderSettings -firstImageName`;
string $path = substituteAllString($fl[0], $f2[0], “”);
int $min = `playbackOptions -q -minTime`;
int $max = `playbackOptions -q -maxTime`;
int $fr = $max – $min;

int $f;
string $all;
string $play;
string $scene = `file -q -sn -shn`;
string $scname = substituteAllString($scene, “.”, “_”);

for ($f=$min;$f <$max;$f++)
{
// playblast selected Cameras
$numInts = size($select);
$ridNum = $numInts +1;
int $i=0;
string $seq[];

for ($i=0;$i < $numInts; $i++)
{
lookThru ($select[$i]);
$frames2[$i] = $path+$scname+”_”+$select[$i];
//print ($frames2[$i]+”.”+$f+”\n”);
playblast -st $f -et $f -forceOverwrite -format image -fp 4 -compression “jpg” -f($frames2[$i]) -viewer 0 -offScreen -percent 100 -quality 70;
}
}
$all = stringArrayToString($frames2, “.* “);

//image player command
$play = ($player+” “+$all+”*”);

if ($player ==”mplay”) $play= ($player+” -V 2 2 -g “+$all+”* &”);
if ($player ==”mplay2″) $play= (“mplay -V 4 1 -g “+$all+”* &”);
if ($player ==”rv”) $play_rv = ($player+” -tile “+$all+”* &”);
if ($player ==”fcheck”) {$play = ($player+” -S “+$all+”* &”);}

print $play;print “\n”;
system( $play );
}

global proc look(){lookThru `ls -sl`;}

string $filterP = `itemFilter -byType camera `;

window cameras;
frameLayout -labelVisible false ;
string $panel = `outlinerPanel`;
columnLayout -adjustableColumn true;
button -label “Playblast selected Cams with RV” -command “playB rv”;
button -label “Playblast selected Cams with Fcheck” -command “playB fcheck”;
button -label “Playblast selected Cams with mPlay quad” -command “playB mplay”;
button -label “Playblast selected Cams with mPlay row” -command “playB mplay2”;

string $outliner = `outlinerPanel -query -outlinerEditor $panel`;
outlinerEditor -edit
-mainListConnection “worldList”
-selectionConnection “modelList”
-f $filterP
-selectCommand look
-showSetMembers true
-setFilter defaultSetFilter
$outliner;
showWindow;

maya effects outliner

its not always easy to find effects-related nodes in bigger maya scene files

this effects outliner shows only “effects”items and adds an handy dynamic Relationshipeditor botton.
(python script)
download it here

import maya.cmds as cmds
import math

# written ny Heribert Raab heribertraab@gmail.com
# create outliner window with show only effect related item’s

#setup filter with nodetypes
filterDyn = cmds.itemFilter(byType=(‘fluidEmitter’,’pointEmitter’,’rigidBody’,’nRigid’,’fluidShape’,’nParticle’,’nucleus’,’particle’,’nCloth’,’rigidConstraint’))

#delete allready open effects outlines
renUI = ‘EffectsOutliner’
if cmds.window(renUI, exists = True):
cmds.deleteUI(renUI)
def dynEditor(*args):
cmds.DynamicRelationshipEditor()

cmds.window(‘EffectsOutliner’,title=’EffectsOutliner’)
cmds.frameLayout( labelVisible=False,)
panel = cmds.outlinerPanel()
outliner = cmds.outlinerPanel(panel, query=True,outlinerEditor=True)
cmds.outlinerEditor( outliner, edit=True, mainListConnection=’worldList’, selectionConnection=’modelList’, filter=filterDyn , showShapes=True, showAttributes=False, showConnected=False, showAnimCurvesOnly=False, autoExpand=True, showDagOnly=True, ignoreDagHierarchy=True, expandConnections=False, showNamespace=True, showCompounds=True, showNumericAttrsOnly=False, highlightActive=True, autoSelectNewObjects=False, doNotSelectNewObjects=False, transmitFilters=False, showSetMembers=True, setFilter=’defaultSetFilter’ )

cmds.columnLayout( adjustableColumn=True )
cmds.button( label=’DynamicRelationshipEditor’, command=dynEditor)
cmds.showWindow()

pixelizer with volumes

i was playing around woth the idea to use a 3d-software package to create pixel retro style renderings. I got good results in Houdini. i using SDF volume to scatter point and instance Geometrie on it. this is very flexible. it allows me to use textured character to colorize the “pixels”.
the nice things about it i can use all rigging and modeling stuff, which 3d-software have to offer. is also allows me to use shadow and other shader tricks to create the look. right in opengl viewport, i can design the Retro-design in realtime. i even can mix it up with non-pixlized object, (examples: for the eyes)

check the test renders.

kill particles on special objects

add attr collisionGeometryIndex to you particle shape and :

 

int $idx = particleShape2.collisionGeometryIndex;

string $geoC[];
string $shape[];

if( $idx != -1 )
{

string $geoC[] = `listConnections particleShape2.collisionGeometry[$idx]`;
string $shape[] = `listConnections ( $geoC[0] + “.localGeometry” )`;
print( $shape[0] + “\n”);
if ($shape[0] == “killcube”) particleShape2.lifespanPP = 0;
}

download it here

new gizmo’s for nuke


i have created new gizmo.
first one:lens distortion filter which zoom pixel like a loupe. and with some controls for glass lens distortion.there is also optional a simple loupe shading but is really basic, its beta
you can download it here or at fxshare.com

the scenond one: similar with the common node in apple’s shake. and i also added some extra controls for finetunning.you can download it here or at fxshare.com