All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
skelDefinition.h
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef USDSKEL_SKELDEFINITION_H
25 #define USDSKEL_SKELDEFINITION_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/usdSkel/api.h"
31 
32 #include "pxr/base/gf/matrix4d.h"
33 #include "pxr/base/gf/matrix4f.h"
34 
35 #include "pxr/base/tf/declarePtrs.h"
36 #include "pxr/base/tf/hashmap.h"
37 #include "pxr/base/tf/refBase.h"
38 #include "pxr/base/tf/weakBase.h"
39 
40 #include "pxr/usd/usdSkel/skeleton.h"
41 #include "pxr/usd/usdSkel/topology.h"
42 
43 #include <atomic>
44 #include <mutex>
45 
46 
47 PXR_NAMESPACE_OPEN_SCOPE
48 
49 
51 
52 
60 {
61 public:
62  virtual ~UsdSkel_SkelDefinition() {}
63 
66  static UsdSkel_SkelDefinitionRefPtr New(const UsdSkelSkeleton& skel);
67 
68  explicit operator bool() const {
69  return static_cast<bool>(_skel);
70  }
71 
72  const UsdSkelSkeleton& GetSkeleton() const { return _skel; }
73 
74  const VtTokenArray& GetJointOrder() const { return _jointOrder; }
75 
76  const UsdSkelTopology& GetTopology() const { return _topology; }
77 
79  template <typename Matrix4>
81 
83  template <typename Matrix4>
85 
87  template <typename Matrix4>
89 
91  template <typename Matrix4>
93 
95  template <typename Matrix4>
97 
99  bool HasBindPose ();
100 
102  bool HasRestPose ();
103 
104 private:
106 
107  bool _Init(const UsdSkelSkeleton& skel);
108 
109  template <int ComputeFlag, typename Matrix4>
110  bool _GetJointSkelRestTransforms(VtArray<Matrix4>* xforms);
111 
112  template <int ComputeFlag, typename Matrix4>
113  bool _GetJointWorldInverseBindTransforms(VtArray<Matrix4>* xforms);
114 
115  template <int ComputeFlag, typename Matrix4>
116  bool _GetJointLocalInverseRestTransforms(VtArray<Matrix4>* xforms);
117 
118  template <int ComputeFlag, typename Matrix4>
119  bool _ComputeJointSkelRestTransforms();
120 
121  template <int ComputeFlag, typename Matrix4>
122  bool _ComputeJointWorldInverseBindTransforms();
123 
124  template <int ComputeFlag, typename Matrix4>
125  bool _ComputeJointLocalInverseRestTransforms();
126 
129  struct _XformHolder {
130  template <typename Matrix4>
131  VtArray<Matrix4>& Get();
132 
133  template <typename Matrix4>
134  const VtArray<Matrix4>& Get() const;
135 
136  VtMatrix4dArray xforms4d;
137  VtMatrix4fArray xforms4f;
138  };
139 
140 private:
141  UsdSkelSkeleton _skel;
142  VtTokenArray _jointOrder;
143  UsdSkelTopology _topology;
144  VtMatrix4dArray _jointLocalRestXforms;
145  VtMatrix4dArray _jointWorldBindXforms;
146  // Properties computed (and cached) on-demand.
147  // Different forms of transforms are cached because different
148  // consumption tasks generally require different transforms.
149  // They are cached on the definition in order to provide cache
150  // sharing across instanced skeletons.
151  _XformHolder _jointSkelRestXforms;
152  _XformHolder _jointWorldInverseBindXforms;
153  _XformHolder _jointLocalInverseRestXforms;
154 
155  std::atomic<int> _flags;
156  std::mutex _mutex;
157 };
158 
159 
160 PXR_NAMESPACE_CLOSE_SCOPE
161 
162 #endif // USDSKEL_SKELDEFINITION_H
bool GetJointSkelRestTransforms(VtArray< Matrix4 > *xforms)
Returns rest pose joint transforms in skel space.
bool GetJointLocalRestTransforms(VtArray< Matrix4 > *xforms)
Returns rest pose joint transforms in joint-local space.
bool GetJointLocalInverseRestTransforms(VtArray< Matrix4 > *xforms)
Returns the inverse of the local-space rest transforms.
Object holding information describing skeleton topology.
Definition: topology.h:45
Structure storing the core definition of a Skeleton.
static UsdSkel_SkelDefinitionRefPtr New(const UsdSkelSkeleton &skel)
Create a definition from a skeleton.
bool HasRestPose()
See UsdSkel_SkeletonQuery::HasRestPose()
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:89
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:72
Represents an arbitrary dimensional rectangular container class.
Definition: array.h:193
Describes a skeleton.
Definition: skeleton.h:63
bool HasBindPose()
See UsdSkel_SkeletonQuery::HasBindPose()
bool GetJointWorldInverseBindTransforms(VtArray< Matrix4 > *xforms)
Returns the inverse of the world-space joint bind transforms.
bool GetJointWorldBindTransforms(VtArray< Matrix4 > *xforms)
Returns bind pose joint transforms in world space.
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:142