makeSubparts C++

Hello,

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.

Any ideas? If you need more info, just ask. :wink:

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.

David

Thanks for the reply! I’ll have a look at it.

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? :wink:

Yes. I found that when looking through source code after my initial post.

A little challenge never hurt anyone :slight_smile:

This may seem like a simple question, but I can’t figure it out: what do I have to include to call auto_bind()?

This is a simple function I wrote, but I get errors about not being able to find the symbol auto_bind.

void AnimPlay(NodePath *path, bool play = true)
{
	AnimControlCollection controls;
	auto_bind(window->get_render().node(), controls, 0);
	if (play)
		controls.loop_all(false);
	else
		controls.stop_all();
}

I tried auto_bind.h and I got linker errors.

(I might try subpart animation at a later time, but for now I think whole body is good enough)

You have to #include “auto_bind.h”. If you are getting linker errors it must be that you haven’t named the complete set of Panda libraries yet.

David