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/".
pull/3236/head
elsid 3 months ago
parent a6e075499b
commit 5532bc61c1
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -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::AnimSource> Animation::addSingleAnimSource(

@ -15,6 +15,7 @@
#include <components/sceneutil/nodecallback.hpp>
#include <components/sceneutil/textkeymap.hpp>
#include <components/sceneutil/util.hpp>
#include <components/vfs/pathutil.hpp>
#include <map>
#include <span>
@ -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

Loading…
Cancel
Save