RavEngine
Loading...
Searching...
No Matches
raw_track.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_TRACK_H_
29#define OZZ_OZZ_ANIMATION_OFFLINE_RAW_TRACK_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// Interpolation mode.
44 enum Value {
45 kStep, // All values following this key, up to the next key, are equal.
46 kLinear, // All value between this key and the next are linearly
47 // interpolated.
48 };
49};
50
51// Keyframe data structure.
52template <typename _ValueType>
54 typedef _ValueType ValueType;
55 RawTrackInterpolation::Value interpolation;
56 float ratio;
57 ValueType value;
58};
59
60namespace internal {
61
62// Offline user-channel animation track type implementation.
63// This offline track data structure is meant to be used for user-channel
64// tracks, aka animation of variables that aren't joint transformation. It is
65// available for tracks of 1 to 4 floats (RawFloatTrack, RawFloat2Track, ...,
66// RawFloat4Track) and quaternions (RawQuaternionTrack). Quaternions differ from
67// float4 because of the specific interpolation and comparison treatment they
68// require. As all other Raw data types, they are not intended to be used in run
69// time. They are used to define the offline track object that can be converted
70// to the runtime one using the a ozz::animation::offline::TrackBuilder. This
71// animation structure exposes a single sequence of keyframes. Keyframes are
72// defined with a ratio, a value and an interpolation mode:
73// - Ratio: A track has no duration, so it uses ratios between 0 (beginning of
74// the track) and 1 (the end), instead of times. This allows to avoid any
75// discrepancy between the durations of tracks and the animation they match
76// with.
77// - Value: The animated value (float, ... float4, quaternion).
78// - Interpolation mode (`ozz::animation::offline::RawTrackInterpolation`):
79// Defines how value is interpolated with the next key. Track structure is then
80// a sorted vector of keyframes. RawTrack structure exposes a Validate()
81// function to check that all the following rules are respected:
82// 1. Keyframes' ratios are sorted in a strict ascending order.
83// 2. Keyframes' ratios are all within [0,1] range.
84// RawTrack that would fail this validation will fail to be converted by
85// the RawTrackBuilder.
86template <typename _ValueType>
87struct OZZ_ANIMOFFLINE_DLL RawTrack {
88 typedef _ValueType ValueType;
90
91 // Validates that all the following rules are respected:
92 // 1. Keyframes' ratios are sorted in a strict ascending order.
93 // 2. Keyframes' ratios are all within [0,1] range.
94 bool Validate() const;
95
96 // Uses intrusive serialization option, as a way to factorize code.
97 // Version and Tag should still be defined for each specialization.
98 void Save(io::OArchive& _archive) const;
99 void Load(io::IArchive& _archive, uint32_t _version);
100
101 // Sequence of keyframes, expected to be sorted.
102 typedef typename ozz::vector<Keyframe> Keyframes;
103 Keyframes keyframes;
104
105 // Name of the track.
106 string name;
107};
108} // namespace internal
109
110// Offline user-channel animation track type instantiation.
111struct OZZ_ANIMOFFLINE_DLL RawFloatTrack : public internal::RawTrack<float> {};
112struct OZZ_ANIMOFFLINE_DLL RawFloat2Track
113 : public internal::RawTrack<math::Float2> {};
114struct OZZ_ANIMOFFLINE_DLL RawFloat3Track
115 : public internal::RawTrack<math::Float3> {};
116struct OZZ_ANIMOFFLINE_DLL RawFloat4Track
117 : public internal::RawTrack<math::Float4> {};
118struct OZZ_ANIMOFFLINE_DLL RawQuaternionTrack
119 : public internal::RawTrack<math::Quaternion> {};
120} // namespace offline
121} // namespace animation
122
123namespace io {
124OZZ_IO_TYPE_VERSION(1, animation::offline::RawFloatTrack)
125OZZ_IO_TYPE_TAG("ozz-raw_float_track", animation::offline::RawFloatTrack)
126OZZ_IO_TYPE_VERSION(1, animation::offline::RawFloat2Track)
127OZZ_IO_TYPE_TAG("ozz-raw_float2_track", animation::offline::RawFloat2Track)
128OZZ_IO_TYPE_VERSION(1, animation::offline::RawFloat3Track)
129OZZ_IO_TYPE_TAG("ozz-raw_float3_track", animation::offline::RawFloat3Track)
130OZZ_IO_TYPE_VERSION(1, animation::offline::RawFloat4Track)
131OZZ_IO_TYPE_TAG("ozz-raw_float4_track", animation::offline::RawFloat4Track)
132OZZ_IO_TYPE_VERSION(1, animation::offline::RawQuaternionTrack)
133OZZ_IO_TYPE_TAG("ozz-raw_quat_track", animation::offline::RawQuaternionTrack)
134} // namespace io
135} // namespace ozz
136#endif // OZZ_OZZ_ANIMATION_OFFLINE_RAW_TRACK_H_
Definition archive.h:174
Definition archive.h:105
Definition raw_track.h:113
Definition raw_track.h:115
Definition raw_track.h:117
Definition raw_track.h:111