RavEngine
Loading...
Searching...
No Matches
animation.h
1//----------------------------------------------------------------------------//
2// //
3// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
4// and distributed under the MIT License (MIT). //
5// //
6// Copyright (c) Guillaume Blanc //
7// //
8// Permission is hereby granted, free of charge, to any person obtaining a //
9// copy of this software and associated documentation files (the "Software"), //
10// to deal in the Software without restriction, including without limitation //
11// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
12// and/or sell copies of the Software, and to permit persons to whom the //
13// Software is furnished to do so, subject to the following conditions: //
14// //
15// The above copyright notice and this permission notice shall be included in //
16// all copies or substantial portions of the Software. //
17// //
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
21// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
24// DEALINGS IN THE SOFTWARE. //
25// //
26//----------------------------------------------------------------------------//
27
28#ifndef OZZ_OZZ_ANIMATION_RUNTIME_ANIMATION_H_
29#define OZZ_OZZ_ANIMATION_RUNTIME_ANIMATION_H_
30
31#include "ozz/animation/runtime/export.h"
32#include "ozz/base/io/archive_traits.h"
33#include "ozz/base/platform.h"
34#include "ozz/base/span.h"
35
36namespace ozz {
37namespace io {
38class IArchive;
39class OArchive;
40} // namespace io
41namespace animation {
42
43// Forward declares the AnimationBuilder, used to instantiate an Animation.
44namespace offline {
45class AnimationBuilder;
46}
47
48// Forward declaration of key frame's type.
49struct Float3Key;
50struct QuaternionKey;
51
52// Defines a runtime skeletal animation clip.
53// The runtime animation data structure stores animation keyframes, for all the
54// joints of a skeleton. This structure is usually filled by the
55// AnimationBuilder and deserialized/loaded at runtime.
56// For each transformation type (translation, rotation and scale), Animation
57// structure stores a single array of keyframes that contains all the tracks
58// required to animate all the joints of a skeleton, matching breadth-first
59// joints order of the runtime skeleton structure. In order to optimize cache
60// coherency when sampling the animation, Keyframes in this array are sorted by
61// time, then by track number.
62class OZZ_ANIMATION_DLL Animation {
63 public:
64 // Builds a default animation.
65 Animation();
66
67 // Allow moves.
69 Animation& operator=(Animation&&);
70
71 // Delete copies.
72 Animation(Animation const&) = delete;
73 Animation& operator=(Animation const&) = delete;
74
75 // Declares the public non-virtual destructor.
76 ~Animation();
77
78 // Gets the animation clip duration.
79 float duration() const { return duration_; }
80
81 // Gets the number of animated tracks.
82 int num_tracks() const { return num_tracks_; }
83
84 // Returns the number of SoA elements matching the number of tracks of *this
85 // animation. This value is useful to allocate SoA runtime data structures.
86 int num_soa_tracks() const { return (num_tracks_ + 3) / 4; }
87
88 // Gets animation name.
89 const char* name() const { return name_ ? name_ : ""; }
90
91 // Gets the buffer of translations keys.
92 span<const Float3Key> translations() const { return translations_; }
93
94 // Gets the buffer of rotation keys.
95 span<const QuaternionKey> rotations() const { return rotations_; }
96
97 // Gets the buffer of scale keys.
98 span<const Float3Key> scales() const { return scales_; }
99
100 // Get the estimated animation's size in bytes.
101 size_t size() const;
102
103 // Serialization functions.
104 // Should not be called directly but through io::Archive << and >> operators.
105 void Save(ozz::io::OArchive& _archive) const;
106 void Load(ozz::io::IArchive& _archive, uint32_t _version);
107
108 private:
109 // AnimationBuilder class is allowed to instantiate an Animation.
110 friend class offline::AnimationBuilder;
111
112 // Internal destruction function.
113 void Allocate(size_t _name_len, size_t _translation_count,
114 size_t _rotation_count, size_t _scale_count);
115 void Deallocate();
116
117 // Duration of the animation clip.
118 float duration_;
119
120 // The number of joint tracks. Can differ from the data stored in translation/
121 // rotation/scale buffers because of SoA requirements.
122 int num_tracks_;
123
124 // Animation name.
125 char* name_;
126
127 // Stores all translation/rotation/scale keys begin and end of buffers.
128 span<Float3Key> translations_;
129 span<QuaternionKey> rotations_;
130 span<Float3Key> scales_;
131};
132} // namespace animation
133
134namespace io {
135OZZ_IO_TYPE_VERSION(6, animation::Animation)
136OZZ_IO_TYPE_TAG("ozz-animation", animation::Animation)
137} // namespace io
138} // namespace ozz
139#endif // OZZ_OZZ_ANIMATION_RUNTIME_ANIMATION_H_
Definition animation.h:62
Definition animation_builder.h:48
Definition archive.h:174
Definition archive.h:105
Definition span.h:37