HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
houdiniXformCommonAPI.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef USDHOUDINI_GENERATED_HOUDINIXFORMCOMMONAPI_H
8 #define USDHOUDINI_GENERATED_HOUDINIXFORMCOMMONAPI_H
9 
10 /// \file usdHoudini/houdiniXformCommonAPI.h
11 
12 #include "pxr/pxr.h"
13 #include "./api.h"
15 #include "pxr/usd/usd/prim.h"
16 #include "pxr/usd/usd/stage.h"
17 #include "./tokens.h"
18 
20 #include "pxr/usd/usdGeom/xformOp.h"
21 
22 #include "pxr/base/vt/value.h"
23 
24 #include "pxr/base/gf/vec3d.h"
25 #include "pxr/base/gf/vec3f.h"
26 #include "pxr/base/gf/matrix4d.h"
27 #include "pxr/base/gf/quatf.h"
28 
29 #include "pxr/base/tf/token.h"
30 #include "pxr/base/tf/type.h"
31 
33 
34 class SdfAssetPath;
35 
36 // -------------------------------------------------------------------------- //
37 // HOUDINIXFORMCOMMONAPI //
38 // -------------------------------------------------------------------------- //
39 
40 /// \class UsdHoudiniHoudiniXformCommonAPI
41 ///
42 /// This class provides API for authoring and retrieving a standard set
43 /// of component transformations which include a scale, a rotation, a
44 /// scale-rotate pivot and a translation. The goal of the API is to enhance
45 /// component-wise interchange. It achieves this by limiting the set of allowed
46 /// basic ops and by specifying the order in which they are applied. In addition
47 /// to the basic set of ops, the 'resetXformStack' bit can also be set to
48 /// indicate whether the underlying xformable resets the parent transformation
49 /// (i.e. does not inherit it's parent's transformation).
50 ///
51 /// \sa UsdHoudiniHoudiniXformCommonAPI::GetResetXformStack()
52 /// \sa UsdHoudiniHoudiniXformCommonAPI::SetResetXformStack()
53 ///
54 /// The operator-bool for the class will inform you whether an existing
55 /// xformable is compatible with this API.
56 ///
57 /// The scale-rotate pivot is represented by a pair of (translate,
58 /// inverse-translate) xformOps around the scale and rotate operations.
59 /// The rotation operation can be any of the six allowed Euler angle sets,
60 /// or a quaternion orientation (xformOp:orient).
61 /// \sa UsdGeomXformOp::Type.
62 ///
63 /// This class is essentially a copy of UsdGeomXformCommonAPI, but with the
64 /// addition of an optional shear component (expressed as a GfMatrx4d in the
65 /// xformOp stack) and a "pivot rotate" component which, like the pivot, is
66 /// applied before the t/r/s operations, and inverted after these operations.
67 /// Whenever possible, this class will not author these Houdini-specific ops,
68 /// and remain compatible with UsdGeomXformCommonAPI.
69 ///
70 /// The xformOpOrder of an xformable that has all of the supported basic ops
71 /// is as follows:
72 /// ["xformOp:translate:pivot",
73 /// "xformOp:rotateXYZ:pivot",
74 /// "xformOp:translate",
75 /// "xformOp:rotateXYZ",
76 /// "xformOp:transform:shear",
77 /// "xformOp:scale",
78 /// "!invert!xformOp:rotateXYZ:pivot",
79 /// "!invert!xformOp:translate:pivot"].
80 ///
81 /// It is worth noting that all of the ops are optional. For example, an
82 /// xformable may have only a translate or a rotate. It would still be
83 /// considered as compatible with this API. Individual SetTranslate(),
84 /// SetRotate(), SetScale() and SetPivot() methods are provided by this API
85 /// to allow such sparse authoring.
86 ///
87 class
90 {
91 public:
92  /// Compile time constant representing what kind of schema this class is.
93  ///
94  /// \sa UsdSchemaKind
95  static const UsdSchemaKind schemaKind = UsdSchemaKind::NonAppliedAPI;
96 
97  /// Construct a UsdHoudiniHoudiniXformCommonAPI on UsdPrim \p prim .
98  /// Equivalent to UsdHoudiniHoudiniXformCommonAPI::Get(prim.GetStage(), prim.GetPath())
99  /// for a \em valid \p prim, but will not immediately throw an error for
100  /// an invalid \p prim
102  : UsdAPISchemaBase(prim)
103  {
104  }
105 
106  /// Construct a UsdHoudiniHoudiniXformCommonAPI on the prim held by \p schemaObj .
107  /// Should be preferred over UsdHoudiniHoudiniXformCommonAPI(schemaObj.GetPrim()),
108  /// as it preserves SchemaBase state.
110  : UsdAPISchemaBase(schemaObj)
111  {
112  }
113 
114  /// Destructor.
115  virtual ~UsdHoudiniHoudiniXformCommonAPI() override;
116 
117  /// Return a vector of names of all pre-declared attributes for this schema
118  /// class and all its ancestor classes. Does not include attributes that
119  /// may be authored by custom/extended methods of the schemas involved.
120  static const TfTokenVector &
121  GetSchemaAttributeNames(bool includeInherited=true);
122 
123  /// Return a UsdHoudiniHoudiniXformCommonAPI holding the prim adhering to this
124  /// schema at \p path on \p stage. If no prim exists at \p path on
125  /// \p stage, or if the prim at that path does not adhere to this schema,
126  /// return an invalid schema object. This is shorthand for the following:
127  ///
128  /// \code
129  /// UsdHoudiniHoudiniXformCommonAPI(stage->GetPrimAtPath(path));
130  /// \endcode
131  ///
133  Get(const UsdStagePtr &stage, const SdfPath &path);
134 
135 protected:
136  /// Returns the kind of schema this class belongs to.
137  ///
138  /// \sa UsdSchemaKind
139  UsdSchemaKind _GetSchemaKind() const override;
140 
141 private:
142  // needs to invoke _GetStaticTfType.
143  friend class UsdSchemaRegistry;
144  static const TfType &_GetStaticTfType();
145 
146  static bool _IsTypedSchema();
147 
148  // override SchemaBase virtuals.
149  const TfType &_GetTfType() const override;
150 
151 public:
152  // ===================================================================== //
153  // Feel free to add custom code below this line, it will be preserved by
154  // the code generator.
155  //
156  // Just remember to:
157  // - Close the class declaration with };
158  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
159  // - Close the include guard with #endif
160  // ===================================================================== //
161  // --(BEGIN CUSTOM CODE)--
162 
163  /// Enumerates the rotation order of the 3-angle Euler rotation.
170  RotationOrderZYX
171  };
172 
173  /// Represents a rotation as either Euler angles with a rotation order,
174  /// or a quaternion orientation. Used by SetXformVectors(),
175  /// GetXformVectors(), and SetRotate() to handle both rotation
176  /// representations uniformly.
178  {
179  public:
180  /// Default constructor: identity Euler rotation (XYZ order, all
181  /// zeros).
182  Rotation();
183 
184  /// Construct an Euler angle rotation.
185  /// \p eulerAngles are in degrees, packed as (X, Y, Z).
187 
188  /// Construct a quaternion orientation.
189  explicit Rotation(const GfQuatf &orient);
190 
191  /// Returns true if this rotation is represented as Euler angles.
192  bool IsEuler() const { return !_isOrient; }
193 
194  /// Returns true if this rotation is represented as a quaternion.
195  bool IsOrient() const { return _isOrient; }
196 
197  /// Returns the Euler angles in degrees, converting from the
198  /// quaternion if necessary.
199  GfVec3f GetEulerAngles() const;
200 
201  /// Returns the Euler angles in degrees in a given rotation order,
202  /// converting from the quaternion or alternative rotation order
203  /// if necessary.
204  GfVec3f GetEulerAnglesWithOrder(RotationOrder order) const;
205 
206  /// Returns the Euler rotation order, converting from the
207  /// quaternion if necessary..
208  RotationOrder GetRotationOrder() const;
209 
210  /// Returns the quaternion value, converting from the
211  /// Euler angles if necessary..
212  GfQuatf GetQuaternion() const;
213 
214  private:
215  bool _isOrient;
216  GfVec3f _eulerAngles;
217  RotationOrder _rotOrder;
218  GfQuatf _quaternion;
219  };
220 
221  /// Enumerates the categories of ops that can be handled by XformCommonAPI.
222  /// For use with CreateXformOps().
223  enum OpFlags
224  {
225  OpNone = 0,
226  OpTranslate = 1,
227  OpPivot = 2,
228  OpRotate = 4,
229  OpScale = 8,
230  OpShear = 16,
231  OpPivotRotate = 32,
232  OpOrient = 64
233  };
234 
235  /// Return type for CreateXformOps().
236  /// Stores the op of each type that is present on the prim.
237  /// The order of members in this struct corresponds to the expected op order
238  /// for XformCommonAPI.
239  struct Ops
240  {
249  };
250 
251  /// Set values for the various component xformOps at a given \p time.
252  ///
253  /// Calling this method will call all of the supported ops to be created,
254  /// even if they only contain default (identity) values.
255  ///
256  /// To author individual operations selectively, use the Set[OpType]()
257  /// API.
258  ///
259  /// The \p rotation parameter encapsulates both the rotation value and
260  /// its representation (Euler angles with rotation order, or quaternion).
261  ///
262  /// \note Once the rotation representation has been established for a
263  /// given xformable (either because of an already defined (and compatible)
264  /// rotate/orient op or from calling SetXformVectors() or SetRotate()),
265  /// it cannot be changed.
266  ///
267  bool SetXformVectors(const GfVec3d &translation,
268  const Rotation &rotation,
269  const GfVec3f &scale,
270  const GfVec3f &shear,
271  const GfVec3f &pivot,
272  const GfVec3f &pivotRotate,
273  const UsdTimeCode time) const;
274 
275  /// Retrieve values of the various component xformOps at a given \p time.
276  /// Identity values are filled in for the component xformOps that don't
277  /// exist or don't have an authored value.
278  ///
279  /// The \p rotation output preserves the prim's native rotation
280  /// representation: Euler angles if the prim has a rotateABC op, or
281  /// quaternion if the prim has an orient op.
282  ///
283  /// \note This method works even on prims with an incompatible xform
284  /// schema, i.e. when the bool operator returns false. When the
285  /// underlying xformable has an incompatible xform schema, it performs a
286  /// full-on matrix decomposition to XYZ Euler rotation order.
287  ///
288  bool GetXformVectors(GfVec3d *translation,
290  GfVec3f *scale,
291  GfVec3f *shear,
292  GfVec3f *pivot,
293  GfVec3f *pivotRot,
294  const UsdTimeCode time) const;
295 
296  /// Retrieve values of the various component xformOps at a given \p time.
297  /// Identity values are filled in for the component xformOps that don't
298  /// exist or don't have an authored value.
299  ///
300  /// This method allows some additional flexibility for xform schemas that
301  /// do not strictly adhere to the xformCommonAPI. For incompatible schemas,
302  /// this method will attempt to reduce the schema into one from which
303  /// component vectors can be extracted by accumulating xformOp transforms
304  /// of the common types.
305  ///
306  /// \note When the underlying xformable has a compatible xform schema, the
307  /// usual component value extraction method is used instead. When the xform
308  /// schema is incompatible and it cannot be reduced by accumulating
309  /// transforms, it performs a full-on matrix decomposition to XYZ Euler
310  /// rotation order.
311  ///
312  bool GetXformVectorsByAccumulation(GfVec3d *translation,
314  GfVec3f *scale,
315  GfVec3f *shear,
316  GfVec3f *pivot,
317  GfVec3f *pivotRotate,
318  const UsdTimeCode time) const;
319 
320  /// Returns whether the xformable resets the transform stack.
321  /// i.e., does not inherit the parent transformation.
322  bool GetResetXformStack() const;
323 
324  /// \anchor XUSD_XformCommonAPI_Set_Individual_Ops
325  /// \name API for setting individual ops independently.
326  ///
327  /// @{
328 
329  /// Set translation at \p time to \p translation.
330  bool SetTranslate(const GfVec3d &translation,
331  const UsdTimeCode time=UsdTimeCode::Default()) const;
332 
333  /// Set pivot position at \p time to \p pivot.
334  bool SetPivot(const GfVec3f &pivot,
335  const UsdTimeCode time=UsdTimeCode::Default()) const;
336 
337  /// Set pivot rotation at \p time to \p pivot.
338  bool SetPivotRotate(const GfVec3f &pivotRotate,
339  const UsdTimeCode time=UsdTimeCode::Default()) const;
340 
341  /// Set rotation at \p time to \p rotation.
342  /// The rotation can be either Euler angles with a rotation order, or a
343  /// quaternion orientation.
344  bool SetRotate(const Rotation &rotation,
345  const UsdTimeCode time=UsdTimeCode::Default()) const;
346 
347  /// Set shear at \p time to \p shear.
348  bool SetShear(const GfVec3f &shear,
349  const UsdTimeCode time=UsdTimeCode::Default()) const;
350 
351  /// Set scale at \p time to \p scale.
352  bool SetScale(const GfVec3f &scale,
353  const UsdTimeCode time=UsdTimeCode::Default()) const;
354 
355  /// Set whether the xformable resets the transform stack.
356  /// i.e., does not inherit the parent transformation.
357  bool SetResetXformStack(bool resetXformStack) const;
358 
359  /// Creates the specified XformCommonAPI-compatible xform ops, or returns
360  /// the existing ops if they already exist. If successful, returns an Ops
361  /// object with all the ops on this prim, identified by type. If the
362  /// requested xform ops couldn't be created or the prim is not
363  /// XformCommonAPI-compatible, returns an Ops object with all invalid ops.
364  ///
365  /// The \p rotOrder is only used if OpRotate is specified. Otherwise,
366  /// it is ignored. (If you don't need to create a rotate op, you might find
367  /// it helpful to use the other overload that takes no rotation order.)
368  Ops CreateXformOps(
370  OpFlags op1=OpNone,
371  OpFlags op2=OpNone,
372  OpFlags op3=OpNone,
373  OpFlags op4=OpNone,
374  OpFlags op5=OpNone,
375  OpFlags op6=OpNone) const;
376 
377  /// \overload
378  /// This overload does not take a rotation order. If you specify
379  /// OpRotate, then this overload assumes RotationOrderXYZ or the
380  /// previously-authored rotation order. (If you do need to create a rotate
381  /// op, you might find it helpful to use the other overload that explicitly
382  /// takes a rotation order.)
383  Ops CreateXformOps(
384  OpFlags op1=OpNone,
385  OpFlags op2=OpNone,
386  OpFlags op3=OpNone,
387  OpFlags op4=OpNone,
388  OpFlags op5=OpNone,
389  OpFlags op6=OpNone) const;
390 
391  /// @}
392 
393  /// \name Computing transforms
394  /// @{
395 
396  /// Return the 4x4 matrix that applies the rotation encoded by rotation
397  /// vector \p rotation using the rotation order \p rotationOrder.
398  ///
399  /// \deprecated Please use the result of ConvertRotationOrderToOpType()
400  /// along with UsdGeomXformOp::GetOpTransform() instead.
401  static GfMatrix4d GetRotationTransform(const GfVec3f &rotation,
403 
404  /// @}
405 
406  /// Converts the given \p rotOrder to the corresponding value in the
407  /// UsdGeomXformOp::Type enum. For example, RotationOrderYZX corresponds to
408  /// TypeRotateYZX. Raises a coding error if \p rotOrder is not one of the
409  /// named enumerators of RotationOrder.
410  static UsdGeomXformOp::Type
411  ConvertRotationOrderToOpType(
413 
414  /// Converts the given \p opType to the corresponding value in the
415  /// UsdHoudiniHoudiniXformCommonAPI::RotationOrder enum. For example, TypeRotateYZX
416  /// corresponds to RotationOrderYZX. Raises a coding error if \p opType is
417  /// not convertible to RotationOrder (i.e., if it isn't a three-axis
418  /// rotation) and returns the default RotationOrderXYZ instead.
420  ConvertOpTypeToRotationOrder(UsdGeomXformOp::Type opType);
421 
422  /// Whether the given \p opType has a corresponding value in the
423  /// UsdHoudiniHoudiniXformCommonAPI::RotationOrder enum (i.e., whether it is a
424  /// three-axis rotation).
425  static bool
426  CanConvertOpTypeToRotationOrder(UsdGeomXformOp::Type opType);
427 
428 protected:
429  /// Returns whether the underlying xformable is compatible with the API.
430  bool _IsCompatible() const override;
431 };
432 
434 
435 #endif
#define USDHOUDINI_API
Definition: api.h:23
Non-applied API schema.
static constexpr UsdTimeCode Default()
Definition: timeCode.h:113
MatType shear(Axis axis0, Axis axis1, typename MatType::value_type shear)
Set the matrix to a shear along axis0 by a fraction of axis1.
Definition: Mat.h:688
GT_API const UT_StringHolder time
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
Definition: vec3f.h:45
UsdHoudiniHoudiniXformCommonAPI(const UsdSchemaBase &schemaObj)
Definition: quatf.h:42
Vec3< typename MatType::value_type > eulerAngles(const MatType &mat, RotationOrder rotationOrder, typename MatType::value_type eps=static_cast< typename MatType::value_type >(1.0e-8))
Return the Euler angles composing the given rotation matrix.
Definition: Mat.h:333
bool IsEuler() const
Returns true if this rotation is represented as Euler angles.
UsdHoudiniHoudiniXformCommonAPI(const UsdPrim &prim=UsdPrim())
GA_API const UT_StringHolder scale
GLdouble GLdouble GLint GLint order
Definition: glad.h:2676
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
SIM_API const UT_StringHolder rotation
Definition: path.h:280
GA_API const UT_StringHolder orient
UsdSchemaKind
Definition: common.h:112
Definition: vec3d.h:45
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
GA_API const UT_StringHolder pivot
Definition: type.h:47
Type
Enumerates the set of all transformation operation types.
Definition: xformOp.h:110
bool IsOrient() const
Returns true if this rotation is represented as a quaternion.
RotationOrder
Enumerates the rotation order of the 3-angle Euler rotation.