RavEngine
Loading...
Searching...
No Matches
raw_skeleton.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_SKELETON_H_
29#define OZZ_OZZ_ANIMATION_OFFLINE_RAW_SKELETON_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/transform.h"
36
37namespace ozz {
38namespace animation {
39namespace offline {
40
41// Off-line skeleton type.
42// This skeleton type is not intended to be used in run time. It is used to
43// define the offline skeleton object that can be converted to the runtime
44// skeleton using the SkeletonBuilder. This skeleton structure exposes joints'
45// hierarchy. A joint is defined with a name, a transformation (its rest_pose
46// pose), and its children. Children are exposed as a public std::vector of
47// joints. This same type is used for skeleton roots, also exposed from the
48// public API. The public API exposed through std:vector's of joints can be used
49// freely with the only restriction that the total number of joints does not
50// exceed Skeleton::kMaxJoints.
51struct OZZ_ANIMOFFLINE_DLL RawSkeleton {
52 // Construct an empty skeleton.
54
55 // The destructor is responsible for deleting the roots and their hierarchy.
57
58 // Offline skeleton joint type.
59 struct Joint {
60 // Type of the list of children joints.
61 typedef ozz::vector<Joint> Children;
62
63 // Children joints.
64 Children children;
65
66 // The name of the joint.
67 ozz::string name;
68
69 // Joint rest pose transformation in local space.
70 math::Transform transform;
71 };
72
73 // Tests for *this validity.
74 // Returns true on success or false on failure if the number of joints exceeds
75 // ozz::Skeleton::kMaxJoints.
76 bool Validate() const;
77
78 // Returns the number of joints of *this animation.
79 // This function is not constant time as it iterates the hierarchy of joints
80 // and counts them.
81 int num_joints() const;
82
83 // Declares the skeleton's roots. Can be empty if the skeleton has no joint.
84 Joint::Children roots;
85};
86
87namespace {
88// Internal function used to iterate through joint hierarchy depth-first.
89template <typename _Fct>
90inline void _IterHierarchyRecurseDF(
91 const RawSkeleton::Joint::Children& _children,
92 const RawSkeleton::Joint* _parent, _Fct& _fct) {
93 for (size_t i = 0; i < _children.size(); ++i) {
94 const RawSkeleton::Joint& current = _children[i];
95 _fct(current, _parent);
96 _IterHierarchyRecurseDF(current.children, &current, _fct);
97 }
98}
99
100// Internal function used to iterate through joint hierarchy breadth-first.
101template <typename _Fct>
102inline void _IterHierarchyRecurseBF(
103 const RawSkeleton::Joint::Children& _children,
104 const RawSkeleton::Joint* _parent, _Fct& _fct) {
105 for (size_t i = 0; i < _children.size(); ++i) {
106 const RawSkeleton::Joint& current = _children[i];
107 _fct(current, _parent);
108 }
109 for (size_t i = 0; i < _children.size(); ++i) {
110 const RawSkeleton::Joint& current = _children[i];
111 _IterHierarchyRecurseBF(current.children, &current, _fct);
112 }
113}
114} // namespace
115
116// Applies a specified functor to each joint in a depth-first order.
117// _Fct is of type void(const Joint& _current, const Joint* _parent) where the
118// first argument is the child of the second argument. _parent is null if the
119// _current joint is the root.
120template <typename _Fct>
121inline _Fct IterateJointsDF(const RawSkeleton& _skeleton, _Fct _fct) {
122 _IterHierarchyRecurseDF(_skeleton.roots, nullptr, _fct);
123 return _fct;
124}
125
126// Applies a specified functor to each joint in a breadth-first order.
127// _Fct is of type void(const Joint& _current, const Joint* _parent) where the
128// first argument is the child of the second argument. _parent is null if the
129// _current joint is the root.
130template <typename _Fct>
131inline _Fct IterateJointsBF(const RawSkeleton& _skeleton, _Fct _fct) {
132 _IterHierarchyRecurseBF(_skeleton.roots, nullptr, _fct);
133 return _fct;
134}
135} // namespace offline
136} // namespace animation
137namespace io {
138OZZ_IO_TYPE_VERSION(1, animation::offline::RawSkeleton)
139OZZ_IO_TYPE_TAG("ozz-raw_skeleton", animation::offline::RawSkeleton)
140
141// Should not be called directly but through io::Archive << and >> operators.
142template <>
143struct OZZ_ANIMOFFLINE_DLL Extern<animation::offline::RawSkeleton> {
144 static void Save(OArchive& _archive,
145 const animation::offline::RawSkeleton* _skeletons,
146 size_t _count);
147 static void Load(IArchive& _archive,
148 animation::offline::RawSkeleton* _skeletons, size_t _count,
149 uint32_t _version);
150};
151} // namespace io
152} // namespace ozz
153#endif // OZZ_OZZ_ANIMATION_OFFLINE_RAW_SKELETON_H_
Definition archive.h:174
Definition archive.h:105
Definition raw_skeleton.h:51
Definition archive.h:271
Definition transform.h:40