[Closed] Rotate object to spline knot
Hi all
I have to align a lot of objects to a specified knot on a a spline.
So i think the simplest way would be to write a script.
So i got a Spline with a certain amount of knots. The script should rotate and translate the selected object to the given knot number.
I know how to move it to the correct coordinates, but i don´t know how to rotate it properly.
Anyone can point me in the right direction?
I found the getInVec and getOutVec, but i don´t really have a clue how to use them (if they are usefull at all).
Thanks,
Gerald
You can use the InVec as the alignment vector, to align an axis of your object. For example, you want to align your node’s Z to the InVec. You can try something like that :
$node.dir = InVec
Thanks for your help.
Unfortunately i still don´t get any usefull results.
Here´s a simple example and the code i used.
Any idea what´s wrong?
for s = 1 to (numSplines $) do
(
for k = 1 to (numKnots $ s) do
(
newObjName=uniquename ("spline_")
newBox = Box pos:( getKnotPoint $ s k) length: 5 height: 5 width: 5 name: newObjName
newBox.dir = ( getInVec $ s k)
)
)
Right, I just realized that InVec doesn’t return the tangent vector itself, but the coordinate of the handle, so you have to recreate the vector. Very easy, just subtract the knot coord with the InVec :
for s = 1 to (numSplines $Line01) do
(
for k = 1 to (numKnots $Line01 s) do
(
newObjName=uniquename ("spline_")
newBox = Box pos:( getKnotPoint $Line01 s k) length: 5 height: 5 width: 5 name: newObjName
newBox.dir = [B](( getInVec $Line01 s k) - ( getKnotPoint $Line01 s k))[/B]
)
)
Since you seem to use straight line, try this.
delete $spline_*
spline = $Line01
for s = 1 to (numSplines spline) do
(
splineKnotCount = numKnots spline s
format "numKnots:%
" splineKnotCount
for k = 1 to splineKnotCount do
(
toolMode.coordsys #view
curDir = [1,0,0]
curKnot = getKnotPoint spline s k
if (k > 1) then
( prevKnot = getKnotPoint spline s (k-1) )
else (prevKnot = undefined)
if (k < splineKnotCount) then
(
nextKnot = getKnotPoint spline s (k+1)
curDir = normalize(curKnot-nextKnot)
)
else
(
nextKnot = undefined
curDir = normalize(prevKnot-curKnot)
)
newObjName = uniquename ("spline_")
newBox = Box pos:(getKnotPoint spline s k) length: 5 height: 5 width: 5 name: newObjName
newBox.dir = curDir
format "curDir %
" curDir
)
)
i don’t know why you need to align an object to a knot and how necessary it but I would do different way. I would use Path_Constraint controller:
(
delete objects
sp = splineshape name:"spline" wirecolor:yellow vertexTicks:on
addnewspline sp
for p in #([0,0,0], [1,1,0], [2,2,0], [4,2,0], [4,5,0]) do addknot sp 1 #corner #line p
updateshape sp
num = numknots sp
step = 100.0/(num-1)
for k=0 to num do
(
pt = point name:("point" + k as string) constantscreensize:off centermarker:off axistripod:on box:on cross:off size:1 wirecolor:orange
c = pt.pos.controller = path path:sp loop:off constantvelocity:off axis:0 follow:on bank:off allowUpsideDown:on
deletekeys pt
c.percent = k*step
)
)
the method doesn’t align to knot, it aligns to average tangent at the knot position. Which makes more sense for me.