Form and Space

creating CG 3D since 2001

  • Connect @
  • Linked in
  • Vimeo
  • Twitter

Multiple Motion Paths

Matthew | November 10, 2011

2 Comments

Here’s a tool for Maya that is similar to a multi-path constraint in Softimage, multi motion paths. Make a new scene, create a curve, create a few objects to attach to the curve, select the objects, and run the script below.

string $selection[] = `ls -selection`; 
int $size = size($selection);

//change this to your curve name
string $path = "curve1";

for($i=0; $i<$size; $i++){
   
   float $uLinearDistribution = 1.0/$size*($i+1);
   float $uRandomDistribution = rand(0,1)/$size*($i+1);
   //print ($uRandomDistribution+"\n");
   
   
   string $motion = `pathAnimation -f 1 -fm 1 -etu 0 -c $path $selection[$i]`;
   string $source = $motion + "_uValue.output";
   string $destination = $motion + ".uValue";
   disconnectAttr $source $destination;
   
   setAttr ($motion + ".uValue") $uLinearDistribution;
   //setAttr ($motion + ".uValue") $uRandomDistribution;
   
}

There's an option for random distribution, just disable the comment. There's no error checking, so use at your own discretion/peril. Each object will have it's own MotionPath node, so check the Attribute Editor for more info.

This will come in handy when we create grapes in the Intro to 3D Modeling course.

2 responses to “Multiple Motion Paths”

  1. Jordan Kohler says:

    Here is a slightly modified version of this script.
    It will use either the first curve in your selection or the first curve available in the scene if no curve is selected.

    /*===========================*/
    //Beginning of Jordan's stuff

    /*First, if there are any curves at all, select one as a backup plan.*/
    string $list_curves[] = `ls -type "nurbsCurve"`;
    string $c_transform[] = `listRelatives -parent $list_curves[0]`;
    string $path = $c_transform[0];

    /*Next, set up selection and size varables independant from Matt's
    so that I don't mess it up, and so I can remove the $path curve from
    Matt's selection.*/
    string $cSel[] = `ls -sl`;
    int $cSize = size($cSel);

    /*Use a 'while' loop (because I am going to need to break out of it if
    it finds a suitable curve) to check each selected object's shape node
    type. If we find a nurbsCurve, use it as the $path and stop looking.*/
    int $ci = 0;
    while ($ci < $cSize){
    $list_curves = `listRelatives -shapes $cSel[$ci]`;
    if (`nodeType $list_curves[0]` == "nurbsCurve"){
    $path = $cSel[$ci];
    $ci = $cSize;
    }
    $ci++;
    }

    /*De-select the $path so that it dosn't try following itself.*/
    select -d $path;

    //End of Jordan's stuff
    /*=====================*/

    string $selection[] = `ls -selection`;
    int $size = size($selection);

    //Deleted!
    //string $path = "curve1";

    for($i=0; $i<$size; $i++){

    float $uLinearDistribution = 1.0/$size*($i+1);
    float $uRandomDistribution = rand(0,1)/$size*($i+1);
    //print ($uRandomDistribution+"\n");

    string $motion = `pathAnimation -f 1 -fm 1 -etu 0 -c $path $selection[$i]`;
    string $source = $motion + "_uValue.output";
    string $destination = $motion + ".uValue";
    disconnectAttr $source $destination;

    setAttr ($motion + ".uValue") $uLinearDistribution;
    //setAttr ($motion + ".uValue") $uRandomDistribution;

    }

    //Oh, Jordan added this too because of that select -d up there.
    select -r $cSel;

  2. Matthew says:

    Thank you for the expanded script! I’m sure former, current, and future students will benefit from your contribution.

Leave a Reply

Twitter

Subscribers

    396