Blending Animations?

I’m having trouble with the animation blending interface in panda. I’m trying to just use the info I found in the Manual

http://panda3d.org/manual/index.php/Actor_Animations

To start with I’d like to have my character play some of its walk animation and some of its talk animation at the same time. My ulimate goal is to smoothly transition between the two animations. (I am not trying to do a multi-part animation where the model does both at the same time).

When I play each animation individually it works fine. When I try to blend them together it just plays the last animation (no apparent blending).

Here’s what I’m trying to do:

myActor= Actor.Actor() 
myActor.loadModel("<myModelPath>")
myActor.loadAnims({"talk":"<myTalkAnimPath>"}) 
myActor.loadAnims({"walk":"<myWalkAnimPath>"}) 

myActor.enableBlend()
myActor.setControlEffect("talk", 0.5)
myActor.setControlEffect("walk", 0.5)
myActor.loop(talk)
myActor.loop('walk')

The above code just causes the ‘walk’ animation to be played as normal. If I switch the order of the calls to ‘loop’ it plays the ‘talk’ animation normally.

Ultimatly I’d like to fade the animations in and out. I found the following forum entry on this:

https://discourse.panda3d.org/viewtopic.php?t=1054

I tried to set this up as well using the following code:

def crossBlend(actor,fadeInAnim,fadeOutAnim,duration): 
    fadeInt = LerpAnimInterval(actor, duration = duration, 
                               startAnim = fadeOutAnim,
                               endAnim = fadeInAnim)
    fadeInt.start()

myActor= Actor.Actor() 
myActor.loadModel("<myModelPath>")
myActor.loadAnims({"talk":"<myTalkAnimPath>"}) 
myActor.loadAnims({"walk":"<myWalkAnimPath>"}) 

myActor.enableBlend()
crossBlend(myActor,'talk','walk',4.0)

My hope was that this code would cross fade the walk anim to the talk anim over a 4 second interval. However, when I do this it seems to instantly pop from the walk anim to the talk anim and stick. Increasing the duration to a huge number doesn’t seem to help.

Again, the animations each play fine on their own, I just can’t seem to blend them together or fade them. Has anyone done any of the above recently? Is there somthing I’m missing in the way the animations are exported/created perhaps?

Thanks for any help on this

I made an example of my problem using the robot fighter demo. Copy and paste this code into a new file in

“C:\Panda3D-1.3.0\samples\Feature-Tutorials–Actors”

directory to see my issue.

Example 1: Using simple animation blending from the manual

import direct.directbase.DirectStart
from pandac.PandaModules import AmbientLight,DirectionalLight
from pandac.PandaModules import LightAttrib
from pandac.PandaModules import TextNode
from pandac.PandaModules import Vec3,Vec4
from direct.showbase.DirectObject import DirectObject
from direct.gui.OnscreenText import OnscreenText
from direct.interval.MetaInterval import Sequence
from direct.interval.FunctionInterval import Func,Wait
from direct.actor import Actor
from random import random
from direct.interval.IntervalGlobal import *
import sys

base.disableMouse()
camera.setPosHpr(14.5, -15.4, 14, 45, -14, 0)
base.setBackgroundColor( 0, 0, 0 )

robot1 = Actor.Actor('models/robot',
      {'leftPunch' : 'models/robot_left_punch', 
       'rightPunch' : 'models/robot_right_punch', 
       'headUp' : 'models/robot_head_up', 
       'headDown' : 'models/robot_head_down'})

#Actors need to be positioned and parented like normal objects
robot1.setPosHprScale(-1,-2.5,4,45,0,0,1.25,1.25,1.25)
robot1.reparentTo(render)
robot1.enableBlend()
robot1.setControlEffect("leftPunch", 0.5)
robot1.setControlEffect("rightPunch", 0.5)
robot1.loop("leftPunch")
robot1.loop("rightPunch")

run()

Expected Behavior: The robot should do half punches w/his left and right arms.

Actual Behavior: The robot just punches w/his right hand.

Example 2: Using LerpAnimInterval

import direct.directbase.DirectStart
from pandac.PandaModules import AmbientLight,DirectionalLight
from pandac.PandaModules import LightAttrib
from pandac.PandaModules import TextNode
from pandac.PandaModules import Vec3,Vec4
from direct.showbase.DirectObject import DirectObject
from direct.gui.OnscreenText import OnscreenText
from direct.interval.MetaInterval import Sequence
from direct.interval.FunctionInterval import Func,Wait
from direct.actor import Actor
from random import random
from direct.interval.IntervalGlobal import *
import sys

def crossBlend(actor,fadeInAnim,fadeOutAnim,duration): 
    fadeInt = LerpAnimInterval(actor, duration = duration, 
                               startAnim = fadeOutAnim,
                               endAnim = fadeInAnim,
                               partName= "modelRoot",
                               lodName ="lodRoot"
                               )
    return fadeInt


base.disableMouse()
camera.setPosHpr(14.5, -15.4, 14, 45, -14, 0)
base.setBackgroundColor( 0, 0, 0 )

robot1 = Actor.Actor('models/robot',
      {'leftPunch' : 'models/robot_left_punch', 
       'rightPunch' : 'models/robot_right_punch', 
       'headUp' : 'models/robot_head_up', 
       'headDown' : 'models/robot_head_down'})

#Actors need to be positioned and parented like normal objects
robot1.setPosHprScale(-1,-2.5,4,45,0,0,1.25,1.25,1.25)
robot1.reparentTo(render)
robot1.enableBlend()



blend1 = crossBlend(robot1,'rightPunch','leftPunch',4.0)

blend2 = crossBlend(robot1,'leftPunch','rightPunch',4.0)

blendSequence = Sequence(blend1,blend2,blend1,blend2,name="blend test")
blendSequence.loop()
run()

Expected: Robot should smoothly throw alternating left/right punches over 4 second intervals

Actual: Nothing happens

Any ideas?

I’m not sure, but I wonder if something has changed in a recent Panda version that has screwed up animation blending. I just recently got Panda reinstalled; previously I had it installed but had to uninstall it when upgrading my Linux Kubuntu box from 6.06 to 6.10. I had a small project which was basically an extended version of the Running Ralph sample that included animation blending between the walk and run animations. It used to work just fine, but with my recent reinstall this animation fails.

Some experimentation just now show that if I start an animation looping and immediately set its control effect to 1.0 it works, but starting with lower values doesn’t, even if the control effect is eventually raised to 1.0 during the animation.

One difference in my code: I’ve been trying to blend the run with a single walk pose, not the full walk animation.

I just tried calling “disableBlend” on my actor and got the following odd error:

  
File "C:\Panda3D-1.3.0\direct\src\actor\Actor.py", line 1182, in disableBlend
    self.enableBlend(PartBundle.BTSingle, partName)
AttributeError: type object 'libpanda.PartBundle' has no attribute 'BTSingle'

BTSingle should be the default non-blending setting. Does the fact that python can’t find it mean there’s some bug w/this version of panda. I’m using 1.3.0

have you imported the right libraries?

This error is coming from within Actor.py so if this were the problem the fact that this library wasn’t imported inside of Actor is a bug.

Just to be safe, I went and stuck this in the calling file.

from pandac.PandaModules import PartBundle

which should import the correct library, but alas, no dice.

I also tried sticking the above line at the top of Actor.py again, no dice.

Hmm. There might be a bug in 1.3.0. But I can attest that it works well in the latest CVS version, though we have changed the interface yet again.

David

Hi,
I have since ugraded to 1.3.2 and still can’t seem to get animation blending to work. On your advice, I’m going to grab the latest stuff from cvs and give it a whirl. Is there anyway you can post a concrete example of how to correctly use the newest animation blending interface? Or maybe just verify that the above code should work?

Thanks

OK, I can confirm that there is definitely a bug in Panda3D 1.3.2. But the good news is that version 1.139 of Actor.py–available from viewCVS, here–fixes the problem. Just download the file from the link and copy it into your c:\Panda3d-1.3.2\direct\src\actor directory, and you should be golden again.

David

That is wonderful and thx again for taking time to make panda a great engine :wink:

cheers
neighborlee

My thanks as well drwr, that patch did the trick.