Hi all,
I was wondering if it’s genuinely possible to load animations
actorModel.loadAnims({"loadedAnimName": animFileName})
and music, sounds
base.loader.loadMusic(soundFileName)
base.loader.loadSfx(soundFileName)
asynchronously, such as within an AsyncTask. Does Panda3D genuinely allow for that, or will there be some sort of chug, albeit a slight one? I know one can load models asynchronously fairly easily with coroutines and the like
modelFuture = base.loader.load_model(modelPath, blocking=False)
modelGotten = await modelFuture
modelGotten.reparentTo(render)
but what of animations and sounds?
EDIT:
It seems to be that the only way to load animations, sounds, etc, asychronously is via a sub-thread, in an AsyncTask for example, but I just wanted to be sure that asychronicity is also enabled for those operations too. I will leave this question open just in case someone knows another way to do this however.
Thanks in advance.
Hi, this is a question that has come up in different Panda3D projects I’ve worked on before. Now, take the following with a grain of salt, but the general solution I’ve found is to actually instantiate the IE animation events before they need to happen.
I have recently updated my Arena FPS sample program in this way, to remove the longstanding win-state hitch when you successfully shoot the NPC. The only code added to resolve the hitch is the following, added near the end of the program just before the game start tasks begin.
# pre-initialize death animation to smooth out win-state animation
# playing for the first time
npc_1_control = actor_data.NPC_1.get_anim_control('death')
if not npc_1_control.is_playing():
actor_data.NPC_1.play('death')
npc_1_control = actor_data.NPC_1.get_anim_control('walking')
if not npc_1_control.is_playing():
actor_data.NPC_1.play('walking')
It can be considered a hack, because really all this is doing is getting the event into working memory before it’s needed “the first time”. But from my experience, it does smooth out new animation events triggering for the first time (even moreso than say threading2 would).
1 Like
Hello, Right now I was starting to want to implement asynchronous loading with Actors, taking some things from the manual, using task chains.
base = ShowBase.ShowBase()
taskMgr.setupTaskChain('new_chain', numThreads = 1)
def mi_t(task):
list = []
a = Actor('example.egg', list_anim)
list.append(a)
# ...
base.messenger.send('end_load', [list])
return task.done
taskMgr.add(mi_t,"task asyn", taskChain = 'new_chain')
base.run()
I saw that the Actor class can load animations asynchronously using enable-async-bind, which seems ideal if you have to load a lot of animations, but I haven’t tried it.