File: osgacontroller.hpp

package info (click to toggle)
openmw 0.49.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,992 kB
  • sloc: cpp: 372,479; xml: 2,149; sh: 1,403; python: 797; makefile: 26
file content (89 lines) | stat: -rw-r--r-- 2,781 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#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>

#include "keyframe.hpp"
#include "nodecallback.hpp"

#include <components/resource/animation.hpp>

namespace SceneUtil
{
    struct EmulatedAnimation
    {
        float mStartTime;
        float mStopTime;
        std::string mName;
    };

    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;

    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>
    {
    public:
        /// @brief Handles the animation for osgAnimation formats
        OsgAnimationController() = default;

        OsgAnimationController(const OsgAnimationController& copy, const osg::CopyOp& copyop);

        META_Object(SceneUtil, OsgAnimationController)

        osg::Callback* getAsCallback() override { return this; }

        /// @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;

        /// @brief Calls animation track update()
        void update(float time, const std::string& animationName);

        /// @brief Called every frame for osgAnimation
        void operator()(osg::Node*, osg::NodeVisitor*);

        /// @brief Sets details of the animations
        void setEmulatedAnimations(const std::vector<EmulatedAnimation>& emulatedAnimations);

        /// @brief Adds an animation track to a model
        void addMergedAnimationTrack(osg::ref_ptr<Resource::Animation> animationTrack);

    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;
    };
#ifdef _MSC_VER
#pragma warning(pop)
#endif
}

#endif