Overte C++ Documentation
AnimSkeleton.h
1 //
2 // AnimSkeleton.h
3 //
4 // Created by Anthony J. Thibault on 9/2/15.
5 // Copyright (c) 2015 High Fidelity, Inc. All rights reserved.
6 //
7 // Distributed under the Apache License, Version 2.0.
8 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
9 //
10 
11 #ifndef hifi_AnimSkeleton
12 #define hifi_AnimSkeleton
13 
14 #include <vector>
15 #include <glm/glm.hpp>
16 #include <glm/gtc/quaternion.hpp>
17 
18 #include <FBXSerializer.h>
19 #include "AnimPose.h"
20 
21 class AnimSkeleton {
22 public:
23  using Pointer = std::shared_ptr<AnimSkeleton>;
24  using ConstPointer = std::shared_ptr<const AnimSkeleton>;
25 
26  explicit AnimSkeleton(const HFMModel& hfmModel);
27  explicit AnimSkeleton(const std::vector<HFMJoint>& joints, const QMap<int, glm::quat> jointOffsets);
28 
29  int nameToJointIndex(const QString& jointName) const;
30  const QString& getJointName(int jointIndex) const;
31  int getNumJoints() const;
32  int getChainDepth(int jointIndex) const;
33 
34  static const int INVALID_JOINT_INDEX { -1 };
35 
36  // the default poses are the orientations of the joints on frame 0.
37  const AnimPose& getRelativeDefaultPose(int jointIndex) const;
38  const AnimPoseVec& getRelativeDefaultPoses() const { return _relativeDefaultPoses; }
39  const AnimPose& getAbsoluteDefaultPose(int jointIndex) const;
40  const AnimPoseVec& getAbsoluteDefaultPoses() const { return _absoluteDefaultPoses; }
41  const glm::mat4& getGeometryOffset() const { return _geometryOffset; }
42 
43  // get pre transform which should include FBX pre potations
44  const AnimPose& getPreRotationPose(int jointIndex) const;
45 
46  // get post transform which might include FBX offset transformations
47  const AnimPose& getPostRotationPose(int jointIndex) const;
48 
49  int getParentIndex(int jointIndex) const {
50  return _parentIndices[jointIndex];
51  }
52 
53  std::vector<int> getChildrenOfJoint(int jointIndex) const;
54 
55  AnimPose getAbsolutePose(int jointIndex, const AnimPoseVec& relativePoses) const;
56 
57  void convertRelativePosesToAbsolute(AnimPoseVec& poses) const;
58  void convertAbsolutePosesToRelative(AnimPoseVec& poses) const;
59 
60  void convertRelativeRotationsToAbsolute(std::vector<glm::quat>& rotations) const;
61  void convertAbsoluteRotationsToRelative(std::vector<glm::quat>& rotations) const;
62 
63  void saveNonMirroredPoses(const AnimPoseVec& poses) const;
64  void restoreNonMirroredPoses(AnimPoseVec& poses) const;
65 
66  void mirrorRelativePoses(AnimPoseVec& poses) const;
67  void mirrorAbsolutePoses(AnimPoseVec& poses) const;
68 
69  void dump(bool verbose) const;
70  void dump(const AnimPoseVec& poses) const;
71 
72  std::vector<int> lookUpJointIndices(const std::vector<QString>& jointNames) const;
73  const HFMCluster getClusterBindMatricesOriginalValues(const int meshIndex, const int clusterIndex) const { return _clusterBindMatrixOriginalValues[meshIndex][clusterIndex]; }
74 
75 protected:
76  void buildSkeletonFromJoints(const std::vector<HFMJoint>& joints, const QMap<int, glm::quat> jointOffsets);
77 
78  std::vector<HFMJoint> _joints;
79  std::vector<int> _parentIndices;
80  int _jointsSize { 0 };
81  AnimPoseVec _relativeDefaultPoses;
82  AnimPoseVec _absoluteDefaultPoses;
83  AnimPoseVec _relativePreRotationPoses;
84  AnimPoseVec _relativePostRotationPoses;
85  mutable AnimPoseVec _nonMirroredPoses;
86  std::vector<int> _nonMirroredIndices;
87  std::vector<int> _mirrorMap;
88  QHash<QString, int> _jointIndicesByName;
89  std::vector<std::vector<HFMCluster>> _clusterBindMatrixOriginalValues;
90  glm::mat4 _geometryOffset;
91 
92  // no copies
93  AnimSkeleton(const AnimSkeleton&) = delete;
94  AnimSkeleton& operator=(const AnimSkeleton&) = delete;
95 };
96 
97 #endif
A single binding to a joint.
Definition: HFM.h:123
The runtime model format.
Definition: HFM.h:302