PDA

View Full Version : Placing objects at Curve CVs


BigRoyNL
05-28-2009, 09:48 PM
Hey Guys,

I've been looking around and can't seem to find the way to place objects at the CVs of a curve. I did find the pointOnCurve (with the parameter) and so on, but I didn't get that to work for me. All I want is just lay out objects at the position of the CVs by a MEL script.

I'm guessing it can't be hard and I'm just looking way past it!
Thanks in advance.

BigRoyNL
05-29-2009, 07:28 AM
I somehow managed to get the thing that I needed, but now I'm running against another problem. This is what I've so far:

int $curveDegree = `getAttr curve1.degree`;
int $curveSpans = `getAttr curve1.spans`;
int $curveCVs = $curveDegree + $curveSpans;
string $currentSelected[] = `ls -sl`;
string $currentSelectedNew[];
string $currentSelectedRef[];
for ($i=0; $i<$curveCVs; $i++) {
float $position[] = `getAttr curve1.controlPoints[$i]`;
while ($currentSelectedRef[0] != $currentSelectedNew[0]) {
string $currentSelectedRef[] = `ls -sl`;
float $curvePosition[] = `xform -q -a -t $currentSelected`;
$position[0] += $curvePosition[0];
$position[1] += $curvePosition[1];
$position[2] += $curvePosition[2];
pickWalk -d Up;
string $currentSelectedNew[] = `ls -sl`;
}
joint -p $position[0] $position[1] $position[2] -name ("ScriptedJoint"+$i);
}

Only the problem now is, is that the created joints are all seperated from each other and not parented as they would've been when they were created right after each other. Is there any way to do this easily with mel scripting? ( I'm actually not interested in 'parenting' them to each other afterwards, but more interested in creating them in one go, because then the joints would become oriented by the placement relative to their 'parent'.) But maybe there's another way for this! Hope somebody can help me out!

Thanks in advance again,

Roy

EDIT:

I now did it this way:
int $curveDegree = `getAttr curve1.degree`;
int $curveSpans = `getAttr curve1.spans`;
int $curveCVs = $curveDegree + $curveSpans;
string $currentSelected[] = `ls -sl`;
string $currentSelectedNew[];
string $currentSelectedRef[];
for ($i=0; $i<$curveCVs; $i++) {
float $position[] = `getAttr curve1.controlPoints[$i]`;
while ($currentSelectedRef[0] != $currentSelectedNew[0]) {
string $currentSelectedRef[] = `ls -sl`;
float $curvePosition[] = `xform -q -a -t $currentSelected`;
$position[0] += $curvePosition[0];
$position[1] += $curvePosition[1];
$position[2] += $curvePosition[2];
pickWalk -d Up;
string $currentSelectedNew[] = `ls -sl`;
}
select -clear;
joint -p $position[0] $position[1] $position[2] -name ("SpineJoint"+$i);
if ($i != 0) {
int $n = $i - 1;
select -r ("SpineJoint"+$n);
joint -e -zso -oj xyz -sao yup ("SpineJoint"+$n);
parent ("SpineJoint"+$i) ("SpineJoint"+$n); }
select -r $currentSelected;
}
select -r SpineJoint0 ;
joint -e -oj xyz -secondaryAxisOrient yup -ch;

The whole part of the xform command and pickwalking up is to get the translation of the parents so the joints can be created at the exact position of the curves CVs, though I now checked and it's not working So I"ll have to find another way.. if anybody knows?
Thanks in advance.


AGAIN, another update:

string $currentSelected[] = `ls -sl`;

// REBUILD NURBS CURVE
$rebuildOnOff = 1;
if ($rebuildOnOff == 1) {
int $rebuildSpans = 3;
int $rebuildDegree = 3;
rebuildCurve -ch 1 -rpo 1 -rt 0 -end 1 -kr 0 -kcp 0 -kep 1 -kt 0 -s 4 -d 3 -tol 0.00155 $currentSelected[0];
}

// CHECK NUMBER OF CVs
int $curveDegree = `getAttr curve1.degree`;
int $curveSpans = `getAttr curve1.spans`;
int $curveCVs = $curveDegree + $curveSpans;

// FOR THE AMOUNT OF CVs CREATE JOINTS AT THE CVs POSITION
for ($i=0; $i<$curveCVs; $i++) {
float $position[] = `getAttr curve1.controlPoints[$i]`;
select -clear;
joint -p $position[0] $position[1] $position[2] -name ("SpineJoint"+$i);

// WHEN THE CREATION IS NOT THE FIRST JOINT, PARENT JOINT TO ONE BEFORE
if ($i != 0) {
int $n = $i - 1;
select -r ("SpineJoint"+$n);
joint -e -zso -oj xyz -sao yup ("SpineJoint"+$n);
parent ("SpineJoint"+$i) ("SpineJoint"+$n); }
select -r $currentSelected;
}

// RE-ORIENT ALL JOINTS
select -r SpineJoint0 ;
joint -e -oj xyz -secondaryAxisOrient yup -ch;

I still need functions for when the curve is not parented in the world or is translated so the joints really get created at the absolute position of the joints.

Crypt
05-29-2009, 08:26 AM
Here is the script that creates the objects on the control vertex of the curve.
For this you need to select the curve first and then the object you want to create on the control vertex of the curve and then run the script.

Script is as follows:::::::::::::
string $sel[];

$sel = `ls -sl`;

create_object($sel);

proc create_object (string $sel[])

{

sel_component($sel[0]);

string $component[];

$component = `ls -fl -sl`;

int $i;

for ($i=0;$i<size($component);$i++)

{

float $pos[];

$pos = `pointPosition $component[$i]`;

string $temp[];

$temp = `duplicate $sel[1]`;

setAttr ($temp[0] + ".translateX") $pos[0];

setAttr ($temp[0] + ".translateY") $pos[1];

setAttr ($temp[0] + ".translateZ") $pos[2];

}

}

proc sel_component(string $name)

{

string $shape_node[];

string $type;

$shape_node = `listRelatives -c $name`;

$type = `nodeType $shape_node`;

switch ($type)

{

case "mesh":

select ($shape_node[0] + ".vtx
");

break;

case "nurbsSurface":

select ($shape_node[0] + ".cv

");

break;

case "nurbsCurve":

select ($shape_node[0] + ".cv
");

break;

}

}

Crypt
05-29-2009, 08:31 AM
This script works in the following way::
First selected object is the source object on whoes control vertex the new object is suppose to be created.
Second selected object is the type of object that you want to create on the previous selected objects control vertex.
I works for poly nurbs and curve..

I hope this has solved your difficulty...

Crypt
05-29-2009, 08:55 AM
I modified the above script and created joints on the cv's of the curve and they are created at one strech and not diferrently and are parented too. I hope this solve's your problem....

The script is as follows:::::::::
string $sel[];

$sel = `ls -sl`;

create_object($sel);

proc create_object (string $sel[])

{

sel_component($sel[0]);

string $component[];

$component = `ls -fl -sl`;

int $i;

for ($i=0;$i<size($component);$i++)

{

float $pos[];

$pos = `pointPosition $component[$i]`;

string $execut = "joint ";

string $name = "joint" + string($i);

$execut = $execut + "-p" +" "+ $pos[0] +" "+ $pos[1] +" "+ $pos[2];

print ($execut + "\n");

eval ($execut);

if ($i>0)

{

joint -e -zso -oj xyz -sao yup $name;

}

clear ($pos);

}

}

proc sel_component(string $name)

{

string $shape_node[];

string $type;

$shape_node = `listRelatives -c $name`;

$type = `nodeType $shape_node`;

switch ($type)

{

case "mesh":

select ($shape_node[0] + ".vtx
");

break;

case "nurbsSurface":

select ($shape_node[0] + ".cv

");

break;

case "nurbsCurve":

select ($shape_node[0] + ".cv
");

break;

}

}

BigRoyNL
05-29-2009, 09:40 AM
Hey Crypt!

Thank you very much.. I analysed your script and didn't read your post about the one that works with the joints and stuff. I got mine to work though, I'm sharing it here now.. and will be using what I've got now on something I'm trying to create. I'll check your 'joints placement' out in a minute. Here's mine:

string $currentSelected[] = `ls -sl`;
$rebuildOnOff = 1;
int $rebuildSpans = 10;
int $rebuildDegree = 3;
$shapeNode = `listRelatives -c $currentSelected[0]`;
$type = `nodeType $shapeNode`;

// CHECK IF ONLY ONE OBJECT IS SELECTED AND IF THIS IS A NURBS CURVE
if (size($currentSelected)> 1) {warning "Select only one NURBS Curve";}
else if ($type != "nurbsCurve") {warning "Select one NURBS Curve";}
else
{

// REBUILD NURBS CURVE IF CHOSEN
if ($rebuildOnOff == 1) {rebuildCurve -ch 1 -rpo 1 -rt 0 -end 1 -kr 0 -kcp 0 -kep 1 -kt 0 -s $rebuildSpans -d $rebuildDegree -tol 0.00155 $currentSelected[0];}

select ($shapeNode[0] + ".cv
");
string $curveCVs[];
$curveCVs = `ls -fl -sl`;
select -clear;
$curveDegree = `getAttr ($currentSelected[0]+".degree")`;
for ($i=0; $i<size($curveCVs); $i++) {

// IF SECOND OR SECOND LAST CV (with curveDegree 3) SKIP JOINT PLACEMENT
if ($i == 1 && $curveDegree == 3) {print "Skipped 2nd CV (because of 3rd degree curve)\n";}
else if ($i == (size($curveCVs)-2) && $curveDegree == 3) {print "Skipped 2nd last CV (because of 3rd degree curve) \n";}

// PLACE JOINTS AT THE POSITIONS OF THE CURVE CVs
else {
float $pos[];
$pos = `pointPosition $curveCVs[$i]`;
joint -p $pos[0] $pos[1] $pos[2];
}
}
}

Crypt
05-29-2009, 10:33 AM
U r welcome....

CGTalk Moderation
05-29-2009, 10:33 AM
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.