HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hermiteCurves.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_HERMITECURVES_H
8 #define USDGEOM_GENERATED_HERMITECURVES_H
9 
10 /// \file usdGeom/hermiteCurves.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usdGeom/api.h"
14 #include "pxr/usd/usdGeom/curves.h"
15 #include "pxr/usd/usd/prim.h"
16 #include "pxr/usd/usd/stage.h"
17 #include "pxr/usd/usdGeom/tokens.h"
18 
19 #include "pxr/base/vt/value.h"
20 
21 #include "pxr/base/gf/vec3d.h"
22 #include "pxr/base/gf/vec3f.h"
23 #include "pxr/base/gf/matrix4d.h"
24 
25 #include "pxr/base/tf/token.h"
26 #include "pxr/base/tf/type.h"
27 
29 
30 class SdfAssetPath;
31 
32 // -------------------------------------------------------------------------- //
33 // HERMITECURVES //
34 // -------------------------------------------------------------------------- //
35 
36 /// \class UsdGeomHermiteCurves
37 ///
38 /// This schema specifies a cubic hermite interpolated curve batch as
39 /// sometimes used for defining guides for animation. While hermite curves can
40 /// be useful because they interpolate through their control points, they are
41 /// not well supported by high-end renderers for imaging. Therefore, while we
42 /// include this schema for interchange, we strongly recommend the use of
43 /// UsdGeomBasisCurves as the representation of curves intended to be rendered
44 /// (ie. hair or grass). Hermite curves can be converted to a Bezier
45 /// representation (though not from Bezier back to Hermite in general).
46 ///
47 /// \section UsdGeomHermiteCurves_Interpolation Point Interpolation
48 ///
49 /// The initial cubic curve segment is defined by the first two points and
50 /// first two tangents. Additional segments are defined by additional
51 /// point / tangent pairs. The number of segments for each non-batched hermite
52 /// curve would be len(curve.points) - 1. The total number of segments
53 /// for the batched UsdGeomHermiteCurves representation is
54 /// len(points) - len(curveVertexCounts).
55 ///
56 /// \section UsdGeomHermiteCurves_Primvars Primvar, Width, and Normal Interpolation
57 ///
58 /// Primvar interpolation is not well specified for this type as it is not
59 /// intended as a rendering representation. We suggest that per point
60 /// primvars would be linearly interpolated across each segment and should
61 /// be tagged as 'varying'.
62 ///
63 /// It is not immediately clear how to specify cubic or 'vertex' interpolation
64 /// for this type, as we lack a specification for primvar tangents. This
65 /// also means that width and normal interpolation should be restricted to
66 /// varying (linear), uniform (per curve element), or constant (per prim).
67 ///
68 ///
70 {
71 public:
72  /// Compile time constant representing what kind of schema this class is.
73  ///
74  /// \sa UsdSchemaKind
76 
77  /// Construct a UsdGeomHermiteCurves on UsdPrim \p prim .
78  /// Equivalent to UsdGeomHermiteCurves::Get(prim.GetStage(), prim.GetPath())
79  /// for a \em valid \p prim, but will not immediately throw an error for
80  /// an invalid \p prim
81  explicit UsdGeomHermiteCurves(const UsdPrim& prim=UsdPrim())
82  : UsdGeomCurves(prim)
83  {
84  }
85 
86  /// Construct a UsdGeomHermiteCurves on the prim held by \p schemaObj .
87  /// Should be preferred over UsdGeomHermiteCurves(schemaObj.GetPrim()),
88  /// as it preserves SchemaBase state.
89  explicit UsdGeomHermiteCurves(const UsdSchemaBase& schemaObj)
90  : UsdGeomCurves(schemaObj)
91  {
92  }
93 
94  /// Destructor.
96  virtual ~UsdGeomHermiteCurves();
97 
98  /// Return a vector of names of all pre-declared attributes for this schema
99  /// class and all its ancestor classes. Does not include attributes that
100  /// may be authored by custom/extended methods of the schemas involved.
102  static const TfTokenVector &
103  GetSchemaAttributeNames(bool includeInherited=true);
104 
105  /// Return a UsdGeomHermiteCurves holding the prim adhering to this
106  /// schema at \p path on \p stage. If no prim exists at \p path on
107  /// \p stage, or if the prim at that path does not adhere to this schema,
108  /// return an invalid schema object. This is shorthand for the following:
109  ///
110  /// \code
111  /// UsdGeomHermiteCurves(stage->GetPrimAtPath(path));
112  /// \endcode
113  ///
115  static UsdGeomHermiteCurves
116  Get(const UsdStagePtr &stage, const SdfPath &path);
117 
118  /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
119  /// is defined (according to UsdPrim::IsDefined()) on this stage.
120  ///
121  /// If a prim adhering to this schema at \p path is already defined on this
122  /// stage, return that prim. Otherwise author an \a SdfPrimSpec with
123  /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
124  /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
125  /// with \p specifier == \a SdfSpecifierDef and empty typeName at the
126  /// current EditTarget for any nonexistent, or existing but not \a Defined
127  /// ancestors.
128  ///
129  /// The given \a path must be an absolute prim path that does not contain
130  /// any variant selections.
131  ///
132  /// If it is impossible to author any of the necessary PrimSpecs, (for
133  /// example, in case \a path cannot map to the current UsdEditTarget's
134  /// namespace) issue an error and return an invalid \a UsdPrim.
135  ///
136  /// Note that this method may return a defined prim whose typeName does not
137  /// specify this schema class, in case a stronger typeName opinion overrides
138  /// the opinion at the current EditTarget.
139  ///
141  static UsdGeomHermiteCurves
142  Define(const UsdStagePtr &stage, const SdfPath &path);
143 
144 protected:
145  /// Returns the kind of schema this class belongs to.
146  ///
147  /// \sa UsdSchemaKind
149  UsdSchemaKind _GetSchemaKind() const override;
150 
151 private:
152  // needs to invoke _GetStaticTfType.
153  friend class UsdSchemaRegistry;
155  static const TfType &_GetStaticTfType();
156 
157  static bool _IsTypedSchema();
158 
159  // override SchemaBase virtuals.
161  const TfType &_GetTfType() const override;
162 
163 public:
164  // --------------------------------------------------------------------- //
165  // TANGENTS
166  // --------------------------------------------------------------------- //
167  /// Defines the outgoing trajectory tangent for each point.
168  /// Tangents should be the same size as the points attribute.
169  ///
170  /// | ||
171  /// | -- | -- |
172  /// | Declaration | `vector3f[] tangents = []` |
173  /// | C++ Type | VtArray<GfVec3f> |
174  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Vector3fArray |
177 
178  /// See GetTangentsAttr(), and also
179  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
180  /// If specified, author \p defaultValue as the attribute's default,
181  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
182  /// the default for \p writeSparsely is \c false.
184  UsdAttribute CreateTangentsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
185 
186 public:
187  // ===================================================================== //
188  // Feel free to add custom code below this line, it will be preserved by
189  // the code generator.
190  //
191  // Just remember to:
192  // - Close the class declaration with };
193  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
194  // - Close the include guard with #endif
195  // ===================================================================== //
196  // --(BEGIN CUSTOM CODE)--
197 
198  /// Represents points and tangents of the same size.
199  ///
200  /// Utility to interleave point and tangent data. This class is immutable.
202  VtArray<GfVec3f> _points;
203  VtArray<GfVec3f> _tangents;
204 
205  explicit PointAndTangentArrays(const VtVec3fArray& interleaved);
206 
207  public:
208 
209  /// Construct empty points and tangents arrays
210  PointAndTangentArrays() = default;
214  default;
216 
217  /// Initializes \p points and \p tangents if they are the same size.
218  ///
219  /// If points and tangents are not the same size, an empty container
220  /// is created.
221  PointAndTangentArrays(const VtVec3fArray& points,
222  const VtVec3fArray& tangents)
223  : _points(points), _tangents(tangents) {
224  if (_points.size() != _tangents.size()) {
225  TF_RUNTIME_ERROR("Points and tangents must be the same size.");
226  _points.clear();
227  _tangents.clear();
228  }
229  }
230 
231  /// Given an \p interleaved points and tangents arrays (P0, T0, ..., Pn,
232  /// Tn), separates them into two arrays (P0, ..., PN) and (T0, ..., Tn).
233  USDGEOM_API static PointAndTangentArrays Separate(const VtVec3fArray& interleaved) {
234  return PointAndTangentArrays(interleaved);
235  }
236 
237  /// Interleaves points (P0, ..., Pn) and tangents (T0, ..., Tn) into
238  /// one array (P0, T0, ..., Pn, Tn).
239  USDGEOM_API VtVec3fArray Interleave() const;
240 
241  /// Returns true if the containers are empty
242  bool IsEmpty() const {
243  // we only need to check the points, as we've verified on
244  // construction that _points and _tangents have the same size
245  return _points.empty();
246  }
247 
248  /// Returns true if there are values
249  explicit operator bool() const { return !IsEmpty(); }
250 
251  /// Get separated points array
252  const VtVec3fArray& GetPoints() const { return _points; }
253 
254  /// Get separated tangents array
255  const VtVec3fArray& GetTangents() const { return _tangents; }
256 
257  bool operator==(const PointAndTangentArrays& other) {
258  return (GetPoints() == other.GetPoints()) &&
259  (GetTangents() == other.GetTangents());
260  }
261  bool operator!=(const PointAndTangentArrays& other) {
262  return !((*this) == other);
263  }
264  };
265 };
266 
268 
269 #endif
const VtVec3fArray & GetPoints() const
Get separated points array.
GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glad.h:2676
static USDGEOM_API PointAndTangentArrays Separate(const VtVec3fArray &interleaved)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
static USDGEOM_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
static const UsdSchemaKind schemaKind
Definition: hermiteCurves.h:75
OutGridT const XformOp bool bool
bool operator!=(const PointAndTangentArrays &other)
#define TF_RUNTIME_ERROR
PointAndTangentArrays & operator=(const PointAndTangentArrays &)=default
Represents a concrete typed schema.
USDGEOM_API UsdAttribute GetTangentsAttr() const
const VtVec3fArray & GetTangents() const
Get separated tangents array.
static USDGEOM_API UsdGeomHermiteCurves Define(const UsdStagePtr &stage, const SdfPath &path)
USDGEOM_API VtVec3fArray Interleave() const
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
PointAndTangentArrays(const VtVec3fArray &points, const VtVec3fArray &tangents)
Definition: path.h:273
bool operator==(const PointAndTangentArrays &other)
UsdSchemaKind
Definition: common.h:112
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
USDGEOM_API UsdSchemaKind _GetSchemaKind() const override
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
PointAndTangentArrays()=default
Construct empty points and tangents arrays.
Definition: type.h:47
#define USDGEOM_API
Definition: api.h:23
UsdGeomHermiteCurves(const UsdSchemaBase &schemaObj)
Definition: hermiteCurves.h:89
UsdGeomHermiteCurves(const UsdPrim &prim=UsdPrim())
Definition: hermiteCurves.h:81
virtual USDGEOM_API ~UsdGeomHermiteCurves()
Destructor.
bool IsEmpty() const
Returns true if the containers are empty.
USDGEOM_API UsdAttribute CreateTangentsAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
Definition: value.h:146
static USDGEOM_API UsdGeomHermiteCurves Get(const UsdStagePtr &stage, const SdfPath &path)