Notifications
Clear all

[Closed] Animating Spline Vertices

My current task will involve animating the motions of a cable between two ships at sea. I will be given a time series of world space coordinates for each vertex of what will be a spline between the two ships.

If for exaple the spline ($Line01) had 3 points and the input data was:
t(frames) | p1(x,y,z) | p2(x,y,z) | p3(x,y,z)
0 | 0.0, 0.0, 0.0 | 1.0, 0.0, 0.0 | 2.0, 0.0, 0.0
50 | 0.0, 0.0, 0.0 | 1.0, 0.0, 3.0 | 2.0, 0.0, 0.0

I tried the following scrpt:

set animate on
animateVertex $Line01 #all
set time 0
setKnotPoint $Line01 1 1 [0.0, 0.0, 0.0]
setKnotPoint $Line01 1 2 [1.0, 0.0, 0.0]
setKnotPoint $Line01 1 3 [2.0, 0.0, 0.0]
updateShape $Line01
set time 50
setKnotPoint $Line01 1 1 [0.0, 0.0, 0.0]
setKnotPoint $Line01 1 2 [1.0, 0.0, 3.0]
setKnotPoint $Line01 1 3 [2.0, 0.0, 0.0]
updateShape $Line01
set animate off

The spline assumes the final shape but no animation keys are set.

I have been told that I need to use controllers with the animateVertex() function, but I am unsure as to how and the correct syntax.

9 Replies

max is a mesh-polygon modeling program.
I would link the position of knots to sth animatable by maxscript for example dummies,vertices…
there is no animation for Editable spline modifier coz it has no Master Ctrl!!!

Thank you.

Here’s a script I wrote to animate the “growth” of a spline. It illustrates the steps you can take to animate spline verts. To test it, select one or more open ended splines, and then run the script.

mapped fn splineGrow obj startFrame:0 = (
 	-- return false if the object cannot be converted to a spline
 	if not canConvertTo obj splineShape do return false
 	-- make sure the shape is a collapsed editable spline obj
 	if classOf obj == line do (
 		addModifier obj (edit_spline())
 		)
 	convertToSplineShape obj
 	animateVertex obj #all
 	startNum = 0
 	-- animate each spline withing the spline object seperately
 	for s = 1 to numSplines obj do (
 		-- create bitarray of knot indexes for current spline
 		local knotArr = #{1..numKnots obj s}
 		-- get the total number of knots
 		local n = knotArr.numberSet
 		-- create array of positions for each knot so we know where they should end up
 		local knotPosArr = for i = 1 to n collect in coordsys obj (getKnotPoint obj s i)
 		-- this is where the magic happens
 		for i = 1 to n do (
 			-- define the end of the following loop
 			local n2 = startNum + (n * 3)
 		-- animate only the Vertex master control points, not the InVec or OutVec points
 			for j = ( (((i * 2) - 1) + i) + startNum ) to n2 by 3 do (
 				-- set keys for the position of the knots
 				animate on (
 		 	-- for the first iteration of the loop, set all the knot positions to the position of the first knot at frame zero
 					if i == 1 do (
 		 		at time 0 obj[#Object__Editable_Spline][#Master][j].value = knotPosArr[i]
 						)
 		 	-- then start setting keys at the startFrame plus the current loop iteration
 	 			at time ((startFrame - 1) + i) obj[#Object__Editable_Spline][#Master][j].value = knotPosArr[i]
 					)
 				)
 			)
 		startNum += n * 3
 		)
 	)
 
 splineGrow getCurrentSelection()

James, whats your script supposed to do?
I ran it on a line, it gave argument count error (wanted 1 got 2).
I moved startFrame=0 inside the function and still got the same error. Then I replaced getcurrentselection() with $ and the spline disappeared.

Move the time slider.

I also tried the script, pretty cool

Psan, you’ll need to change this: splineGrow getCurrentSelection()
to this: splineGrow ( getCurrentSelection() )

much like how the addmodifer function works when adding modifers.

galagast,
Thanks, putting it in brackets did the job.

James,
Very interesting script, sometimes I overlook the obvious

Thanks for the catch. I should really test my scripts before I post, but I thought the one extra line added at the bottom would be harmless enough.

I should also point out that this will work with a spline shape that has more than one spline in it, and if you want the spline to start “growing” at a frame other than zero then use the extra “startFrame” parameter. Something like. “splineGrow (getCurrentSelection()) startFrame:100”.