vsg: include/vsg/animation/Animation.h Source File

vsg 1.1.3 VulkanSceneGraph library

Loading...
Searching...
No Matches
Animation.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2024 Robert Osfield
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
13</editor-fold> */
14
15#include <vsg/core/Allocator.h>
16#include <vsg/core/Inherit.h>
17#include <vsg/core/Visitor.h>
18
19namespace vsg
20{
21
23 class VSG_DECLSPEC AnimationSampler : public Inherit<Visitor, AnimationSampler>
24 {
25 public:
26 AnimationSampler();
27 AnimationSampler(const AnimationSampler& rhs, const CopyOp& copyop = {});
28
29 std::string name;
30
31 virtual void update(double time) = 0;
32 virtual double maxTime() const = 0;
33
34 public:
35 int compare(const Object& rhs) const override;
36
37 void read(Input& input) override;
38 void write(Output& output) const override;
39 };
40 VSG_type_name(vsg::AnimationSampler);
41
43 class VSG_DECLSPEC Animation : public Inherit<Object, Animation>
44 {
45 public:
46 Animation();
47 Animation(const Animation& rhs, const CopyOp& copyop = {});
48
49 std::string name;
50
51 enum Mode
52 {
53 ONCE,
54 REPEAT,
55 FORWARD_AND_BACK
56 };
57
59 Mode mode = REPEAT;
60
62 double time = 0.0;
63
65 double speed = 1.0;
66
68 using Samplers = std::vector<ref_ptr<AnimationSampler>>;
69 Samplers samplers;
70
72 virtual bool start(double simulationTime, double startTime = 0.0);
73
75 virtual bool update(double simulationTime);
76
78 virtual bool stop(double simulationTime);
79
81 bool active() const { return _active; }
82
84 virtual double maxTime() const;
85
86 public:
87 ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return Animation::create(*this, copyop); }
88 int compare(const Object& rhs) const override;
89
90 template<class N, class V>
91 static void t_traverse(N& node, V& visitor)
92 {
93 for (auto& sampler : node.samplers) sampler->accept(visitor);
94 }
95 void traverse(Visitor& visitor) override { t_traverse(*this, visitor); }
96 void traverse(ConstVisitor& visitor) const override { t_traverse(*this, visitor); }
97
98 void read(Input& input) override;
99 void write(Output& output) const override;
100
101 protected:
102 // start time point of animation to be used to calaculate the current time to use when looking up current values
103 bool _active = false;
104 double _previousSimulationTime = 0.0;
105 double _maxTime = 0.0;
106 };
107 VSG_type_name(vsg::Animation);
108
109 using Animations = std::vector<ref_ptr<Animation>, allocator_affinity_nodes<ref_ptr<Animation>>>;
110
111} // namespace vsg
vsg::Animation
Animation class that controls a single animation made up of one more samplers.
Definition Animation.h:44
vsg::Animation::maxTime
virtual double maxTime() const
compute the max time from the highest time keyframes in the available samplers
vsg::Animation::clone
ref_ptr< Object > clone(const CopyOp &copyop={}) const override
Definition Animation.h:87
vsg::Animation::active
bool active() const
return true if this animation is being actively updated.
Definition Animation.h:81
vsg::Animation::Samplers
std::vector< ref_ptr< AnimationSampler > > Samplers
Animation samplers provide the means for mapping the local animation time.
Definition Animation.h:68
vsg::Animation::update
virtual bool update(double simulationTime)
update the samplers
vsg::Animation::stop
virtual bool stop(double simulationTime)
signal that this animation is to stop
vsg::Animation::compare
int compare(const Object &rhs) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
vsg::Animation::start
virtual bool start(double simulationTime, double startTime=0.0)
initialize this animation start time
vsg::AnimationSampler
Base class for animation samplers that sample animation data and set associated scene graph objects.
Definition Animation.h:24
vsg::AnimationSampler::compare
int compare(const Object &rhs) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
vsg::CopyOp
Definition Object.h:42
vsg::Inherit
Definition Inherit.h:28
vsg::Input
Definition Input.h:44
vsg::Object
Definition Object.h:60
vsg::Output
Definition Output.h:41
vsg::Visitor
Definition Visitor.h:172
vsg::ref_ptr
Definition ref_ptr.h:22