PDA

View Full Version : xyz combination to drive blendshapes


arjan_meerten
12-23-2006, 03:30 PM
Hi, I want to make an expression that wil drive a blendshape with the belonging xyz combination of a joint. For example the combination of the rotation axis of a joint (50,-70,90) will drive blendshape A and the combination (-50,-70,0) will drive blendshape B but the other blendshapes has to be zero. So I have about 12 combinations of the joints xyz rotation axis and those will drive 12 different blendshapes.
Can anybody help me with this?
tnx

Arjan

micle
12-24-2006, 10:30 PM
in this case set driven keys are the simplest way :)

arjan_meerten
12-25-2006, 01:54 AM
tnx for the reply, but the problem with driven keys is that you only can have one attribute as a driver and I have 3 different attributes.

micle
12-25-2006, 06:52 AM
welll you can create a node/expression that calculate the distance from the origin (or from your rig base transform) and the sdk it ;)

arjan_meerten
12-25-2006, 01:10 PM
Hi, I just made an expression like this.
It kind of works. As a test I made 5 cubes and named them A,B,C,D and E and I made a cube with the name control. The translate Y wil be driven by the rotation of the control.
I'm not really a programmer so it wont be very efficient. It works with all the cubes except B. With rotation B (90,60,0) the translateY of cube B is 1 but also cube D is on 0.5 and it should be zero.

//defines the different rotations

vector $A = <<-90,0,0>>;
vector $B = <<90,60,0>>;
vector $C = <<0,-60,90>>;
vector $D = <<90,60,-90>>;
vector $E = <<0,0,90>>;

//the driver
vector $cntrl = <<control.rotateX,control.rotateY,control.rotateZ>>;

//defines the length between the driver and the different rotations
float $Adis = mag($A - $cntrl);
float $Bdis = mag($B - $cntrl);
float $Cdis = mag($C - $cntrl);
float $Ddis = mag($D - $cntrl);
float $Edis = mag($E - $cntrl);

//defines the lowest distance between A
float $BAleng = mag($B - $A);
float $CAleng = mag($C - $A);
float $DAleng = mag($D - $A);
float $EAleng = mag($E - $A);

float $Amax[] = {$BAleng,$CAleng,$DAleng,$EAleng};

$AlowVal = 360;
for ($i = 1; $i < `size $Amax`; $i++)
{
if ($Amax[$i] < $AlowVal)
$AlowVal = $Amax[$i];
}

//defines the lowest distance between B
float $ABleng = mag($A - $B);
float $CBleng = mag($C - $B);
float $DBleng = mag($D - $B);
float $EBleng = mag($E - $B);

float $Bmax[] = {$ABleng,$CBleng,$DBleng,$EBleng};

$BlowVal = 360;
for ($i = 1; $i < `size $Bmax`; $i++)
{
if ($Bmax[$i] < $BlowVal)
$BlowVal = $Bmax[$i];
}

//defines the lowest distance between C
float $BCleng = mag($B - $C);
float $ACleng = mag($A - $C);
float $DCleng = mag($D - $C);
float $ECleng = mag($E - $C);

float $Cmax[] = {$BCleng,$ACleng,$DCleng,$ECleng};

$ClowVal = 360;
for ($i = 1; $i < `size $Cmax`; $i++)
{
if ($Cmax[$i] < $ClowVal)
$ClowVal = $Cmax[$i];
}

//defines the lowest distance between D
float $BDleng = mag($B - $D);
float $CDleng = mag($C - $D);
float $ADleng = mag($A - $D);
float $EDleng = mag($E - $D);

float $Dmax[] = {$BDleng,$CDleng,$ADleng,$EDleng};

$DlowVal = 360;
for ($i = 1; $i < `size $Dmax`; $i++)
{
if ($Dmax[$i] < $DlowVal)
$DlowVal = $Dmax[$i];
}

//defines the lowest distance between E
float $BEleng = mag($B - $E);
float $CEleng = mag($C - $E);
float $DEleng = mag($D - $E);
float $AEleng = mag($A - $E);

float $Emax[] = {$BEleng,$CEleng,$DEleng,$AEleng};

$ElowVal = 360;
for ($i = 1; $i < `size $Emax`; $i++)
{
if ($Emax[$i] < $ElowVal)
$ElowVal = $Emax[$i];
}

//calculates the value for the blendshapes
float $Ablend = ($Adis - -$AlowVal)/-$AlowVal;
float $Bblend = ($Bdis - -$BlowVal)/-$BlowVal;
float $Cblend = ($Cdis - -$ClowVal)/-$ClowVal;
float $Dblend = ($Ddis - -$DlowVal)/-$DlowVal;
float $Eblend = ($Edis - -$ElowVal)/-$ElowVal;

//blendshapes
A.translateY = clamp(0,1,$Ablend+2);
B.translateY = clamp(0,1,$Bblend+2);
C.translateY = clamp(0,1,$Cblend+2);
D.translateY = clamp(0,1,$Dblend+2);
E.translateY = clamp(0,1,$Eblend+2);

//print($AlowVal);

If you paste this in the script editor it will create the cubes, the expression and it wil keyframes the different rotations.

polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -n A;
polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -n B;
move -r 0 0 -1 ;
polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -n C;
move -r 0 0 -2 ;
polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -n D;
move -r 0 0 -3 ;
polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -n E;
move -r 0 0 -4 ;
polyCube -w 3 -h 3 -d 3 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -n control;
move -r 4 0 0 ;

currentTime 0;
setAttr "control.rotateX" -90;
setAttr "control.rotateY" 0;
setAttr "control.rotateZ" 0;
setKeyframe "control.rx";
setKeyframe "control.ry";
setKeyframe "control.rz";

currentTime 1;
setAttr "control.rotateX" 90;
setAttr "control.rotateY" 60;
setAttr "control.rotateZ" 0;
setKeyframe "control.rx";
setKeyframe "control.ry";
setKeyframe "control.rz";

currentTime 2;
setAttr "control.rotateX" 0;
setAttr "control.rotateY" -60;
setAttr "control.rotateZ" 90;
setKeyframe "control.rx";
setKeyframe "control.ry";
setKeyframe "control.rz";

currentTime 3;
setAttr "control.rotateX" 90;
setAttr "control.rotateY" 60;
setAttr "control.rotateZ" -90;
setKeyframe "control.rx";
setKeyframe "control.ry";
setKeyframe "control.rz";

currentTime 4;
setAttr "control.rotateX" 0;
setAttr "control.rotateY" 0;
setAttr "control.rotateZ" 90;
setKeyframe "control.rx";
setKeyframe "control.ry";
setKeyframe "control.rz";

playbackOptions -min 0 -max 4 ;

expression -s "//defines the different rotations\r\n\r\nvector $A = <<-90,0,0>>;\r\nvector $B = <<90,60,0>>;\r\nvector $C = <<0,-60,90>>;\r\nvector $D = <<90,60,-90>>;\r\nvector $E = <<0,0,90>>;\r\n\r\n//the driver\r\nvector $cntrl = <>;\r\n\r\n//defines the length between the driver and the different rotations\r\nfloat $Adis = mag($A - $cntrl);\r\nfloat $Bdis = mag($B - $cntrl);\r\nfloat $Cdis = mag($C - $cntrl);\r\nfloat $Ddis = mag($D - $cntrl);\r\nfloat $Edis = mag($E - $cntrl);\r\n\r\n//defines the lowest distance between A\r\nfloat $BAleng = mag($B - $A);\r\nfloat $CAleng = mag($C - $A);\r\nfloat $DAleng = mag($D - $A);\r\nfloat $EAleng = mag($E - $A);\r\n\r\nfloat $Amax[] = {$BAleng,$CAleng,$DAleng,$EAleng};\r\n\r\n$AlowVal = 360;\r\nfor ($i = 1; $i < `size $Amax`; $i++)\r\n{\r\nif ($Amax[$i] < $AlowVal)\r\n$AlowVal = $Amax[$i];\r\n}\r\n\r\n//defines the lowest distance between B\r\nfloat $ABleng = mag($A - $B);\r\nfloat $CBleng = mag($C - $B);\r\nfloat $DBleng = mag($D - $B);\r\nfloat $EBleng = mag($E - $B);\r\n\r\nfloat $Bmax[] = {$ABleng,$CBleng,$DBleng,$EBleng};\r\n\r\n$BlowVal = 360;\r\nfor ($i = 1; $i < `size $Bmax`; $i++)\r\n{\r\nif ($Bmax[$i] < $BlowVal)\r\n$BlowVal = $Bmax[$i];\r\n}\r\n\r\n//defines the lowest distance between C\r\nfloat $BCleng = mag($B - $C);\r\nfloat $ACleng = mag($A - $C);\r\nfloat $DCleng = mag($D - $C);\r\nfloat $ECleng = mag($E - $C);\r\n\r\nfloat $Cmax[] = {$BCleng,$ACleng,$DCleng,$ECleng};\r\n\r\n$ClowVal = 360;\r\nfor ($i = 1; $i < `size $Cmax`; $i++)\r\n{\r\nif ($Cmax[$i] < $ClowVal)\r\n$ClowVal = $Cmax[$i];\r\n}\r\n\r\n//defines the lowest distance between D\r\nfloat $BDleng = mag($B - $D);\r\nfloat $CDleng = mag($C - $D);\r\nfloat $ADleng = mag($A - $D);\r\nfloat $EDleng = mag($E - $D);\r\n\r\nfloat $Dmax[] = {$BDleng,$CDleng,$ADleng,$EDleng};\r\n\r\n$DlowVal = 360;\r\nfor ($i = 1; $i < `size $Dmax`; $i++)\r\n{\r\nif ($Dmax[$i] < $DlowVal)\r\n$DlowVal = $Dmax[$i];\r\n}\r\n\r\n//defines the lowest distance between E\r\nfloat $BEleng = mag($B - $E);\r\nfloat $CEleng = mag($C - $E);\r\nfloat $DEleng = mag($D - $E);\r\nfloat $AEleng = mag($A - $E);\r\n\r\nfloat $Emax[] = {$BEleng,$CEleng,$DEleng,$AEleng};\r\n\r\n$ElowVal = 360;\r\nfor ($i = 1; $i < `size $Emax`; $i++)\r\n{\r\nif ($Emax[$i] < $ElowVal)\r\n$ElowVal = $Emax[$i];\r\n}\r\n\r\n//calculates the value for the blendshapes\r\nfloat $Ablend = ($Adis - -$AlowVal)/-$AlowVal;\r\nfloat $Bblend = ($Bdis - -$BlowVal)/-$BlowVal;\r\nfloat $Cblend = ($Cdis - -$ClowVal)/-$ClowVal;\r\nfloat $Dblend = ($Ddis - -$DlowVal)/-$DlowVal;\r\nfloat $Eblend = ($Edis - -$ElowVal)/-$ElowVal;\r\n\r\n//blendshapes\r\nA.translateY = clamp(0,1,$Ablend+2);\r\nB.translateY = clamp(0,1,$Bblend+2);\r\nC.translateY = clamp(0,1,$Cblend+2);\r\nD.translateY = clamp(0,1,$Dblend+2);\r\nE.translateY = clamp(0,1,$Eblend+2);\r\n\r\n//print($AlowVal);" -o "" -ae 1 -uc all ;

CGTalk Moderation
12-25-2006, 01:10 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.