mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-28 14:53:58 +00:00
Move bone rename logic to ColladaDescriptionVisitor, undo formatting/refactoring
This commit is contained in:
parent
ceabeab0fd
commit
a51d560174
@ -1457,9 +1457,10 @@ namespace MWRender
|
||||
}
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Node> created = getModelInstance(mResourceSystem, model, baseonly, inject, defaultSkeleton);
|
||||
if (!forceskeleton)
|
||||
{
|
||||
osg::ref_ptr<osg::Node> 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<osg::Node> created
|
||||
= getModelInstance(mResourceSystem, model, baseonly, inject, defaultSkeleton);
|
||||
osg::ref_ptr<SceneUtil::Skeleton> skel = dynamic_cast<SceneUtil::Skeleton*>(created.get());
|
||||
if (!skel)
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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(), '_', ' ');
|
||||
|
@ -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<Resource::Animation> 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")
|
||||
|
@ -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<std::pair<std::string, std::string>> renameList;
|
||||
|
||||
// Collecting updates
|
||||
for (const auto& influence : *vertexInfluenceMap)
|
||||
std::vector<std::string> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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())
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user