mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-20 21:41:35 +00:00
Move bone rename logic to ColladaDescriptionVisitor, undo formatting/refactoring
This commit is contained in:
parent
ceabeab0fd
commit
a51d560174
8 changed files with 23 additions and 25 deletions
|
@ -1457,9 +1457,10 @@ namespace MWRender
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::ref_ptr<osg::Node> created = getModelInstance(mResourceSystem, model, baseonly, inject, defaultSkeleton);
|
|
||||||
if (!forceskeleton)
|
if (!forceskeleton)
|
||||||
{
|
{
|
||||||
|
osg::ref_ptr<osg::Node> created
|
||||||
|
= getModelInstance(mResourceSystem, model, baseonly, inject, defaultSkeleton);
|
||||||
mInsert->addChild(created);
|
mInsert->addChild(created);
|
||||||
mObjectRoot = created->asGroup();
|
mObjectRoot = created->asGroup();
|
||||||
if (!mObjectRoot)
|
if (!mObjectRoot)
|
||||||
|
@ -1475,6 +1476,8 @@ namespace MWRender
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
osg::ref_ptr<osg::Node> created
|
||||||
|
= getModelInstance(mResourceSystem, model, baseonly, inject, defaultSkeleton);
|
||||||
osg::ref_ptr<SceneUtil::Skeleton> skel = dynamic_cast<SceneUtil::Skeleton*>(created.get());
|
osg::ref_ptr<SceneUtil::Skeleton> skel = dynamic_cast<SceneUtil::Skeleton*>(created.get());
|
||||||
if (!skel)
|
if (!skel)
|
||||||
{
|
{
|
||||||
|
|
|
@ -41,6 +41,7 @@ namespace MWRender
|
||||||
osg::Quat orient = worldOrient * mRotate * worldOrientInverse * matrix.getRotate();
|
osg::Quat orient = worldOrient * mRotate * worldOrientInverse * matrix.getRotate();
|
||||||
matrix.setRotate(orient);
|
matrix.setRotate(orient);
|
||||||
matrix.setTrans(matrix.getTrans() + worldOrientInverse * mOffset);
|
matrix.setTrans(matrix.getTrans() + worldOrientInverse * mOffset);
|
||||||
|
|
||||||
node->setMatrix(matrix);
|
node->setMatrix(matrix);
|
||||||
|
|
||||||
// If we are linked to a bone we must call setMatrixInSkeletonSpace
|
// If we are linked to a bone we must call setMatrixInSkeletonSpace
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace Misc::StringUtils
|
||||||
bool operator()(char x, char y) const { return toLower(x) < toLower(y); }
|
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::string newName(oldName);
|
||||||
std::replace(newName.begin(), newName.end(), '_', ' ');
|
std::replace(newName.begin(), newName.end(), '_', ' ');
|
||||||
|
|
|
@ -88,7 +88,9 @@ namespace Resource
|
||||||
{
|
{
|
||||||
//"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")
|
if (animation->getName() == "Default")
|
||||||
|
{
|
||||||
animation->setName(std::string("idle"));
|
animation->setName(std::string("idle"));
|
||||||
|
}
|
||||||
|
|
||||||
osg::ref_ptr<Resource::Animation> mergedAnimationTrack = new Resource::Animation;
|
osg::ref_ptr<Resource::Animation> mergedAnimationTrack = new Resource::Animation;
|
||||||
const std::string animationName = animation->getName();
|
const std::string animationName = animation->getName();
|
||||||
|
@ -97,7 +99,7 @@ namespace Resource
|
||||||
const osgAnimation::ChannelList& channels = animation->getChannels();
|
const osgAnimation::ChannelList& channels = animation->getChannels();
|
||||||
for (const auto& channel : channels)
|
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()));
|
channel->setTargetName(Misc::StringUtils::underscoresToSpaces(channel->getTargetName()));
|
||||||
|
|
||||||
if (name == "Bip01 R Clavicle")
|
if (name == "Bip01 R Clavicle")
|
||||||
|
|
|
@ -271,6 +271,11 @@ namespace Resource
|
||||||
|
|
||||||
void apply(osg::Node& node) override
|
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 (osg::StateSet* stateset = node.getStateSet())
|
||||||
{
|
{
|
||||||
if (stateset->getRenderingHint() == osg::StateSet::TRANSPARENT_BIN)
|
if (stateset->getRenderingHint() == osg::StateSet::TRANSPARENT_BIN)
|
||||||
|
@ -362,27 +367,18 @@ namespace Resource
|
||||||
if (!vertexInfluenceMap)
|
if (!vertexInfluenceMap)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::vector<std::pair<std::string, std::string>> renameList;
|
std::vector<std::string> renameList;
|
||||||
|
for (const auto& [boneName, unused] : *vertexInfluenceMap)
|
||||||
// Collecting updates
|
|
||||||
for (const auto& influence : *vertexInfluenceMap)
|
|
||||||
{
|
{
|
||||||
const std::string& oldBoneName = influence.first;
|
if (boneName.find('_') != std::string::npos)
|
||||||
std::string newBoneName = Misc::StringUtils::underscoresToSpaces(oldBoneName);
|
renameList.push_back(boneName);
|
||||||
if (newBoneName != oldBoneName)
|
|
||||||
renameList.emplace_back(oldBoneName, newBoneName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Applying updates (cant update map while iterating it!)
|
for (const std::string& oldName : renameList)
|
||||||
for (const auto& rename : renameList)
|
|
||||||
{
|
{
|
||||||
const std::string& oldName = rename.first;
|
const std::string newName = Misc::StringUtils::underscoresToSpaces(oldName);
|
||||||
const std::string& newName = rename.second;
|
|
||||||
|
|
||||||
// Check if new name already exists to avoid overwriting
|
|
||||||
if (vertexInfluenceMap->find(newName) == vertexInfluenceMap->end())
|
if (vertexInfluenceMap->find(newName) == vertexInfluenceMap->end())
|
||||||
(*vertexInfluenceMap)[newName] = std::move((*vertexInfluenceMap)[oldName]);
|
(*vertexInfluenceMap)[newName] = std::move((*vertexInfluenceMap)[oldName]);
|
||||||
|
|
||||||
vertexInfluenceMap->erase(oldName);
|
vertexInfluenceMap->erase(oldName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,15 +45,11 @@ namespace SceneUtil
|
||||||
|
|
||||||
void ProcessExtraDataVisitor::apply(osg::Node& node)
|
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())
|
if (!mSceneMgr->getSoftParticles())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::string source;
|
std::string source;
|
||||||
|
|
||||||
constexpr float defaultFalloffDepth = 300.f; // arbitrary value that simply looks good with common cases
|
constexpr float defaultFalloffDepth = 300.f; // arbitrary value that simply looks good with common cases
|
||||||
|
|
||||||
if (node.getUserValue(Misc::OsgUserValues::sExtraData, source) && !source.empty())
|
if (node.getUserValue(Misc::OsgUserValues::sExtraData, source) && !source.empty())
|
||||||
|
|
|
@ -134,7 +134,7 @@ namespace SceneUtil
|
||||||
return osg::Vec3f();
|
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;
|
std::string animationName;
|
||||||
float newTime = time;
|
float newTime = time;
|
||||||
|
|
|
@ -60,7 +60,7 @@ namespace SceneUtil
|
||||||
osg::Vec3f getTranslation(float time) const override;
|
osg::Vec3f getTranslation(float time) const override;
|
||||||
|
|
||||||
/// @brief Handles finding bone position in the animation
|
/// @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()
|
/// @brief Calls animation track update()
|
||||||
void update(float time, const std::string& animationName);
|
void update(float time, const std::string& animationName);
|
||||||
|
|
Loading…
Reference in a new issue