Problems with animated object lifetime and transformation controls

Please help! Hi 3DS people, I've spent the last 2 days trying to resolve some tricky (but probably very simple) problems with an air-traffic animation I'm working on. This is getting really urgent now so I'd be super-grateful for assistance. I attach the code and data file. Problems are:

1. objects are supposed to be created at specific times, but for some reason they are all in the animation (mostly motionless) from t=1.

2. grateful for any suggestions as to how to kill (delete) planes once they've reached their destination? I can code to kill them if they don't move, but can't figure out how to remove objects from the animation.

3. the code is nearly controlling object rotation correctly, but some objects briefly spin for some reason when they turn anti-clockwise (possibly through an axis). I've spent hours adjusting the atan code (as well as trying atan2) but can't figure out why this is happening, and it really undermines the whole animation.

The arrays are:
- frame: the time index position for each data row
- flight: flight number
- points: flight x-y-z position data
- planes/listlastpos/listlastdir: remembers IDs, positions and directions

*** PLEASE NOTE THE ANIMATION IS A QUITE LARGE SCALE - YOU NEED TO ZOOM OUT TO SEE IT ***

resetMaxFile #noPrompt
(
	--Initialise arrays
	global frame	= #()
	global flight = #()
	global points = #()
 
	--Read in the movement data
	local theFile = openFile "C:\\flights.txt"
	while not eof theFile do (
		t = (readValue theFile as integer)
		f = (readValue theFile as string)
		append frame t
		append flight f
		p = Point3 (readValue theFile as float) (readValue theFile as float) (readValue theFile as float)
		append points p
	)
	close theFile
 
	-- Initialise unique plane data arrays
	global planes = #()
	global listlastpos = #()
	global listlastdir = #()
)
 
 
	--Animate objects
	animate on 
(	
	animationRange = interval 1 frame[frame.count]
	--Initialise row-counter 'k'
	k = 1
 
	for t in 1 to frame[frame.count] do
	(
		at time (t)
		(
			while t == frame[k] do --Undertake action in relevant frames only
			(
				-- Initialise new plane
				if appendIfUnique planes flight[k] then
					(
						--Create new object - WHY DO THEY ALL APPEAR AT FRAME 1?
						Plane length:2000 width:2000 pos:points[k] isSelected:on
						$Plane001.name = flight[k]
						append listlastpos points[k]
						append listlastdir 0
					)
 
				else -- Plane already exists
					(
						-- Move plane to new position
						execute ("select $" + flight[k] as string)
						$.pos = points[k]
 
						--Retreive data on last transformations
						id = findItem planes (flight[k] as string)
						lastpos = listlastpos[id]
						lastdir = listlastdir[id]
 
						--Calculate current direction vector
						dirVec = normalize(points[k] - lastpos)
 
						--Calculate intended rotation
						rot = atan (dirVec.y/dirVec.x)
						if dirVec.x < 0 and dirVec.y > 0 then rot = 180+rot
						if dirVec.x < 0 and dirVec.y < 0 then rot = -180+rot
 
						--Unapply last transformations and apply new ones
						rot_obj = eulerangles 0 0 -lastdir -- Undo direction
						rotate $ rot_obj
 
						rot_obj = eulerangles 0 0 rot -- New direction
						rotate $ rot_obj
						-- WHY DO SOME OF THE OBJECTS SPIN WHEN TURNING ANTI-CLOCKWISE?
 
						--Remember current position and rotation
						listlastpos[id] = points[k]
						listlastdir[id] = rot
					)
 
				--Kill old planes (how to make them disappear when they've stopped moving?
 
				k = k+1
			)
		)
	)
	print "done"
)
AttachmentSize
flights.txt43.38 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Garp's picture

Animate the visibility.

Another common solution is to move the object out of sight.

barigazy's picture
geotheory's picture

Thanks chaps. I tried that method..

.. using the code below. Now half of the objects don't appear at all, and some of the ones that do appear still don't disappear when they stop moving.

if dirVec.x < 10 and dirVec.y <10 then
(
	macros.run "Modifier Stack" "Convert_to_Poly"
	faceCount = polyop.getnumFaces $
	deleteObjFace = polyop.deleteFaces
	for face in faceCount to 1 by -1 do deleteObjFace $ face
)
<\code>
 
The issue seems to me that with the current approach the create and delete commands do not take place at time x.  I might have to revert to repositioning below the floor-line.
barigazy's picture

You can not animate delete

Don't try to animate delete operaton.
Use visibiliti controller or put some material
and animate opacity from 100 to 0.
If you want to convert something to editable poly better use

convertto $ Editable_Poly

bga

geotheory's picture

Thanks again

I've tried this, and the other suggestions made. I'm still getting the same problem. There is something in the way the data is being processed that I'm just not understanding. I think I'll have to play around with the the position data in Excel and hide objects below the ground before and after they are needed.

All this does not really impress me about Max I have to say. I can do pretty much anything I want in Processing, but this just seems like torture.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.