|
|
|
@ -31,74 +31,172 @@ namespace Resource
|
|
|
|
|
, mVFS(vfs)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RetrieveAnimationsVisitor::belongsToLeftUpperExtremity(const std::string& name)
|
|
|
|
|
{
|
|
|
|
|
static const std::string_view boneNames[25] = {
|
|
|
|
|
"bip01_l_clavicle",
|
|
|
|
|
"left_clavicle",
|
|
|
|
|
"bip01_l_upperarm",
|
|
|
|
|
"left_upper_arm",
|
|
|
|
|
"bip01_l_forearm",
|
|
|
|
|
"bip01_l_hand",
|
|
|
|
|
"left_hand",
|
|
|
|
|
"left_wrist",
|
|
|
|
|
"shield_bone",
|
|
|
|
|
"bip01_l_pinky1",
|
|
|
|
|
"bip01_l_pinky2",
|
|
|
|
|
"bip01_l_pinky3",
|
|
|
|
|
"bip01_l_ring1",
|
|
|
|
|
"bip01_l_ring2",
|
|
|
|
|
"bip01_l_ring3",
|
|
|
|
|
"bip01_l_middle1",
|
|
|
|
|
"bip01_l_middle2",
|
|
|
|
|
"bip01_l_middle3",
|
|
|
|
|
"bip01_l_pointer1",
|
|
|
|
|
"bip01_l_pointer2",
|
|
|
|
|
"bip01_l_pointer3",
|
|
|
|
|
"bip01_l_thumb1",
|
|
|
|
|
"bip01_l_thumb2",
|
|
|
|
|
"bip01_l_thumb3",
|
|
|
|
|
"left_forearm"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void RetrieveAnimationsVisitor::apply(osg::Node& node)
|
|
|
|
|
for (size_t i = 0; i < 25; i++)
|
|
|
|
|
{
|
|
|
|
|
if (name == boneNames[i])
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RetrieveAnimationsVisitor::belongsToRightUpperExtremity(const std::string& name)
|
|
|
|
|
{
|
|
|
|
|
if (node.libraryName() == std::string_view("osgAnimation") && node.className() == std::string_view("Bone")
|
|
|
|
|
&& Misc::StringUtils::lowerCase(node.getName()) == std::string_view("bip01"))
|
|
|
|
|
static const std::string_view boneNames[25] = {
|
|
|
|
|
"bip01_r_clavicle",
|
|
|
|
|
"right_clavicle",
|
|
|
|
|
"bip01_r_upperarm",
|
|
|
|
|
"right_upper_arm",
|
|
|
|
|
"bip01_r_forearm",
|
|
|
|
|
"bip01_r_hand",
|
|
|
|
|
"right_hand",
|
|
|
|
|
"right_wrist",
|
|
|
|
|
"bip01_r_thumb1",
|
|
|
|
|
"bip01_r_thumb2",
|
|
|
|
|
"bip01_r_thumb3",
|
|
|
|
|
"weapon_bone",
|
|
|
|
|
"bip01_r_pinky1",
|
|
|
|
|
"bip01_r_pinky2",
|
|
|
|
|
"bip01_r_pinky3",
|
|
|
|
|
"bip01_r_ring1",
|
|
|
|
|
"bip01_r_ring2",
|
|
|
|
|
"bip01_r_ring3",
|
|
|
|
|
"bip01_r_middle1",
|
|
|
|
|
"bip01_r_middle2",
|
|
|
|
|
"bip01_r_middle3",
|
|
|
|
|
"bip01_r_pointer1",
|
|
|
|
|
"bip01_r_pointer2",
|
|
|
|
|
"bip01_r_pointer3",
|
|
|
|
|
"right_forearm"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < 25; i++)
|
|
|
|
|
{
|
|
|
|
|
osg::ref_ptr<SceneUtil::OsgAnimationController> callback = new SceneUtil::OsgAnimationController();
|
|
|
|
|
if (name == boneNames[i])
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<SceneUtil::EmulatedAnimation> emulatedAnimations;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RetrieveAnimationsVisitor::addKeyframeController(const std::string& name, const osg::Node& node)
|
|
|
|
|
{
|
|
|
|
|
osg::ref_ptr<SceneUtil::OsgAnimationController> callback = new SceneUtil::OsgAnimationController();
|
|
|
|
|
|
|
|
|
|
callback->setName(name);
|
|
|
|
|
|
|
|
|
|
std::vector<SceneUtil::EmulatedAnimation> emulatedAnimations;
|
|
|
|
|
|
|
|
|
|
for (const auto& animation : mAnimationManager->getAnimationList())
|
|
|
|
|
for (const auto& animation : mAnimationManager->getAnimationList())
|
|
|
|
|
{
|
|
|
|
|
if (animation)
|
|
|
|
|
{
|
|
|
|
|
if (animation)
|
|
|
|
|
if (animation->getName()
|
|
|
|
|
== "Default") //"Default" is osg dae plugin's default naming scheme for unnamed animations
|
|
|
|
|
{
|
|
|
|
|
if (animation->getName()
|
|
|
|
|
== "Default") //"Default" is osg dae plugin's default naming scheme for unnamed animations
|
|
|
|
|
{
|
|
|
|
|
animation->setName(
|
|
|
|
|
std::string("idle")); // animation naming scheme "idle: start" and "idle: stop" is the
|
|
|
|
|
// default idle animation that OpenMW seems to want to play
|
|
|
|
|
}
|
|
|
|
|
animation->setName(
|
|
|
|
|
std::string("idle")); // animation naming scheme "idle: start" and "idle: stop" is the
|
|
|
|
|
// default idle animation that OpenMW seems to want to play
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<Resource::Animation> mergedAnimationTrack = new Resource::Animation;
|
|
|
|
|
const std::string animationName = animation->getName();
|
|
|
|
|
mergedAnimationTrack->setName(animationName);
|
|
|
|
|
osg::ref_ptr<Resource::Animation> mergedAnimationTrack = new Resource::Animation;
|
|
|
|
|
const std::string animationName = animation->getName();
|
|
|
|
|
mergedAnimationTrack->setName(animationName);
|
|
|
|
|
|
|
|
|
|
const osgAnimation::ChannelList& channels = animation->getChannels();
|
|
|
|
|
for (const auto& channel : channels)
|
|
|
|
|
const osgAnimation::ChannelList& channels = animation->getChannels();
|
|
|
|
|
for (const auto& channel : channels)
|
|
|
|
|
{
|
|
|
|
|
if (name == "Bip01 R Clavicle")
|
|
|
|
|
{
|
|
|
|
|
if (!belongsToRightUpperExtremity(channel->getTargetName())) continue;
|
|
|
|
|
}
|
|
|
|
|
else if (name == "Bip01 L Clavicle")
|
|
|
|
|
{
|
|
|
|
|
mergedAnimationTrack->addChannel(channel.get()->clone()); // is ->clone needed?
|
|
|
|
|
if (!belongsToLeftUpperExtremity(channel->getTargetName())) continue;
|
|
|
|
|
}
|
|
|
|
|
else if (belongsToRightUpperExtremity(channel->getTargetName()) || belongsToLeftUpperExtremity(channel->getTargetName())) continue;
|
|
|
|
|
|
|
|
|
|
callback->addMergedAnimationTrack(mergedAnimationTrack);
|
|
|
|
|
mergedAnimationTrack->addChannel(channel.get()->clone()); // is ->clone needed?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float startTime = animation->getStartTime();
|
|
|
|
|
float stopTime = startTime + animation->getDuration();
|
|
|
|
|
callback->addMergedAnimationTrack(mergedAnimationTrack);
|
|
|
|
|
|
|
|
|
|
SceneUtil::EmulatedAnimation emulatedAnimation;
|
|
|
|
|
emulatedAnimation.mStartTime = startTime;
|
|
|
|
|
emulatedAnimation.mStopTime = stopTime;
|
|
|
|
|
emulatedAnimation.mName = animationName;
|
|
|
|
|
emulatedAnimations.emplace_back(emulatedAnimation);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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" 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))
|
|
|
|
|
{
|
|
|
|
|
mTarget.mTextKeys.emplace(parseTimeSignature(line), parseTextKey(line));
|
|
|
|
|
}
|
|
|
|
|
SceneUtil::EmulatedAnimation emulatedAnimation;
|
|
|
|
|
emulatedAnimation.mStartTime = startTime;
|
|
|
|
|
emulatedAnimation.mStopTime = stopTime;
|
|
|
|
|
emulatedAnimation.mName = animationName;
|
|
|
|
|
emulatedAnimations.emplace_back(emulatedAnimation);
|
|
|
|
|
}
|
|
|
|
|
catch (std::exception&)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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) << "No textkey file found for " << mNormalized;
|
|
|
|
|
mTarget.mTextKeys.emplace(parseTimeSignature(line), parseTextKey(line));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (std::exception&)
|
|
|
|
|
{
|
|
|
|
|
Log(Debug::Warning) << "No textkey file found for " << mNormalized;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback->setEmulatedAnimations(emulatedAnimations);
|
|
|
|
|
mTarget.mKeyframeControllers.emplace(name, callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback->setEmulatedAnimations(emulatedAnimations);
|
|
|
|
|
mTarget.mKeyframeControllers.emplace(node.getName(), callback);
|
|
|
|
|
void RetrieveAnimationsVisitor::apply(osg::Node& node)
|
|
|
|
|
{
|
|
|
|
|
if (node.libraryName() == std::string_view("osgAnimation") && node.className() == std::string_view("Bone")
|
|
|
|
|
&& Misc::StringUtils::lowerCase(node.getName()) == std::string_view("bip01"))
|
|
|
|
|
{
|
|
|
|
|
addKeyframeController("bip01", node); /* Character root */
|
|
|
|
|
//addKeyframeController("Bip01 Spine1", node); /* Torso */
|
|
|
|
|
addKeyframeController("Bip01 L Clavicle", node); /* Left arm */
|
|
|
|
|
addKeyframeController("Bip01 R Clavicle", node); /* Right arm */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
traverse(node);
|
|
|
|
|