Mini-Challenge #5. Are you ready?


try to cover at least all types/kinds of animation that I give in the test.
but the main idea is to find any source of animation…


here is a reference point (my version):

	t1 = timestamp()
	m1 = heapfree
	a = findAnimatedNodes()
	format "nodes:%
	time:% memory:%
" a.count (timestamp() - t1) (m1 - heapfree)
/* result is:
	time:244 memory:1704L

my first attempt was ~1.5 sec to get them all…

~15 secs for 10,000 nodes is VERY slow. I was really shocked.
~2.5 secs is still slow. But hopefully we will find a better solution.


here are some numbers (not 100% sure that I’m right):
only transform animation: 183
only modifiers animation: 111
only material animation: 197


Enjoy the challenge!
Happy Turkey for all Americans and Have a Nice Day for all of us!


Hmm this is proving to be pretty difficult. There are so many damn properties to check!!

So far I have a function that checks for baseObject properties, modifier properties and controllers (recursively). I still need to add materials but this is quite tricky.

time:94 memory:39544L

P.S. I’m a little unsure what the memory usage means. Is this the memory consumed by the function during processing? In bytes or kb, or something else?


you are in very good speed and in good memory usage. i don’t think that the memory leaking is an issue of this challenge. but it’s a right practice to check the memory usage. when you call any of your functions you have to be sure that the function will complete before it eats all memory and crashes the system.

How to check if there is animation on an object?

i know that anyone who works with animation sooner or later meets this task.
i’m not asking everyone for sharing the code (because it might be your personal treasure), but i appreciate the seeing your numbers to compare. thanks.


This is not the way to do it, but I’ll put it out there for people to rip on:

 	fn findAnimatedNodes =
 		sceneSelection = selection as array
 		arrAnims = #()
 		for i=1 to sceneSelection.count do
 			local check = false
 			for j=1 to 20 do (try(if (sceneSelection[i][3][j].keys != undefined) then (check = true))catch())
 			for j=1 to 20 do (try(if (sceneSelection[i][4][j].keys != undefined) then (check = true))catch())
 			for j=1 to 20 do (try(if (sceneSelection[i][5][j].keys != undefined) then (check = true))catch())
 			if check == true then (append arrAnims sceneSelection[i])
 		return arrAnims
 		t1 = timestamp()
 		m1 = heapfree
 		a = findAnimatedNodes()
 		format "nodes:%
	time:% memory:%
" a.count (timestamp() - t1) (m1 - heapfree)


I’m sure this isn’t the way to do it, or if I’m even returning the array that you wanted denisT.
I’m interested in seeing other’s code :slight_smile:


796 keyed nodes found

don’t know if I missed something…


you are not missing, you are finding more than me :slight_smile:
which is absolutely possible.
and you do it very fast!

can you post at least the bitarray of keyed object index numbers?
like #{objects[n0],objects[n…], …}

	local ss = StringStream ""; showClass "*Float:*controller*"  to:ss; seek ss 0
	local clas = #()
	while not eof ss do append clas (execute (filterString (readLine ss) ":")[1])
	local sset = #()
	for c in clas do
		local insts = getClassInstances c
		local keyed = for o in insts where o.keys.count > 0 collect o
		join sset keyed
	local all = #()
	for c in sset do join all (refs.dependentNodes c)
	all = makeUniqueArray all
-- 	format "nodes: %
" all.count

– 104ms
– nodes found: 632

well denisT, now that I check, I forgot to make the array Unique.
tried to change the seed, but random always gives less than 700 keyed nodes

max TV has a option to display only animated tracks, but it misses a lot of tracks!


you check only float controllers, but it might be any type. in real life you don’t know which type of controllers are animated in the scene. so you have to check them all.


I was hoping to add to the list the missing/complex tracks, thinking that max has a fixed amount of controllers.

but your right, I’m gonna try something else, more like brute force… :slight_smile:


this is my attempt at thinking out of the $Box :stuck_out_tongue:

	local ts = timestamp()
	local mem = heapfree
	global animatedNodes = #()
	fn myCallbackFilterFunction theAnimatable theParent theSubAnimIndex theGrandParent theNode = 
		if isController theanimatable and theanimatable.keys.count>0 then
			appendIfUnique animatedNodes theNode
		else true
	with redraw off
		trackbar.filter = #all
		local filtind = maxops.trackbar.registerFilter myCallbackFilterFunction undefined "." 1 active:on
		select objects
		maxops.trackbar.redraw forceRedraw:on
		maxops.trackbar.unregisterfilter filtind
		format "Time: %ms
" (timestamp()-ts)
		format "Memory: %
" (mem-heapfree)
		format "Nodes Found: %
" ((animatedNodes).count)
Time: 132ms
Memory: 352L
Nodes Found: 753


Just to quickly clarify Denis,

The array of nodes that is output - are you looking for an array of every node and every material that has an animation, or every single value that is animated?

IE does the array contain:

#(box01, box02, box03)
#(box01 scale controller, box01transform controller, box02 rotate controller, box03 rotate controller)

I guess the second one would be more useful as you can have access to all keys very easily. Is this what you’re after?


Hm, I wonder how we’ll look for correctness with such an unpredictable amount of animated nodes. I get 600 invariably but is that correct?

My function is not even optimized but the most interesting is, I think, after test it on different Max versions on my computer, I get so freakish and weird results:

Max 9 SP2 64: nodes:600 | time:8907 memory:4351776L
Max 2009 x32: nodes:600 | time:1922 memory:1520L
Max 2009 x64: nodes:600 | time:265 memory:105848L
Max 2011 x32: nodes:600 | time:688 memory:2712248L
Max 2011 x64: nodes:600 | time:516 memory:4877968L

So, as you see, its so easy to make wrong conclusions, and so difficult to reach meaningful conclusions.
Code optimization in Max is a (how to say…) pitfall (:


the list of all animated controllers is more useful, but let’s talk now just about the list of animated nodes.


that was my plan for tomorrow, but you showed it first.
at first glance everything looks right and complete… using the method is also easy to collect keyed controllers as well.
can we filter only material or ca sources?


OK thanks for the clarification.

This is what I came up with last night. Looking at the code this morning it looks like the wrong way to go about doing it, but it executes quite quickly I guess. Surely the best method is one that picks up every node even if it is very slow, and once we know the complete total number of animated nodes we can then optimise. It’s interesting that everyone is getting different totals!

time:65 memory:94872L

	local animatedNodes = #()
	local found = false
	--Recursively work through object controllers to find any keys
	function findCtrlKeys obj index = (
		if obj.controller[index].keys.count > 0 then (
			append animatedNodes obj
			found = true
		else (
			if obj.controller[index+1] != undefined and not found do findCtrlKeys obj (index+1)

	--Main function
	function findAnimatedNodes = (
		--Loop through all nodes
		for a in $* do (
			found = false
			--Find any keys in object controllers
			findCtrlKeys a 1
			--Find any keys in object base properties
			if not found do (
				propNames = getPropNames a
				for b in propNames while not found do (
					ctrl = (getPropertyController a.baseObject b)
					if ctrl != undefined do if ctrl.keys.count > 0 do (
						append animatedNodes a
						found = true
			--Find any keys in object modifier properties
			if not found do (
				for b in a.modifiers do (
					propNames = getPropNames b
					for c in propNames while not found do (
						ctrl = (getPropertyController b c)
						if ctrl != undefined do if ctrl.keys.count > 0 do (
							append animatedNodes a
							found = true
		--Loop through all materials
		--Add recursive function here
		return animatedNodes
	--Run Function with timestamp
	t1 = timestamp()
	m1 = heapfree
	a = findAnimatedNodes()
	format "nodes:%
	time:% memory:%
" a.count (timestamp() - t1) (m1 - heapfree)


heh… max, max, max… 2011 is slower than 2009… show you method please … it will be very interesting to see the bottleneck