Tag: snap

Pole vector maths

In my old rig, the lower limbs rotate in single plane only. That simplifies the story. Just put a locator under the FK lower limb, having the same world position as the pvCtrl at initial pose. Snapping to FK means snapping the pvCtrl to this locator because the rotate plane is always correct.

But I want rig like Stewart, where the lower limbs can rotate sideway. This involves simple vector maths.

global proc vector calcPvWPos( string $P1, string $P2, string $P3 ) {
 
     vector $a = `xform -q -ws -t $P1`;
     vector $b = `xform -q -ws -t $P2`;
     vector $c = `xform -q -ws -t $P3`;
 
     vector $AC = $c - $a;
     vector $AB = $b - $a;
 
     // projV = (|b|cos@) ^AC = (a.b/|a|) ^AC
     vector $projV = ( dotProduct($AC,$AB,0) / mag($AC) ) * `unit $AC`;
 
     vector $pvDirV = unit($AB - $projV);
 
     // move it out a bit
     return ( $b + mag($AB) * $pvDirV );
}

Space switching + fk/ik snapping

Finally, space switching and fk/ik snapping work using scriptJob. Mel procedures are stored in scriptNode and called by scriptJob once the file is loaded. This is the method I learned by breaking Stewart of Animation Mentor.

The trickest part is “keyable” space switching. Since I’m using scriptJob’s “attributeChange” event, if the “space” attribute is directly keyed, scrubbing the timeline will change the value and unexpectedly invoke the proc.

My solution is to move the keys to another attribute.

  1. Create the space switching attribute, “space”, as non-keyable and hidden.
  2. Create another attribute, “spaceNow”, which is keyable, driving original “space” ( as a space indicator and not to be changed directly by user ).
  3. Create one more attribute, “spaceSwitch”, which is non-keyable, used to change space non-pop, and used by attributeChange event.

Having attributes in single control I could key the transform and space at once. This avoids missing selection or keys if I want to adjust timing later.

By the way, you still need to use the copy and paste worldspace fix if the position of control changes before or after the switching frame.