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 #include "pxr/usd/usdSkel/skinningQuery.h"
25
26 #include "pxr/base/gf/interval.h"
27 #include "pxr/base/gf/matrix4d.h"
28 #include "pxr/base/gf/matrix4f.h"
29
30 #include "pxr/base/tf/pyContainerConversions.h"
31 #include "pxr/base/tf/pyPtrHelpers.h"
32 #include "pxr/base/tf/pyResultConversions.h"
33 #include "pxr/base/tf/pyUtils.h"
34 #include "pxr/base/tf/wrapTypeHelpers.h"
35
36 #include "pxr/usd/usd/pyConversions.h"
37 #include "pxr/usd/usdGeom/boundable.h"
38
39 #include <boost/python.hpp>
40
41
42 using namespace boost::python;
43
44 PXR_NAMESPACE_USING_DIRECTIVE
45
46
47 namespace {
48
49
50 object
_ComputeJointInfluences(const UsdSkelSkinningQuery & self,UsdTimeCode time)51 _ComputeJointInfluences(const UsdSkelSkinningQuery& self, UsdTimeCode time)
52 {
53 VtIntArray indices;
54 VtFloatArray weights;
55 if (self.ComputeJointInfluences(&indices, &weights, time)) {
56 return boost::python::make_tuple(indices, weights);
57 }
58 return object();
59 }
60
61
62 object
_ComputeVaryingJointInfluences(const UsdSkelSkinningQuery & self,size_t numPoints,UsdTimeCode time)63 _ComputeVaryingJointInfluences(const UsdSkelSkinningQuery& self,
64 size_t numPoints,
65 UsdTimeCode time)
66 {
67 VtIntArray indices;
68 VtFloatArray weights;
69 if (self.ComputeVaryingJointInfluences(numPoints, &indices,
70 &weights, time)) {
71 return boost::python::make_tuple(indices, weights);
72 }
73 return object();
74 }
75
76
77 std::vector<double>
_GetTimeSamples(const UsdSkelSkinningQuery & self)78 _GetTimeSamples(const UsdSkelSkinningQuery& self)
79 {
80 std::vector<double> times;
81 self.GetTimeSamples(×);
82 return times;
83 }
84
85
86 std::vector<double>
_GetTimeSamplesInInterval(const UsdSkelSkinningQuery & self,const GfInterval & interval)87 _GetTimeSamplesInInterval(const UsdSkelSkinningQuery& self,
88 const GfInterval& interval)
89 {
90 std::vector<double> times;
91 self.GetTimeSamplesInInterval(interval, ×);
92 return times;
93 }
94
95
96 object
_GetJointOrder(const UsdSkelSkinningQuery & self)97 _GetJointOrder(const UsdSkelSkinningQuery& self)
98 {
99 VtTokenArray jointOrder;
100 if (self.GetJointOrder(&jointOrder))
101 return object(jointOrder);
102 return {};
103 }
104
105
106 object
_GetBlendShapeOrder(const UsdSkelSkinningQuery & self)107 _GetBlendShapeOrder(const UsdSkelSkinningQuery& self)
108 {
109 VtTokenArray blendShapeOrder;
110 if (self.GetBlendShapeOrder(&blendShapeOrder))
111 return object(blendShapeOrder);
112 return {};
113 }
114
115 template <typename Matrix4>
116 bool
_ComputeSkinnedPoints(const UsdSkelSkinningQuery & self,const VtArray<Matrix4> & xforms,VtVec3fArray & points,UsdTimeCode time)117 _ComputeSkinnedPoints(const UsdSkelSkinningQuery& self,
118 const VtArray<Matrix4>& xforms,
119 VtVec3fArray& points,
120 UsdTimeCode time)
121 {
122 return self.ComputeSkinnedPoints(xforms, &points, time);
123 }
124
125
126 template <typename Matrix4>
127 Matrix4
_ComputeSkinnedTransform(const UsdSkelSkinningQuery & self,const VtArray<Matrix4> & xforms,UsdTimeCode time)128 _ComputeSkinnedTransform(const UsdSkelSkinningQuery& self,
129 const VtArray<Matrix4>& xforms,
130 UsdTimeCode time)
131 {
132 Matrix4 xform;
133 self.ComputeSkinnedTransform(xforms, &xform, time);
134 return xform;
135 }
136
137
138 } // namespace
139
140
wrapUsdSkelSkinningQuery()141 void wrapUsdSkelSkinningQuery()
142 {
143 using This = UsdSkelSkinningQuery;
144
145 class_<This>("SkinningQuery")
146
147 .def(!self)
148
149 .def("__str__", &This::GetDescription)
150
151 .def("GetPrim", &This::GetPrim,
152 return_value_policy<return_by_value>())
153
154 .def("HasJointInfluences", &This::HasJointInfluences)
155
156 .def("HasBlendShapes", &This::HasBlendShapes)
157
158 .def("GetNumInfluencesPerComponent",
159 &This::GetNumInfluencesPerComponent)
160
161 .def("GetInterpolation", &This::GetInterpolation,
162 return_value_policy<return_by_value>())
163
164 .def("IsRigidlyDeformed", &This::IsRigidlyDeformed)
165
166 .def("GetGeomBindTransformAttr", &This::GetGeomBindTransformAttr,
167 return_value_policy<return_by_value>())
168
169 .def("GetJointIndicesPrimvar", &This::GetJointIndicesPrimvar,
170 return_value_policy<return_by_value>())
171
172 .def("GetJointWeightsPrimvar", &This::GetJointWeightsPrimvar,
173 return_value_policy<return_by_value>())
174
175 .def("GetBlendShapesAttr", &This::GetBlendShapesAttr,
176 return_value_policy<return_by_value>())
177
178 .def("GetBlendShapeTargetsRel", &This::GetBlendShapeTargetsRel,
179 return_value_policy<return_by_value>())
180
181 // deprecated
182 .def("GetMapper", &This::GetMapper,
183 return_value_policy<return_by_value>())
184
185 .def("GetJointMapper", &This::GetJointMapper,
186 return_value_policy<return_by_value>())
187
188 .def("GetBlendShapeMapper", &This::GetBlendShapeMapper,
189 return_value_policy<return_by_value>())
190
191 .def("GetJointOrder", &_GetJointOrder)
192
193 .def("GetBlendShapeOrder", &_GetBlendShapeOrder)
194
195 .def("GetTimeSamples", &_GetTimeSamples)
196
197 .def("GetTimeSamplesInInterval", &_GetTimeSamplesInInterval)
198
199 .def("ComputeJointInfluences", &_ComputeJointInfluences,
200 (arg("time")=UsdTimeCode::Default()))
201
202 .def("ComputeVaryingJointInfluences", &_ComputeVaryingJointInfluences,
203 (arg("numPoints"), arg("time")=UsdTimeCode::Default()))
204
205 .def("ComputeSkinnedPoints", &_ComputeSkinnedPoints<GfMatrix4d>,
206 (arg("xforms"), arg("points"),
207 arg("time")=UsdTimeCode::Default()))
208
209 .def("ComputeSkinnedPoints", &_ComputeSkinnedPoints<GfMatrix4f>,
210 (arg("xforms"), arg("points"),
211 arg("time")=UsdTimeCode::Default()))
212
213 .def("ComputeSkinnedTransform", &_ComputeSkinnedTransform<GfMatrix4d>,
214 (arg("xforms"),
215 arg("time")=UsdTimeCode::Default()))
216
217 .def("ComputeSkinnedTransform", &_ComputeSkinnedTransform<GfMatrix4f>,
218 (arg("xforms"),
219 arg("time")=UsdTimeCode::Default()))
220
221 .def("ComputeExtentsPadding",
222 static_cast<float (UsdSkelSkinningQuery::*)(
223 const VtMatrix4dArray&,
224 const UsdGeomBoundable&) const>(
225 &This::ComputeExtentsPadding),
226 (arg("skelRestXforms"),
227 arg("boundable"),
228 arg("time")=UsdTimeCode::Default()))
229
230 .def("ComputeExtentsPadding",
231 static_cast<float (UsdSkelSkinningQuery::*)(
232 const VtMatrix4fArray&,
233 const UsdGeomBoundable&) const>(
234 &This::ComputeExtentsPadding),
235 (arg("skelRestXforms"),
236 arg("boundable"),
237 arg("time")=UsdTimeCode::Default()))
238
239 .def("GetGeomBindTransform", &This::GetGeomBindTransform,
240 (arg("time")=UsdTimeCode::Default()))
241 ;
242 }
243