Notifications
Clear all

[Closed] Spline Vertex animation

Hi everyone,
I am a new guy to max script and getting in to it slowly. I want to create a tool to create a spline between two picked objects and animate the vertices as a electric shock. The animation is happening but only for one vertex in the forloop. code is given below.

Rollout electric "Create Electric wave"
(
	local startObj,
		endObj
		
	
	pickbutton pickObj01 "Pick Wave Start"
	label startobj_lbl "---None---"
	pickbutton pickObj02 "Pick Wave End"
	label endobj_lbl "---None---"
	spinner numVert "Num of Verts: " range:[0,100,6] type:#integer--
	button create "Create Bolt"
	button anim "Animate"
	fn createSpline =
	(
		sS = splineShape pos:startObj.pos name:"animShape"
		addnewspline sS 
		addknot sS 1 #Corner #line startObj.pos
		addknot sS 1 #Corner #line endObj.pos
		select sS
		subdividesegment sS 1 1 numVert.value
		select sS
		allvert = numknots sS
		for i = 1 to allvert do
		(
			setKnotType sS 1 i #corner
			)
		updateShape sS
		convertToSplineShape sS
		)
	fn animateSpline = 
	(
		local sS = $animShape,
		animStart = animationRange.start,
		animEnd = animationRange.end,
		vertcount = numknots sS
		animatevertex sS #all
		animate on
			for t in animStart to animEnd by 2 do
				for i in 3 to vertcount-1 do
					at time t
					(					
						sS[4][8][i].controller = bezier_point3()
						sS[4][8][i].controller.value= random [5,5,5] [-5,-5,-5] 
						updateshape sS
						)
		)
	
	on pickObj01 picked obj do
	(
		startObj = obj
		startobj_lbl.text = obj.name		
		)
	on pickObj02 picked obj do
	(
		endObj = obj
		endobj_lbl.text = obj.name		
		)
	on create pressed do
	(
		createSpline ()
		)
	on anim pressed do
	(
		animateSpline()
		)
	)
	createDialog electric
4 Replies
 lo1

I haven’t read all your code carefully but I’m pretty sure you don’t want to reset the controller of each vertex for every frame:

sS[4][8][i].controller = bezier_point3()

you probably want to do this once before the loop.

I am basically trying to set the number of vertex from the spinner input and want to animate the vertices from 2 to total vertex count-1. I want to change the position of the vertex for every 2 frames in the animation Range. And forgot to add to ask how would i get the current position of the vertexes so that i want to move them only -5 to 5 in every axis randomly. Hope I made it clear what i want.
Thank you

each vertex has 3 controller values in/vertex/out, you just have to animate the vertex values. To animate from second vertex to count-1 you could use this

for i = 2 to vertexcount-1 do
(
    at time t
    (
        k = (i * 3) - 1
        sS[4][8][k].controller.value = random [5,5,5] [-5,-5,-5]
    )
)

Ah Oh…Thanks Mr.Akram Parvez. That was a lot of help.