View Full Version : animate line with its vertex?
03 March 2009, 02:33 AM
I just want to animate a line wiht its vertex use the position value
03 March 2009, 12:41 PM
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 :|
03 March 2009, 08:39 PM
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 -- 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,
03 March 2009, 01:45 AM
thank you ,guys
Its kind of you to take time to reply my questions
03 March 2009, 01:59 AM
JHN, I run your code in max 8,the result is as follow:
$Editable_Spline:MySpline05 @ [0.000000,0.000000,0.000000]
but I get nothing in the viewport
what's wrong with that?
03 March 2009, 10:00 AM
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.
03 March 2009, 02:23 PM
If only it were that simple :\
theSpline = $
$Line:Line01 @ [40.000000,-0.000002,50.000000]
animateVertex theSpline #all
theTrack = theSpline
theTrackIndex = 3 * (1 - 1) + 2
theKey = addNewKey theTrack[theTrackIndex].controller 10
#Bezier Point3 key(1 @ 10f)
theKey.value = [10,0,0]
getKnotPoint theSpline 1 1
getKnotPoint theSpline 1 2
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) :\
03 March 2009, 12:44 AM
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
uh,I want to use the points record the deformation to make an animation
03 March 2009, 02:46 AM
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
all I want to do is change the xyz value by output value ,and anyone have ideas or suggestion? thanks
03 March 2009, 10:04 AM
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.
03 March 2009, 10:57 AM
$.modifiers.createHelper 4 will make 4 controls.
Lookup Spline_IK_Control in the manual it's near the bottom of the page.
03 March 2009, 11:18 AM
thanks johan, I hadn't checked the help, just probed the mod for properties
03 March 2009, 02:03 AM
thanks for reply
but I am a newer , have no idea about the spline_ik controller , I read the help but seems got nothing more
03 March 2009, 02:55 AM
when I move one point manually in max viewport , why the other points will follow moving?
can there any methods let them independed
03 March 2009, 01:55 PM
I assume you using the splineIk modifier.
You have to set the "Link Types" option to "no linking".
Then the nulls won't be parented.
03 March 2009, 01:59 PM
thanks , JHN
when a problem solved , always there is another question appeared , just like life
then here I meet another problem
if I have created 10 points with the createhelper function , how can use for loops to select the points and update their postion from a dat file , and also I like to make an animation with the position change
03 March 2009, 02:13 PM
I think the "read data value" question is being answered in another thread, right?
About getting the points you can use the #helper_list property of the modifier
getProperty $.modifiers #helper_list
Assuming modifiers is the modifier. If you create a modifier in script you could also directly call the getProperty on the modifier like
getProperty theSplineIKMod #helper_list
Provided theSplineIKMod is the variable pointing to the modifier.
It will return an array of helpers, which you can use to apply the data to.
03 March 2009, 02:13 AM
uh , thanks JHN
although I did not catch all what you said, but can get something useful
maybe I should post a newthread to talk about the spline IK control
03 March 2009, 02:13 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.