Notifications
Clear all

[Closed] animate line with its vertex?

I just want to animate a line wiht its vertex use the position value

17 Replies

huh… I would have simply suggested ‘with animate on at time T ( setKnotPiont shapeObj splineIndex knotIndex )’, but apparenty that doesn’t create any keyframes.

You’d have to manipulate the positions of the knots directly via the subanims, I would guess… must be an easier way though

 JHN

No there is no easier way… that I know of…


 /* CREATE A SPLINE */
 theSpline = splineShape name:(uniqueName #MySpline) wirecolor:orange   -- create a base spline
 addNewSpline theSpline	 -- add a spline
 for i = 1 to 10 do
    addKnot theSpline 1 #smooth #curve [random (-10*i) (10*i),random (-10*i) (10*i),random (-10*i) (10*i)]  -- add some knots
 updateShape theSpline	  -- Now draw the shape in the viewport
 
 /* ANIMATE THE SPLINE */
 animateVertex theSpline #all	   -- gives point3 controllers to all verts, very important!!!
 kc = numKnots theSpline
 for i = animationRange.start.frame as integer to animationRange.end.frame as integer by 10 do (	-- loop over the timeRange
    theTrack = theSpline[4][8]  -- this is the masterblock controller where all point3 controllers live
    local count = 1
    for k = 1 to kc do  -- loop through knots
    (
 	   theTrackIndex = 3 * ( count - 1 ) + 2 -- this subcontroller, every third controller, starting from 2
 	   theKey = addNewKey theTrack[theTrackIndex].controller i -- set key on time i
 	   theKey.value  = [random (-1*i) (1*i),random (-1*i) (1*i),random (-1*i) (1*i)]   -- Set the value!
 	   count += 1
    ) -- end for k
 ) -- end i
 
    
Basic steps, make sure animateVertex spline #all is being run and then loop over the masterblock subcontrollers every third controller starting from 2 adding keyframes.

Hope this helps,
-Johan

thank you ,guys
Its kind of you to take time to reply my questions

JHN, I run your code in max 8,the result is as follow:

 $Editable_Spline:MySpline05 @ [0.000000,0.000000,0.000000]
1
OK
OK
OK
10
OK
OK 

but I get nothing in the viewport
what’s wrong with that?

 JHN

Maybe you’re hiding spline shapes? Try shift+s… it’s a long shot, I know…
I should work, I’m pretty certain it’s doesn’t have “new” code in it, but I’m on 2009 so I cannot check it in 8…

Maybe someone else can test it.

Goodluck,
-Johan

If only it were that simple :\


theSpline = $
$Line:Line01 @ [40.000000,-0.000002,50.000000]
animateVertex theSpline #all
OK
theTrack = theSpline[4][8]
SubAnim:Master
theTrackIndex = 3 * (1 - 1) + 2
2
theKey = addNewKey theTrack[theTrackIndex].controller 10
#Bezier Point3 key(1 @ 10f)
theKey.value = [10,0,0]
[10,0,0]
updateShape theSpline
OK
numKnots theSpline
2
getKnotPoint theSpline 1 1
[50,-2.18557e-006,50]
getKnotPoint theSpline 1 2
[60,-2.18557e-006,50]

The knot positions are in local coordinate space (simple multiplication by (inverse theSpline.transform) fixes that). And then there’s the tangent handles (if any) :\

JHN , today I have your code run, but the result was not what I expected ,what I want is to move the point of the curve , and then the whole line will get a deformation , well ,when curve points selected then the listener will record :subobjectLevel = 1
modPanel.setCurrentObject $.baseObject
deselect $.baseObject.points
select $.baseObject.points[]

uh,I want to use the points record the deformation to make an animation

today I read the helps and find some code that seem like as I wanted but some different


on execute do

(

new_z = $.pos.z

for s = 1 to (numSplines $) do

(

for k = 1 to (numKnots $ s) do

(

knt = getKnotPoint $ s k

in_vec = getInVec $ s k

out_vec = getOutVec $ s k

knt.z = in_vec.z = out_vec.z = new_z

setInVec $ s k in_vec

setOutVec $ s k out_vec

setKnotPoint $ s k knt

)--end k loop

)--end s loop

updateshape $

)--end execute


 

all I want to do is change the xyz value by output value ,and anyone have ideas or suggestion? thanks

You could approach this differently and add a splineIK modifier to the spline and use script to move the pointhelpers around. I couldn’t see a method to create the helpers via script, although Rich will be able to figure that out how to press the button on the UI.

The modifier then has a .helper_list property which is a node array of the points that you could cycle through and transform however you liked. Gets you out of the realms of sub-object transforms, and means you can set keyframes that you can edit easilly.

Page 1 / 2