HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
xformCommonAPI.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 USDGEOM_GENERATED_XFORMCOMMONAPI_H
8 #define USDGEOM_GENERATED_XFORMCOMMONAPI_H
9 
10 /// \file usdGeom/xformCommonAPI.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usdGeom/api.h"
15 #include "pxr/usd/usd/prim.h"
16 #include "pxr/usd/usd/stage.h"
17 #include "pxr/usd/usdGeom/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 
28 #include "pxr/base/tf/token.h"
29 #include "pxr/base/tf/type.h"
30 
32 
33 class SdfAssetPath;
34 
35 // -------------------------------------------------------------------------- //
36 // XFORMCOMMONAPI //
37 // -------------------------------------------------------------------------- //
38 
39 /// \class UsdGeomXformCommonAPI
40 ///
41 /// This class provides API for authoring and retrieving a standard set
42 /// of component transformations which include a scale, a rotation, a
43 /// scale-rotate pivot and a translation. The goal of the API is to enhance
44 /// component-wise interchange. It achieves this by limiting the set of allowed
45 /// basic ops and by specifying the order in which they are applied. In addition
46 /// to the basic set of ops, the 'resetXformStack' bit can also be set to
47 /// indicate whether the underlying xformable resets the parent transformation
48 /// (i.e. does not inherit it's parent's transformation).
49 ///
50 /// \sa UsdGeomXformCommonAPI::GetResetXformStack()
51 /// \sa UsdGeomXformCommonAPI::SetResetXformStack()
52 ///
53 /// The operator-bool for the class will inform you whether an existing
54 /// xformable is compatible with this API.
55 ///
56 /// The scale-rotate pivot is represented by a pair of (translate,
57 /// inverse-translate) xformOps around the scale and rotate operations.
58 /// The rotation operation can be any of the six allowed Euler angle sets.
59 /// \sa UsdGeomXformOp::Type.
60 ///
61 /// The xformOpOrder of an xformable that has all of the supported basic ops
62 /// is as follows:
63 /// ["xformOp:translate", "xformOp:translate:pivot", "xformOp:rotateXYZ",
64 /// "xformOp:scale", "!invert!xformOp:translate:pivot"].
65 ///
66 /// It is worth noting that all of the ops are optional. For example, an
67 /// xformable may have only a translate or a rotate. It would still be
68 /// considered as compatible with this API. Individual SetTranslate(),
69 /// SetRotate(), SetScale() and SetPivot() methods are provided by this API
70 /// to allow such sparse authoring.
71 ///
73 {
74 public:
75  /// Compile time constant representing what kind of schema this class is.
76  ///
77  /// \sa UsdSchemaKind
79 
80  /// Construct a UsdGeomXformCommonAPI on UsdPrim \p prim .
81  /// Equivalent to UsdGeomXformCommonAPI::Get(prim.GetStage(), prim.GetPath())
82  /// for a \em valid \p prim, but will not immediately throw an error for
83  /// an invalid \p prim
84  explicit UsdGeomXformCommonAPI(const UsdPrim& prim=UsdPrim())
85  : UsdAPISchemaBase(prim)
86  {
87  }
88 
89  /// Construct a UsdGeomXformCommonAPI on the prim held by \p schemaObj .
90  /// Should be preferred over UsdGeomXformCommonAPI(schemaObj.GetPrim()),
91  /// as it preserves SchemaBase state.
92  explicit UsdGeomXformCommonAPI(const UsdSchemaBase& schemaObj)
93  : UsdAPISchemaBase(schemaObj)
94  {
95  }
96 
97  /// Destructor.
99  virtual ~UsdGeomXformCommonAPI();
100 
101  /// Return a vector of names of all pre-declared attributes for this schema
102  /// class and all its ancestor classes. Does not include attributes that
103  /// may be authored by custom/extended methods of the schemas involved.
105  static const TfTokenVector &
106  GetSchemaAttributeNames(bool includeInherited=true);
107 
108  /// Return a UsdGeomXformCommonAPI holding the prim adhering to this
109  /// schema at \p path on \p stage. If no prim exists at \p path on
110  /// \p stage, or if the prim at that path does not adhere to this schema,
111  /// return an invalid schema object. This is shorthand for the following:
112  ///
113  /// \code
114  /// UsdGeomXformCommonAPI(stage->GetPrimAtPath(path));
115  /// \endcode
116  ///
118  static UsdGeomXformCommonAPI
119  Get(const UsdStagePtr &stage, const SdfPath &path);
120 
121 
122 protected:
123  /// Returns the kind of schema this class belongs to.
124  ///
125  /// \sa UsdSchemaKind
127  UsdSchemaKind _GetSchemaKind() const override;
128 
129 private:
130  // needs to invoke _GetStaticTfType.
131  friend class UsdSchemaRegistry;
133  static const TfType &_GetStaticTfType();
134 
135  static bool _IsTypedSchema();
136 
137  // override SchemaBase virtuals.
139  const TfType &_GetTfType() const override;
140 
141 public:
142  // ===================================================================== //
143  // Feel free to add custom code below this line, it will be preserved by
144  // the code generator.
145  //
146  // Just remember to:
147  // - Close the class declaration with };
148  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
149  // - Close the include guard with #endif
150  // ===================================================================== //
151  // --(BEGIN CUSTOM CODE)--
152 
153  /// Enumerates the rotation order of the 3-angle Euler rotation.
161  };
162 
163  /// Enumerates the categories of ops that can be handled by XformCommonAPI.
164  /// For use with CreateXformOps().
165  enum OpFlags {
166  OpNone = 0,
168  OpPivot = 2,
169  OpRotate = 4,
170  OpScale = 8,
171  };
172 
173  /// Return type for CreateXformOps().
174  /// Stores the op of each type that is present on the prim.
175  /// The order of members in this struct corresponds to the expected op order
176  /// for XformCommonAPI.
177  struct Ops {
183  };
184 
185  /// Set values for the various component xformOps at a given \p time.
186  ///
187  /// Calling this method will call all of the supported ops to be created,
188  /// even if they only contain default (identity) values.
189  ///
190  /// To author individual operations selectively, use the Set[OpType]()
191  /// API.
192  ///
193  /// \note Once the rotation order has been established for a given xformable
194  /// (either because of an already defined (and compatible) rotate op or
195  /// from calling SetXformVectors() or SetRotate()), it cannot be changed.
196  ///
198  bool SetXformVectors(const GfVec3d &translation,
199  const GfVec3f &rotation,
200  const GfVec3f &scale,
201  const GfVec3f &pivot,
202  RotationOrder rotOrder,
203  const UsdTimeCode time) const;
204 
205  /// Retrieve values of the various component xformOps at a given \p time.
206  /// Identity values are filled in for the component xformOps that don't
207  /// exist or don't have an authored value.
208  ///
209  /// \note This method works even on prims with an incompatible xform schema,
210  /// i.e. when the bool operator returns false.
211  ///
212  /// When the underlying xformable has an incompatible xform schema, it
213  /// performs a full-on matrix decomposition to XYZ rotation order.
214  ///
216  bool GetXformVectors(GfVec3d *translation,
217  GfVec3f *rotation,
218  GfVec3f *scale,
219  GfVec3f *pivot,
220  RotationOrder *rotOrder,
221  const UsdTimeCode time) const;
222 
223  /// Retrieve values of the various component xformOps at a given \p time.
224  /// Identity values are filled in for the component xformOps that don't
225  /// exist or don't have an authored value.
226  ///
227  /// This method allows some additional flexibility for xform schemas that
228  /// do not strictly adhere to the xformCommonAPI. For incompatible schemas,
229  /// this method will attempt to reduce the schema into one from which
230  /// component vectors can be extracted by accumulating xformOp transforms
231  /// of the common types.
232  ///
233  /// \note When the underlying xformable has a compatible xform schema, the
234  /// usual component value extraction method is used instead. When the xform
235  /// schema is incompatible and it cannot be reduced by accumulating
236  /// transforms, it performs a full-on matrix decomposition to XYZ rotation
237  /// order.
238  ///
240  bool GetXformVectorsByAccumulation(GfVec3d* translation,
241  GfVec3f* rotation,
242  GfVec3f* scale,
243  GfVec3f* pivot,
245  const UsdTimeCode time) const;
246 
247  /// Returns whether the xformable resets the transform stack.
248  /// i.e., does not inherit the parent transformation.
250  bool GetResetXformStack() const;
251 
252  /// \anchor UsdGeomXformCommonAPI_Set_Individual_Ops
253  /// \name API for setting individual ops independently.
254  ///
255  /// @{
256 
257  /// Set translation at \p time to \p translation.
259  bool SetTranslate(const GfVec3d &translation,
260  const UsdTimeCode time=UsdTimeCode::Default()) const;
261 
262  /// Set pivot position at \p time to \p pivot.
264  bool SetPivot(const GfVec3f &pivot,
265  const UsdTimeCode time=UsdTimeCode::Default()) const;
266 
267  /// Set rotation at \p time to \p rotation.
269  bool SetRotate(const GfVec3f &rotation,
271  const UsdTimeCode time=UsdTimeCode::Default()) const;
272 
273  /// Set scale at \p time to \p scale.
275  bool SetScale(const GfVec3f &scale,
276  const UsdTimeCode time=UsdTimeCode::Default()) const;
277 
278  /// Set whether the xformable resets the transform stack.
279  /// i.e., does not inherit the parent transformation.
281  bool SetResetXformStack(bool resetXformStack) const;
282 
283  /// Creates the specified XformCommonAPI-compatible xform ops, or returns
284  /// the existing ops if they already exist. If successful, returns an Ops
285  /// object with all the ops on this prim, identified by type. If the
286  /// requested xform ops couldn't be created or the prim is not
287  /// XformCommonAPI-compatible, returns an Ops object with all invalid ops.
288  ///
289  /// The \p rotOrder is only used if OpRotate is specified. Otherwise,
290  /// it is ignored. (If you don't need to create a rotate op, you might find
291  /// it helpful to use the other overload that takes no rotation order.)
294  RotationOrder rotOrder,
295  OpFlags op1=OpNone,
296  OpFlags op2=OpNone,
297  OpFlags op3=OpNone,
298  OpFlags op4=OpNone) const;
299 
300  /// \overload
301  /// This overload does not take a rotation order. If you specify
302  /// OpRotate, then this overload assumes RotationOrderXYZ or the
303  /// previously-authored rotation order. (If you do need to create a rotate
304  /// op, you might find it helpful to use the other overload that explicitly
305  /// takes a rotation order.)
308  OpFlags op1=OpNone,
309  OpFlags op2=OpNone,
310  OpFlags op3=OpNone,
311  OpFlags op4=OpNone) const;
312 
313  /// @}
314 
315  /// \name Computing transforms
316  /// @{
317 
318  /// Return the 4x4 matrix that applies the rotation encoded by rotation
319  /// vector \p rotation using the rotation order \p rotationOrder.
320  ///
321  /// \deprecated Please use the result of ConvertRotationOrderToOpType()
322  /// along with UsdGeomXformOp::GetOpTransform() instead.
325  const GfVec3f &rotation,
326  const UsdGeomXformCommonAPI::RotationOrder rotationOrder);
327 
328  /// @}
329 
330  /// Converts the given \p rotOrder to the corresponding value in the
331  /// UsdGeomXformOp::Type enum. For example, RotationOrderYZX corresponds to
332  /// TypeRotateYZX. Raises a coding error if \p rotOrder is not one of the
333  /// named enumerators of RotationOrder.
336  RotationOrder rotOrder);
337 
338  /// Converts the given \p opType to the corresponding value in the
339  /// UsdGeomXformCommonAPI::RotationOrder enum. For example, TypeRotateYZX
340  /// corresponds to RotationOrderYZX. Raises a coding error if \p opType is
341  /// not convertible to RotationOrder (i.e., if it isn't a three-axis
342  /// rotation) and returns the default RotationOrderXYZ instead.
345  UsdGeomXformOp::Type opType);
346 
347  /// Whether the given \p opType has a corresponding value in the
348  /// UsdGeomXformCommonAPI::RotationOrder enum (i.e., whether it is a
349  /// three-axis rotation).
352  UsdGeomXformOp::Type opType);
353 
354 protected:
355  /// Returns whether the underlying xformable is compatible with the API.
357  bool _IsCompatible() const override;
358 };
359 
360 
362 
363 #endif
static USDGEOM_API RotationOrder ConvertOpTypeToRotationOrder(UsdGeomXformOp::Type opType)
static USDGEOM_API GfMatrix4d GetRotationTransform(const GfVec3f &rotation, const UsdGeomXformCommonAPI::RotationOrder rotationOrder)
UsdGeomXformCommonAPI(const UsdPrim &prim=UsdPrim())
Non-applied API schema.
static constexpr UsdTimeCode Default()
Definition: timeCode.h:113
USDGEOM_API bool SetPivot(const GfVec3f &pivot, const UsdTimeCode time=UsdTimeCode::Default()) const
Set pivot position at time to pivot.
GT_API const UT_StringHolder time
UsdGeomXformCommonAPI(const UsdSchemaBase &schemaObj)
USDGEOM_API bool SetResetXformStack(bool resetXformStack) const
static const UsdSchemaKind schemaKind
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
Definition: vec3f.h:45
USDGEOM_API bool GetXformVectors(GfVec3d *translation, GfVec3f *rotation, GfVec3f *scale, GfVec3f *pivot, RotationOrder *rotOrder, const UsdTimeCode time) const
static USDGEOM_API bool CanConvertOpTypeToRotationOrder(UsdGeomXformOp::Type opType)
static USDGEOM_API UsdGeomXformOp::Type ConvertRotationOrderToOpType(RotationOrder rotOrder)
GA_API const UT_StringHolder scale
USDGEOM_API bool _IsCompatible() const override
Returns whether the underlying xformable is compatible with the API.
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
SIM_API const UT_StringHolder rotation
USDGEOM_API bool SetRotate(const GfVec3f &rotation, UsdGeomXformCommonAPI::RotationOrder rotOrder=RotationOrderXYZ, const UsdTimeCode time=UsdTimeCode::Default()) const
Set rotation at time to rotation.
Definition: path.h:273
USDGEOM_API bool SetTranslate(const GfVec3d &translation, const UsdTimeCode time=UsdTimeCode::Default()) const
Set translation at time to translation.
USDGEOM_API bool SetXformVectors(const GfVec3d &translation, const GfVec3f &rotation, const GfVec3f &scale, const GfVec3f &pivot, RotationOrder rotOrder, const UsdTimeCode time) const
UsdSchemaKind
Definition: common.h:112
static USDGEOM_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
virtual USDGEOM_API ~UsdGeomXformCommonAPI()
Destructor.
RotationOrder
Enumerates the rotation order of the 3-angle Euler rotation.
Definition: vec3d.h:45
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static USDGEOM_API UsdGeomXformCommonAPI Get(const UsdStagePtr &stage, const SdfPath &path)
GA_API const UT_StringHolder pivot
Definition: type.h:47
USDGEOM_API Ops CreateXformOps(RotationOrder rotOrder, OpFlags op1=OpNone, OpFlags op2=OpNone, OpFlags op3=OpNone, OpFlags op4=OpNone) const
Type
Enumerates the set of all transformation operation types.
Definition: xformOp.h:110
#define USDGEOM_API
Definition: api.h:23
USDGEOM_API bool GetXformVectorsByAccumulation(GfVec3d *translation, GfVec3f *rotation, GfVec3f *scale, GfVec3f *pivot, UsdGeomXformCommonAPI::RotationOrder *rotOrder, const UsdTimeCode time) const
USDGEOM_API UsdSchemaKind _GetSchemaKind() const override
USDGEOM_API bool GetResetXformStack() const
USDGEOM_API bool SetScale(const GfVec3f &scale, const UsdTimeCode time=UsdTimeCode::Default()) const
Set scale at time to scale.