Showing posts with label maya. Show all posts
Showing posts with label maya. Show all posts

Friday, 12 November 2010

Shark Swim Cycle



Tried to get layered animation working in blender but the NLA didn't seem to work the way I wanted it to (like animation layers in maya) so I gave up for the morning and tried to animate a swim cycle.  That didn't go too well either - I'd build the flippers on the model far too low down and they looked unnatural in what should have been their rest pose by their side.  My spline IK rig which was meant to make animating the sine wave easier ended up making it harder as I had far too few bones controlling the spline to get a smooth enough wave.  Added to that the tail could have done with a few more bones to smooth out the motion.  The looping destroys the effect of the fake caustics and volumetrics somewhat, but never mind, I hate default grey (or 'Material.001' as its otherwise known).

Thursday, 4 November 2010

Week 4 Line Test and Maya

Week 4 - pushing and pulling and last week's bouncy ball with a mesh deform to vertex color based shader I coded in MEL.




code...

int $numberOfVertices[]=`polyEvaluate -vertex pSphere1`;
string $neighbouredges[];
string $neighbourverts[];
float $edge_start_original[3];
float $edge_end_original[3];
float $edge_start_deformed[3];
float $edge_end_deformed[3];
float $diff_original[3];
float $diff_deformed[3];
float $total_length_original;
float $total_length_deformed;
float $stretch_amount[];
int $edges[];
int $i=0;
for($i=0;$i<$numberOfVertices[0];$i++)
 {
 //find neighbour edges
 $neighbouredges=`polyInfo -ve pSphereShape1.vtx[$i]`;
 string $buffer[];
 int $num_tokens = `tokenize $neighbouredges[0] $buffer`;
 $num_tokens-=2;
 for ($k=0;$k<$num_tokens;$k++)
  {
  $edges[$k]=(int)$buffer[$k+2];
  }
 //now convert the edges to lengths

 $total_length_original=0;
 $total_length_deformed=0;
 for ($l=0;$l<$num_tokens;$l++)
  {
  $neighbourverts=`polyInfo -ev pSphereShape1.e[$edges[$l]]`;
  tokenize $neighbourverts[0] $buffer;
  int $verts[2];
  $verts[0]=(int)$buffer[2];
  $verts[1]=(int)$buffer[3];

  //get edge lengths
  $edge_start_original=`xform -ws -q -t pSphereShape1Orig.vtx[$verts[0]]`;
  $edge_end_original=`xform -ws -q -t pSphereShape1Orig.vtx[$verts[1]]`;
  $edge_start_deformed=`xform -ws -q -t pSphereShape1.vtx[$verts[0]]`;
  $edge_end_deformed=`xform -ws -q -t pSphereShape1.vtx[$verts[1]]`;
  $diff_original[0]=$edge_end_original[0]-$edge_start_original[0];
  $diff_original[1]=$edge_end_original[1]-$edge_start_original[1];
  $diff_original[2]=$edge_end_original[2]-$edge_start_original[2];
  $diff_deformed[0]=$edge_end_deformed[0]-$edge_start_deformed[0];
  $diff_deformed[1]=$edge_end_deformed[1]-$edge_start_deformed[1];
  $diff_deformed[2]=$edge_end_deformed[2]-$edge_start_deformed[2];
  $total_length_original+=sqrt(pow($diff_original[0],2)+pow($diff_original[1],2)+pow($diff_original[2],2));
  $total_length_deformed+=sqrt(pow($diff_deformed[0],2)+pow($diff_deformed[1],2)+pow($diff_deformed[2],2));
  }
 $stretch_amount[$i]=($total_length_deformed/$total_length_original);
 }

//find max and min
float $max_stretch=-1;
float $min_stretch=-1;
for($i=0;$i<$numberOfVertices[0];$i++)
 {
 if($max_stretch==-1 && $min_stretch==-1)
  {
  $max_stretch=$stretch_amount[$i];
  $min_stretch=$stretch_amount[$i];
  }
 if($max_stretch<$stretch_amount[$i])$max_stretch=$stretch_amount[$i];
 if($min_stretch>$stretch_amount[$i])$min_stretch=$stretch_amount[$i];
 }

for($i=0;$i<$numberOfVertices[0];$i++)
 {
 if($min_stretch!=$max_stretch)$stretch_amount[$i]=($stretch_amount[$i]-$min_stretch)*(1/($max_stretch-$min_stretch));
 else $stretch_amount[$i]=0;
 polyColorPerVertex -colorR $stretch_amount[$i] pSphereShape1.vtx[$i];
 polyColorPerVertex -colorG $stretch_amount[$i] pSphereShape1.vtx[$i];
 polyColorPerVertex -colorB $stretch_amount[$i] pSphereShape1.vtx[$i];
 }