/* */

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!

Thursday 24 March 2011

Tuples - Intro

Tuples are immutable sequences and are created simply by separating value with commas;
1,2,3, you have a tuple!
Usually you'd enclose the tuple in parenthesis:
x = 1,2,3
x
(1,2,3)
() → creates an empty tuple
42, → creates a tuple with 1 value (42,). The added comma specifies its a tuple
note the difference a comma can make:
3x(40+2)
126
3x(40+2,)
(42,42,42)

String formatting with Dictionaries

phonebook = {'Beth' : '9102' , 'Alice' : '2341' , 'Cecil' : '3228' }
"Cecil's phone number is %(Cecil)s." %phonebook
"Cecil's phone number is 3258."

The (Cecil) points to that particular key, 'phonebook' directs towards the dictionary.

Advantages of Dictionaries over Lists

x = []
x = [42] = 'Foobar'
-error
x = {}
x[42] = 'Foobar'
x
{42 : 'Foobar'}
When we try to assign a value to position 42 in a list it returns an error because items 0-41 dont exist. Because a dictionary relies on mapping rather than sequencing, the key can be created.    

dictionary functions

len(d) - returns number of items (key-value pairs) in d
d[k] - returns the value associated with the key 'k'
d[k]= v - assigns the value 'v' to key 'k'
k in d - checks if the key 'k' is in dictionary 'd'

-dict

The dict function creates a dictionary from other mappings (other dictionaries) or from sequences of pairs (key,value):
items =[('name', 'Jim'), ('age', 42)]
d= dict(items)
d
{'age' : 42, 'name' : 'Jim'}
d['name']
'Jim'

Also can be used with keyword argument:
d= dict(name= 'Jim', age= 42)
d
{'age' : 42,  'name' : 'Jim'}

Wednesday 23 March 2011

-in

in; the membership operator....
name= raw_input('whats yer name? ')
if 's' in name:
    print 'Your name contains the letter "s"'
else:
    print 'Your name doesn't have the letter "s"'

Comparisons

Comparisons are boolean operations and utilise operators to return a true or false answer (o or 1).

x=y= [1,2,3]
z= [1,2,3]
x==y
True
x==z
True
x is y
True
x is z
Flase

The == simply means 'same value' - Slight differeation from a single =, we use this to assign a value to a variable, we use the double == to test whether two values are equal.
The is operator tests if they are the same object - in the above example x is not the same object as z (although they share the same value). Lists can be equal but not identicle.

-lower

returns the lower case version of the string:
'Trotsky Hammer Prowl'.lower()
'trotsky hammer prowl'

-Join

Joins the elements of a sequence, does the opposite of split:
seq = [1,2,3,4,5]
sep = '+'
sep join(seq)

This would give an error because we are trying to join a list of numbers with an opeator. If the sequence consisted of:
['1','2','3','4','5']
the reult would be different
'1+2+3+4+5'

Conversion specifiers

%s-
Mark the place where the string/value is to be inserted. %s means to convert to a string.

Strings - Intro

Strings are immutable and support standard sequence operations:


indexing, slicing, multiplication, membership, length, minimum, maximum.

tuple

The tuple function takes a sequence and converts it to a tuple:

tuple([1,2,3])
(1,2,3)
tuple(abc)
('a','b','c')
tuple((1,2,3)) → takes a tuple within a tuple and converts it to one tuple
(1,2,3)

Creating Dictioanries

phonebook = {'Alice' : '2341', 'Beth' : '9102', 'Cecil' : '3258'}

Phone books consist of pairs - their 'key' and irs corresponding item.
e.g. the key 'Alice' has a value of '2341'.
This script has expressed the values as 'strings' and not integeres in order to avoid them being interpreted as octagonal numbers.

Creating an empty dictionary is written:

phonebook = {}

Dictionary - Intro

Dictionaries:
  • refer to value by mapping 'mapping'
  • values don't have an order, but stored in a 'key'
  • 'key's' can be numbers, strings, tuples

Access tuple elements

x = 1,2,3
x[1]
2 → indexing is the same procedure as lists
x[0:2]
(1,2) → again same as lists, index items from 0 up to 2 (excluding 2)

  • Tuples can be used as keys when mapping.

Tuesday 22 March 2011

Using 'key' in sort

x = ['add', 'acme', 'aerate', 'aardvark', 'abalone']
x.sort(key = len)
x
['add', 'acme', 'aerate', 'abalone', 'aardvark']

This example uses 'len' as the key function - it arranges the items in order of their length.

Sorting tutorial online:

http://wiki.python.org/moin/HowTo/Sorting 

Sorted

x = [4,6,2,1,7,9]
y= sorted(x)
x
[4,6,2,1,7,9]
y
[1,2,4,6,7,9]

Sorted function very similar to 'sort'. Can also be used on a sequence:

sorted('Python')
['P,' 'h', 'o', 'n', 't', 'y']

Arranges the string into an alphabetical sequence.

Sort

Sort a list into numerical order - this changes the original rather than returning a copy of the list;

x = [4,6,2,1,7,9]
x.sort()
x
[1,2,4,6,7,9]

Reverse

reverse elements in a list;

x = [1,2,3]
x.reverse()
x
[3,2,1]

This reverses the list but doesn't return anything.

Remove

removes 1st occurance of a value in a list;

x = ['to', 'be', 'or', 'not', 'to', 'be']
x.remove('be')
x
['to', 'or', 'not','to', 'be' ]

Pop

x= [1,2,3,]
x.pop()
3

Deletes the last entry of the list

x
[1,2]
x.pop(0) - specifies which item to delete
1 - returns the value of the item it just deleted
x
[2]

Insert

insert an object into specified position in a list:

numbers [1,2,3,4,,5,6]
numbers.insert(3,'four') - insert 'four' at position 3
number
[1,2,3,'four',5,6,7]

Index

Knights = ['Richard', 'of ', 'York', 'Gave', 'Battle', 'in', 'vein']
Knights.index('York')
2
Knights.index('pudding')
-error

Finds the word in the list and returns its position.

Count

['to','be','or','not','to','be'].count ('to')
2

This counts the amount of times a given object appears in the list (in this case the word 'to')

Extend

append several items at once:

a = [1,2,3]
b = [4,5,6]
a.extend(b)
a
[1,2,3,4,5,6]

This is similar to concatenation except the variable 'a' is modified. In concatenation, the result would create a new variable.

Append

lst = [1,2,3,]
lst.append(4)
lst
[1,2,3,4]

Simply adds the value in the brackets to the variable (note the variable was declared 'lst' and not 'list'. 'list' is a function and would have given an error).

Remove elements

numbers = [1,2,3,4,5,]
numbers [1,4] = []
numbers = [1,5]

This has similar effect to the delete statement and is related to replace. In this case you are simply replacing all the elements from position 1 up to (but not including) position 4 and replacing it with [] - an empty list. The items that survive in the list are those in position [0,4]. 

Insert elements

numbers = [1,5]
numbers [1:1] = [2,3,4]
numbers
[1,2,3,4,5,]

The inserted elements are placed in the list at position 1

List statement, assign to slices

name = list('Pearl')
name
['P','e','a,'r','l'']
name[2:] = list('ar')
name
['P','e','a','r']

List statement turned the string ('Pearl') into a list.
The list('ar') replaces anything from position 2 onwards in the name list, hence it's new value being ['P','e','a','r']

Deletion

names = ['Alice', 'Beth', 'Julie', 'Cecil', 'Gary']
del names [2]
names
['Alice', 'Beth', 'Cecil', 'Gary']

Use the del function to delete item from list.

Changing Lists

- assignment:
x = [1,1,1] - Declare list and its values
x[1] = 2 - Assign value of 2 to position 1
x
[1,2,1,] - New value of x

To change list items, index the item you want to change (x[1]) and assign a new value to it (x[1] =2).

Len Min/Max

example:

numbers = [100, 34, 678]
len(numbers)
3

max(numbers)
678

min(numbers)
34

max(2,3)
3

min(2,3)

Len function returns either the highest or lowest values in a sequence (the first two examples) or directly as a sequence argument (the last two examples).

Summary

Sequences - data structure with numbered elements
Membership - whether a value can be found in a sequence
Methods - like functions but are tied to a specific value
Vectors   
                        =                    ||V|| =√(12²+(-5²))
Vectors are split into two values:
  1. magnitude - the length of the vector 
  2. direction - the direction of the vector 
magnitude is expressed as ||V||  - V stands for vector, so the magnitude of vector [12 -5] would be written ||12 -5||
magnitude =           ||V|| =√(a²+b²)
= V=√(12²+(-5²))