HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
volume.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 USDVOL_GENERATED_VOLUME_H
8 #define USDVOL_GENERATED_VOLUME_H
9 
10 /// \file usdVol/volume.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usdVol/api.h"
14 #include "pxr/usd/usdGeom/gprim.h"
15 #include "pxr/usd/usd/prim.h"
16 #include "pxr/usd/usd/stage.h"
17 
18 #include "pxr/base/vt/value.h"
19 
20 #include "pxr/base/gf/vec3d.h"
21 #include "pxr/base/gf/vec3f.h"
22 #include "pxr/base/gf/matrix4d.h"
23 
24 #include "pxr/base/tf/token.h"
25 #include "pxr/base/tf/type.h"
26 
28 
29 class SdfAssetPath;
30 
31 // -------------------------------------------------------------------------- //
32 // VOLUME //
33 // -------------------------------------------------------------------------- //
34 
35 /// \class UsdVolVolume
36 ///
37 /// A renderable volume primitive. A volume is made up of any number
38 /// of FieldBase primitives bound together in this volume. Each
39 /// FieldBase primitive is specified as a relationship with a
40 /// namespace prefix of "field".
41 ///
42 /// The relationship name is used by the renderer to associate
43 /// individual fields with the named input parameters on the volume
44 /// shader. Using this indirect approach to connecting fields to
45 /// shader parameters (rather than using the field prim's name)
46 /// allows a single field to be reused for different shader inputs, or
47 /// to be used as different shader parameters when rendering different
48 /// Volumes. This means that the name of the field prim is not
49 /// relevant to its contribution to the volume prims which refer to
50 /// it. Nor does the field prim's location in the scene graph have
51 /// any relevance, and Volumes may refer to fields anywhere in the
52 /// scene graph. **However**, unless Field prims need to be shared
53 /// by multiple Volumes, a Volume's Field prims should be located
54 /// under the Volume in namespace, for enhanced organization.
55 ///
56 class UsdVolVolume : public UsdGeomGprim
57 {
58 public:
59  /// Compile time constant representing what kind of schema this class is.
60  ///
61  /// \sa UsdSchemaKind
63 
64  /// Construct a UsdVolVolume on UsdPrim \p prim .
65  /// Equivalent to UsdVolVolume::Get(prim.GetStage(), prim.GetPath())
66  /// for a \em valid \p prim, but will not immediately throw an error for
67  /// an invalid \p prim
68  explicit UsdVolVolume(const UsdPrim& prim=UsdPrim())
69  : UsdGeomGprim(prim)
70  {
71  }
72 
73  /// Construct a UsdVolVolume on the prim held by \p schemaObj .
74  /// Should be preferred over UsdVolVolume(schemaObj.GetPrim()),
75  /// as it preserves SchemaBase state.
76  explicit UsdVolVolume(const UsdSchemaBase& schemaObj)
77  : UsdGeomGprim(schemaObj)
78  {
79  }
80 
81  /// Destructor.
83  virtual ~UsdVolVolume();
84 
85  /// Return a vector of names of all pre-declared attributes for this schema
86  /// class and all its ancestor classes. Does not include attributes that
87  /// may be authored by custom/extended methods of the schemas involved.
89  static const TfTokenVector &
90  GetSchemaAttributeNames(bool includeInherited=true);
91 
92  /// Return a UsdVolVolume holding the prim adhering to this
93  /// schema at \p path on \p stage. If no prim exists at \p path on
94  /// \p stage, or if the prim at that path does not adhere to this schema,
95  /// return an invalid schema object. This is shorthand for the following:
96  ///
97  /// \code
98  /// UsdVolVolume(stage->GetPrimAtPath(path));
99  /// \endcode
100  ///
101  USDVOL_API
102  static UsdVolVolume
103  Get(const UsdStagePtr &stage, const SdfPath &path);
104 
105  /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
106  /// is defined (according to UsdPrim::IsDefined()) on this stage.
107  ///
108  /// If a prim adhering to this schema at \p path is already defined on this
109  /// stage, return that prim. Otherwise author an \a SdfPrimSpec with
110  /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
111  /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
112  /// with \p specifier == \a SdfSpecifierDef and empty typeName at the
113  /// current EditTarget for any nonexistent, or existing but not \a Defined
114  /// ancestors.
115  ///
116  /// The given \a path must be an absolute prim path that does not contain
117  /// any variant selections.
118  ///
119  /// If it is impossible to author any of the necessary PrimSpecs, (for
120  /// example, in case \a path cannot map to the current UsdEditTarget's
121  /// namespace) issue an error and return an invalid \a UsdPrim.
122  ///
123  /// Note that this method may return a defined prim whose typeName does not
124  /// specify this schema class, in case a stronger typeName opinion overrides
125  /// the opinion at the current EditTarget.
126  ///
127  USDVOL_API
128  static UsdVolVolume
129  Define(const UsdStagePtr &stage, const SdfPath &path);
130 
131 protected:
132  /// Returns the kind of schema this class belongs to.
133  ///
134  /// \sa UsdSchemaKind
135  USDVOL_API
136  UsdSchemaKind _GetSchemaKind() const override;
137 
138 private:
139  // needs to invoke _GetStaticTfType.
140  friend class UsdSchemaRegistry;
141  USDVOL_API
142  static const TfType &_GetStaticTfType();
143 
144  static bool _IsTypedSchema();
145 
146  // override SchemaBase virtuals.
147  USDVOL_API
148  const TfType &_GetTfType() const override;
149 
150 public:
151  // ===================================================================== //
152  // Feel free to add custom code below this line, it will be preserved by
153  // the code generator.
154  //
155  // Just remember to:
156  // - Close the class declaration with };
157  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
158  // - Close the include guard with #endif
159  // ===================================================================== //
160  // --(BEGIN CUSTOM CODE)--
161 
162  // --------------------------------------------------------------------- //
163  /// \name Field Attachment and Inspection
164  /// @{
165  // --------------------------------------------------------------------- //
166 
167  typedef std::map<TfToken, SdfPath> FieldMap;
168 
169  /// Return a map of field relationship names to the fields themselves,
170  /// represented as prim paths. This map provides all the information
171  /// that should be needed to tie fields to shader parameters and render
172  /// this volume.
173  ///
174  /// The field relationship names that server as the map keys will have
175  /// the field namespace stripped from them.
176  USDVOL_API
177  FieldMap GetFieldPaths() const;
178 
179  /// Checks if there is an existing field relationship with a given name.
180  /// This query will return \c true even for a field relationship that
181  /// has been blocked and therefore will not contribute to the map
182  /// returned by GetFieldRelationships()
183  ///
184  /// The name lookup automatically applies the field relationship
185  /// namespacing, if it isn't specified in the name token.
186  USDVOL_API
187  bool HasFieldRelationship(const TfToken &name) const;
188 
189  /// Checks if there is an existing field relationship with a given name,
190  /// and if so, returns the path to the Field prim it targets, or else
191  /// the empty path.
192  ///
193  /// The name lookup automatically applies the field relationship
194  /// namespacing, if it isn't specified in the name token.
195  USDVOL_API
196  SdfPath GetFieldPath(const TfToken &name) const;
197 
198  /// Creates a relationship on this volume that targets the specified field.
199  /// If an existing relationship exists with the same name, it is replaced
200  /// (since only one target is allowed for each named relationship).
201  ///
202  /// Returns \c true if the relationship was successfully created and set -
203  /// it is legal to call this method for a field relationship that already
204  /// "exists", i.e. already posesses scene description, as this is the
205  /// only method we provide for setting a field relatioonship's value, to help
206  /// enforce that field relationships can have only a single (or no) target.
207  ///
208  /// \param fieldPath - can be a prim path, or the path of another
209  /// relationship, to effect \ref usd_relationship_forwarding
210  ///
211  /// The name lookup automatically applies the field relationship
212  /// namespacing, if it isn't specified in the name token.
213  USDVOL_API
215  const SdfPath &fieldPath) const;
216 
217  /// Blocks an existing field relationship on this volume, ensuring it
218  /// will not be enumerated by GetFieldPaths().
219  ///
220  /// Returns true if the relationship existed, false if it did not. In other
221  /// words the return value indicates whether the volume prim was changed.
222  ///
223  /// The name lookup automatically applies the field relationship
224  /// namespacing, if it isn't specified in the name token.
225  USDVOL_API
226  bool BlockFieldRelationship(const TfToken &name) const;
227 
228 private:
229  /// Return \p name prepended with the field namespace, if it isn't
230  /// already prefixed.
231  ///
232  /// Does not validate name as a legal relationship identifier.
233  static TfToken _MakeNamespaced(const TfToken& name);
234 };
235 
237 
238 #endif
static USDVOL_API UsdVolVolume Get(const UsdStagePtr &stage, const SdfPath &path)
static const UsdSchemaKind schemaKind
Definition: volume.h:62
USDVOL_API FieldMap GetFieldPaths() const
virtual USDVOL_API ~UsdVolVolume()
Destructor.
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USDVOL_API bool HasFieldRelationship(const TfToken &name) const
UsdVolVolume(const UsdPrim &prim=UsdPrim())
Definition: volume.h:68
Definition: token.h:70
Represents a concrete typed schema.
UsdVolVolume(const UsdSchemaBase &schemaObj)
Definition: volume.h:76
Definition: prim.h:116
static USDVOL_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:273
USDVOL_API bool BlockFieldRelationship(const TfToken &name) const
USDVOL_API SdfPath GetFieldPath(const TfToken &name) const
UsdSchemaKind
Definition: common.h:112
USDVOL_API bool CreateFieldRelationship(const TfToken &name, const SdfPath &fieldPath) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
USDVOL_API UsdSchemaKind _GetSchemaKind() const override
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Definition: type.h:47
#define USDVOL_API
Definition: api.h:23
std::map< TfToken, SdfPath > FieldMap
Definition: volume.h:167
static USDVOL_API UsdVolVolume Define(const UsdStagePtr &stage, const SdfPath &path)