I have a character that I want to play separate animations on the top and bottom parts of it’s armature. How would I set this up in C++?
I can’t find reference to the C++ version of python’s actor.makeSubpart in either the docs or the source code. Also, are NodePaths the same as actors in C++? Or do you have to declare them as an ActorNode?
What I’m looking for is how to call the function and play the animations.
Thanks,
Frankie
Edit: Well I figured out that I don’t need ActorNodes for this. But I’m still looking for Subparts usage.
I’m having trouble even finding the play and loop functions in either the docs. I just got to the point in my game where I need to turn animations on and off and can’t understand what functions to call.
I setup my avatar like this. Is there a special NodePath for actors?
mainActor = window->load_model(framework.get_models(), "res/Char");
mainActor.reparent_to(window->get_render());
window->load_model(mainActor, "res/Char-walk");
mainActor.reparent_to(window->get_render());
mainActor.set_scale(0.1);
mainActor.set_pos(1, 1, 0);
window->loop_animations(0); // I want to get rid of this and play animations by name and part during tasks
Take a look at the C++ code in WindowFramework::loop_animations():
void WindowFramework::
loop_animations(int hierarchy_match_flags) {
// If we happened to load up both a character file and its matching
// animation file, attempt to bind them together now and start the
// animations looping.
auto_bind(get_render().node(), _anim_controls, hierarchy_match_flags);
_anim_controls.loop_all(true);
}
So, this tells you that if you want to do it yourself, you need an AnimControlsCollection object (that’s what _anim_controls is), and you can call auto_bind() on the root of your graph and pass in your AnimControlsCollection. Then you can use the AnimControlsCollection to stop and start your animations as required.
To do sub-part animations, you can’t use auto_bind(). Instead, you have to bind your animations with a lower-level operation. You’ll have to find the PartBundle that corresponds with your actor, and the AnimBundle that corresponds with your animation, and call PartBundle::bind_anim(), which accepts the AnimBundle and a PartSubset. The PartSubset describes the particular joints you wish to bind. The return value of bind_anim() is a single AnimControl, which you can use to control the animation.
You can find the PartBundle and AnimBundle by walking through the scene graph, which is what auto_bind() does. In fact, auto_bind() is just a convenience function to walk through the scene graph, find the bundles, and call bind_anim() on each of the found bundles, and store the resulting AnimControl’s in the indicated AnimControlCollection.
As far as I have understood, Actors and ActorNodes are two entirely distinct classes that only share similar names (Actor is for animation, I think, while ActorNode is for physics). On top of that, if I am not totally mistaken, the Actor class is a convenience only available to Python coders, for it has not been implemented in C++, yet.
So C++ coders have a little harder time with Panda, but this is what makes it fun, don’t you think?