/* */

Saturday, 14 January 2012

Parent add shape

Really useful technique for adding ctrl curves to a null Group.

1. Create your null Grp position, freeze trnsfrms etc, etc.
2. Create your Ctrl Curve and move it into position.
3. Select the curve shape (important to select the shape node by pressing down arrow key)
4. Select Null Grp
5. Type following code:
         parent -s -r

Done! Selet the curve, move it about, it now controls the null group. Select the curve in the hypergraph, delete it - the curve in the viewport is still there, it's connected to the group.

Tuesday, 10 January 2012

UV Driver

For use in ball joint areas such as shoulder and hip joints. Involves referencing the UV coordinates of a nurbs patch to drive a corrective blend shape or influence object.  

Create a nurbs patch:
Make sure its twice as wide as the upper arm joint
1 linear surface degree
X axis pointing down
1 U patch
1 V patch

Snap it to shoulder joint

Create Locator:
Point constain it to the elbow joint
Geometry constrain it to the nurbs patch
Now when the elbow joint moves, the locator translates on the nurbs patch


Create a "closestPointOnSurface" Node, name it cpos:
MEL code: createNode closestPointOnSurface -n cpos;

Open Connection Editor:
Load "cpos" into the inputs
Load Nurbs patch shape node (select and press down arrow for shape)
connect World position (patch shape node) to cpos input surface

Select Locator:
Load it into Outputs of the connection editor
connect its translate into the inPosition of the cpos Node

Select cpos in the channel box (under locators outputs)
load it into Outputs of the Connection Editor


Create new node - a point on surface Node:
MEL code: createNode pointOnSurfaceInfo -n posi;
Load it into Inputs of Connection Editor
Expand "result" under cpos
Connect its parameter U to posi parameter U
Connect its parameter V to posi parameter V

Reload Nurbs patch shapenode into Outputs
connect its worldSpace into the inputSurface of the posi Node


Set Driven Keys:
Now we'll create an object that will have an attribute driven  by the U and V parameter of the posi Node.
select it, go to Animate - set driven key
select the "posi" Node, load it as driver
In this example we'll control the scale Z of the sphere with the U Parameter and the Scale Y
with the V Parameter.
Select the "Parameter U" in the right hand column of the sdk window
Select the "Scale Z" of the nurbsSphere1
Hit "key" button to set default
Translate IK handle so its U position is at 0 on the patch
Scale the nurbsSphere1 in Z to whatever size you want it (I went to 2)
Hit "key" button
Translate IK handle so its U position is at 1 on the patch
Scale the nurbsSphere1 in Z to whatever size you want it (I went to 0.5)
Hit "key" button


Now when you translate the IK back and forwards, the nurbssphere's scale Z will change in
accordance with the U value of posi. This could be used as an influence object, alternatively
could be used to drive a corrective blend shape.

Sunday, 8 January 2012

simple window

Simple bog standard window to get the ball rolling, which begins with an if statement to check the window doesn't already exist. If this is the case, a deleteUI command is called to get rid of it.

if (cmds.window(myWindow, exists=True)):
    cmds.deleteUI( myWindow)

#Checks the window doesnt already exist, if so, it'll go ahead and delete the window and start from #scratch.

myWindow = cmds.window(title = "Slider Window", width =100, height = 200)
cmds.showWindow(myWindow)

#Creates a window withe title "Slider Window", width/height 100/200 respectively. Show window is #essential to display it on screen.

Sunday, 9 October 2011

buggy suspension dynamics



Quick test using maya's dynamics system and a poly helix which has a blendshap on it. There's a dynamic spring constraint which drives the position of the bottom of the spring.

Problem with this test is the bottom goes right through the top position due to the momentum on the first swing. In reality the upward motion would cause it to bend and move out in the x or z axis as it finds somewhere to go - the springs length cannot physically pass beyond a certain point.

This is not really an issue with a cars suspention because it is physically constrained by its pistons so cannot travel beyond its shortest point.

buggy suspension spring

Getting the suspension springs to behave right is fairly straight forward, but there are a few annoying pitfalls which will have you going in time consuming circles if you're not careful.
The springs are deformed using a blendshape - my first instinct was to use the helix's creation history height field to drive the stretch. Applying this I soon discovered the deformation occurs from the centre and expands out in the y axis, which is unrealistic. A car suspension springs deformation works from the top down.

To overcome this I used a MEL script called "spiral" which creates a cv curve with the height radius and coil number specified by the user.

The command is as follows:

spiral (Height, Radius, Coils)

The parameters should be identical to the poly helix's dimension's so the curve runs through it's centre you usually have to scale it in x -1 and rotate it in y by 180 degrees to match it up). Once the curve is created, attach it to the poly helix via a wire deformer, then add a joint chain which runs through the centre of the spiral (give it a generous amount).

Skin the joint chain to the spiral curve and scale each joint in x (excluding the end joint unless its oriented correctly). You should be getting a nice even deformation down the poly helix, with no flattening as it stretches.

Pitfalls

So up intil now, things have appeared pretty straight forward, but there are a couple of things to look out for when building this set-up.

flattening out:

Image left is the initial state of the spring - it has a spiral curve driving it which in turn is driven by a joint chain. So far so good. Next step is to test it out by scaling the joints (minus the last one) in x to stretch it out. 

When scaled in x it is painfully obvious the deformation is wrong - the spring flattens out at the bottom.This occurred because I initially build the poly helix with its coils too tight together, which means the wire deformer's coils are affecting more than one coil each. So this means going back, rebuilding the spring with more generously spacd coils and repeating the process - not the end of the world, but something to bare in mind from the start.




<< 01 02 03 04 05 06 07 08 09 10 >>


Saturday, 10 September 2011

Match Pivot Script

Quick script i've put together that'll match the worldspace pivot point of one object to the other. Very simple just useful for modelling and rigigng purposes:


//Match Pivot by jim dunford 10/09/2011

string $object[] = `ls -sl`;

int $arraySize = `size $object`;
if ($arraySize < 2)
print "only one object selected";
else

{
vector $e = `xform -q -rp -ws $object[0]`;
setAttr($object[1]+ ".translateX") ($e.x);
setAttr($object[1]+ ".translateY") ($e.y);
setAttr($object[1]+ ".translateZ") ($e.z);
print "great success!";
}



<< 01 02 03 04 05 06 07 08 09 10 >>

Wednesday, 6 April 2011

FkIK Switch

As per kind instructions form Brian Kenny on the Rigging 101 forum, the x-axis remains pointing down the ik line, point constrained between the fk and ik knee. The z and y translates are then zero'd out to return it along the ik line.

I've drawn a 1 degree spline to illustrate the angle I need the twist control to rotate in order to match up with the fk knee's rotation.

Many thanks to Brian for his help on this - he's probably saved me about 2 weeks work!