From fcd6e915d43b0779668ce0b2476e36cd838c8412 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Fri, 9 Aug 2019 12:58:20 +0400 Subject: [PATCH] Fallback for long animation groups --- apps/openmw/mwmechanics/character.cpp | 31 +++++++++++++++++++---- apps/openmw/mwmechanics/character.hpp | 2 ++ apps/openmw/mwmechanics/weapontype.hpp | 10 ++++---- apps/openmw/mwrender/characterpreview.cpp | 11 ++++++++ 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 4d8868250..9f3a88193 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -414,6 +414,27 @@ void CharacterController::onClose() } } +std::string CharacterController::getWeaponAnimation(int weaponType) const +{ + std::string weaponGroup = getWeaponType(weaponType)->mLongGroup; + bool isRealWeapon = weaponType != ESM::Weapon::HandToHand && weaponType != ESM::Weapon::Spell && weaponType != ESM::Weapon::None; + if (isRealWeapon && !mAnimation->hasAnimation(weaponGroup)) + { + static const std::string oneHandFallback = getWeaponType(ESM::Weapon::LongBladeOneHand)->mLongGroup; + static const std::string twoHandFallback = getWeaponType(ESM::Weapon::LongBladeTwoHand)->mLongGroup; + + const ESM::WeaponType* weapInfo = getWeaponType(weaponType); + + // For real two-handed melee weapons use 2h swords animations as fallback, otherwise use the 1h ones + if (weapInfo->mFlags & ESM::WeaponType::TwoHanded && weapInfo->mWeaponClass == ESM::WeaponType::Melee) + weaponGroup = twoHandFallback; + else if (isRealWeapon) + weaponGroup = oneHandFallback; + } + + return weaponGroup; +} + std::string CharacterController::fallbackShortWeaponGroup(const std::string& baseGroupName, MWRender::Animation::BlendMask* blendMask) { bool isRealWeapon = mWeaponType != ESM::Weapon::HandToHand && mWeaponType != ESM::Weapon::Spell && mWeaponType != ESM::Weapon::None; @@ -838,7 +859,7 @@ CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Anim if (mWeaponType != ESM::Weapon::None) { mUpperBodyState = UpperCharState_WeapEquiped; - mCurrentWeapon = getWeaponType(mWeaponType)->mLongGroup; + mCurrentWeapon = getWeaponAnimation(mWeaponType); } if(mWeaponType != ESM::Weapon::None && mWeaponType != ESM::Weapon::Spell && mWeaponType != ESM::Weapon::HandToHand) @@ -1259,7 +1280,7 @@ bool CharacterController::updateWeaponState(CharacterState& idle) if (!weaponChanged) { // Note: we do not disable unequipping animation automatically to avoid body desync - weapgroup = getWeaponType(mWeaponType)->mLongGroup; + weapgroup = getWeaponAnimation(mWeaponType); mAnimation->play(weapgroup, priorityWeapon, MWRender::Animation::BlendMask_All, false, 1.0f, "unequip start", "unequip stop", 0.0f, 0); @@ -1287,8 +1308,8 @@ bool CharacterController::updateWeaponState(CharacterState& idle) { forcestateupdate = true; mAnimation->showCarriedLeft(updateCarriedLeftVisible(weaptype)); + weapgroup = getWeaponAnimation(weaptype); - weapgroup = getWeaponType(weaptype)->mLongGroup; // Note: controllers for ranged weapon should use time for beginning of animation to play shooting properly, // for other weapons they should use absolute time. Some mods rely on this behaviour (to rotate throwing projectiles, for example) ESM::WeaponType::Class weaponClass = getWeaponType(weaptype)->mWeaponClass; @@ -1327,7 +1348,7 @@ bool CharacterController::updateWeaponState(CharacterState& idle) } mWeaponType = weaptype; - mCurrentWeapon = getWeaponType(mWeaponType)->mLongGroup; + mCurrentWeapon = getWeaponAnimation(mWeaponType); if(!upSoundId.empty() && !isStillWeapon) { @@ -1342,7 +1363,7 @@ bool CharacterController::updateWeaponState(CharacterState& idle) mUpperBodyState = UpperCharState_Nothing; mAnimation->disable(mCurrentWeapon); mWeaponType = ESM::Weapon::None; - mCurrentWeapon = getWeaponType(mWeaponType)->mLongGroup; + mCurrentWeapon = getWeaponAnimation(mWeaponType); } } } diff --git a/apps/openmw/mwmechanics/character.hpp b/apps/openmw/mwmechanics/character.hpp index 27b646e33..614beca1c 100644 --- a/apps/openmw/mwmechanics/character.hpp +++ b/apps/openmw/mwmechanics/character.hpp @@ -232,6 +232,8 @@ class CharacterController : public MWRender::Animation::TextKeyListener std::string fallbackShortWeaponGroup(const std::string& baseGroupName, MWRender::Animation::BlendMask* blendMask = nullptr); + std::string getWeaponAnimation(int weaponType) const; + public: CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim); virtual ~CharacterController(); diff --git a/apps/openmw/mwmechanics/weapontype.hpp b/apps/openmw/mwmechanics/weapontype.hpp index fcb3068be..344dab1ed 100644 --- a/apps/openmw/mwmechanics/weapontype.hpp +++ b/apps/openmw/mwmechanics/weapontype.hpp @@ -69,7 +69,7 @@ namespace MWMechanics ESM::Weapon::ShortBladeOneHand, { /* short group */ "1s", - /* long group */ "weapononehand", + /* long group */ "shortbladeonehand", /* sound ID */ "Item Weapon Shortblade", /* attach bone */ "Weapon Bone", /* sheath bone */ "Bip01 ShortBladeOneHand", @@ -97,7 +97,7 @@ namespace MWMechanics ESM::Weapon::BluntOneHand, { /* short group */ "1b", - /* long group */ "weapononehand", + /* long group */ "bluntonehand", /* sound ID */ "Item Weapon Blunt", /* attach bone */ "Weapon Bone", /* sheath bone */ "Bip01 BluntOneHand", @@ -111,7 +111,7 @@ namespace MWMechanics ESM::Weapon::AxeOneHand, { /* short group */ "1b", - /* long group */ "weapononehand", + /* long group */ "bluntonehand", /* sound ID */ "Item Weapon Blunt", /* attach bone */ "Weapon Bone", /* sheath bone */ "Bip01 LongBladeOneHand", @@ -139,7 +139,7 @@ namespace MWMechanics ESM::Weapon::AxeTwoHand, { /* short group */ "2b", - /* long group */ "weapontwohand", + /* long group */ "bluntwohand", /* sound ID */ "Item Weapon Blunt", /* attach bone */ "Weapon Bone", /* sheath bone */ "Bip01 AxeTwoClose", @@ -153,7 +153,7 @@ namespace MWMechanics ESM::Weapon::BluntTwoClose, { /* short group */ "2b", - /* long group */ "weapontwohand", + /* long group */ "bluntwohand", /* sound ID */ "Item Weapon Blunt", /* attach bone */ "Weapon Bone", /* sheath bone */ "Bip01 BluntTwoClose", diff --git a/apps/openmw/mwrender/characterpreview.cpp b/apps/openmw/mwrender/characterpreview.cpp index 069b88c7c..b2552e598 100644 --- a/apps/openmw/mwrender/characterpreview.cpp +++ b/apps/openmw/mwrender/characterpreview.cpp @@ -309,6 +309,17 @@ namespace MWRender // We still should use one-handed animation as fallback if (mAnimation->hasAnimation(inventoryGroup)) groupname = inventoryGroup; + else + { + static const std::string oneHandFallback = "inventory" + MWMechanics::getWeaponType(ESM::Weapon::LongBladeOneHand)->mLongGroup; + static const std::string twoHandFallback = "inventory" + MWMechanics::getWeaponType(ESM::Weapon::LongBladeTwoHand)->mLongGroup; + + // For real two-handed melee weapons use 2h swords animations as fallback, otherwise use the 1h ones + if (weaponInfo->mFlags & ESM::WeaponType::TwoHanded && weaponInfo->mWeaponClass == ESM::WeaponType::Melee) + groupname = twoHandFallback; + else + groupname = oneHandFallback; + } } }