RavEngine
Loading...
Searching...
No Matches
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_RUNTIME_SKELETON_H_
29#define OZZ_OZZ_ANIMATION_RUNTIME_SKELETON_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 math {
42struct SoaTransform;
43}
44namespace animation {
45
46// Forward declaration of SkeletonBuilder, used to instantiate a skeleton.
47namespace offline {
48class SkeletonBuilder;
49}
50
51// This runtime skeleton data structure provides a const-only access to joint
52// hierarchy, joint names and rest-pose. This structure is filled by the
53// SkeletonBuilder and can be serialize/deserialized.
54// Joint names, rest-poses and hierarchy information are all stored in separate
55// arrays of data (as opposed to joint structures for the RawSkeleton), in order
56// to closely match with the way runtime algorithms use them. Joint hierarchy is
57// packed as an array of parent jont indices (16 bits), stored in depth-first
58// order. This is enough to traverse the whole joint hierarchy. See
59// IterateJointsDF() from skeleton_utils.h that implements a depth-first
60// traversal utility.
61class OZZ_ANIMATION_DLL Skeleton {
62 public:
63 // Defines Skeleton constant values.
64 enum Constants {
65
66 // Defines the maximum number of joints.
67 // This is limited in order to control the number of bits required to store
68 // a joint index. Limiting the number of joints also helps handling worst
69 // size cases, like when it is required to allocate an array of joints on
70 // the stack.
71 kMaxJoints = 1024,
72
73 // Defines the maximum number of SoA elements required to store the maximum
74 // number of joints.
75 kMaxSoAJoints = (kMaxJoints + 3) / 4,
76
77 // Defines the index of the parent of the root joint (which has no parent in
78 // fact).
79 kNoParent = -1,
80 };
81
82 // Builds a default skeleton.
83 Skeleton();
84
85 // Allow move.
87 Skeleton& operator=(Skeleton&&);
88
89 // Disables copy and assignation.
90 Skeleton(Skeleton const&) = delete;
91 Skeleton& operator=(Skeleton const&) = delete;
92
93 // Declares the public non-virtual destructor.
94 ~Skeleton();
95
96 // Returns the number of joints of *this skeleton.
97 int num_joints() const { return static_cast<int>(joint_parents_.size()); }
98
99 // Returns the number of soa elements matching the number of joints of *this
100 // skeleton. This value is useful to allocate SoA runtime data structures.
101 int num_soa_joints() const { return (num_joints() + 3) / 4; }
102
103 // Returns joint's rest poses. Rest poses are stored in soa format.
104 span<const math::SoaTransform> joint_rest_poses() const {
105 return joint_rest_poses_;
106 }
107
108 // Returns joint's parent indices range.
109 span<const int16_t> joint_parents() const { return joint_parents_; }
110
111 // Returns joint's name collection.
112 span<const char* const> joint_names() const {
113 return span<const char* const>(joint_names_.begin(), joint_names_.end());
114 }
115
116 // Serialization functions.
117 // Should not be called directly but through io::Archive << and >> operators.
118 void Save(ozz::io::OArchive& _archive) const;
119 void Load(ozz::io::IArchive& _archive, uint32_t _version);
120
121 private:
122 // Internal allocation/deallocation function.
123 // Allocate returns the beginning of the contiguous buffer of names.
124 char* Allocate(size_t _char_count, size_t _num_joints);
125 void Deallocate();
126
127 // SkeletonBuilder class is allowed to instantiate an Skeleton.
128 friend class offline::SkeletonBuilder;
129
130 // Buffers below store joint informations in joing depth first order. Their
131 // size is equal to the number of joints of the skeleton.
132
133 // Rest pose of every joint in local space.
134 span<math::SoaTransform> joint_rest_poses_;
135
136 // Array of joint parent indexes.
137 span<int16_t> joint_parents_;
138
139 // Stores the name of every joint in an array of c-strings.
140 span<char*> joint_names_;
141};
142} // namespace animation
143
144namespace io {
145OZZ_IO_TYPE_VERSION(2, animation::Skeleton)
146OZZ_IO_TYPE_TAG("ozz-skeleton", animation::Skeleton)
147} // namespace io
148} // namespace ozz
149#endif // OZZ_OZZ_ANIMATION_RUNTIME_SKELETON_H_
Definition skeleton.h:61
Definition skeleton_builder.h:47
Definition archive.h:174
Definition archive.h:105
Definition span.h:37