Problem of the day

Hi guys. So here’s more of a design question that I’m trying to solve today.
As it is really a mess exporting 3D animations from Maya to several dae files (The from -> to frame in animations doesn’t seem to work) and we would have to work with one maya file/animation I decided to write my own animation module instead where we define animationname and start/stop for the cursor in a json file. We then have one single animation containing all animationclips and then just set the cursor to the correct place to start and stop.
This could be a matter to change but hey… for now we try this out.

Now to todays nut to crack:
I want to be able to track all animations being played by storing them in an “active” table. To be able to see the progress of the animation I am keying all the animations with the model url. Like this:
{ [msg.url(“themodel url”)] = { animation_table_in_here }}

Now this does not work as msg.urls will not be the same if you create them twice. Here is a small test made with msg.url() and go.get_id()

    local gid1 = go.get_id()
	local gid2 = go.get_id()
	local u1 = msg.url()
	local u2 = msg.url()
	local tbl = {}
	tbl[gid1] = "reachable with gid2"
	tbl[u1] = "not reachable with u2"
	print( gid1 == gid2 )
	print( u1 == u2 )
	print(tbl[gid2])
	print(tbl[u2])
	
	--[[ CONSOLE RESULTS:
	DEBUG:SCRIPT: true
	DEBUG:SCRIPT: true
	DEBUG:SCRIPT: reachable with gid2
	DEBUG:SCRIPT: nil
	--]]

Basically. There is obviously a way to use go id’s as keys (as they are pointing to the same adress everytime). Is there a way to do this with specific component?
I want to be able to reach the animation state from anywhere in the code with something simple as: anim_module.get_state(msg.url("/obj#model"))
and no… I really don’t want to key things with strings.

:slight_smile:

Yeah, that’s an annoying thing with URLs. You could convert the url to a string key inside the anim_module.get_state() function:

local key = hash_to_hex(url.socket) .. hash_to_hex(url.path) .. hash_to_hex(url.fragment or hash(""))

And if you’re worried about performance you could cache the whole thing, sacrificing a bit of memory for performance.

1 Like

Well, I might misunderstand this statement, but with release 1.2.105, DEF-1995, you can now pre create and reuse msg.url()'s due to the fact that they are now in fact directly derived from hashing each part (socket, path, fragment)

But, yes to use it as a key in a table, we’d need to add a better helper function for it, or as @britzl mentions, you can create a workaround

1 Like

Big thanks guys.
I believe I want to work without reusing the same msg.url() passing it around or storing it somewhere central. Would have been nice just to pass in the url string (sometimes full and sometimes just component string) and it would have been solved. Will go with your solution Björn and see later on if it impacts performance too much.

1 Like