Scripting For Animation and VFX: Week 2
Scripting for Animation and VFX: Week 2
Expressions
In order to improve writing expressions, I will work on small projects to solve small problems with expressions and work up to solving larger problems and combining simple expressions in order to make more complicated ones.
DAG and DG
DAG stands for Direct Acyclic Graphs and DG stands for Dependency Graphs.
DAG:
Directed Acyclic Graphs are directed graphs that do not have directed cycles. Directed graphs are made up of vertices and edges, each edge is directed from one to another. In DAG graphs the edges will never form a loop. Direct Acyclic Graphs are topologically ordered. The paths in the graph are linear.
Maya uses DAG graphs when parenting objects. The child of a parent object can not also be the parent. So parenting can not form loops.
DG;
Dependency Graphs are directed graphs graphs that represent the dependency of objects towards each other.
Dependency graphs can show the transfer of data. These are not acyclical, as data can go both ways.
One way to see these differences is when creating geometry. Creating geometry creates several nodes in the hyper graph. For example creating a cube makes a node called polyCube and a node called pCube. PolyCube is a DG node. It produces vertices of the cube. That information is sent to the pCubeShape node. This nodes contains the information on the vertices, what the faces look like and how the normalls are facing. PCube node determines where this object is in space, with out it the shape would not know where it is. The PCube node acts as a pivot point. PCube is separate from the other nodes in the hyper graph.
Variables and Functions in MEL
Arrays
Work like lists. They can store multiple items in them.
Print
print is a function that can be used to print text, as well as the value and results of variables and functions.
Is
Returns the names and optionally the type names of the objects in the scene.
setAttr
setAttr can be used to change the value of different attribute of objects. setAttr can be used to change the translateY value of an object. This function is very useful for a variety of problems. By using setAttr in a script and one can automate changing the attributes of many objects, simplifying the process.
select
Select shows flags that are associated with objects. These show different attributes of the object.
rename
rename function can rename an object.
For-in loop iterating through a selection
For a for-in loop i decided to try to make a staircase by raising each object in a selection by an amount that would increase through iteration of the loop. My goal is to be able to make a bunch of cubes or other objects and have them form a staircase formation by changing their translation values.
First step is writing code that detects user selection. I followed along with the videos on blackboard learn to get this started.
string $selection[] = `ls -sl`;
I followed along with the video to recreate the rename for in loop.
int $num = 1;
for ($each in $selection)
{
rename $each ("box_" + $num);
$num = $num + 1;
}
this for in loop iterates through a selection and uses the rename function to name the cubes box. The variable num is created before the loop so that is can be increased through each iteration of the loop without using the given value over and over.
I added these lines to the loop to move the cubes along the x and y axis to create a stair case. I also added a line of code to increase the scale of each cube along the z axis to make the stair case get wider as it goes up.
int $num = 1;
for ($each in $selection)
{
rename $each ("box_" + $num);
setAttr ($each + ".ty") ($num);
setAttr ($each + ".tx") ($num);
setAttr ($each + ".sz") ($num);
$num = $num + 1;
}
Comments
Post a Comment