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 PXR_USD_USD_SKEL_ANIM_QUERY_H
25 #define PXR_USD_USD_SKEL_ANIM_QUERY_H
26 
27 /// \file usdSkel/animQuery.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/usdSkel/api.h"
31 
32 #include "pxr/base/tf/declarePtrs.h"
33 #include "pxr/base/vt/types.h"
34 
35 #include "pxr/usd/sdf/path.h"
36 #include "pxr/usd/usd/prim.h"
37 #include "pxr/usd/usd/timeCode.h"
38 
39 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
42 
43 class GfMatrix4d;
44 class UsdAttribute;
45 class UsdSkelCache;
46 
47 
48 TF_DECLARE_REF_PTRS(UsdSkel_AnimQueryImpl);
49 
50 
51 /// \class UsdSkelAnimQuery
52 ///
53 /// Class providing efficient queries of primitives that provide skel animation.
54 class UsdSkelAnimQuery
55 {
56 public:
57     USDSKEL_API
UsdSkelAnimQuery()58     UsdSkelAnimQuery() {}
59 
60     /// Return true if this query is valid.
IsValid()61     bool IsValid() const { return (bool)_impl; }
62 
63     /// Boolean conversion operator. Equivalent to IsValid().
64     explicit operator bool() const { return IsValid(); }
65 
66     /// Equality comparison.  Return true if \a lhs and \a rhs represent the
67     /// same UsdSkelAnimQuery, false otherwise.
68     friend bool operator==(const UsdSkelAnimQuery& lhs,
69                            const UsdSkelAnimQuery& rhs) {
70         return lhs.GetPrim() == rhs.GetPrim();
71     }
72 
73     /// Inequality comparison. Return false if \a lhs and \a rhs represent the
74     /// same UsdSkelAnimQuery, true otherwise.
75     friend bool operator!=(const UsdSkelAnimQuery& lhs,
76                            const UsdSkelAnimQuery& rhs) {
77         return !(lhs == rhs);
78     }
79 
80     // hash_value overload for std/boost hash.
hash_value(const UsdSkelAnimQuery & query)81     friend size_t hash_value(const UsdSkelAnimQuery& query) {
82         return hash_value(query.GetPrim());
83     }
84 
85     /// Return the primitive this anim query reads from.
86     USDSKEL_API
87     UsdPrim GetPrim() const;
88 
89     /// Compute joint transforms in joint-local space.
90     /// Transforms are returned in the order specified by the joint ordering
91     /// of the animation primitive itself.
92     template <typename Matrix4>
93     USDSKEL_API
94     bool ComputeJointLocalTransforms(
95              VtArray<Matrix4>* xforms,
96              UsdTimeCode time=UsdTimeCode::Default()) const;
97 
98     /// Compute translation,rotation,scale components of the joint transforms
99     /// in joint-local space. This is provided to facilitate direct streaming
100     /// of animation data in a form that can efficiently be processed for
101     /// animation blending.
102     USDSKEL_API
103     bool ComputeJointLocalTransformComponents(
104              VtVec3fArray* translations,
105              VtQuatfArray* rotations,
106              VtVec3hArray* scales,
107              UsdTimeCode time=UsdTimeCode::Default()) const;
108 
109     USDSKEL_API
110     bool ComputeBlendShapeWeights(
111              VtFloatArray* weights,
112              UsdTimeCode time=UsdTimeCode::Default()) const;
113 
114     /// Get the time samples at which values contributing to joint transforms
115     /// are set. This only computes the time samples for sampling transforms in
116     /// joint-local space, and does not include time samples affecting the
117     /// root transformation.
118     ///
119     /// \sa UsdAttribute::GetTimeSamples
120     USDSKEL_API
121     bool GetJointTransformTimeSamples(std::vector<double>* times) const;
122 
123     /// Get the time samples at which values contributing to joint transforms
124     /// are set, over \p interval. This only computes the time samples for
125     /// sampling transforms in joint-local space, and does not include time
126     /// samples affecting the root transformation.
127     ///
128     /// \sa UsdAttribute::GetTimeSamplesInInterval
129     USDSKEL_API
130     bool GetJointTransformTimeSamplesInInterval(const GfInterval& interval,
131                                                 std::vector<double>* times) const;
132 
133     /// Get the attributes contributing to JointTransform computations
134     USDSKEL_API
135     bool GetJointTransformAttributes(std::vector<UsdAttribute>* attrs) const;
136 
137     /// Return true if it possible, but not certain, that joint transforms
138     /// computed through this animation query change over time, false otherwise.
139     ///
140     /// \sa UsdAttribute::ValueMightBeTimeVayring
141     USDSKEL_API
142     bool JointTransformsMightBeTimeVarying() const;
143 
144     /// Get the time samples at which values contributing to blend shape weights
145     /// have been set.
146     ///
147     /// \sa UsdAttribute::GetTimeSamples
148     USDSKEL_API
149     bool GetBlendShapeWeightTimeSamples(std::vector<double>* attrs) const;
150 
151     /// Get the time samples at which values contributing to blend shape weights
152     /// are set, over \p interval.
153     ///
154     /// \sa UsdAttribute::GetTimeSamplesInInterval
155     USDSKEL_API
156     bool GetBlendShapeWeightTimeSamplesInInterval(const GfInterval& interval,
157                                                   std::vector<double>* times) const;
158 
159     /// Get the attributes contributing to blendshape weight computations.
160     USDSKEL_API
161     bool GetBlendShapeWeightAttributes(std::vector<UsdAttribute>* attrs) const;
162 
163     /// Return true if it possible, but not certain, that the blend shape
164     /// weights computed through this animation query change over time,
165     /// false otherwise.
166     ///
167     /// \sa UsdAttribute::ValueMightBeTimeVayring
168     USDSKEL_API
169     bool BlendShapeWeightsMightBeTimeVarying() const;
170 
171     /// Returns an array of tokens describing the ordering of joints in the
172     /// animation.
173     ///
174     /// \sa UsdSkelSkeleton::GetJointOrder
175     USDSKEL_API
176     VtTokenArray GetJointOrder() const;
177 
178     /// Returns an array of tokens describing the ordering of blend shape
179     /// channels in the animation.
180     USDSKEL_API
181     VtTokenArray GetBlendShapeOrder() const;
182 
183     USDSKEL_API
184     std::string GetDescription() const;
185 
186 private:
UsdSkelAnimQuery(const UsdSkel_AnimQueryImplRefPtr & impl)187     UsdSkelAnimQuery(const UsdSkel_AnimQueryImplRefPtr& impl)
188         :  _impl(impl) {}
189 
190     UsdSkel_AnimQueryImplRefPtr _impl;
191 
192     friend class UsdSkel_CacheImpl;
193 };
194 
195 
196 PXR_NAMESPACE_CLOSE_SCOPE
197 
198 #endif // PXR_USD_USD_SKEL_ANIM_QUERY_H
199