PDA

View Full Version : Object position to spline offset with python


pgrooff
06-07-2012, 10:45 AM
I have placed an object on a spline using the spline offset.
On the next frame I want to position the object a bit further on the spline, thus increase the spline offset a bit and replace the object.
Now is my question, how to get the spline offset using the objects position?

Below the code I use at this moment.
It seems ok for a straight spline, but when I change (round) the spline a bit, something goes wrong.

spl = op[c4d.ID_USERDATA, 3] #spline link
sh=SplineHelp() #Add an instance of the spline helper class
sh.InitSpline(spl) # initialize spline

#get offset on spline based on object position
pos0 = sh.GetPosition(0) # get 'origin' position spline offset=0
objmtx = current_object.GetMg() # Get the object's global matrix
diff = objmtx.off # get object position

dist = (diff-pos0).GetLength() # get difference between spline origin and object


currentoffset = sh.GetOffsetFromUnit(dist) # get offset on spline

CGTalk Moderation
06-07-2012, 10:45 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.