diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 1807b0050f..729c69f58b 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -1457,9 +1457,10 @@ namespace MWRender } } - osg::ref_ptr created = getModelInstance(mResourceSystem, model, baseonly, inject, defaultSkeleton); if (!forceskeleton) { + osg::ref_ptr created + = getModelInstance(mResourceSystem, model, baseonly, inject, defaultSkeleton); mInsert->addChild(created); mObjectRoot = created->asGroup(); if (!mObjectRoot) @@ -1475,6 +1476,8 @@ namespace MWRender } else { + osg::ref_ptr created + = getModelInstance(mResourceSystem, model, baseonly, inject, defaultSkeleton); osg::ref_ptr skel = dynamic_cast(created.get()); if (!skel) { diff --git a/apps/openmw/mwrender/rotatecontroller.cpp b/apps/openmw/mwrender/rotatecontroller.cpp index 73c4cddff5..47b271c40d 100644 --- a/apps/openmw/mwrender/rotatecontroller.cpp +++ b/apps/openmw/mwrender/rotatecontroller.cpp @@ -41,6 +41,7 @@ namespace MWRender osg::Quat orient = worldOrient * mRotate * worldOrientInverse * matrix.getRotate(); matrix.setRotate(orient); matrix.setTrans(matrix.getTrans() + worldOrientInverse * mOffset); + node->setMatrix(matrix); // If we are linked to a bone we must call setMatrixInSkeletonSpace diff --git a/components/misc/strings/algorithm.hpp b/components/misc/strings/algorithm.hpp index 2bf7125c8b..18f72104bd 100644 --- a/components/misc/strings/algorithm.hpp +++ b/components/misc/strings/algorithm.hpp @@ -15,7 +15,7 @@ namespace Misc::StringUtils bool operator()(char x, char y) const { return toLower(x) < toLower(y); } }; - inline std::string underscoresToSpaces(const std::string_view& oldName) + inline std::string underscoresToSpaces(const std::string_view oldName) { std::string newName(oldName); std::replace(newName.begin(), newName.end(), '_', ' '); diff --git a/components/resource/keyframemanager.cpp b/components/resource/keyframemanager.cpp index 67a434e47b..84e7a7e311 100644 --- a/components/resource/keyframemanager.cpp +++ b/components/resource/keyframemanager.cpp @@ -88,7 +88,9 @@ namespace Resource { //"Default" is osg dae plugin's default naming scheme for unnamed animations if (animation->getName() == "Default") + { animation->setName(std::string("idle")); + } osg::ref_ptr mergedAnimationTrack = new Resource::Animation; const std::string animationName = animation->getName(); @@ -97,7 +99,7 @@ namespace Resource const osgAnimation::ChannelList& channels = animation->getChannels(); for (const auto& channel : channels) { - // Repalce channel target name to match the renamed bones/transforms + // Replace channel target name to match the renamed bones/transforms channel->setTargetName(Misc::StringUtils::underscoresToSpaces(channel->getTargetName())); if (name == "Bip01 R Clavicle") diff --git a/components/resource/scenemanager.cpp b/components/resource/scenemanager.cpp index b8272c8b26..3b7deeaab3 100644 --- a/components/resource/scenemanager.cpp +++ b/components/resource/scenemanager.cpp @@ -271,6 +271,11 @@ namespace Resource void apply(osg::Node& node) override { + // If an osgAnimation bone/transform, ensure underscores in name are replaced with spaces + // this is for compatibility reasons + if (node.libraryName() == std::string_view("osgAnimation") && node.className() == std::string_view("Bone")) + node.setName(Misc::StringUtils::underscoresToSpaces(node.getName())); + if (osg::StateSet* stateset = node.getStateSet()) { if (stateset->getRenderingHint() == osg::StateSet::TRANSPARENT_BIN) @@ -362,27 +367,18 @@ namespace Resource if (!vertexInfluenceMap) return; - std::vector> renameList; - - // Collecting updates - for (const auto& influence : *vertexInfluenceMap) + std::vector renameList; + for (const auto& [boneName, unused] : *vertexInfluenceMap) { - const std::string& oldBoneName = influence.first; - std::string newBoneName = Misc::StringUtils::underscoresToSpaces(oldBoneName); - if (newBoneName != oldBoneName) - renameList.emplace_back(oldBoneName, newBoneName); + if (boneName.find('_') != std::string::npos) + renameList.push_back(boneName); } - // Applying updates (cant update map while iterating it!) - for (const auto& rename : renameList) + for (const std::string& oldName : renameList) { - const std::string& oldName = rename.first; - const std::string& newName = rename.second; - - // Check if new name already exists to avoid overwriting + const std::string newName = Misc::StringUtils::underscoresToSpaces(oldName); if (vertexInfluenceMap->find(newName) == vertexInfluenceMap->end()) (*vertexInfluenceMap)[newName] = std::move((*vertexInfluenceMap)[oldName]); - vertexInfluenceMap->erase(oldName); } } diff --git a/components/sceneutil/extradata.cpp b/components/sceneutil/extradata.cpp index 8d024d5824..5e91830bba 100644 --- a/components/sceneutil/extradata.cpp +++ b/components/sceneutil/extradata.cpp @@ -45,15 +45,11 @@ namespace SceneUtil void ProcessExtraDataVisitor::apply(osg::Node& node) { - // If an osgAnimation bone/transform, ensure underscores in name are replaced with spaces - // this is for compatibility reasons - if (node.libraryName() == std::string_view("osgAnimation") && node.className() == std::string_view("Bone")) - node.setName(Misc::StringUtils::underscoresToSpaces(node.getName())); - if (!mSceneMgr->getSoftParticles()) return; std::string source; + constexpr float defaultFalloffDepth = 300.f; // arbitrary value that simply looks good with common cases if (node.getUserValue(Misc::OsgUserValues::sExtraData, source) && !source.empty()) diff --git a/components/sceneutil/osgacontroller.cpp b/components/sceneutil/osgacontroller.cpp index 40b6640973..5a3ae60293 100644 --- a/components/sceneutil/osgacontroller.cpp +++ b/components/sceneutil/osgacontroller.cpp @@ -134,7 +134,7 @@ namespace SceneUtil return osg::Vec3f(); } - osg::Matrixf OsgAnimationController::getTransformForNode(float time, const std::string& name) const + osg::Matrixf OsgAnimationController::getTransformForNode(float time, const std::string_view name) const { std::string animationName; float newTime = time; diff --git a/components/sceneutil/osgacontroller.hpp b/components/sceneutil/osgacontroller.hpp index 000580631c..bb9a621760 100644 --- a/components/sceneutil/osgacontroller.hpp +++ b/components/sceneutil/osgacontroller.hpp @@ -60,7 +60,7 @@ namespace SceneUtil osg::Vec3f getTranslation(float time) const override; /// @brief Handles finding bone position in the animation - osg::Matrixf getTransformForNode(float time, const std::string& name) const; + osg::Matrixf getTransformForNode(float time, const std::string_view name) const; /// @brief Calls animation track update() void update(float time, const std::string& animationName);