From 5532bc61c1e6db1724b63aece5af20e7824c3618 Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 6 Oct 2024 16:15:42 +0200 Subject: [PATCH] Support additional animation sources not only for 2 letter extensions If extension is not 2 letters length (e.g. not .kf), replacing last 3 last charaters leads to weird results like: "meshes/basicplayer.dae" -> "animations/basicplayer./" According to the doc this should be "animations/basicplayer/". --- apps/openmw/mwrender/animation.cpp | 26 +++++++++++++++++--------- apps/openmw/mwrender/animation.hpp | 3 ++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index d6cad42e39..80ba39c465 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -658,16 +658,24 @@ namespace MWRender return mKeyframes->mTextKeys; } - void Animation::loadAllAnimationsInFolder(const std::string& model, const std::string& baseModel) + void Animation::loadAdditionalAnimations(VFS::Path::NormalizedView model, const std::string& baseModel) { - std::string animationPath = model; - if (animationPath.find("meshes") == 0) - { - animationPath.replace(0, 6, "animations"); - } - animationPath.replace(animationPath.size() - 3, 3, "/"); + constexpr VFS::Path::NormalizedView meshes("meshes/"); + if (!model.value().starts_with(meshes.value())) + return; + + std::string path(model.value()); + + constexpr VFS::Path::NormalizedView animations("animations/"); + path.replace(0, meshes.value().size(), animations.value()); + + const std::string::size_type extensionStart = path.find_last_of(VFS::Path::extensionSeparator); + if (extensionStart == std::string::npos) + return; + + path.replace(extensionStart, path.size() - extensionStart, "/"); - for (const auto& name : mResourceSystem->getVFS()->getRecursiveDirectoryIterator(animationPath)) + for (const VFS::Path::Normalized& name : mResourceSystem->getVFS()->getRecursiveDirectoryIterator(path)) { if (Misc::getFileExtension(name) == "kf") { @@ -686,7 +694,7 @@ namespace MWRender addSingleAnimSource(kfname, baseModel); if (Settings::game().mUseAdditionalAnimSources) - loadAllAnimationsInFolder(kfname, baseModel); + loadAdditionalAnimations(kfname, baseModel); } std::shared_ptr Animation::addSingleAnimSource( diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 36a84ba2ab..d398c5b727 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -281,7 +282,7 @@ namespace MWRender */ void setObjectRoot(const std::string& model, bool forceskeleton, bool baseonly, bool isCreature); - void loadAllAnimationsInFolder(const std::string& model, const std::string& baseModel); + void loadAdditionalAnimations(VFS::Path::NormalizedView model, const std::string& baseModel); /** Adds the keyframe controllers in the specified model as a new animation source. * @note Later added animation sources have the highest priority when it comes to finding a particular