From ffc64205c52884dc234e1d0eab2cb42d0b4dcff6 Mon Sep 17 00:00:00 2001 From: unelsson Date: Fri, 14 Oct 2022 01:29:52 +0300 Subject: [PATCH 01/10] Force collada animation layers, remove nif blend mask detection. --- apps/openmw/mwrender/animation.cpp | 25 ++- apps/openmw/mwrender/animation.hpp | 1 + components/resource/keyframemanager.cpp | 222 +++++++++++++++++------- components/resource/keyframemanager.hpp | 4 + 4 files changed, 189 insertions(+), 63 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 088ecd4600..d8926adb38 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -571,6 +571,7 @@ namespace MWRender const std::string& name = node->getName(); for (size_t i = 1; i < sNumBlendMasks; i++) { + Log(Debug::Warning) << "blendmaskname:" << name; if (name == sBlendMaskRoots[i]) return i; } @@ -583,6 +584,27 @@ namespace MWRender return 0; } + size_t Animation::detectColladaBlendMask(const osg::Node* node, const std::string& blendmaskName) const + { + static const std::string_view sBlendMaskRoots[sNumBlendMasks] = { + "", /* Lower body / character root */ + "Bip01 Spine1", /* Torso */ + "Bip01 L Clavicle", /* Left arm */ + "Bip01 R Clavicle", /* Right arm */ + }; + + for (size_t i = 1; i < sNumBlendMasks; i++) + { + Log(Debug::Warning) << "blendmaskname:" << blendmaskName; + if (blendmaskName == sBlendMaskRoots[i]) + return i; + } + assert(node->getNumParents() > 0); + node = node->getParent(0); + + return 0; + } + const SceneUtil::TextKeyMap& Animation::AnimSource::getTextKeys() const { return mKeyframes->mTextKeys; @@ -646,7 +668,8 @@ namespace MWRender osg::Node* node = found->second; - size_t blendMask = detectBlendMask(node); + size_t blendMask = detectColladaBlendMask(node, it->second->getName()); + Log(Debug::Warning) << "blendmask " << blendMask << " ctrl name: " << it->second->getName(); // clone the controller, because each Animation needs its own ControllerSource osg::ref_ptr cloned diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index d7d99dc303..5a3658b67b 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -293,6 +293,7 @@ namespace MWRender void resetActiveGroups(); size_t detectBlendMask(const osg::Node* node) const; + size_t detectColladaBlendMask(const osg::Node* node, const std::string& blendmaskName) const; /* Updates the position of the accum root node for the given time, and * returns the wanted movement vector from the previous time. */ diff --git a/components/resource/keyframemanager.cpp b/components/resource/keyframemanager.cpp index e87520caa9..6881078a17 100644 --- a/components/resource/keyframemanager.cpp +++ b/components/resource/keyframemanager.cpp @@ -31,74 +31,172 @@ namespace Resource , mVFS(vfs) { } + + bool RetrieveAnimationsVisitor::belongsToLeftUpperExtremity(const std::string& name) + { + static const std::string_view boneNames[25] = { + "bip01_l_clavicle", + "left_clavicle", + "bip01_l_upperarm", + "left_upper_arm", + "bip01_l_forearm", + "bip01_l_hand", + "left_hand", + "left_wrist", + "shield_bone", + "bip01_l_pinky1", + "bip01_l_pinky2", + "bip01_l_pinky3", + "bip01_l_ring1", + "bip01_l_ring2", + "bip01_l_ring3", + "bip01_l_middle1", + "bip01_l_middle2", + "bip01_l_middle3", + "bip01_l_pointer1", + "bip01_l_pointer2", + "bip01_l_pointer3", + "bip01_l_thumb1", + "bip01_l_thumb2", + "bip01_l_thumb3", + "left_forearm" + }; + + for (size_t i = 0; i < 25; i++) + { + if (name == boneNames[i]) + return true; + } + + return false; + } + + bool RetrieveAnimationsVisitor::belongsToRightUpperExtremity(const std::string& name) + { + static const std::string_view boneNames[25] = { + "bip01_r_clavicle", + "right_clavicle", + "bip01_r_upperarm", + "right_upper_arm", + "bip01_r_forearm", + "bip01_r_hand", + "right_hand", + "right_wrist", + "bip01_r_thumb1", + "bip01_r_thumb2", + "bip01_r_thumb3", + "weapon_bone", + "bip01_r_pinky1", + "bip01_r_pinky2", + "bip01_r_pinky3", + "bip01_r_ring1", + "bip01_r_ring2", + "bip01_r_ring3", + "bip01_r_middle1", + "bip01_r_middle2", + "bip01_r_middle3", + "bip01_r_pointer1", + "bip01_r_pointer2", + "bip01_r_pointer3", + "right_forearm" + }; + + for (size_t i = 0; i < 25; i++) + { + if (name == boneNames[i]) + return true; + } + + return false; + } + + void RetrieveAnimationsVisitor::addKeyframeController(const std::string& name, const osg::Node& node) + { + osg::ref_ptr callback = new SceneUtil::OsgAnimationController(); + + callback->setName(name); + + std::vector emulatedAnimations; + + for (const auto& animation : mAnimationManager->getAnimationList()) + { + if (animation) + { + if (animation->getName() + == "Default") //"Default" is osg dae plugin's default naming scheme for unnamed animations + { + animation->setName( + std::string("idle")); // animation naming scheme "idle: start" and "idle: stop" is the + // default idle animation that OpenMW seems to want to play + } + + osg::ref_ptr mergedAnimationTrack = new Resource::Animation; + const std::string animationName = animation->getName(); + mergedAnimationTrack->setName(animationName); + + const osgAnimation::ChannelList& channels = animation->getChannels(); + for (const auto& channel : channels) + { + if (name == "Bip01 R Clavicle") + { + if (!belongsToRightUpperExtremity(channel->getTargetName())) continue; + } + else if (name == "Bip01 L Clavicle") + { + if (!belongsToLeftUpperExtremity(channel->getTargetName())) continue; + } + else if (belongsToRightUpperExtremity(channel->getTargetName()) || belongsToLeftUpperExtremity(channel->getTargetName())) continue; + + mergedAnimationTrack->addChannel(channel.get()->clone()); // is ->clone needed? + } + + callback->addMergedAnimationTrack(mergedAnimationTrack); + + float startTime = animation->getStartTime(); + float stopTime = startTime + animation->getDuration(); + + SceneUtil::EmulatedAnimation emulatedAnimation; + emulatedAnimation.mStartTime = startTime; + emulatedAnimation.mStopTime = stopTime; + emulatedAnimation.mName = animationName; + emulatedAnimations.emplace_back(emulatedAnimation); + } + } + + // mTextKeys is a nif-thing, used by OpenMW's animation system + // Format is likely "AnimationName: [Keyword_optional] [Start OR Stop]" + // AnimationNames are keywords like idle2, idle3... AiPackages and various mechanics control which + // animations are played Keywords can be stuff like Loop, Equip, Unequip, Block, InventoryHandtoHand, + // InventoryWeaponOneHand, PickProbe, Slash, Thrust, Chop... even "Slash Small Follow" osgAnimation formats + // should have a .txt file with the same name, each line holding a textkey and whitespace separated time + // value e.g. idle: start 0.0333 + try + { + Files::IStreamPtr textKeysFile = mVFS->get(changeFileExtension(mNormalized, "txt")); + std::string line; + while (getline(*textKeysFile, line)) + { + mTarget.mTextKeys.emplace(parseTimeSignature(line), parseTextKey(line)); + } + } + catch (std::exception&) + { + Log(Debug::Warning) << "No textkey file found for " << mNormalized; + } + + callback->setEmulatedAnimations(emulatedAnimations); + mTarget.mKeyframeControllers.emplace(name, callback); + } void RetrieveAnimationsVisitor::apply(osg::Node& node) { if (node.libraryName() == std::string_view("osgAnimation") && node.className() == std::string_view("Bone") && Misc::StringUtils::lowerCase(node.getName()) == std::string_view("bip01")) { - osg::ref_ptr callback = new SceneUtil::OsgAnimationController(); - - std::vector emulatedAnimations; - - for (const auto& animation : mAnimationManager->getAnimationList()) - { - if (animation) - { - if (animation->getName() - == "Default") //"Default" is osg dae plugin's default naming scheme for unnamed animations - { - animation->setName( - std::string("idle")); // animation naming scheme "idle: start" and "idle: stop" is the - // default idle animation that OpenMW seems to want to play - } - - osg::ref_ptr mergedAnimationTrack = new Resource::Animation; - const std::string animationName = animation->getName(); - mergedAnimationTrack->setName(animationName); - - const osgAnimation::ChannelList& channels = animation->getChannels(); - for (const auto& channel : channels) - { - mergedAnimationTrack->addChannel(channel.get()->clone()); // is ->clone needed? - } - - callback->addMergedAnimationTrack(mergedAnimationTrack); - - float startTime = animation->getStartTime(); - float stopTime = startTime + animation->getDuration(); - - SceneUtil::EmulatedAnimation emulatedAnimation; - emulatedAnimation.mStartTime = startTime; - emulatedAnimation.mStopTime = stopTime; - emulatedAnimation.mName = animationName; - emulatedAnimations.emplace_back(emulatedAnimation); - } - } - - // mTextKeys is a nif-thing, used by OpenMW's animation system - // Format is likely "AnimationName: [Keyword_optional] [Start OR Stop]" - // AnimationNames are keywords like idle2, idle3... AiPackages and various mechanics control which - // animations are played Keywords can be stuff like Loop, Equip, Unequip, Block, InventoryHandtoHand, - // InventoryWeaponOneHand, PickProbe, Slash, Thrust, Chop... even "Slash Small Follow" osgAnimation formats - // should have a .txt file with the same name, each line holding a textkey and whitespace separated time - // value e.g. idle: start 0.0333 - try - { - Files::IStreamPtr textKeysFile = mVFS->get(changeFileExtension(mNormalized, "txt")); - std::string line; - while (getline(*textKeysFile, line)) - { - mTarget.mTextKeys.emplace(parseTimeSignature(line), parseTextKey(line)); - } - } - catch (std::exception&) - { - Log(Debug::Warning) << "No textkey file found for " << mNormalized; - } - - callback->setEmulatedAnimations(emulatedAnimations); - mTarget.mKeyframeControllers.emplace(node.getName(), callback); + addKeyframeController("bip01", node); /* Character root */ + //addKeyframeController("Bip01 Spine1", node); /* Torso */ + addKeyframeController("Bip01 L Clavicle", node); /* Left arm */ + addKeyframeController("Bip01 R Clavicle", node); /* Right arm */ } traverse(node); diff --git a/components/resource/keyframemanager.hpp b/components/resource/keyframemanager.hpp index 2ed1696def..22cb011c75 100644 --- a/components/resource/keyframemanager.hpp +++ b/components/resource/keyframemanager.hpp @@ -18,7 +18,11 @@ namespace Resource RetrieveAnimationsVisitor(SceneUtil::KeyframeHolder& target, osg::ref_ptr animationManager, const std::string& normalized, const VFS::Manager* vfs); + + bool belongsToLeftUpperExtremity(const std::string& name); + bool belongsToRightUpperExtremity(const std::string& name); + void addKeyframeController(const std::string& name, const osg::Node& node); virtual void apply(osg::Node& node) override; private: From d8de56e33c36e0615dd872649ddde98a855f13d9 Mon Sep 17 00:00:00 2001 From: unelsson Date: Fri, 14 Oct 2022 14:31:03 +0300 Subject: [PATCH 02/10] Coding style improvements, add Torso animation layer --- components/resource/keyframemanager.cpp | 53 +++++++++++++++++++------ components/resource/keyframemanager.hpp | 1 + 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/components/resource/keyframemanager.cpp b/components/resource/keyframemanager.cpp index 6881078a17..b98ed5396b 100644 --- a/components/resource/keyframemanager.cpp +++ b/components/resource/keyframemanager.cpp @@ -34,7 +34,8 @@ namespace Resource bool RetrieveAnimationsVisitor::belongsToLeftUpperExtremity(const std::string& name) { - static const std::string_view boneNames[25] = { + const int bodypartCount = 25; + static const std::array boneNames = { "bip01_l_clavicle", "left_clavicle", "bip01_l_upperarm", @@ -61,19 +62,20 @@ namespace Resource "bip01_l_thumb3", "left_forearm" }; - - for (size_t i = 0; i < 25; i++) + + for (unsigned short int i = 0; i < bodypartCount; i++) { if (name == boneNames[i]) return true; } - + return false; } bool RetrieveAnimationsVisitor::belongsToRightUpperExtremity(const std::string& name) { - static const std::string_view boneNames[25] = { + const int bodypartCount = 25; + static const std::array boneNames = { "bip01_r_clavicle", "right_clavicle", "bip01_r_upperarm", @@ -100,16 +102,33 @@ namespace Resource "bip01_r_pointer3", "right_forearm" }; - - for (size_t i = 0; i < 25; i++) + + for (unsigned short int i = 0; i < bodypartCount; i++) { if (name == boneNames[i]) return true; } - + return false; } + bool RetrieveAnimationsVisitor::belongsToTorso(const std::string& name) + { + const int bodypartCount = 8; + static const std::array boneNames = { + "bip01_spine1", "bip01_spine2", "bip01_neck", "bip01_head", "head", "neck", "chest", "groin" + }; + + for (unsigned short int i = 0; i < bodypartCount; i++) + { + if (name == boneNames[i]) + return true; + } + + return false; + } + + void RetrieveAnimationsVisitor::addKeyframeController(const std::string& name, const osg::Node& node) { osg::ref_ptr callback = new SceneUtil::OsgAnimationController(); @@ -139,13 +158,23 @@ namespace Resource { if (name == "Bip01 R Clavicle") { - if (!belongsToRightUpperExtremity(channel->getTargetName())) continue; + if (!belongsToRightUpperExtremity(channel->getTargetName())) + continue; } else if (name == "Bip01 L Clavicle") { - if (!belongsToLeftUpperExtremity(channel->getTargetName())) continue; + if (!belongsToLeftUpperExtremity(channel->getTargetName())) + continue; } - else if (belongsToRightUpperExtremity(channel->getTargetName()) || belongsToLeftUpperExtremity(channel->getTargetName())) continue; + else if (name == "Bip01 Spine1") + { + if (!belongsToTorso(channel->getTargetName())) + continue; + } + else if (belongsToRightUpperExtremity(channel->getTargetName()) + || belongsToLeftUpperExtremity(channel->getTargetName()) + || belongsToTorso(channel->getTargetName())) + continue; mergedAnimationTrack->addChannel(channel.get()->clone()); // is ->clone needed? } @@ -194,7 +223,7 @@ namespace Resource && Misc::StringUtils::lowerCase(node.getName()) == std::string_view("bip01")) { addKeyframeController("bip01", node); /* Character root */ - //addKeyframeController("Bip01 Spine1", node); /* Torso */ + addKeyframeController("Bip01 Spine1", node); /* Torso */ addKeyframeController("Bip01 L Clavicle", node); /* Left arm */ addKeyframeController("Bip01 R Clavicle", node); /* Right arm */ } diff --git a/components/resource/keyframemanager.hpp b/components/resource/keyframemanager.hpp index 22cb011c75..685b8eb277 100644 --- a/components/resource/keyframemanager.hpp +++ b/components/resource/keyframemanager.hpp @@ -21,6 +21,7 @@ namespace Resource bool belongsToLeftUpperExtremity(const std::string& name); bool belongsToRightUpperExtremity(const std::string& name); + bool belongsToTorso(const std::string& name); void addKeyframeController(const std::string& name, const osg::Node& node); virtual void apply(osg::Node& node) override; From 7ef6b3cb62dbca3a5f60db3fe8b41f93837500e6 Mon Sep 17 00:00:00 2001 From: unelsson Date: Fri, 14 Oct 2022 14:32:20 +0300 Subject: [PATCH 03/10] automatic clang format --- components/resource/keyframemanager.cpp | 91 +++++++------------------ 1 file changed, 23 insertions(+), 68 deletions(-) diff --git a/components/resource/keyframemanager.cpp b/components/resource/keyframemanager.cpp index b98ed5396b..8f35341334 100644 --- a/components/resource/keyframemanager.cpp +++ b/components/resource/keyframemanager.cpp @@ -31,104 +31,59 @@ namespace Resource , mVFS(vfs) { } - + bool RetrieveAnimationsVisitor::belongsToLeftUpperExtremity(const std::string& name) { const int bodypartCount = 25; - static const std::array boneNames = { - "bip01_l_clavicle", - "left_clavicle", - "bip01_l_upperarm", - "left_upper_arm", - "bip01_l_forearm", - "bip01_l_hand", - "left_hand", - "left_wrist", - "shield_bone", - "bip01_l_pinky1", - "bip01_l_pinky2", - "bip01_l_pinky3", - "bip01_l_ring1", - "bip01_l_ring2", - "bip01_l_ring3", - "bip01_l_middle1", - "bip01_l_middle2", - "bip01_l_middle3", - "bip01_l_pointer1", - "bip01_l_pointer2", - "bip01_l_pointer3", - "bip01_l_thumb1", - "bip01_l_thumb2", - "bip01_l_thumb3", - "left_forearm" - }; - + static const std::array boneNames + = { "bip01_l_clavicle", "left_clavicle", "bip01_l_upperarm", "left_upper_arm", "bip01_l_forearm", + "bip01_l_hand", "left_hand", "left_wrist", "shield_bone", "bip01_l_pinky1", "bip01_l_pinky2", + "bip01_l_pinky3", "bip01_l_ring1", "bip01_l_ring2", "bip01_l_ring3", "bip01_l_middle1", + "bip01_l_middle2", "bip01_l_middle3", "bip01_l_pointer1", "bip01_l_pointer2", "bip01_l_pointer3", + "bip01_l_thumb1", "bip01_l_thumb2", "bip01_l_thumb3", "left_forearm" }; + for (unsigned short int i = 0; i < bodypartCount; i++) { if (name == boneNames[i]) return true; } - + return false; } - + bool RetrieveAnimationsVisitor::belongsToRightUpperExtremity(const std::string& name) { const int bodypartCount = 25; - static const std::array boneNames = { - "bip01_r_clavicle", - "right_clavicle", - "bip01_r_upperarm", - "right_upper_arm", - "bip01_r_forearm", - "bip01_r_hand", - "right_hand", - "right_wrist", - "bip01_r_thumb1", - "bip01_r_thumb2", - "bip01_r_thumb3", - "weapon_bone", - "bip01_r_pinky1", - "bip01_r_pinky2", - "bip01_r_pinky3", - "bip01_r_ring1", - "bip01_r_ring2", - "bip01_r_ring3", - "bip01_r_middle1", - "bip01_r_middle2", - "bip01_r_middle3", - "bip01_r_pointer1", - "bip01_r_pointer2", - "bip01_r_pointer3", - "right_forearm" - }; - + static const std::array boneNames = { "bip01_r_clavicle", "right_clavicle", + "bip01_r_upperarm", "right_upper_arm", "bip01_r_forearm", "bip01_r_hand", "right_hand", "right_wrist", + "bip01_r_thumb1", "bip01_r_thumb2", "bip01_r_thumb3", "weapon_bone", "bip01_r_pinky1", "bip01_r_pinky2", + "bip01_r_pinky3", "bip01_r_ring1", "bip01_r_ring2", "bip01_r_ring3", "bip01_r_middle1", "bip01_r_middle2", + "bip01_r_middle3", "bip01_r_pointer1", "bip01_r_pointer2", "bip01_r_pointer3", "right_forearm" }; + for (unsigned short int i = 0; i < bodypartCount; i++) { if (name == boneNames[i]) return true; } - + return false; } bool RetrieveAnimationsVisitor::belongsToTorso(const std::string& name) { const int bodypartCount = 8; - static const std::array boneNames = { - "bip01_spine1", "bip01_spine2", "bip01_neck", "bip01_head", "head", "neck", "chest", "groin" - }; - + static const std::array boneNames + = { "bip01_spine1", "bip01_spine2", "bip01_neck", "bip01_head", "head", "neck", "chest", "groin" }; + for (unsigned short int i = 0; i < bodypartCount; i++) { if (name == boneNames[i]) return true; } - + return false; } - void RetrieveAnimationsVisitor::addKeyframeController(const std::string& name, const osg::Node& node) { osg::ref_ptr callback = new SceneUtil::OsgAnimationController(); @@ -155,7 +110,7 @@ namespace Resource const osgAnimation::ChannelList& channels = animation->getChannels(); for (const auto& channel : channels) - { + { if (name == "Bip01 R Clavicle") { if (!belongsToRightUpperExtremity(channel->getTargetName())) @@ -174,7 +129,7 @@ namespace Resource else if (belongsToRightUpperExtremity(channel->getTargetName()) || belongsToLeftUpperExtremity(channel->getTargetName()) || belongsToTorso(channel->getTargetName())) - continue; + continue; mergedAnimationTrack->addChannel(channel.get()->clone()); // is ->clone needed? } From 2efc6917364b69729f0f07d4d7e5ed9eeadf52fc Mon Sep 17 00:00:00 2001 From: unelsson Date: Fri, 14 Oct 2022 14:52:08 +0300 Subject: [PATCH 04/10] clang format --- components/resource/keyframemanager.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/resource/keyframemanager.hpp b/components/resource/keyframemanager.hpp index 685b8eb277..94dccb77f4 100644 --- a/components/resource/keyframemanager.hpp +++ b/components/resource/keyframemanager.hpp @@ -18,7 +18,7 @@ namespace Resource RetrieveAnimationsVisitor(SceneUtil::KeyframeHolder& target, osg::ref_ptr animationManager, const std::string& normalized, const VFS::Manager* vfs); - + bool belongsToLeftUpperExtremity(const std::string& name); bool belongsToRightUpperExtremity(const std::string& name); bool belongsToTorso(const std::string& name); From 33afcbdc13e4b957aeff4013890b176f5b0f525b Mon Sep 17 00:00:00 2001 From: unelsson Date: Mon, 14 Nov 2022 14:23:47 +0200 Subject: [PATCH 05/10] Use common function for blendmask detection, remove extra debug logs --- apps/openmw/mwrender/animation.cpp | 29 +++-------------------------- apps/openmw/mwrender/animation.hpp | 3 +-- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index d8926adb38..2efe7ccd61 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -557,7 +557,7 @@ namespace MWRender mResetAccumRootCallback->setAccumulate(mAccumulate); } - size_t Animation::detectBlendMask(const osg::Node* node) const + size_t Animation::detectBlendMask(const osg::Node* node, const std::string& controllerName) const // controllerName is used for Collada animated deforming models { static const std::string_view sBlendMaskRoots[sNumBlendMasks] = { "", /* Lower body / character root */ @@ -571,8 +571,7 @@ namespace MWRender const std::string& name = node->getName(); for (size_t i = 1; i < sNumBlendMasks; i++) { - Log(Debug::Warning) << "blendmaskname:" << name; - if (name == sBlendMaskRoots[i]) + if (name == sBlendMaskRoots[i] || controllerName == sBlendMaskRoots[i]) return i; } @@ -584,27 +583,6 @@ namespace MWRender return 0; } - size_t Animation::detectColladaBlendMask(const osg::Node* node, const std::string& blendmaskName) const - { - static const std::string_view sBlendMaskRoots[sNumBlendMasks] = { - "", /* Lower body / character root */ - "Bip01 Spine1", /* Torso */ - "Bip01 L Clavicle", /* Left arm */ - "Bip01 R Clavicle", /* Right arm */ - }; - - for (size_t i = 1; i < sNumBlendMasks; i++) - { - Log(Debug::Warning) << "blendmaskname:" << blendmaskName; - if (blendmaskName == sBlendMaskRoots[i]) - return i; - } - assert(node->getNumParents() > 0); - node = node->getParent(0); - - return 0; - } - const SceneUtil::TextKeyMap& Animation::AnimSource::getTextKeys() const { return mKeyframes->mTextKeys; @@ -668,8 +646,7 @@ namespace MWRender osg::Node* node = found->second; - size_t blendMask = detectColladaBlendMask(node, it->second->getName()); - Log(Debug::Warning) << "blendmask " << blendMask << " ctrl name: " << it->second->getName(); + size_t blendMask = detectBlendMask(node, it->second->getName()); // clone the controller, because each Animation needs its own ControllerSource osg::ref_ptr cloned diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 5a3658b67b..b241c3b931 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -292,8 +292,7 @@ namespace MWRender */ void resetActiveGroups(); - size_t detectBlendMask(const osg::Node* node) const; - size_t detectColladaBlendMask(const osg::Node* node, const std::string& blendmaskName) const; + size_t detectBlendMask(const osg::Node* node, const std::string& controllerName) const; /* Updates the position of the accum root node for the given time, and * returns the wanted movement vector from the previous time. */ From 960019cf657b20dbdecaeeaca942d357d1a748a0 Mon Sep 17 00:00:00 2001 From: unelsson Date: Mon, 14 Nov 2022 14:29:54 +0200 Subject: [PATCH 06/10] Cleaner code --- components/resource/keyframemanager.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/components/resource/keyframemanager.cpp b/components/resource/keyframemanager.cpp index 8f35341334..0cb0864a96 100644 --- a/components/resource/keyframemanager.cpp +++ b/components/resource/keyframemanager.cpp @@ -34,19 +34,14 @@ namespace Resource bool RetrieveAnimationsVisitor::belongsToLeftUpperExtremity(const std::string& name) { - const int bodypartCount = 25; - static const std::array boneNames + static const std::array boneNames = { "bip01_l_clavicle", "left_clavicle", "bip01_l_upperarm", "left_upper_arm", "bip01_l_forearm", "bip01_l_hand", "left_hand", "left_wrist", "shield_bone", "bip01_l_pinky1", "bip01_l_pinky2", "bip01_l_pinky3", "bip01_l_ring1", "bip01_l_ring2", "bip01_l_ring3", "bip01_l_middle1", "bip01_l_middle2", "bip01_l_middle3", "bip01_l_pointer1", "bip01_l_pointer2", "bip01_l_pointer3", "bip01_l_thumb1", "bip01_l_thumb2", "bip01_l_thumb3", "left_forearm" }; - for (unsigned short int i = 0; i < bodypartCount; i++) - { - if (name == boneNames[i]) - return true; - } + if (std::find(boneNames.begin(), boneNames.end(), name) != boneNames.end()) return true; return false; } From 4676ac4ac93cd12c243cc5a165c943619f1530db Mon Sep 17 00:00:00 2001 From: unelsson Date: Mon, 14 Nov 2022 14:49:35 +0200 Subject: [PATCH 07/10] Cleaner code part 2 --- components/resource/keyframemanager.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/components/resource/keyframemanager.cpp b/components/resource/keyframemanager.cpp index 0cb0864a96..c3753bc570 100644 --- a/components/resource/keyframemanager.cpp +++ b/components/resource/keyframemanager.cpp @@ -48,33 +48,23 @@ namespace Resource bool RetrieveAnimationsVisitor::belongsToRightUpperExtremity(const std::string& name) { - const int bodypartCount = 25; - static const std::array boneNames = { "bip01_r_clavicle", "right_clavicle", + static const std::array boneNames = { "bip01_r_clavicle", "right_clavicle", "bip01_r_upperarm", "right_upper_arm", "bip01_r_forearm", "bip01_r_hand", "right_hand", "right_wrist", "bip01_r_thumb1", "bip01_r_thumb2", "bip01_r_thumb3", "weapon_bone", "bip01_r_pinky1", "bip01_r_pinky2", "bip01_r_pinky3", "bip01_r_ring1", "bip01_r_ring2", "bip01_r_ring3", "bip01_r_middle1", "bip01_r_middle2", "bip01_r_middle3", "bip01_r_pointer1", "bip01_r_pointer2", "bip01_r_pointer3", "right_forearm" }; - for (unsigned short int i = 0; i < bodypartCount; i++) - { - if (name == boneNames[i]) - return true; - } + if (std::find(boneNames.begin(), boneNames.end(), name) != boneNames.end()) return true; return false; } bool RetrieveAnimationsVisitor::belongsToTorso(const std::string& name) { - const int bodypartCount = 8; - static const std::array boneNames + static const std::array boneNames = { "bip01_spine1", "bip01_spine2", "bip01_neck", "bip01_head", "head", "neck", "chest", "groin" }; - for (unsigned short int i = 0; i < bodypartCount; i++) - { - if (name == boneNames[i]) - return true; - } + if (std::find(boneNames.begin(), boneNames.end(), name) != boneNames.end()) return true; return false; } From c71504eeb04356ace0f351658d57548030b135c2 Mon Sep 17 00:00:00 2001 From: unelsson Date: Sat, 31 Dec 2022 00:33:35 +0200 Subject: [PATCH 08/10] Better comments --- components/resource/keyframemanager.cpp | 10 ++++------ components/resource/keyframemanager.hpp | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/components/resource/keyframemanager.cpp b/components/resource/keyframemanager.cpp index c3753bc570..9e9acfe0c6 100644 --- a/components/resource/keyframemanager.cpp +++ b/components/resource/keyframemanager.cpp @@ -81,12 +81,10 @@ namespace Resource { if (animation) { - if (animation->getName() - == "Default") //"Default" is osg dae plugin's default naming scheme for unnamed animations + //"Default" is osg dae plugin's default naming scheme for unnamed animations + if (animation->getName() == "Default") { - animation->setName( - std::string("idle")); // animation naming scheme "idle: start" and "idle: stop" is the - // default idle animation that OpenMW seems to want to play + animation->setName(std::string("idle")); } osg::ref_ptr mergedAnimationTrack = new Resource::Animation; @@ -116,7 +114,7 @@ namespace Resource || belongsToTorso(channel->getTargetName())) continue; - mergedAnimationTrack->addChannel(channel.get()->clone()); // is ->clone needed? + mergedAnimationTrack->addChannel(channel.get()->clone()); } callback->addMergedAnimationTrack(mergedAnimationTrack); diff --git a/components/resource/keyframemanager.hpp b/components/resource/keyframemanager.hpp index 94dccb77f4..138838c0f7 100644 --- a/components/resource/keyframemanager.hpp +++ b/components/resource/keyframemanager.hpp @@ -11,7 +11,7 @@ namespace Resource { - /// @brief extract animations to OpenMW's animation system + /// @brief extract animations from OSG formats to OpenMW's animation system class RetrieveAnimationsVisitor : public osg::NodeVisitor { public: From d60fd86719e12e3343d2d4df6df857e4f4fd53cb Mon Sep 17 00:00:00 2001 From: unelsson Date: Sat, 31 Dec 2022 00:52:05 +0200 Subject: [PATCH 09/10] clang format --- apps/openmw/mwrender/animation.cpp | 3 ++- components/resource/keyframemanager.cpp | 30 +++++++++++++------------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 2efe7ccd61..749ac9e66c 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -557,7 +557,8 @@ namespace MWRender mResetAccumRootCallback->setAccumulate(mAccumulate); } - size_t Animation::detectBlendMask(const osg::Node* node, const std::string& controllerName) const // controllerName is used for Collada animated deforming models + // controllerName is used for Collada animated deforming models + size_t Animation::detectBlendMask(const osg::Node* node, const std::string& controllerName) const { static const std::string_view sBlendMaskRoots[sNumBlendMasks] = { "", /* Lower body / character root */ diff --git a/components/resource/keyframemanager.cpp b/components/resource/keyframemanager.cpp index 9e9acfe0c6..c547d0f9f0 100644 --- a/components/resource/keyframemanager.cpp +++ b/components/resource/keyframemanager.cpp @@ -34,27 +34,28 @@ namespace Resource bool RetrieveAnimationsVisitor::belongsToLeftUpperExtremity(const std::string& name) { - static const std::array boneNames - = { "bip01_l_clavicle", "left_clavicle", "bip01_l_upperarm", "left_upper_arm", "bip01_l_forearm", - "bip01_l_hand", "left_hand", "left_wrist", "shield_bone", "bip01_l_pinky1", "bip01_l_pinky2", - "bip01_l_pinky3", "bip01_l_ring1", "bip01_l_ring2", "bip01_l_ring3", "bip01_l_middle1", - "bip01_l_middle2", "bip01_l_middle3", "bip01_l_pointer1", "bip01_l_pointer2", "bip01_l_pointer3", - "bip01_l_thumb1", "bip01_l_thumb2", "bip01_l_thumb3", "left_forearm" }; + static const std::array boneNames = { "bip01_l_clavicle", "left_clavicle", "bip01_l_upperarm", "left_upper_arm", + "bip01_l_forearm", "bip01_l_hand", "left_hand", "left_wrist", "shield_bone", "bip01_l_pinky1", + "bip01_l_pinky2", "bip01_l_pinky3", "bip01_l_ring1", "bip01_l_ring2", "bip01_l_ring3", "bip01_l_middle1", + "bip01_l_middle2", "bip01_l_middle3", "bip01_l_pointer1", "bip01_l_pointer2", "bip01_l_pointer3", + "bip01_l_thumb1", "bip01_l_thumb2", "bip01_l_thumb3", "left_forearm" }; - if (std::find(boneNames.begin(), boneNames.end(), name) != boneNames.end()) return true; + if (std::find(boneNames.begin(), boneNames.end(), name) != boneNames.end()) + return true; return false; } bool RetrieveAnimationsVisitor::belongsToRightUpperExtremity(const std::string& name) { - static const std::array boneNames = { "bip01_r_clavicle", "right_clavicle", - "bip01_r_upperarm", "right_upper_arm", "bip01_r_forearm", "bip01_r_hand", "right_hand", "right_wrist", - "bip01_r_thumb1", "bip01_r_thumb2", "bip01_r_thumb3", "weapon_bone", "bip01_r_pinky1", "bip01_r_pinky2", - "bip01_r_pinky3", "bip01_r_ring1", "bip01_r_ring2", "bip01_r_ring3", "bip01_r_middle1", "bip01_r_middle2", - "bip01_r_middle3", "bip01_r_pointer1", "bip01_r_pointer2", "bip01_r_pointer3", "right_forearm" }; + static const std::array boneNames = { "bip01_r_clavicle", "right_clavicle", "bip01_r_upperarm", + "right_upper_arm", "bip01_r_forearm", "bip01_r_hand", "right_hand", "right_wrist", "bip01_r_thumb1", + "bip01_r_thumb2", "bip01_r_thumb3", "weapon_bone", "bip01_r_pinky1", "bip01_r_pinky2", "bip01_r_pinky3", + "bip01_r_ring1", "bip01_r_ring2", "bip01_r_ring3", "bip01_r_middle1", "bip01_r_middle2", "bip01_r_middle3", + "bip01_r_pointer1", "bip01_r_pointer2", "bip01_r_pointer3", "right_forearm" }; - if (std::find(boneNames.begin(), boneNames.end(), name) != boneNames.end()) return true; + if (std::find(boneNames.begin(), boneNames.end(), name) != boneNames.end()) + return true; return false; } @@ -64,7 +65,8 @@ namespace Resource static const std::array boneNames = { "bip01_spine1", "bip01_spine2", "bip01_neck", "bip01_head", "head", "neck", "chest", "groin" }; - if (std::find(boneNames.begin(), boneNames.end(), name) != boneNames.end()) return true; + if (std::find(boneNames.begin(), boneNames.end(), name) != boneNames.end()) + return true; return false; } From fe7660eec8c02efa4c65f6d8496d7d176c8fcdbc Mon Sep 17 00:00:00 2001 From: unelsson Date: Sat, 31 Dec 2022 00:53:36 +0200 Subject: [PATCH 10/10] clang-format again --- apps/openmw/mwrender/animation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 749ac9e66c..919f8a9e8e 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -558,7 +558,7 @@ namespace MWRender } // controllerName is used for Collada animated deforming models - size_t Animation::detectBlendMask(const osg::Node* node, const std::string& controllerName) const + size_t Animation::detectBlendMask(const osg::Node* node, const std::string& controllerName) const { static const std::string_view sBlendMaskRoots[sNumBlendMasks] = { "", /* Lower body / character root */