Enabling animation interpolation in C++

Hi all,

I’m trying to switch on animation interpolation to stop the frames being so jumpy in my C++ application, as it says in panda3d.org/manual/index.php … Animations. Unfortunately it only has a python guide on the C++ page, and I have been unable to find the correpsonding set_blend() function in the C++ documentation. Does anyone know how to switch this on?

By the way, I have also tried deleting my model cache and setting interpolate-frames 1 in the config prc script but this has no effect. To check that it is working I have slowed the animation down using set_play_rate(), I’m not sure if this would have an effect?

EDIT: Oh, and also I am loading bam files from the disk rather than eggs. Does this information get baked into the bams?

Thanks in advance.

Setting “interpolate-frames 1” would work if you were loading eggs, but this setting gets baked into the bams. You can also set it at the time you generate bams.

The alternative, to set this option at runtime, is to call PartBundle::set_frame_blend_flag(), which is the low-level implementation of Actor.setBlend(). You can get the PartBundle with Character::get_bundle(0).

David

Thanks for the information. Unfortunately I am getting a crash, here is what I am doing:

[code]

((Character*)this->junkernp.node())->get_bundle(0)->set_frame_blend_flag(true);
[\code]

I have a feeling that the nodepath that I am using isn’t a character objects, hence when I cast it to a character and call get_bundle(0) it crashes. Here is how a load the mode and animations.

[code]

//Load just the geometry for the model with no animations
this->junkernp = this->window->load_model(this->window->get_panda_framework()->get_models(), “junker.bam”);

//Add each animation one at a time
this->window->load_model(this->junkernp, “anim1.bam”);
this->window->load_model(this->junkernp, “anim2.bam”);
this->window->load_model(this->junkernp, “anim3.bam”);

//Auto bind the animations to controls
auto_bind(this->junkernp.node(), this->junker_anims, PartGroup::HMF_ok_part_extra | PartGroup::HMF_ok_anim_extra | PartGroup::HMF_ok_wrong_root_name);
[\code]

Any ideas how to get the character object from this?

Thanks.

Sure, the top node of the result of load_model() is generally a ModelRoot node. The Character node will be some child of that node, often the first child, but not necessarily. You can find it with code like this:

NodePath child = this->junkernp.find("**/+Character");
assert(!child.is_empty());
Character *ch = DCAST(Character, child.node());
assert(ch != NULL);
PartBundle *bundle = ch->get_bundle(0);
assert(bundle != NULL);
bundle->set_frame_blend_flag(true);

Note that a responsible coder always checks return values for error conditions before calling through. :slight_smile: Also, the DCAST macro is provided as a type-safe cast; it will print an error message and return NULL if the object in question is not actually a Character node. (Though this type-checking is disabled if NDEBUG is defined; in this case, it compiles to the same thing as a static cast.)

David

Thanks David, worked like a charm. Normally I would check return values, but the code I posted isn’t the actual code that I’m using. I paraphrased it for the forum :slight_smile:. Thanks again!