RavEngine
Loading...
Searching...
No Matches
raw_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_OFFLINE_RAW_ANIMATION_H_
29#define OZZ_OZZ_ANIMATION_OFFLINE_RAW_ANIMATION_H_
30
31#include "ozz/animation/offline/export.h"
32#include "ozz/base/containers/string.h"
33#include "ozz/base/containers/vector.h"
34#include "ozz/base/io/archive_traits.h"
35#include "ozz/base/maths/quaternion.h"
36#include "ozz/base/maths/vec_float.h"
37
38namespace ozz {
39namespace animation {
40namespace offline {
41
42// Offline animation type.
43// This animation type is not intended to be used in run time. It is used to
44// define the offline animation object that can be converted to the runtime
45// animation using the AnimationBuilder.
46// This animation structure exposes tracks of keyframes. Keyframes are defined
47// with a time and a value which can either be a translation (3 float x, y, z),
48// a rotation (a quaternion) or scale coefficient (3 floats x, y, z). Tracks are
49// defined as a set of three different std::vectors (translation, rotation and
50// scales). Animation structure is then a vector of tracks, along with a
51// duration value.
52// Finally the RawAnimation structure exposes Validate() function to check that
53// it is valid, meaning that all the following rules are respected:
54// 1. Animation duration is greater than 0.
55// 2. Keyframes' time are sorted in a strict ascending order.
56// 3. Keyframes' time are all within [0,animation duration] range.
57// Animations that would fail this validation will fail to be converted by the
58// AnimationBuilder.
59struct OZZ_ANIMOFFLINE_DLL RawAnimation {
60 // Constructs a valid RawAnimation with a 1s default duration.
62
63 // Tests for *this validity.
64 // Returns true if animation data (duration, tracks) is valid:
65 // 1. Animation duration is greater than 0.
66 // 2. Keyframes' time are sorted in a strict ascending order.
67 // 3. Keyframes' time are all within [0,animation duration] range.
68 bool Validate() const;
69
70 // Get the estimated animation's size in bytes.
71 size_t size() const;
72
73 // Defines a raw translation key frame.
75 // Key frame time.
76 float time;
77
78 // Key frame value.
79 typedef math::Float3 Value;
80 Value value;
81
82 // Provides identity transformation for a translation key.
83 static math::Float3 identity() { return math::Float3::zero(); }
84 };
85
86 // Defines a raw rotation key frame.
87 struct RotationKey {
88 // Key frame time.
89 float time;
90
91 // Key frame value.
92 typedef math::Quaternion Value;
93 math::Quaternion value;
94
95 // Provides identity transformation for a rotation key.
96 static math::Quaternion identity() { return math::Quaternion::identity(); }
97 };
98
99 // Defines a raw scaling key frame.
100 struct ScaleKey {
101 // Key frame time.
102 float time;
103
104 // Key frame value.
105 typedef math::Float3 Value;
106 math::Float3 value;
107
108 // Provides identity transformation for a scale key.
109 static math::Float3 identity() { return math::Float3::one(); }
110 };
111
112 // Defines a track of key frames for a bone, including translation, rotation
113 // and scale.
114 struct JointTrack {
115 typedef ozz::vector<TranslationKey> Translations;
116 Translations translations;
117 typedef ozz::vector<RotationKey> Rotations;
118 Rotations rotations;
119 typedef ozz::vector<ScaleKey> Scales;
120 Scales scales;
121
122 // Validates track. See RawAnimation::Validate for more details.
123 // Use an infinite value for _duration if unknown. This will validate
124 // keyframe orders, but not maximum duration.
125 bool Validate(float _duration) const;
126 };
127
128 // Returns the number of tracks of this animation.
129 int num_tracks() const { return static_cast<int>(tracks.size()); }
130
131 // Stores per joint JointTrack, ie: per joint animation key-frames.
132 // tracks_.size() gives the number of animated joints.
133 ozz::vector<JointTrack> tracks;
134
135 // The duration of the animation. All the keys of a valid RawAnimation are in
136 // the range [0,duration].
137 float duration;
138
139 // Name of the animation.
140 ozz::string name;
141};
142} // namespace offline
143} // namespace animation
144namespace io {
145OZZ_IO_TYPE_VERSION(3, animation::offline::RawAnimation)
146OZZ_IO_TYPE_TAG("ozz-raw_animation", animation::offline::RawAnimation)
147
148// Should not be called directly but through io::Archive << and >> operators.
149template <>
150struct OZZ_ANIMOFFLINE_DLL Extern<animation::offline::RawAnimation> {
151 static void Save(OArchive& _archive,
152 const animation::offline::RawAnimation* _animations,
153 size_t _count);
154 static void Load(IArchive& _archive,
155 animation::offline::RawAnimation* _animations, size_t _count,
156 uint32_t _version);
157};
158} // namespace io
159} // namespace ozz
160#endif // OZZ_OZZ_ANIMATION_OFFLINE_RAW_ANIMATION_H_
Definition archive.h:174
Definition archive.h:105
Definition raw_animation.h:59
Definition archive.h:271
Definition vec_float.h:67
Definition quaternion.h:41