Animations are not being loaded

Return to C++ coding using Panda3D

Animations are not being loaded

Postby CarlosNovaes » Sat Mar 10, 2012 10:40 pm

Hello,

I am trying to extend the tutorial with a small model created in blender. The model get loaded and rendered, but there are no animations to play. If I call pview from command line it shows no animations but if called from the chicken exporter (inside blender) plays animations nicely.

(I used the tag code on the console output as it does not change the identation)

I did the following in c++

Code: Select all
NodePath dummy = window->load_model(framework.get_models(), "./Models/Dummy/Dummy");
dummy.reparent_to(window->get_render());
dummy.ls(std::cout, 4);


This gave the console output:

Code: Select all
    ModelRoot Dummy.egg T:(pos 0 10 0 scale 0.2)
      PandaNode
        Character Armature
          GeomNode  (1 geoms: S:(MaterialAttrib TextureAttrib TransparencyAttrib))
        AnimBundleNode Kick
        AnimBundleNode Punch


So I think that the animations are exported correctly, but the code continues:

Code: Select all
AnimControlCollection dummy_anims;
int ret;
auto_bind(dummy.node(), dummy_anims, 0);
ret=dummy_anims.get_num_anims();
std::cout << "Loaded " << ret << " animations!" << std::endl;


printing the following to stdout:

Code: Select all
Loaded 0 animations!


and the final lines does not animate the model:
Code: Select all
dummy_anims.loop("Punch",true);
window->loop_animations(0);
// Run the engine.
framework.main_loop();
// Shut down the engine when done.
framework.close_framework();
return (0);


I am expecting that the call to auto_bind would populate the AnimControlCollection, but found put that no animation was bind to the model. Am I doing something wrong?

Thank you.
CarlosNovaes
 
Posts: 7
Joined: Wed Mar 07, 2012 8:33 pm
Location: Brasil

Postby CarlosNovaes » Sun Mar 11, 2012 7:36 am

I was able to bind the animations with
Code: Select all
auto_bind(dummy.node(), dummy_anims, ~0);


Can someone clarify me what is that flag passed as final argument to auto_bind. The default value would be zero from the auto_bind.h header, but there are posts with the ~0 as argument and it did the job.

At last I found out that to get individual animations to work as I select I need to do:
Code: Select all
int animnum=2; //Select a valid animation index
dummy_animation = dummy_anims.get_anim(animnum);
mystring = dummy_anims.get_anim_name(animnum);
std::cout << "Got anim named >" << mystring << "<" <<std::endl;
if (dummy_animation->has_anim()){
  std::cout << "Animation Node is OK!!!" << std::endl;
}
else{
  std::cout << "Animation Node is BAD!!!" << std::endl;
}
dummy_anims.loop(mystring.c_str(),true);


I was even able to add a few more animations and got they working very well. Panda3d seens pretty easy and fun to work, although there are some things not clear to me.

Thank you.
CarlosNovaes
 
Posts: 7
Joined: Wed Mar 07, 2012 8:33 pm
Location: Brasil

Postby drwr » Tue Apr 24, 2012 2:30 pm

The third parameter to auto_bind() controls how forgiving the matching of animation to model should be. With 0, the default, it is important that all of your joint names (and the character name) be the same between animation and model. With ~0, as forgiving as possible, it will work even if some of your names do not match.

David
drwr
 
Posts: 11425
Joined: Fri Feb 13, 2004 12:42 pm
Location: Glendale, CA

Postby CarlosNovaes » Sun Apr 29, 2012 8:09 am

drwr wrote:The third parameter to auto_bind() controls how forgiving the matching of animation to model should be. With 0, the default, it is important that all of your joint names (and the character name) be the same between animation and model. With ~0, as forgiving as possible, it will work even if some of your names do not match.

David


Thank you, I was able to get a single animation working also in pview. It took me some time to figure it out, maybe I got the wrong thinking paradigm for it.
So, lets say, if I want to create a model with many animations in a single .egg (or .bam) file and let my C++ code load the model and pick a animation, by its name, to play, then do I always have to pass ~0 as flag value?
CarlosNovaes
 
Posts: 7
Joined: Wed Mar 07, 2012 8:33 pm
Location: Brasil

Postby drwr » Mon May 07, 2012 1:08 pm

You should assign the same character name to the model and all of its intended animations. The purpose of the character name is to indicate which skeleton the animation is intended to be used with.

This is not the same name as the animation name, which can be different for each animation, without requiring ~0.

David
drwr
 
Posts: 11425
Joined: Fri Feb 13, 2004 12:42 pm
Location: Glendale, CA


Return to C++ coding using Panda3D

Who is online

Users browsing this forum: Bing [Bot] and 0 guests