View Full Version : equidistant locators along an editable curve?

03 March 2009, 05:07 PM
Hi peeps,
I'm trying to set up a script that will space a given number of locators along a curve. I then want to be able to edit this curve and have the locators re-space themselves accordingly.

I've already been able to set something like this up by reading the normalized U parameter value on a pointOnCurve info node.
This works if the curve has nicely spaced CVs but as soon as the curve gets edited, the U parameter is no longer even, ie. a parameter of 0.5 is not necessarily midway along the curve.
I've looked into arclen and arcLengthDimension but while the latter seemed promising I couldn't find a way to have it give me the parameter at a given length.

Is there a better way of doing this? I've read about closestPointOnCurve but I'd prefer not to do this through plugins.



03 March 2009, 05:26 PM
Probably not what you are looking for, but, you could use an motion path and an animation snapshot. There is an option for it to update interactively as well, should have probably checked this before saying there was not. :p

03 March 2009, 06:25 PM
Yep attach to motion path is the way to go, and it's normalized over the lengh of the curve ;) I use it all the time in setup.


03 March 2009, 09:17 PM
Thanks guys. I did have a look into a motion path too now but it seems to work the same way as pointOnCurve in that it uses the curve's parametrization.

If you run this script and then play the animation you'll see what I mean. The locator slows down in the middle. Or you can set the parameter to 0.25, you'll see it doesn't end up quarter-ways but closer to the middle due to the way the CVs are distributed. Or you can move any of the two middle CVs along the curve, the locator will move allthough the length of the curve hasn't changed.

curve -d 3 -p -1.1 0 0 -p 0.55 0 0 -p -0.45 0 0 -p 0.9 0 0 -k 0 -k 0 -k 0 -k 1 -k 1 -k 1 ;
spaceLocator -p 0 0 0;
select locator1 curve1;
pathAnimation -fractionMode false -follow false -startTimeU `playbackOptions -query -minTime` -endTimeU `playbackOptions -query -maxTime`;

It's been a while but in 3ds max I remember you'd animate by percentage, so 25% would always be a quarter way along an animation path. Would there be anything similar in Maya? (or even a workaround?)


03 March 2009, 03:25 AM
Take a look at this thread (, might help.

03 March 2009, 02:15 PM
It's been a while but in 3ds max I remember you'd animate by percentage, so 25% would always be a quarter way along an animation path. Would there be anything similar in Maya? (or even a workaround?)


you can do same thing if you select locator, and in inputs or history channel you will see U Value under motionPath you can break connection and adjust it your self. 0 = 0 % 1 = 100%

03 March 2009, 03:14 PM
Thanks guys.
vvkonline: if I do that on the curve created in the script further up, setting the locator to 0.25 is not quarter of the way along the path. It's 0.25 along the paramater length of the curve which is not the same.

I got a pointer from someone which solved it though. I'd unfortunately dismissed using rebuildCurve earlier because I thought it was a one-off thing that would only run at script execution but I see I can turn on construction history.
Now with rebuildCurve and ch on I can rebuild a second curve that will be evenly parametrized yet be able to edit the original curve without regard for how I space the CVs.

string $originalCurve = `curve -n "originalCurve" -d 3 -p -1.1 0 0 -p 0.55 0 0 -p -0.45 0 0 -p 0.9 0 0 -k 0 -k 0 -k 0 -k 1 -k 1 -k 1` ;
string $rebuildCurve[] = (`rebuildCurve -n "rebuildCurve" -ch 1 -rt 0 -kr 0 -rpo 0 $originalCurve`);
string $locator[] = `spaceLocator -p 0 0 0` ;
select $locator[0] $rebuildCurve[0];
pathAnimation -fractionMode false -follow false -startTimeU
`playbackOptions -query -minTime` -endTimeU `playbackOptions -query

Maybe there's a better way but for now this works for me.


03 March 2009, 12:39 AM
Actually you guys were right about using pathAnimation but fractionmode has to be set to true (its false by default) to get the right behavior (0.25 being quarterways)



03 March 2009, 01:10 PM
I'm currently working on node and a part of it needs a similar function. This uses the API but as it's Python can be used in the script editor.

import maya.OpenMaya as om
import maya.cmds as m
def equiCurvePoint(curveName, numPnts):
dag = om.MDagPath()
obj = om.MObject()
space = om.MSpace.kWorld
array = om.MDoubleArray()
list = om.MSelectionList()
list.getDagPath(0, dag, obj)

curveFn = om.MFnNurbsCurve(dag)
length = curveFn.length()

for i in range(numPnts):
point = om.MPoint()
param = curveFn.findParamFromLength(i*((1/float(numPnts-1))*length))
curveFn.getPointAtParam(param, point, space)
m.spaceLocator(p = [point[0], point[1], point[2]])

CGTalk Moderation
03 March 2009, 01:10 PM
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.