Hi All,
I've wrotten a script which sets up a couple of controls for a camera so that I can animate camera shake by hand. It's pretty primitive but works fine. However - I've run into some trouble...I suspect this is down to how Maya's apparently inconsistant way of naming camera Shape nodes.
If a camera is called shotCamera then the shape node is called shotCamera1
However is a camera is called camera1 then the shape node is called cameraShape1
Does anyone know why Maya shifts the number to the end like this - or how to allow for it in a simple script such as the one below....
// get selected camera name and position
string $cN[];
$cN = ls -sl
;
string $cameraName = $cN[0];
$cP = getAttr ( $cameraName + ".translate" )
;
// get target name and target position
string $targetName;
$targetName = ($cN[0] + "_aim");
$tP = getAttr ( $targetName + ".translate" )
;
// copy animation from target
copyKey -time ":" -float ":" -hierarchy none -controlPoints 0 -shape 1 { ($targetName + ".translateX"), ($targetName + ".translateY"), ($targetName + ".translateZ")};
// put camera and aim to setup positions
setAttr ( $targetName + ".translateX" ) 0;
setAttr ( $targetName + ".translateY" ) 0;
setAttr ( $targetName + ".translateZ" ) 0;
setAttr ( $cameraName + ".translateX" ) 0;
setAttr ( $cameraName + ".translateY" ) 0;
setAttr ( $cameraName + ".translateZ" ) 5;
setAttr ( $targetName + "Shape.visibility" ) 1;
select $targetName;
// set name for new target
string $newTarget;
$newTarget = ($cameraName + "_aimGroup");
group;
rename $newTarget ;
string $newTargetShape;
$newTargetShape = ( $cameraName + "Shape" );
createNode -n $newTargetShape -p $newTarget locator;
setAttr ( $newTargetShape + ".localScaleX" ) 2;
setAttr ( $newTargetShape + ".localScaleY" ) 2;
setAttr ( $newTargetShape + ".localScaleZ" ) 2;
// hide the old aim
setAttr ( $targetName + ".visibility" ) 0;
// create circles
string $smallName;
$smallName = ( $cameraName + "_smallShake" );
circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0 -s 8 -ch 1; objectMoveCommand;
rename $smallName;
DeleteHistory;
string $bigName;
$bigName = ( $cameraName + "_bigShake" );
circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0 -s 8 -ch 1; objectMoveCommand;
rename $bigName;
scale -r 1.666875 1.666875 1.666875 ;
DeleteHistory;
// need to rotate circles to face camera
setAttr ( $bigName + ".rotateX" ) -90;
setAttr ( $smallName + ".rotateX" ) -90;
// parenting to new Target
parent $smallName $newTarget;
parent $bigName $newTarget;
// orienting shakers to camera
orientConstraint -mo -weight 1 $cameraName $smallName;
orientConstraint -mo -weight 1 $cameraName $bigName;
orientConstraint -mo -weight 1 $cameraName $newTarget;
// apply the final point constraint to the camera_aim
pointConstraint $bigName $smallName $targetName;
// move camera and aim group back to start positions
setAttr ( $cameraName + ".translateX" ) $cP[0];
setAttr ( $cameraName + ".translateY" ) $cP[1];
setAttr ( $cameraName + ".translateZ" ) $cP[2];
setAttr ( $newTarget + ".translateX" ) $tP[0];
setAttr ( $newTarget + ".translateY" ) $tP[1];
setAttr ( $newTarget + ".translateZ" ) $tP[2];
// change circle colours
setAttr ( $bigName + "Shape.overrideEnabled" ) 1;
setAttr ( $bigName + "Shape.overrideColor" ) 17;
setAttr ( $smallName + "Shape.overrideEnabled") 1;
setAttr ( $smallName + "Shape.overrideColor") 4;
setAttr ( $newTarget + ".overrideEnabled") 1;
setAttr ( $newTarget + ".overrideColor") 18;
// paste keys into new target
pasteKey -time 1 -float 1 -option insert -copies 1 -connect 1 -timeOffset 0 -floatOffset 0 -valueOffset 0 { $newTarget };
// paste keys into new target
pasteKey -time 1 -float 1 -option insert -copies 1 -connect 1 -timeOffset 0 -floatOffset 0 -valueOffset 0 { $newTarget };