All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
xformCommonAPI.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 USDGEOM_GENERATED_XFORMCOMMONAPI_H
25 #define USDGEOM_GENERATED_XFORMCOMMONAPI_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/usdGeom/api.h"
29 #include "pxr/usd/usdGeom/xformable.h"
30 #include "pxr/usd/usd/schemaBase.h"
31 #include "pxr/usd/usd/stage.h"
32 
33 #include "pxr/base/gf/vec3d.h"
34 #include "pxr/base/gf/vec3f.h"
35 
36 #include "pxr/base/tf/token.h"
37 #include "pxr/base/tf/type.h"
38 
39 #include <vector>
40 
41 PXR_NAMESPACE_OPEN_SCOPE
42 
43 
44 // -------------------------------------------------------------------------- //
45 // XFORMCOMMONAPI //
46 // -------------------------------------------------------------------------- //
47 
89 {
90 public:
91  explicit UsdGeomXformCommonAPI(const UsdPrim &prim=UsdPrim())
92  : UsdSchemaBase(prim)
93  , _xformable(UsdGeomXformable(prim))
94  , _computedOpIndices(false)
95  , _translateOpIndex(_InvalidIndex)
96  , _rotateOpIndex(_InvalidIndex)
97  , _scaleOpIndex(_InvalidIndex)
98  , _pivotOpIndex(_InvalidIndex)
99  {
100  bool resetsXformStack = false;
101  _xformOps = _xformable.GetOrderedXformOps(&resetsXformStack);
102  }
103 
104  explicit UsdGeomXformCommonAPI(
105  const UsdGeomXformable& xformable)
106  : UsdSchemaBase(xformable.GetPrim())
107  , _xformable(xformable)
108  , _computedOpIndices(false)
109  , _translateOpIndex(_InvalidIndex)
110  , _rotateOpIndex(_InvalidIndex)
111  , _scaleOpIndex(_InvalidIndex)
112  , _pivotOpIndex(_InvalidIndex)
113  {
114  bool resetsXformStack = false;
115  _xformOps = _xformable.GetOrderedXformOps(&resetsXformStack);
116  }
117 
119  USDGEOM_API
120  virtual ~UsdGeomXformCommonAPI();
121 
131  USDGEOM_API
132  static UsdGeomXformCommonAPI
133  Get(const UsdStagePtr &stage, const SdfPath &path);
134 
135 protected:
137  USDGEOM_API
138  bool _IsCompatible() const override;
139 
140 public:
141 
144  RotationOrderXYZ,
145  RotationOrderXZY,
146  RotationOrderYXZ,
147  RotationOrderYZX,
148  RotationOrderZXY,
149  RotationOrderZYX
150  };
151 
164  USDGEOM_API
165  bool SetXformVectors(const GfVec3d &translation,
166  const GfVec3f &rotation,
167  const GfVec3f &scale,
168  const GfVec3f &pivot,
169  RotationOrder rotOrder,
170  const UsdTimeCode time);
171 
182  USDGEOM_API
183  bool GetXformVectors(GfVec3d *translation,
184  GfVec3f *rotation,
185  GfVec3f *scale,
186  GfVec3f *pivot,
187  RotationOrder *rotOrder,
188  const UsdTimeCode time);
189 
206  USDGEOM_API
207  bool GetXformVectorsByAccumulation(GfVec3d* translation,
208  GfVec3f* rotation,
209  GfVec3f* scale,
210  GfVec3f* pivot,
212  const UsdTimeCode time);
213 
216  USDGEOM_API
217  bool GetResetXformStack() const;
218 
223 
225  USDGEOM_API
226  bool SetTranslate(const GfVec3d &translation,
227  const UsdTimeCode time=UsdTimeCode::Default());
228 
230  USDGEOM_API
231  bool SetPivot(const GfVec3f &pivot,
232  const UsdTimeCode time=UsdTimeCode::Default());
233 
235  USDGEOM_API
236  bool SetRotate(const GfVec3f &rotation,
237  UsdGeomXformCommonAPI::RotationOrder rotOrder=RotationOrderXYZ,
238  const UsdTimeCode time=UsdTimeCode::Default());
239 
241  USDGEOM_API
242  bool SetScale(const GfVec3f &scale,
243  const UsdTimeCode time=UsdTimeCode::Default());
244 
247  USDGEOM_API
248  bool SetResetXformStack(bool resetXformStack) const;
249 
251 
254 
257  USDGEOM_API
259  const GfVec3f &rotation,
260  const UsdGeomXformCommonAPI::RotationOrder rotationOrder);
261 
263 
264 private:
265 
266  // Computes and stores op indices in the data members.
267  bool _ComputeOpIndices();
268 
269  // Computes and stored op indices if the xformable is compatible.
270  //
271  // Returns false if the xformable is incompabible or if there was a problem
272  // computing op indices.
273  //
274  bool _VerifyCompatibility();
275 
276  // Used to determine compatibility.
277  bool _ValidateAndComputeXformOpIndices(int *translateOpIndex=NULL,
278  int *pivotOpIndex=NULL,
279  int *rotateOpIndex=NULL,
280  int *scaleOpIndex=NULL) const;
281 
282  // Convenience functions
283  bool _HasTranslateOp() const {
284  return TF_VERIFY(_computedOpIndices) &&
285  _translateOpIndex != _InvalidIndex;
286  }
287 
288  bool _HasRotateOp() const {
289  return TF_VERIFY(_computedOpIndices) &&
290  _rotateOpIndex != _InvalidIndex;
291  }
292 
293  bool _HasScaleOp() const {
294  return TF_VERIFY(_computedOpIndices) &&
295  _scaleOpIndex != _InvalidIndex;
296  }
297 
298  bool _HasPivotOp () const {
299  return TF_VERIFY(_computedOpIndices) &&
300  _pivotOpIndex != _InvalidIndex;
301  }
302 
303 private:
304  // The xformable schema object on which this API operates.
305  UsdGeomXformable _xformable;
306 
307  static const int _InvalidIndex = -1;
308 
309  // Records whether the component xform ops indices have been computed and
310  // cached in the data members below. This happens the first time
311  // _IsCompatible is called, which is invoked inside the bool operator.
312  bool _computedOpIndices;
313 
314  // Copy of the ordered xform ops.
315  std::vector<UsdGeomXformOp> _xformOps;
316 
317  // Various op indices.
318  int _translateOpIndex;
319  int _rotateOpIndex;
320  int _scaleOpIndex;
321  int _pivotOpIndex;
322 };
323 
324 
325 PXR_NAMESPACE_CLOSE_SCOPE
326 
327 #endif
USDGEOM_API bool SetXformVectors(const GfVec3d &translation, const GfVec3f &rotation, const GfVec3f &scale, const GfVec3f &pivot, RotationOrder rotOrder, const UsdTimeCode time)
Set values for the various component xformOps at a given time.
static USDGEOM_API GfMatrix4d GetRotationTransform(const GfVec3f &rotation, const UsdGeomXformCommonAPI::RotationOrder rotationOrder)
Return the 4x4 matrix that applies the rotation encoded by rotation vector rotation using the rotatio...
USDGEOM_API bool SetTranslate(const GfVec3d &translation, const UsdTimeCode time=UsdTimeCode::Default())
Set translation at time to translation.
USDGEOM_API bool SetRotate(const GfVec3f &rotation, UsdGeomXformCommonAPI::RotationOrder rotOrder=RotationOrderXYZ, const UsdTimeCode time=UsdTimeCode::Default())
Set rotation at time to rotation.
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
USDGEOM_API bool SetScale(const GfVec3f &scale, const UsdTimeCode time=UsdTimeCode::Default())
Set scale at time to scale.
USDGEOM_API bool _IsCompatible() const override
Returns whether the underlying xformable is compatible with the API.
USDGEOM_API bool GetResetXformStack() const
Returns whether the xformable resets the transform stack.
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
Definition: diagnostic.h:289
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
USDGEOM_API bool SetResetXformStack(bool resetXformStack) const
Set whether the xformable resets the transform stack.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:131
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
static USDGEOM_API UsdGeomXformCommonAPI Get(const UsdStagePtr &stage, const SdfPath &path)
Return a UsdGeomXformCommonAPI holding the xformable adhering to this API at path on stage...
static constexpr UsdTimeCode Default()
Produce a UsdTimeCode representing the sentinel value for &#39;default&#39;.
Definition: timeCode.h:113
This class provides API for authoring and retrieving a standard set of component transformations whic...
USDGEOM_API bool SetPivot(const GfVec3f &pivot, const UsdTimeCode time=UsdTimeCode::Default())
Set pivot position at time to pivot.
USDGEOM_API std::vector< UsdGeomXformOp > GetOrderedXformOps(bool *resetsXformStack) const
Return the ordered list of transform operations to be applied to this prim, in least-to-most-local or...
Basic type for a vector of 3 double components.
Definition: vec3d.h:63
RotationOrder
Enumerates the rotation order of the 3-angle Euler rotation.
USD_API UsdSchemaBase(const UsdPrim &prim=UsdPrim())
Construct and store prim as the held prim.
The base class for all schema types in Usd.
Definition: schemaBase.h:56
USDGEOM_API bool GetXformVectors(GfVec3d *translation, GfVec3f *rotation, GfVec3f *scale, GfVec3f *pivot, RotationOrder *rotOrder, const UsdTimeCode time)
Retrieve values of the various component xformOps at a given time.
Base class for all transformable prims, which allows arbitrary sequences of component affine transfor...
Definition: xformable.h:252
USDGEOM_API bool GetXformVectorsByAccumulation(GfVec3d *translation, GfVec3f *rotation, GfVec3f *scale, GfVec3f *pivot, UsdGeomXformCommonAPI::RotationOrder *rotOrder, const UsdTimeCode time)
Retrieve values of the various component xformOps at a given time.
virtual USDGEOM_API ~UsdGeomXformCommonAPI()
Destructor.
UsdPrim GetPrim() const
Return this schema object&#39;s held prim.
Definition: schemaBase.h:119