phix314
11-15-2008, 07:45 PM
I think I'm digging myself deeper here.
What I need is this script to:
1) Create the constraint
2) Suck out the values of rotation that ensue
3) Delete the original constraint and reset the nurbs control object
4) Create a cluster to rotate the CVs so it's level (as drawn)
5) Group the cluster and Curve so it can be used as an orient constraint on the joint
Like I said, I think I'm digging myself deeper than I'd like. I just want to have a nurbs curve be useable as an orient constraint without the rotation values going all wacko.
If anything, this is a good exercise on coding in MEL, regardless of if I'm way off track.
BTW, this code works as is, just creates the group and the center pivot is off where it should.
global proc orient_Constrain(){
string $selection[] = `ls -sl`;
string $joint = $selection[0];
string $control = $selection[1];
//assign a random suffix to the orient name
int $random = `rand 0 1000`;
string $orientName = $joint + "_" + $control + "CUSTOMORIENT" + $random;
//print $orientName;
orientConstraint -offset 0 0 0 -weight 1 -name $orientName;
float $rotX[] = `getAttr $control.rotateX`;
float $rotY[] = `getAttr $control.rotateY`;
float $rotZ[] = `getAttr $control.rotateZ`;
/* DEBUG ROTATION */
//print ("Rotation X: " + $rotX[0] + " " + $rotX[1] + "\n");
//print ("Rotation Y: " + $rotY[0] + " " + $rotY[1] + "\n");
//print ("Rotation Z: " + $rotZ[0] + " " + $rotZ[1] + "\n");
vector $rotValues = <<$rotX[0], $rotY[0], $rotZ[0]>>;
delete $orientName;
setAttr ($control+".rotateX") ($rotValues.x);
setAttr ($control+".rotateY") ($rotValues.y);
setAttr ($control+".rotateZ") ($rotValues.z);
select -r $control;
makeIdentity -a true -t 1 -r 1 -s 1;
//code from http://ewertb.soundlinker.com/mel/mel.058.htm
string $curve = $control;
int $numSpans = `getAttr ( $curve + ".spans" )`;
int $degree = `getAttr ( $curve + ".degree" )`;
int $form = `getAttr ( $curve + ".form" )`;
int $numCVs = $numSpans + $degree;
// Adjust for periodic curve:
if ( $form == 2 ){
$numCVs -= $degree;
}
//print $numCVs;
//create the cluster
select -r $control.cv[0:$numCVs];
string $clusterName = "controlCurvesCluster" + $random;
cluster -n $clusterName -envelope 1;
string $fullClusterName = $clusterName + "Handle";
setAttr ($clusterName + "Handle.rotateX") ($rotValues.x);
setAttr ($clusterName + "Handle.rotateY") ($rotValues.y);
setAttr ($clusterName + "Handle.rotateZ") ($rotValues.z);
string $groupName = ($control + "_OrientGroup");
group -n $groupName $fullClusterName $control;
float $jointCenterX = `getAttr $joint.translateX`;
float $jointCenterY = `getAttr $joint.translateY`;
float $jointCenterZ = `getAttr $joint.translateZ`;
xform -ws -cp $groupName;
/*
string $clusterDeleteName = $clusterName + "Handle";
delete $clusterDeleteName;
string $finalOrientName = $control + "_" + $joint + "orientConstraint";
orientConstraint -name $finalOrientName -w 1 $control $joint;
*/
}
//orient_Constrain();
What I need is this script to:
1) Create the constraint
2) Suck out the values of rotation that ensue
3) Delete the original constraint and reset the nurbs control object
4) Create a cluster to rotate the CVs so it's level (as drawn)
5) Group the cluster and Curve so it can be used as an orient constraint on the joint
Like I said, I think I'm digging myself deeper than I'd like. I just want to have a nurbs curve be useable as an orient constraint without the rotation values going all wacko.
If anything, this is a good exercise on coding in MEL, regardless of if I'm way off track.
BTW, this code works as is, just creates the group and the center pivot is off where it should.
global proc orient_Constrain(){
string $selection[] = `ls -sl`;
string $joint = $selection[0];
string $control = $selection[1];
//assign a random suffix to the orient name
int $random = `rand 0 1000`;
string $orientName = $joint + "_" + $control + "CUSTOMORIENT" + $random;
//print $orientName;
orientConstraint -offset 0 0 0 -weight 1 -name $orientName;
float $rotX[] = `getAttr $control.rotateX`;
float $rotY[] = `getAttr $control.rotateY`;
float $rotZ[] = `getAttr $control.rotateZ`;
/* DEBUG ROTATION */
//print ("Rotation X: " + $rotX[0] + " " + $rotX[1] + "\n");
//print ("Rotation Y: " + $rotY[0] + " " + $rotY[1] + "\n");
//print ("Rotation Z: " + $rotZ[0] + " " + $rotZ[1] + "\n");
vector $rotValues = <<$rotX[0], $rotY[0], $rotZ[0]>>;
delete $orientName;
setAttr ($control+".rotateX") ($rotValues.x);
setAttr ($control+".rotateY") ($rotValues.y);
setAttr ($control+".rotateZ") ($rotValues.z);
select -r $control;
makeIdentity -a true -t 1 -r 1 -s 1;
//code from http://ewertb.soundlinker.com/mel/mel.058.htm
string $curve = $control;
int $numSpans = `getAttr ( $curve + ".spans" )`;
int $degree = `getAttr ( $curve + ".degree" )`;
int $form = `getAttr ( $curve + ".form" )`;
int $numCVs = $numSpans + $degree;
// Adjust for periodic curve:
if ( $form == 2 ){
$numCVs -= $degree;
}
//print $numCVs;
//create the cluster
select -r $control.cv[0:$numCVs];
string $clusterName = "controlCurvesCluster" + $random;
cluster -n $clusterName -envelope 1;
string $fullClusterName = $clusterName + "Handle";
setAttr ($clusterName + "Handle.rotateX") ($rotValues.x);
setAttr ($clusterName + "Handle.rotateY") ($rotValues.y);
setAttr ($clusterName + "Handle.rotateZ") ($rotValues.z);
string $groupName = ($control + "_OrientGroup");
group -n $groupName $fullClusterName $control;
float $jointCenterX = `getAttr $joint.translateX`;
float $jointCenterY = `getAttr $joint.translateY`;
float $jointCenterZ = `getAttr $joint.translateZ`;
xform -ws -cp $groupName;
/*
string $clusterDeleteName = $clusterName + "Handle";
delete $clusterDeleteName;
string $finalOrientName = $control + "_" + $joint + "orientConstraint";
orientConstraint -name $finalOrientName -w 1 $control $joint;
*/
}
//orient_Constrain();
