HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
constraintTarget.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 PXR_USD_USD_GEOM_CONSTRAINT_TARGET_H
8 #define PXR_USD_USD_GEOM_CONSTRAINT_TARGET_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/usd/usdGeom/api.h"
12 #include "pxr/usd/usd/attribute.h"
13 
14 #include <string>
15 
17 
18 
19 class GfMatrix4d;
20 class UsdGeomXformCache;
21 
22 /// \class UsdGeomConstraintTarget
23 ///
24 /// Schema wrapper for UsdAttribute for authoring and introspecting
25 /// attributes that are constraint targets.
26 ///
27 /// Constraint targets correspond roughly to what some DCC's call locators.
28 /// They are coordinate frames, represented as (animated or static) GfMatrix4d
29 /// values. We represent them as attributes in USD rather than transformable
30 /// prims because generally we require no other coordinated information about
31 /// a constraint target other than its name and its matrix value, and because
32 /// attributes are more concise than prims.
33 ///
34 /// Because consumer clients often care only about the identity and value of
35 /// constraint targets and may be able to usefully consume them without caring
36 /// about the actual geometry with which they may logically correspond,
37 /// UsdGeom aggregates all constraint targets onto a model's root prim,
38 /// assuming that an exporter will use property namespacing within the
39 /// constraint target attribute's name to indicate a path to a prim within
40 /// the model with which the constraint target may correspond.
41 ///
42 /// To facilitate instancing, and also position-tweaking of baked assets, we
43 /// stipulate that constraint target values always be recorded in
44 /// <b>model-relative transformation space</b>. In other words, to get the
45 /// world-space value of a constraint target, transform it by the
46 /// local-to-world transformation of the prim on which it is recorded.
47 /// ComputeInWorldSpace() will perform this calculation.
48 ///
49 /// \todo Provide API for extracting prim or property path from a target's
50 /// namespaced name.
51 ///
53 {
54 public:
55 
56  // Default constructor returns an invalid ConstraintTarget. Exists for
57  // container classes
59  {
60  /* NOTHING */
61  }
62 
63  /// Speculative constructor that will produce a valid
64  /// UsdGeomConstraintTarget when \p attr already represents an attribute
65  /// that is a UsdGeomConstraintTarget, and produces an \em invalid
66  /// UsdGeomConstraintTarget otherwise (i.e.
67  /// \ref UsdGeomConstraintTarget_explicit_bool will return false).
68  ///
69  /// Calling \c UsdGeomConstraintTarget::IsValid(attr) will return the
70  /// same truth value as the object returned by this constructor, but if
71  /// you plan to subsequently use the ConstraintTarget anyways, just
72  /// construct the object and bool-evaluate it before proceeding.
74  explicit UsdGeomConstraintTarget(const UsdAttribute &attr);
75 
76  /// Test whether a given UsdAttribute represents valid ConstraintTarget,
77  /// which implies that creating a UsdGeomConstraintTarget from the attribute
78  /// will succeed.
79  ///
80  /// Success implies that \c attr.IsDefined() is true.
82  static bool IsValid(const UsdAttribute &attr);
83 
84  // ---------------------------------------------------------------
85  /// \name UsdAttribute API
86  // ---------------------------------------------------------------
87 
88  /// Allow UsdGeomConstraintTarget to auto-convert to UsdAttribute, so you
89  /// can pass a UsdGeomConstraintTarget to any function that accepts a
90  /// UsdAttribute or const-ref thereto.
91  operator UsdAttribute const& () const { return _attr; }
92 
93  /// Explicit UsdAttribute extractor
94  UsdAttribute const &GetAttr() const { return _attr; }
95 
96  /// Return true if the wrapped UsdAttribute::IsDefined(), and in
97  /// addition the attribute is identified as a ConstraintTarget.
98  bool IsDefined() const { return IsValid(_attr); }
99 
100 
101  /// \anchor UsdGeomConstraintTarget_explicit_bool
102  /// Explicit bool conversion operator. A ConstraintTarget object converts
103  /// to \c true iff it is valid for querying and authoring values and
104  /// metadata (which is identically equivalent to IsDefined()). It converts
105  /// to \c false otherwise.
106  explicit operator bool() const {
107  return IsDefined();
108  }
109 
110  /// Get the attribute value of the ConstraintTarget at \p time
113  const;
114 
115  /// Set the attribute value of the ConstraintTarget at \p time
117  bool Set(const GfMatrix4d& value, UsdTimeCode time = UsdTimeCode::Default())
118  const;
119 
120  /// Get the stored identifier unique to the enclosing model's namespace for
121  /// this constraint target.
122  /// \sa SetIdentifier()
124  TfToken GetIdentifier() const;
125 
126  /// Explicitly sets the stored identifier to the given string. Clients are
127  /// responsible for ensuring the uniqueness of this identifier within the
128  /// enclosing model's namespace.
130  void SetIdentifier(const TfToken &identifier);
131 
132  /// Returns the fully namespaced constraint attribute name, given the
133  /// constraint name.
135  static TfToken GetConstraintAttrName(const std::string &constraintName);
136 
137  /// Computes the value of the constraint target in world space.
138  ///
139  /// If a valid UsdGeomXformCache is provided in the argument \p xfCache,
140  /// it is used to evaluate the CTM of the model to which the constraint
141  /// target belongs.
142  ///
143  /// To get the constraint value in model-space (or local space), simply
144  /// use UsdGeomConstraintTarget::Get(), since the authored values must
145  /// already be in model-space.
146  ///
149  UsdGeomXformCache *xfCache=NULL) const;
150 
151 private:
152 
153  UsdAttribute _attr;
154 };
155 
156 
158 
159 #endif // USD_CONSTRAINT_TARGET_H
static constexpr UsdTimeCode Default()
Definition: timeCode.h:113
GT_API const UT_StringHolder time
GLsizei const GLfloat * value
Definition: glcorearb.h:824
USDGEOM_API void SetIdentifier(const TfToken &identifier)
USDGEOM_API bool Set(const GfMatrix4d &value, UsdTimeCode time=UsdTimeCode::Default()) const
Set the attribute value of the ConstraintTarget at time.
USDGEOM_API TfToken GetIdentifier() const
OutGridT const XformOp bool bool
static USDGEOM_API bool IsValid(const UsdAttribute &attr)
Definition: token.h:70
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USDGEOM_API bool Get(GfMatrix4d *value, UsdTimeCode time=UsdTimeCode::Default()) const
Get the attribute value of the ConstraintTarget at time.
#define USDGEOM_API
Definition: api.h:23
static USDGEOM_API TfToken GetConstraintAttrName(const std::string &constraintName)
UsdAttribute const & GetAttr() const
Explicit UsdAttribute extractor.
USDGEOM_API GfMatrix4d ComputeInWorldSpace(UsdTimeCode time=UsdTimeCode::Default(), UsdGeomXformCache *xfCache=NULL) const