Skip to content

Commit

Permalink
Character: added option force_animblend
Browse files Browse the repository at this point in the history
Switches skeleton to `Ogre::SkeletonAnimationBlendMode::ANIMBLEND_[AVERAGE/CUMULATIVE]`
  • Loading branch information
ohlidalp committed Oct 12, 2022
1 parent f5bcae9 commit 9c57646
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions source/main/gfx/GfxCharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ GfxCharacter::GfxCharacter(Character* character)
MaterialPtr mat2 = mat1->clone("tracks/" + xc_instance_name);
entity->setMaterialName("tracks/" + xc_instance_name);

// setup animations
if (character->getCharacterDocument()->animblend_cumulative)
{
entity->getSkeleton()->setBlendMode(ANIMBLEND_CUMULATIVE);
}

// setup diagnostic UI
for (CharacterAnimDef const& def : xc_character->m_character_def->anims)
{
Expand Down
12 changes: 12 additions & 0 deletions source/main/resources/character_fileformat/CharacterFileFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ std::string CharacterParser::GetParam(int pos)
return "";
}

static ForceAnimBlend ParseForceAnimBlend(std::string const& line)
{
if (line == "none") return ForceAnimBlend::NONE;
if (line == "average") return ForceAnimBlend::AVERAGE;
if (line == "cumulative") return ForceAnimBlend::CUMULATIVE;
return ForceAnimBlend::NONE;
}

void CharacterParser::TokenizeCurrentLine()
{
// Recognizes quoted strings!
Expand Down Expand Up @@ -122,6 +130,10 @@ void CharacterParser::ProcessCurrentLine()
{
m_def->mesh_name = GetParam(1);
}
else if (StartsWith(m_cur_line, "force_animblend"))
{
m_def->force_animblend = ParseForceAnimBlend(GetParam(1));
}
else if (StartsWith(m_cur_line, "begin_animation"))
{
m_ctx.in_anim = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,20 @@ struct CharacterAnimDef
float weight = 1.0f;
};

enum class ForceAnimBlend //!< Should a specific `Ogre::SkeletonAnimationBlendMode` be forced, or should we keep what the .skeleton file defines?
{
NONE, //!< Use what's defined in the skeleton, see '<skeleton blendmode="">' in the XML.
AVERAGE,
CUMULATIVE
};

struct CharacterDocument
{
std::string character_name;
std::string mesh_name;
std::vector<CharacterAnimDef> anims;
std::vector<SkeletalAnimOptions> skeletal_anim_opts;
ForceAnimBlend force_animblend = ForceAnimBlend::NONE; //!< Should a specific `Ogre::SkeletonAnimationBlendMode` be forced, or should we keep what the .skeleton file defines?

CharacterAnimDef* getAnimById(int id)
{
Expand Down

0 comments on commit 9c57646

Please sign in to comment.