Posts Tagged ‘Maya’

Inherited Transformation

Thursday, November 17th, 2011

Here’s a simple script for a long chain of parented objects.
Create a bunch of cubes in one place, select then all in the viewport, and run this script. Marquee select them all again, and transform the objects to see the effect. This takes advantage of inherited transformation.


string $null[] = `ls -tr -sl`;

int $n = size($null);

for($i = 0; $i < $n; $i++){
if($i != $n-1){
parent $null[$i] $null[$i+1];
}
}

Scripting

Tuesday, November 15th, 2011

Yesterday I was asked by one of my students, Andrew, where I learned scripting and what sources I’d recommend for learning scripting. To the first question, I learned on my own, with no formal training. I bought books, I read websites on the topic, and I read the SDKs of the software, over and over again. I gradually became more familiar with the syntax, the logic, and my own patience. In 2002, I started with Actionscript, AS, for Flash, which is based on a type of J-script, and from there I graduated to Softimage XSI. XSI had large libriaries of examples in the SDK, software developers kit, written in J-script, and I was able to read and write from those examples based on my experience with Actionscript 1.0. In 2008, I was back into Actionscript for a short while, on the social networking website prototype, at that point it was now AS 3.0. A fully object oriented programming language, or OOP, and I took to that right away. It took me several years of work in XSI and AS to understand OOP. I’ve also attempted to learn Python, though I haven’t committed the time and resources to use it well enough.

It takes me a long time to write code of any kind, and I require 50-60% guidance, the rest I dream up on my own. Whenever the software couldn’t solve a problem, or when I became very curious on how something works in a software, I’d take the time to write it myself. Sometimes, I’ll automate a task, just to see it in code, and from there it encourages me to take on something a little bigger. Changing software, like the switch from Lightwave to Softimage XSI back in 2005, motivates me to make tools to ease my transition from one software to software. For example, I’m quite happy with my abiility to model with curves in Maya, and I’d like that ability in Softimage (curve modeling being one of SI’s weaknesses).

As for the second question, here is a list of books in my library that have helped me over the years. I recommend all of these authors.

Any book on the subject of J-script or programming syntax and logic. Each language has it’s own particulars, but all languages share similar rules. Learning one language makes learning a second far easier.

Python
John Zelle (Personlly, if I were to start all over again, I’d start here. Not because it’s pythin, but because this guy is a great teacher).

Actionscript
Keith Peters
Joshua Davis (I’m not sure if he has published anything recently).

MEL (Maya Embedded Language)
David Gould

There are many other good references, but these authors stand out in my mind. You can find more information about these authors and other great people by sifting through my links to the right.

I have to mention that programming has led me to love math. More specifically, programming has allowed me to see math in action, and I understand it better and apply it better as a result of learning programming.

Multiple Motion Paths

Thursday, November 10th, 2011

Here’s a tool for Maya that is similar to a multi-path constraint in Softimage. 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.

Iterated Space Transformation

Tuesday, November 8th, 2011

One of my classroom assignments is to model a spiraling staircase. I find this assignment to be very exciting, as it introduces my students to modeling with multi-dimensional arrays. Then my one of my students, Casey, found a reference on Google images that I hadn’t seen before. A sculpture by Peter Coffin at the Saatchi Gallery.

Untitled (Spiral Staircase)
2007
Aluminum and steel
670.6 x 670.6 x 213.4 cm
Peter Coffin

Now, this is interesting, and it peaked my curiosity to try and recreate it in Maya.

Start with a radial array.  A radial array is quite simple, but to then rotate each step, incrementing from one to another, in their local space required MEL scripting. Essentially, I have a box remodeled into the form of the step, then it is grouped twice. I leave the first group at the origin, then translate the second group on the Z axis to a distance equal to the diameter of the main ring in the sculpture. From here I create a radial array using Duplicate Special. In Duplicate Special, I use copy and instance leaf node (so all the steps can be modeled simultaneously). I make as many copies as there are steps, about 71 steps at 5 degrees on the Rotation Y axis. I use 71 because I already have one, for a total of 72. The twist requires the script. I begin the script by collecting all the objects in the selection, so all the steps (the polygon mesh). Then I find the current rotation attribute value, change the value by adding it’s own value with and offset value, then set the attribute with the new value. This enables the user to transform an entire group of objects without rebuilding the array using Duplicate Special.

//The value of the increment, floating point
float $nX = 5.0;
float $nY = 0.0;
float $nZ = 0.0;
//The attribute to change.
string $attr = "rotate";

string $attributeX = "." + $attr + "X";
string $attributeY = "." + $attr + "Y";
string $attributeZ = "." + $attr + "Z";

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

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

float $X;
float $Y;
float $Z;

float $offsetX;
float $offsetY;
float $offsetZ;

$X += $nX;
$Y += $nY;
$Z += $nZ;

float $attrX = getAttr ($nodes[$i] + $attributeX);
float $attrY = getAttr ($nodes[$i] + $attributeY);
float $attrZ = getAttr ($nodes[$i] + $attributeZ);

$offsetX = $attrX + $X;
$offsetY = $attrY + $Y;
$offsetZ = $attrZ + $Z;

setAttr ($nodes[$i] + "." + $attr) -type "double3" $offsetX $offsetY $offsetZ;
}

I also made a version using vectors, but I’ve found this version to be unstable. The Z value will randomly produce huge jumps in value. If you have an idea of how to make this version better, do tell.


string $myAttr = "translate";
//The value of the increment
vector $vIncrement = << 0.0, 0.0, 3.0 >>;

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

//to include the first object, use $i=0
for($i = 1; $i < $size; $i+=1){
vector $v;
vector $vOffset;
$v += $vIncrement;
vector $vAttr = getAttr ($selection[$i] + "." + $myAttr);
$vOffset = $vAttr + $v;
setAttr ($selection[$i] + "." + $myAttr) -type "double3" ($vOffset.x) ($vOffset.y) ($vOffset.z);
}

Infinite Stairwell

Attempt

At this point, the only thing that can make this better, is if it were adjustable in real-time and animatable.   I’ll leave it to Casey to solve the rest.

Maya: Wireframe Rendering

Sunday, October 2nd, 2011

Courtesy of a former student’s guidelines, Scott Grasso, here’s a video demonstrating how to set up a mesh for wireframe rendering for a sub-division surface mesh. It’s quite simple, and I like that. This is perfect for setting up your demonstration reel. With a little more planning, the wireframe can be rendered on a white constant shader, and then multiply that render with the beauty pass to showcase the wireframe over the final render.

from the training video on wireframe rendering

Wireframe Rendering