Assigning key frames to many vertex points for a path constraint

Assigning key frames to many vertex points for a path constraint

Rob_Durham
Enthusiast Enthusiast
759 Views
4 Replies
Message 1 of 5

Assigning key frames to many vertex points for a path constraint

Rob_Durham
Enthusiast
Enthusiast

 

Hi,

 

This is a re-post from the general modelling forum as I realised it was more of a programming issue than a modelling issue and I've received no responses there anyway!

 

The goal;

 

Using a path constraint, have an object follow an elliptical path with thousands of vertex points. Each consecutive vertex point is a consecutive key frame.

 

The problem;

 

Because there are thousands of vertices and because the progress of an object on a path constraint is determined by percentage it would take me hours to do this manually. 

 

Possible solution

 

I can use AutoCAD's data extraction tool to export the coordinates of an ellipse to a spreadsheet. I can use the spreadsheet to add any additional script that may be necessary and I have found a maxscript that will read from a .csv file and draw objects at xyz coordinates contained within it. I was thinking that another maxscript may be able to actually duplicate the ellipse by perhaps drawing a dummy object at each coordinate and then drawing a line between each one. It would also need to assign an incremental key frame to each coordinate.

 

A pseudo script might look a little like this:

 

Draw dummy at xyz coordinate 1

Draw dummy at xyz coordinate 2

etc

etc

Draw line from xyz coordinate 1 to xyz coordinate 2

Draw line from xyz coordinate 2 to xyz coordinate 3

etc

etc

Select line as a path constraint

Assign key frame 1 to coordinate 1

Assign key frame 2 to coordinate 2 

 

Sorry I don't know maxscript but the above I would imagine would be the process?

 

Another option would be to simply import the ellipse geometry directly from the AutoCAD dwg, apply a path constraint and somehow have a script set each vertex position as a key frame. The trouble with this method however is that I don't think it would know how to order the vertex coordinates incrementally?

 

Either way I'm stumped at the moment so any help would be much appreciated.

0 Likes
Accepted solutions (1)
760 Views
4 Replies
Replies (4)
Message 2 of 5

drew_avis
Autodesk
Autodesk

Hi there, I think what you want to do is create a new splineShape object, add a new spline to it, and add knots to the spline based on your imported data.  Here's a really simple bit of code adapted from the docs to show you what it looks like:

 

sp = splineShape()
addnewSpline sp
addKnot sp 1 #smooth #curve [20,10,0]
addKnot sp 1 #smooth #curve [-20,11,0]
addKnot sp 1 #smooth #curve [-20,-11,0]
addKnot sp 1 #smooth #curve [20,-10,0]
close sp 1
updateShape sp

s = sphere()

pc = path_constraint()
s.position.controller = pc
pc.path = sp

Check out the SplineShape documentation for more details. http://help.autodesk.com/view/3DSMAX/2018/ENU/?guid=__files_GUID_6C6A35EB_DD5F_40C1_9869_0938849F684...

 

I need to think about the animation keys for each knot, I'll post again when I have a sample for that, but this should get you started.

 

Hope that helps,

Drew



Drew Avis
Content Experience Designer
0 Likes
Message 3 of 5

Rob_Durham
Enthusiast
Enthusiast

Thanks Drew,

 

That certainly does seem to be the first step working.

 

I look forward to the next step.

 

Thanks again

 

Rob.

0 Likes
Message 4 of 5

drew_avis
Autodesk
Autodesk
Accepted solution

Hi Rob, so I don't think you need the path constraint controller, you can set the object's position directly using the point data.  Here's what I came up with:

 

pt_array = #([46.9715,-22.8284,18.8499],
[53.5638,2.9877,18.8499],
[58.0018,41.7387,18.8499],
[54.6452,53.2799,18.8499],
[48.1278,65.5195,18.8499],
[3.16677,94.2637,18.8499],
[-21.2341,82.2081,18.8499],
[-54.9876,43.4941,18.8499],
[-79.779,15.0592,18.8499],
[-98.9776,-8.35027,18.8499],
[-107.349,-59.1189,18.8499],
[-87.16,-93.8554,18.8499],
[-70.383,-110.632,18.8499],
[-53.606,-127.409,18.8499],
[-45.8135,-131.2,18.8499],
[-34.4538,-136.025,18.8499],
[1.36025,-111.722,18.8499],
[26.7701,-71.442,18.8499],
[47.2292,-25.2001,18.8499],
[45.6122,-21.4692,18.8499])

sp = splineShape()
addnewSpline sp
for i = 1 to pt_array.count do (
	addKnot sp 1 #smooth #curve pt_array[i]
)

close sp 1
updateShape sp

s = sphere()

animate on (
	for i = 1 to pt_array.count do (
		at time i s.position = pt_array[i]
		
	)	
)

Hope that helps,

Drew



Drew Avis
Content Experience Designer
Message 5 of 5

Rob_Durham
Enthusiast
Enthusiast

Thanks Drew,

 

It worked perfectly.

0 Likes