From 9c57646986064d34719f078c2d23e2a50bd440d0 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Fri, 30 Sep 2022 14:30:05 +0200 Subject: [PATCH] Character: added option `force_animblend` Switches skeleton to `Ogre::SkeletonAnimationBlendMode::ANIMBLEND_[AVERAGE/CUMULATIVE]` --- source/main/gfx/GfxCharacter.cpp | 6 ++++++ .../character_fileformat/CharacterFileFormat.cpp | 12 ++++++++++++ .../character_fileformat/CharacterFileFormat.h | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/source/main/gfx/GfxCharacter.cpp b/source/main/gfx/GfxCharacter.cpp index 03f166ca7c..e529a234cf 100644 --- a/source/main/gfx/GfxCharacter.cpp +++ b/source/main/gfx/GfxCharacter.cpp @@ -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) { diff --git a/source/main/resources/character_fileformat/CharacterFileFormat.cpp b/source/main/resources/character_fileformat/CharacterFileFormat.cpp index de98a8b01f..b9c8de586c 100644 --- a/source/main/resources/character_fileformat/CharacterFileFormat.cpp +++ b/source/main/resources/character_fileformat/CharacterFileFormat.cpp @@ -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! @@ -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; diff --git a/source/main/resources/character_fileformat/CharacterFileFormat.h b/source/main/resources/character_fileformat/CharacterFileFormat.h index 4ea91d9f24..27ecce37f6 100644 --- a/source/main/resources/character_fileformat/CharacterFileFormat.h +++ b/source/main/resources/character_fileformat/CharacterFileFormat.h @@ -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 '' in the XML. + AVERAGE, + CUMULATIVE +}; + struct CharacterDocument { std::string character_name; std::string mesh_name; std::vector anims; + std::vector 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) {