1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-03 17:37:18 +00:00
OpenMW/components/sceneutil/osgacontroller.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

90 lines
2.7 KiB
C++
Raw Normal View History

2020-11-18 23:11:56 +00:00
#ifndef OPENMW_COMPONENTS_SCENEUTIL_OSGACONTROLLER_HPP
#define OPENMW_COMPONENTS_SCENEUTIL_OSGACONTROLLER_HPP
#include <osg/Node>
#include <osg/NodeVisitor>
#include <osg/ref_ptr>
#include <osgAnimation/UpdateMatrixTransform>
2022-08-15 21:04:54 +00:00
#include "keyframe.hpp"
#include "nodecallback.hpp"
2020-11-18 23:11:56 +00:00
#include <components/resource/animation.hpp>
namespace SceneUtil
2020-11-18 23:11:56 +00:00
{
struct EmulatedAnimation
{
float mStartTime;
float mStopTime;
std::string mName;
};
2020-11-18 23:11:56 +00:00
class LinkVisitor : public osg::NodeVisitor
{
public:
LinkVisitor();
virtual void link(osgAnimation::UpdateMatrixTransform* umt);
virtual void setAnimation(Resource::Animation* animation);
virtual void apply(osg::Node& node) override;
2020-11-18 23:11:56 +00:00
protected:
Resource::Animation* mAnimation;
};
#ifdef _MSC_VER
#pragma warning(push)
/*
* Warning C4250: 'SceneUtil::OsgAnimationController': inherits 'osg::Callback::osg::Callback::asCallback' via
* dominance, there is no way to solved this if an object must inherit from both osg::Object and osg::Callback
*/
#pragma warning(disable : 4250)
#endif
class OsgAnimationController : public SceneUtil::KeyframeController,
public SceneUtil::NodeCallback<OsgAnimationController>
2020-11-18 23:11:56 +00:00
{
public:
/// @brief Handles the animation for osgAnimation formats
2022-10-05 21:45:17 +00:00
OsgAnimationController() = default;
2020-11-18 23:11:56 +00:00
OsgAnimationController(const OsgAnimationController& copy, const osg::CopyOp& copyop);
2020-11-18 23:11:56 +00:00
META_Object(SceneUtil, OsgAnimationController)
2020-11-18 23:11:56 +00:00
osg::Callback* getAsCallback() override { return this; }
2020-11-18 23:11:56 +00:00
/// @brief Handles the location of the instance
osg::Vec3f getTranslation(float time) const override;
/// @brief Handles finding bone position in the animation
osg::Matrixf getTransformForNode(float time, const std::string_view name) const;
2020-11-18 23:11:56 +00:00
/// @brief Calls animation track update()
2021-06-23 21:13:59 +00:00
void update(float time, const std::string& animationName);
2020-11-18 23:11:56 +00:00
/// @brief Called every frame for osgAnimation
void operator()(osg::Node*, osg::NodeVisitor*);
2020-11-18 23:11:56 +00:00
/// @brief Sets details of the animations
2021-06-23 21:13:59 +00:00
void setEmulatedAnimations(const std::vector<EmulatedAnimation>& emulatedAnimations);
2020-11-18 23:11:56 +00:00
/// @brief Adds an animation track to a model
void addMergedAnimationTrack(osg::ref_ptr<Resource::Animation> animationTrack);
2020-11-18 23:11:56 +00:00
private:
bool mNeedToLink = true;
osg::ref_ptr<LinkVisitor> mLinker;
std::vector<osg::ref_ptr<Resource::Animation>>
mMergedAnimationTracks; // Used only by osgAnimation-based formats (e.g. dae)
std::vector<EmulatedAnimation> mEmulatedAnimations;
2020-11-18 23:11:56 +00:00
};
#ifdef _MSC_VER
#pragma warning(pop)
#endif
2020-11-18 23:11:56 +00:00
}
#endif