COGS
Computer Graphics Structures library
Skeleton.h
1 /*
2  Copyright (C) Skeletex Research, s.r.o. - All Rights Reserved
3  Unauthorized copying of this file, via any medium is strictly prohibited
4  Proprietary and confidential
5 */
6 #ifndef COGS_SKELETON_H
7 #define COGS_SKELETON_H
8 #include <map>
9 #include <Utils/GeometryStructures.h>
10 #include <COGS/SkeletonPose.h>
11 #include <COGS/API.h>
12 
13 
14 
15 namespace cogs
16 {
17  class Bone;
18 
19 
20 
22  class COGS_API Skeleton
23  {
24  public:
25 
27  struct BaseProperty
28  {
29  BaseProperty(const uint32_t size)
30  : size_(size)
31  {};
32  virtual ~BaseProperty() {};
33 
34  const uint32_t size_;
35  };
36 
42  template<class T>
43  struct Property : public BaseProperty
44  {
45  Property(const T &new_data)
46  : BaseProperty(sizeof(*this)), data_(new_data)
47  {};
48 
49  virtual ~Property() override {};
50 
52  const T GetData() const
53  {
54  return data_;
55  };
56  private:
57  const T data_;
58  };
59 
61  Skeleton();
62 
64  Skeleton(const Skeleton &skeleton);
65 
67  Skeleton &operator=(const Skeleton &skeleton);
68 
70  ~Skeleton();
71 
73  std::string GetName() const;
74 
76  void SetName(const std::string &new_name);
77 
79  std::vector<Bone *> GetAllBones() const;
80 
82  std::vector<std::string> GetAllBoneCaptions() const;
83 
85  std::vector<Bone *> GetBones(const std::vector<std::string> &bone_captions) const;
86 
88  Bone *GetBone(const uint32_t id) const;
89 
91  Bone *GetBone(const std::string &bone_caption) const;
92 
94  std::vector<Bone *> GetRootBones() const;
95 
97  void Clear();
98 
100  unsigned GetBoneCount() const;
101 
103  Bone *AddBone(const std::string &name, const std::string &parent_name, const glm::vec3 &tail_position);
104 
106  Bone *AddBone(const std::string &name, const std::string &parent_name, const BoneTransform &transform);
107 
109  Bone *AddBoneToRoot(const std::string &name, const glm::vec3 &tail_position);
110 
112  Bone *AddBoneToRoot(const std::string &name, const BoneTransform &transform);
113 
115  void RollBasis(const std::string &bone_name, const float roll_angle);
116 
118  void ApplyBoneLengths(const std::vector<float> &bone_lengths);
119 
126  void SortBySkeleton(const cogs::Skeleton &ref_skeleton);
127 
140  void InterpolateTo(const cogs::Skeleton &target_skel, float target_weight, cogs::Skeleton *out_skeleton) const;
141 
143  SkeletonPose GetCurrentPose() const;
144 
146  SkeletonPose GetCurrentPose(const std::vector<std::string> &bone_order) const;
147 
149  void ApplyPose(const SkeletonPose &pose, bool ignore_root_transform = false);
150 
152  void ApplyBindpose();
153 
155  void ApplyCurrentPoseAsBindpose();
156 
158  [[deprecated]]
159  BaseProperty *GetProperty(const std::string &prop) const;
160 
162  template<class T>
163  [[deprecated]]
164  T GetProperty(const std::string &prop) const
165  {
166  assert(HasProperty(prop));
167  return ((Property<T> *)(properties_.at(prop)))->GetData();
168  }
169 
171  template<class T>
172  [[deprecated]]
173  void SetProperty(const std::string &prop, const T &value)
174  {
175  if (HasProperty(prop))
176  {
177  delete properties_[prop];
178  }
179  properties_[prop] = new Property<T>(value);
180  }
181 
183  [[deprecated]]
184  bool HasProperty(const std::string &prop) const;
185 
188 
189  protected:
190 
191  std::string name_;
192 
193  cogs::Transform bind_transform;
194 
195  std::unordered_map<std::string, BaseProperty *> properties_;
196 
197  std::map <std::string, Bone *> bone_for_name_;
198  std::vector<Bone *> bones_;
199  std::vector<Bone *> root_bones_;
200  unsigned bone_count_ = 0;
201 
202  Bone *CreateNewBone(const std::string &caption);
203  Bone *CreateBoneClone(const cogs::Bone *bone);
204  void MakeCloneOf(const Skeleton &skeleton);
205 
206  void OnTransformChange();
207  };
208 
209 
211  COGS_API std::vector<geom::LineSegment3> ToLineSegments(const cogs::Skeleton &skeleton);
212 
214  COGS_API std::vector<cogs::Skeleton> SplitIntoSingleBoneSkeletons(const cogs::Skeleton &skeleton);
215 
217  COGS_API geom::Aabb3 GetAabb3(const Skeleton &skeleton);
218 }
219 
220 #endif /* !COGS_SKELETON_H */
Namespace of "Computer Graphic Structures" library, which implement many core classes and structures...
Definition: AabbHierarchy.h:8
Abstract helper class used for storage of skeleton properties.
Definition: Skeleton.h:27
Class used for effective management of transformation matrix by handling translation, rotation and scaling separately.
Definition: Transform.h:26
const T GetData() const
Returns stored data.
Definition: Skeleton.h:52
3D Graph structure, usually representing topology of a 3D model.
Definition: Skeleton.h:22
Class used for effective management and manipulation with bone transformation.
Definition: BoneTransform.h:24
void SetProperty(const std::string &prop, const T &value)
Sets specific skeleton property. If property do not exist yet, creates new property record...
Definition: Skeleton.h:173
COGS_API std::vector< cogs::Skeleton > SplitIntoSingleBoneSkeletons(const cogs::Skeleton &skeleton)
Splits skeleton into one bone skeletons.
Structure used for storage of specific configuration of bone transformations in a skeleton...
Definition: SkeletonPose.h:8
cogs::Transform transform
Transformation of the entire skeleton.
Definition: Skeleton.h:187
T GetProperty(const std::string &prop) const
Returns specific skeleton property.
Definition: Skeleton.h:164
COGS_API geom::Aabb3 GetAabb3(const Skeleton &skeleton)
Returns bounding box wrapping all skeleton bones.
Template class used for storage of skeleton properties.
Definition: Skeleton.h:43
COGS_API std::vector< geom::LineSegment3 > ToLineSegments(const cogs::Skeleton &skeleton)
Converts bones of skeleton to the array of line segments ordered by bone ids.