hi, i am new and i am tryng to get the interpoletions point between the control points, i have reach the api to try to get them but nothing appears, only the position of the handler and the controls points.How can i get this points?
It really is very well hidden, but you can find blenders python-api here:
There click on “Curve” and browse the documentation, also “BezTriple” will be important for you. The interpolation type has to be set for the BezierTriples of the CurNurbs of the curve. Don’t forget to recalc() the curve after changing.
hth and regards
pgr1973, he wants the point data between the points, not the interpolation value of a point.
One way I have done this in MaxScript and it may work for Blender as well is this technique.
Create your curve (for this example it will be a circle) and make sure the CurvePath button is pressed.
Create an Empty and assign a path constraint to it.
Set the curve for the empty to be the circle.
At this point, you should be able to scrub the timeline and get the position anywhere on the path by simply looking at the position of the empty at any given time.
Set up a loop that moves through time and simply examine the position of the empty at any given frame.
Sorry I don’t have anycode for you. I assume you can set up a loop to move the playback head through time (MEL and MaxScript) allow this functionality, let’s hope Blender python does as well.
Oh, I thought that:
> i am tryng to get the interpoletions point between the control points,
meant, he wants the “point between the handles” and that
> i have reach the api to try to get them
meant, he wants to get them via python. gg
But whatever he really wants to get, the curvestuff is fully accessible (and can be manipulated) via python. I just went through that stuff with my “Meandering-Paths” script.
> […] let’s hope Blender python does as well.
Yes, it does … (went through that also … g)
This is a little off topic, Paddy, but how would I set up a loop to scan time?
So there is an API call to give me the position on a curve if I am 50% through the curve?
Hm, maybe we’re talking at cross purposes. Which kind of curve are you talking about?
The Python-API let’s you move the “Playhead” back and forth nad gives you acces to IPO-Curves. The Python API let’s you also get every knot, handle and interpolationtype of a 2D/3D-Curve in the scene.
Each curve in Blender (2D/3D-curve in the scene used for something) is made out of “curNurbs”, which are made out of “BezTriples”. Each BezTriple is made out of three points/knots (1st handle, point/knot, 2nd handle), where each of these is defined through a vector made out of three coordinates (X-Position, Y-Position, Z-Position).
So you can get the position of each “curNurb” (which is the location of the “point” from the BezTriple). Depending on the type of curve-interpolation (vector, bezier, nurb) you’ll can get each curve-position between two points with some calculations (I don’t think the python-api has such a function, but maybe in blenders mathutils is something to make that calculation easier). I don’t know the formulas for that by heart, but it is possible and some googeling (or taking a geometry-book) should bring the needed formulas, as they are not very complicated.
In case you are talking about IPO-Curves: yes, the blender-api gives you the Y-Position of an IPO-Curve at given X-Value (being the time). Either (the deprecated) “evaluate(time)” or “getitem(time)”.
But maybe you meant something totally different …?
(I don’t think the python-api has such a function, but maybe in blenders mathutils is something to make that calculation easier).
The above setup I describe allows you to use objects (ie the empty on the curve) to solve the problem of returning an xyz point on a curve when you are x% through the curve. But you do have to scan time to make the objects move.
thx to both, i have seek in the google in i find a simple explanation about this problem, i have solved using a simple algorithms that yuo can find here http://www.people.nnov.ru/fractal/Splines/Bezier.htm
I needed this for a tree making tool, as long as your using bezier, this function works. I copied from blenders code and may add to the API.
Its a little odd in that it works on X,Y and Z axies separately
# Copied from blender, we could wrap this! - BKE_curve.c # But probably not toooo bad in python def forward_diff_bezier(q0, q1, q2, q3, pointlist, steps, axis): f= float(steps) rt0= q0 rt1= 3.0*(q1-q0)/f f*= f rt2= 3.0*(q0-2.0*q1+q2)/f f*= steps rt3= (q3-q0+3.0*(q1-q2))/f q0= rt0 q1= rt1+rt2+rt3 q2= 2*rt2+6*rt3 q3= 6*rt3 if axis == None: for a in xrange(steps+1): pointlist[a] = q0 q0+= q1 q1+= q2 q2+= q3; else: for a in xrange(steps+1): pointlist[a][axis] = q0 q0+= q1 q1+= q2 q2+= q3;
See wizard_curve2tree.py in blenders SVN for example usage.
cubic bezier equation:
def cubicBezier(a, b, c, d, t): return (1-t)*(1-t)*(1-t)*a + 3*t*(1-t)*(1-t)*b + 3*t*t*(1-t)*c + t*t*t*d t = 0 while t < 1.01: bx = cubicBezier(s, s, s, s, t) by = cubicBezier(s, s, s, s, t) bz = cubicBezier(s, s, s, s, t) t += 0.01
of course, a prerequisite is that you already have re-arranged your bezier-triples into segments with four points (start, start_handle, end_handle, end)
I downloaded wizard_curve2tree.py and opened blender 2.45.
I create a bezier curve.
I execute the script from the Wizard menu with the curve selected.
I get a console error. “Cannot import name ClosestPointOnLine”
I don’t see any usage information here:
How can this script help me get the X,Y,Z postion from any point on a curve?