enbee
09-27-2005, 04:22 PM
I have been writing a mel script that creates a tentacle along a curve and I have run into a strange problem that I just can't get past. I am using a IK spline with a nurbs cylinder skinned to the bones. To create the taper I am trying to scale on Y and Z for each joint. However I can't get the second to last joint to scale properly. If I scale that joint it loses the IK spline connection and the whole thing jumps off the curve. Why would that happen? Is it something with the way I'm doing to IK spline or the taper? I have been staring at this way too long.
Any help is appreciated
global proc new_tent(float $radius) {
// selection variables
string $selected_curves[] = `ls -sl`;
string $current_curve;
// curve variables
float $curve_length;
int $num_of_joints;
// cylinder variables
string $cyl_name;
string $num_cyl_spans;
// joint creation variables
string $cur_joint_name;
string $prev_joint_name;
string $root_joint_name;
string $final_joint_name;
float $y_offset;
float $y_pos;
// taper variables
float $taper_length;
float $taper_value;
// utility variables
int $i;
int $j;
// create one tentacle for each curve selected
for ($current_curve in $selected_curves) {
$curve_length = `arclen $current_curve`;
$num_of_joints = int($curve_length);
/* create nurbs cylinder */
$cyl_name = $current_curve + "_cylinder";
cylinder -r $radius
-hr ($curve_length/$radius)
-p 0 ($curve_length/2) 0
-ax 0 1 0
-d 3
-s 10
-nsp $num_of_joints
-ch 1
-n $cyl_name;
/* create joints */
$cur_joint_name = "";
$y_pos = 0;
$y_offset = $curve_length/$num_of_joints;
for ($j = 0; $j <= $num_of_joints; $j++) {
$prev_joint_name = $cur_joint_name;
$cur_joint_name = $current_curve + "_joint" + ($j+1);
joint -p 0 $y_pos 0
-n $cur_joint_name;
if ($j != 0) {
joint -e
-zso
-oj xyz
-sao yup $prev_joint_name;
}
else {
$root_joint_name = $cur_joint_name;
}
$y_pos += $y_offset;
}
$final_joint_name = $cur_joint_name;
/* smooth bind cylinder to joints */
select $cyl_name;
select -tgl $root_joint_name;
newSkinCluster "-mi 1 -dr 1";
/* even trying to force it doesnt work
setAttr ( $current_curve + "_joint" + $num_of_joints + ".scaleY" ) 0;
setAttr ( $current_curve + "_joint" + $num_of_joints + ".scaleZ" ) 0;
*/
/* create IK spline solver */
select -r ($root_joint_name + ".rotatePivot");
select -add ($final_joint_name + ".rotatePivot");
select -add $current_curve;
ikHandle -sol ikSplineSolver -ccv false -ns 3;
/* make tentacle taper */
$taper_length = 30;
for ( $i = 0; $i <= $taper_length; $i++) {
$taper_value = linstep( 0, sqrt($taper_length), sqrt($taper_length - $i) );
setAttr ( $current_curve + "_joint" + (($num_of_joints - $taper_length) + $i) + ".scaleY" ) $taper_value;
setAttr ( $current_curve + "_joint" + (($num_of_joints - $taper_length) + $i) + ".scaleZ" ) $taper_value;
}
} //end curve select for loop
} //end new_tent
Any help is appreciated
global proc new_tent(float $radius) {
// selection variables
string $selected_curves[] = `ls -sl`;
string $current_curve;
// curve variables
float $curve_length;
int $num_of_joints;
// cylinder variables
string $cyl_name;
string $num_cyl_spans;
// joint creation variables
string $cur_joint_name;
string $prev_joint_name;
string $root_joint_name;
string $final_joint_name;
float $y_offset;
float $y_pos;
// taper variables
float $taper_length;
float $taper_value;
// utility variables
int $i;
int $j;
// create one tentacle for each curve selected
for ($current_curve in $selected_curves) {
$curve_length = `arclen $current_curve`;
$num_of_joints = int($curve_length);
/* create nurbs cylinder */
$cyl_name = $current_curve + "_cylinder";
cylinder -r $radius
-hr ($curve_length/$radius)
-p 0 ($curve_length/2) 0
-ax 0 1 0
-d 3
-s 10
-nsp $num_of_joints
-ch 1
-n $cyl_name;
/* create joints */
$cur_joint_name = "";
$y_pos = 0;
$y_offset = $curve_length/$num_of_joints;
for ($j = 0; $j <= $num_of_joints; $j++) {
$prev_joint_name = $cur_joint_name;
$cur_joint_name = $current_curve + "_joint" + ($j+1);
joint -p 0 $y_pos 0
-n $cur_joint_name;
if ($j != 0) {
joint -e
-zso
-oj xyz
-sao yup $prev_joint_name;
}
else {
$root_joint_name = $cur_joint_name;
}
$y_pos += $y_offset;
}
$final_joint_name = $cur_joint_name;
/* smooth bind cylinder to joints */
select $cyl_name;
select -tgl $root_joint_name;
newSkinCluster "-mi 1 -dr 1";
/* even trying to force it doesnt work
setAttr ( $current_curve + "_joint" + $num_of_joints + ".scaleY" ) 0;
setAttr ( $current_curve + "_joint" + $num_of_joints + ".scaleZ" ) 0;
*/
/* create IK spline solver */
select -r ($root_joint_name + ".rotatePivot");
select -add ($final_joint_name + ".rotatePivot");
select -add $current_curve;
ikHandle -sol ikSplineSolver -ccv false -ns 3;
/* make tentacle taper */
$taper_length = 30;
for ( $i = 0; $i <= $taper_length; $i++) {
$taper_value = linstep( 0, sqrt($taper_length), sqrt($taper_length - $i) );
setAttr ( $current_curve + "_joint" + (($num_of_joints - $taper_length) + $i) + ".scaleY" ) $taper_value;
setAttr ( $current_curve + "_joint" + (($num_of_joints - $taper_length) + $i) + ".scaleZ" ) $taper_value;
}
} //end curve select for loop
} //end new_tent
