PDA

View Full Version : curve thru 2 locators


qkuotidian
11-22-2010, 12:16 PM
Hello guys,
The idea of this script is to create a curve thru 2 locators specified by user and update curve position by changing locators’ positions. But when I tried to do opposite, update locators’ positions by changing curve position – it did not work. Does anyone know, what is wrong here and is it possible to simplify or do it in a different way?

Just create 2 locators, select them and run the script:

string $locators[2]=`ls -sl`;
// 1st point
float $point_0x=`getAttr ($locators[0]+".translateX")`;
float $point_0y=`getAttr ($locators[0]+".translateY")`;
float $point_0z=`getAttr ($locators[0]+".translateZ")`;

// 2nd point
float $point_1x=`getAttr ($locators[1]+".translateX")`;
float $point_1y=`getAttr ($locators[1]+".translateY")`;
float $point_1z=`getAttr ($locators[1]+".translateZ")`;


curve -d 1 -p $point_0x $point_0y $point_0z
-p $point_1x $point_1y $point_1z;

connectAttr -f locator1.translate curve1.cv[0];
connectAttr -f locator2.translate curve1.cv[1];

connectAttr -f curve1.cv[0] locator1.translate;
connectAttr -f curve1.cv[1] locator2.translate;

shcmack
11-22-2010, 12:43 PM
I would make clusters for the curve so that it always follows the locators (if that's what you want?).

//Get the selected locators
$locators = `ls -sl`;

//Get the worldspace position of locator 1
$loc1 = `xform -q -ws -t $locators[0]`;
//Get the worldspace position of locator 2
$loc2 = `xform -q -ws -t $locators[1]`;

//Create the curve
$curve = `curve -d 1 -p $loc1[0] $loc1[1] $loc1[2] -p $loc2[0] $loc2[1] $loc2[2]`;

//Create a cluster on each end of the curve
$cluster1 = `cluster -n ($locators[0] + "_cluster") ($curve + ".cv[0]")`;
$cluster2 = `cluster -n ($locators[1] + "_cluster") ($curve + ".cv[1]")`;

//Parent cluster1 under locator1, and cluster2 under locator2
parent $cluster1[1] $locators[0];
parent $cluster2[1] $locators[1];

//Hide the clusterHandles
setAttr ($cluster1[1] + ".visibility") 0;
setAttr ($cluster2[1] + ".visibility") 0;

qkuotidian
11-23-2010, 11:22 AM
jornp, thanks for reply.
your script really helped.

CGTalk Moderation
11-23-2010, 11:22 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.