mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 03:15:32 +00:00
Use accompanying txt file for textkeys in osgAnimation formats
This commit is contained in:
parent
45fde84f4f
commit
d5844b0982
2 changed files with 65 additions and 13 deletions
|
@ -18,7 +18,9 @@
|
|||
namespace Resource
|
||||
{
|
||||
|
||||
RetrieveAnimationsVisitor::RetrieveAnimationsVisitor(SceneUtil::KeyframeHolder& target, osg::ref_ptr<osgAnimation::BasicAnimationManager> animationManager) : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN), mTarget(target), mAnimationManager(animationManager) {}
|
||||
RetrieveAnimationsVisitor::RetrieveAnimationsVisitor(SceneUtil::KeyframeHolder& target, osg::ref_ptr<osgAnimation::BasicAnimationManager> animationManager,
|
||||
const std::string& normalized, const VFS::Manager* vfs) :
|
||||
osg::NodeVisitor(TRAVERSE_ALL_CHILDREN), mTarget(target), mAnimationManager(animationManager), mNormalized(normalized), mVFS(vfs) {}
|
||||
|
||||
void RetrieveAnimationsVisitor::apply(osg::Node& node)
|
||||
{
|
||||
|
@ -39,27 +41,19 @@ namespace Resource
|
|||
|
||||
osg::ref_ptr<Resource::Animation> mergedAnimationTrack = new Resource::Animation;
|
||||
std::string animationName = animation->getName();
|
||||
std::string start = animationName + std::string(": start");
|
||||
std::string stop = animationName + std::string(": stop");
|
||||
mergedAnimationTrack->setName(animationName);
|
||||
|
||||
const osgAnimation::ChannelList& channels = animation->getChannels();
|
||||
for (const auto& channel: channels)
|
||||
{
|
||||
mergedAnimationTrack->addChannel(channel.get()->clone()); // is ->clone needed?
|
||||
}
|
||||
mergedAnimationTrack->setName(animation->getName());
|
||||
|
||||
callback->addMergedAnimationTrack(mergedAnimationTrack);
|
||||
|
||||
float startTime = animation->getStartTime();
|
||||
float stopTime = startTime + animation->getDuration();
|
||||
|
||||
// mTextKeys is a nif-thing, used by OpenMW's animation system
|
||||
// Format is likely "AnimationName: [Keyword_optional] [Start OR Stop]"
|
||||
// AnimationNames are keywords like idle2, idle3... AiPackages and various mechanics control which animations are played
|
||||
// Keywords can be stuff like Loop, Equip, Unequip, Block, InventoryHandtoHand, InventoryWeaponOneHand, PickProbe, Slash, Thrust, Chop... even "Slash Small Follow"
|
||||
mTarget.mTextKeys.emplace(startTime, std::move(start));
|
||||
mTarget.mTextKeys.emplace(stopTime, std::move(stop));
|
||||
|
||||
SceneUtil::EmulatedAnimation emulatedAnimation;
|
||||
emulatedAnimation.mStartTime = startTime;
|
||||
emulatedAnimation.mStopTime = stopTime;
|
||||
|
@ -67,12 +61,62 @@ namespace Resource
|
|||
emulatedAnimations.emplace_back(emulatedAnimation);
|
||||
}
|
||||
}
|
||||
|
||||
// mTextKeys is a nif-thing, used by OpenMW's animation system
|
||||
// Format is likely "AnimationName: [Keyword_optional] [Start OR Stop]"
|
||||
// AnimationNames are keywords like idle2, idle3... AiPackages and various mechanics control which animations are played
|
||||
// Keywords can be stuff like Loop, Equip, Unequip, Block, InventoryHandtoHand, InventoryWeaponOneHand, PickProbe, Slash, Thrust, Chop... even "Slash Small Follow"
|
||||
// osgAnimation formats should have a .txt file with the same name, each line holding a textkey and whitespace separated time value
|
||||
// e.g. idle: start 0.0333
|
||||
try
|
||||
{
|
||||
Files::IStreamPtr textKeysFile = mVFS->get(changeFileExtension(mNormalized, "txt"));
|
||||
std::string line;
|
||||
while ( getline (*textKeysFile, line) )
|
||||
{
|
||||
Log(Debug::Warning) << "add textkey ***" << parseTextKey(line) << "***" << parseTimeSignature(line) << "***";
|
||||
mTarget.mTextKeys.emplace(parseTimeSignature(line), std::move(parseTextKey(line)));
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
Log(Debug::Warning) << "No textkey file found for " << mNormalized;
|
||||
}
|
||||
|
||||
callback->setEmulatedAnimations(emulatedAnimations);
|
||||
mTarget.mKeyframeControllers.emplace(node.getName(), callback);
|
||||
}
|
||||
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
std::string RetrieveAnimationsVisitor::parseTextKey(const std::string& line)
|
||||
{
|
||||
size_t spacePos = line.find_last_of(' ');
|
||||
if (spacePos != std::string::npos)
|
||||
return line.substr(0, spacePos);
|
||||
return "";
|
||||
}
|
||||
|
||||
double RetrieveAnimationsVisitor::parseTimeSignature(const std::string& line)
|
||||
{
|
||||
size_t spacePos = line.find_last_of(' ');
|
||||
double time = 0.0;
|
||||
if (spacePos != std::string::npos && spacePos + 1 < line.size())
|
||||
time = std::stod(line.substr(spacePos + 1));
|
||||
return time;
|
||||
}
|
||||
|
||||
std::string RetrieveAnimationsVisitor::changeFileExtension(const std::string file, const std::string ext)
|
||||
{
|
||||
size_t extPos = file.find_last_of('.');
|
||||
if (extPos != std::string::npos && extPos+1 < file.size())
|
||||
{
|
||||
return file.substr(0, extPos + 1) + ext;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Resource
|
||||
|
@ -110,7 +154,7 @@ namespace Resource
|
|||
osg::ref_ptr<osgAnimation::BasicAnimationManager> bam = dynamic_cast<osgAnimation::BasicAnimationManager*> (scene->getUpdateCallback());
|
||||
if (bam)
|
||||
{
|
||||
Resource::RetrieveAnimationsVisitor rav(*loaded.get(), bam);
|
||||
Resource::RetrieveAnimationsVisitor rav(*loaded.get(), bam, normalized, mVFS);
|
||||
scene->accept(rav);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,13 +15,21 @@ namespace Resource
|
|||
class RetrieveAnimationsVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
RetrieveAnimationsVisitor(SceneUtil::KeyframeHolder& target, osg::ref_ptr<osgAnimation::BasicAnimationManager> animationManager);
|
||||
RetrieveAnimationsVisitor(SceneUtil::KeyframeHolder& target, osg::ref_ptr<osgAnimation::BasicAnimationManager> animationManager,
|
||||
const std::string& normalized, const VFS::Manager* vfs);
|
||||
|
||||
virtual void apply(osg::Node& node) override;
|
||||
|
||||
private:
|
||||
|
||||
std::string changeFileExtension(const std::string file, const std::string ext);
|
||||
std::string parseTextKey(const std::string& line);
|
||||
double parseTimeSignature(const std::string& line);
|
||||
|
||||
SceneUtil::KeyframeHolder& mTarget;
|
||||
osg::ref_ptr<osgAnimation::BasicAnimationManager> mAnimationManager;
|
||||
std::string mNormalized;
|
||||
const VFS::Manager* mVFS;
|
||||
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue