Files
Bret Curtis e8f6c25d1a Cache animation data as std::shared_ptr, dropping their osg::Object base
SceneUtil::KeyframeHolder and SceneUtil::AnimBlendRules are pure data — a
map of keyframe controllers and a vector of blend rules. Nothing attaches
them to a scene graph; both classes existed as osg::Object only because
the cache stored them via osg::ref_ptr. With the value-type seam from the
previous MR in place, they can be plain classes cached as
std::shared_ptr<const T>, and the TemplateRef pins in AnimBlendRulesManager
become an aliasing shared_ptr that keeps the cached base and override rules
alive while merged rules are in use.
2026-10-05 17:36:58 +02:00

55 lines
1.6 KiB
C++

#ifndef OPENMW_COMPONENTS_SCENEUTIL_KEYFRAME_HPP
#define OPENMW_COMPONENTS_SCENEUTIL_KEYFRAME_HPP
#include <map>
#include <optional>
#include <osg/Object>
#include <components/sceneutil/controller.hpp>
#include <components/sceneutil/textkeymap.hpp>
namespace SceneUtil
{
/// @note Derived classes are expected to derive from osg::Callback and implement getAsCallback().
class KeyframeController : public SceneUtil::Controller, public virtual osg::Object
{
public:
KeyframeController() {}
KeyframeController(const KeyframeController& copy, const osg::CopyOp& copyop)
: SceneUtil::Controller(copy)
{
}
std::shared_ptr<float> mTime = std::make_shared<float>(0.0f);
struct KfTransform
{
std::optional<osg::Vec3f> mTranslation;
std::optional<osg::Quat> mRotation;
std::optional<float> mScale;
};
virtual osg::Vec3f getTranslation(float time) const { return osg::Vec3f(); }
virtual KfTransform getCurrentTransformation(osg::NodeVisitor* nv) { return KfTransform(); }
/// @note We could drop this function in favour of osg::Object::asCallback from OSG 3.6 on.
virtual osg::Callback* getAsCallback() = 0;
};
/// Wrapper object containing the animation track and its KeyframeControllers.
struct KeyframeHolder
{
TextKeyMap mTextKeys;
/// Controllers mapped to node name.
using KeyframeControllerMap = std::map<std::string, osg::ref_ptr<const KeyframeController>>;
KeyframeControllerMap mKeyframeControllers;
};
}
#endif