HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
materialAPI.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 USDRI_GENERATED_MATERIALAPI_H
8 #define USDRI_GENERATED_MATERIALAPI_H
9 
10 /// \file usdRi/materialAPI.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usdRi/api.h"
15 #include "pxr/usd/usd/prim.h"
16 #include "pxr/usd/usd/stage.h"
17 #include "pxr/usd/usdRi/tokens.h"
18 
19 #include "pxr/usd/usdShade/input.h"
22 
23 
24 #include "pxr/base/vt/value.h"
25 
26 #include "pxr/base/gf/vec3d.h"
27 #include "pxr/base/gf/vec3f.h"
28 #include "pxr/base/gf/matrix4d.h"
29 
30 #include "pxr/base/tf/token.h"
31 #include "pxr/base/tf/type.h"
32 
34 
35 class SdfAssetPath;
36 
37 // -------------------------------------------------------------------------- //
38 // RIMATERIALAPI //
39 // -------------------------------------------------------------------------- //
40 
41 /// \class UsdRiMaterialAPI
42 ///
43 ///
44 /// \deprecated Materials should use UsdShadeMaterial instead.
45 /// This schema will be removed in a future release.
46 ///
47 /// This API provides outputs that connect a material prim to prman
48 /// shaders and RIS objects.
49 ///
50 /// For any described attribute \em Fallback \em Value or \em Allowed \em Values below
51 /// that are text/tokens, the actual token is published and defined in \ref UsdRiTokens.
52 /// So to set an attribute to the value "rightHanded", use UsdRiTokens->rightHanded
53 /// as the value.
54 ///
56 {
57 public:
58  /// Compile time constant representing what kind of schema this class is.
59  ///
60  /// \sa UsdSchemaKind
62 
63  /// Construct a UsdRiMaterialAPI on UsdPrim \p prim .
64  /// Equivalent to UsdRiMaterialAPI::Get(prim.GetStage(), prim.GetPath())
65  /// for a \em valid \p prim, but will not immediately throw an error for
66  /// an invalid \p prim
67  explicit UsdRiMaterialAPI(const UsdPrim& prim=UsdPrim())
68  : UsdAPISchemaBase(prim)
69  {
70  }
71 
72  /// Construct a UsdRiMaterialAPI on the prim held by \p schemaObj .
73  /// Should be preferred over UsdRiMaterialAPI(schemaObj.GetPrim()),
74  /// as it preserves SchemaBase state.
75  explicit UsdRiMaterialAPI(const UsdSchemaBase& schemaObj)
76  : UsdAPISchemaBase(schemaObj)
77  {
78  }
79 
80  /// Destructor.
81  USDRI_API
82  virtual ~UsdRiMaterialAPI();
83 
84  /// Return a vector of names of all pre-declared attributes for this schema
85  /// class and all its ancestor classes. Does not include attributes that
86  /// may be authored by custom/extended methods of the schemas involved.
87  USDRI_API
88  static const TfTokenVector &
89  GetSchemaAttributeNames(bool includeInherited=true);
90 
91  /// Return a UsdRiMaterialAPI holding the prim adhering to this
92  /// schema at \p path on \p stage. If no prim exists at \p path on
93  /// \p stage, or if the prim at that path does not adhere to this schema,
94  /// return an invalid schema object. This is shorthand for the following:
95  ///
96  /// \code
97  /// UsdRiMaterialAPI(stage->GetPrimAtPath(path));
98  /// \endcode
99  ///
100  USDRI_API
101  static UsdRiMaterialAPI
102  Get(const UsdStagePtr &stage, const SdfPath &path);
103 
104 
105  /// Returns true if this <b>single-apply</b> API schema can be applied to
106  /// the given \p prim. If this schema can not be a applied to the prim,
107  /// this returns false and, if provided, populates \p whyNot with the
108  /// reason it can not be applied.
109  ///
110  /// Note that if CanApply returns false, that does not necessarily imply
111  /// that calling Apply will fail. Callers are expected to call CanApply
112  /// before calling Apply if they want to ensure that it is valid to
113  /// apply a schema.
114  ///
115  /// \sa UsdPrim::GetAppliedSchemas()
116  /// \sa UsdPrim::HasAPI()
117  /// \sa UsdPrim::CanApplyAPI()
118  /// \sa UsdPrim::ApplyAPI()
119  /// \sa UsdPrim::RemoveAPI()
120  ///
121  USDRI_API
122  static bool
123  CanApply(const UsdPrim &prim, std::string *whyNot=nullptr);
124 
125  /// Applies this <b>single-apply</b> API schema to the given \p prim.
126  /// This information is stored by adding "RiMaterialAPI" to the
127  /// token-valued, listOp metadata \em apiSchemas on the prim.
128  ///
129  /// \return A valid UsdRiMaterialAPI object is returned upon success.
130  /// An invalid (or empty) UsdRiMaterialAPI object is returned upon
131  /// failure. See \ref UsdPrim::ApplyAPI() for conditions
132  /// resulting in failure.
133  ///
134  /// \sa UsdPrim::GetAppliedSchemas()
135  /// \sa UsdPrim::HasAPI()
136  /// \sa UsdPrim::CanApplyAPI()
137  /// \sa UsdPrim::ApplyAPI()
138  /// \sa UsdPrim::RemoveAPI()
139  ///
140  USDRI_API
141  static UsdRiMaterialAPI
142  Apply(const UsdPrim &prim);
143 
144 protected:
145  /// Returns the kind of schema this class belongs to.
146  ///
147  /// \sa UsdSchemaKind
148  USDRI_API
149  UsdSchemaKind _GetSchemaKind() const override;
150 
151 private:
152  // needs to invoke _GetStaticTfType.
153  friend class UsdSchemaRegistry;
154  USDRI_API
155  static const TfType &_GetStaticTfType();
156 
157  static bool _IsTypedSchema();
158 
159  // override SchemaBase virtuals.
160  USDRI_API
161  const TfType &_GetTfType() const override;
162 
163 public:
164  // --------------------------------------------------------------------- //
165  // SURFACE
166  // --------------------------------------------------------------------- //
167  ///
168  ///
169  /// | ||
170  /// | -- | -- |
171  /// | Declaration | `token outputs:ri:surface` |
172  /// | C++ Type | TfToken |
173  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
174  USDRI_API
176 
177  /// See GetSurfaceAttr(), and also
178  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
179  /// If specified, author \p defaultValue as the attribute's default,
180  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
181  /// the default for \p writeSparsely is \c false.
182  USDRI_API
183  UsdAttribute CreateSurfaceAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
184 
185 public:
186  // --------------------------------------------------------------------- //
187  // DISPLACEMENT
188  // --------------------------------------------------------------------- //
189  ///
190  ///
191  /// | ||
192  /// | -- | -- |
193  /// | Declaration | `token outputs:ri:displacement` |
194  /// | C++ Type | TfToken |
195  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
196  USDRI_API
198 
199  /// See GetDisplacementAttr(), and also
200  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
201  /// If specified, author \p defaultValue as the attribute's default,
202  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
203  /// the default for \p writeSparsely is \c false.
204  USDRI_API
205  UsdAttribute CreateDisplacementAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
206 
207 public:
208  // --------------------------------------------------------------------- //
209  // VOLUME
210  // --------------------------------------------------------------------- //
211  ///
212  ///
213  /// | ||
214  /// | -- | -- |
215  /// | Declaration | `token outputs:ri:volume` |
216  /// | C++ Type | TfToken |
217  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
218  USDRI_API
219  UsdAttribute GetVolumeAttr() const;
220 
221  /// See GetVolumeAttr(), and also
222  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
223  /// If specified, author \p defaultValue as the attribute's default,
224  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
225  /// the default for \p writeSparsely is \c false.
226  USDRI_API
227  UsdAttribute CreateVolumeAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
228 
229 public:
230  // ===================================================================== //
231  // Feel free to add custom code below this line, it will be preserved by
232  // the code generator.
233  //
234  // Just remember to:
235  // - Close the class declaration with };
236  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
237  // - Close the include guard with #endif
238  // ===================================================================== //
239  // --(BEGIN CUSTOM CODE)--
240 
241  /// A constructor for creating a MaterialAPI object from a material prim.
242  explicit UsdRiMaterialAPI(const UsdShadeMaterial& material)
243  : UsdRiMaterialAPI(material.GetPrim())
244  {
245  }
246 
247  // --------------------------------------------------------------------- //
248  /// \name Outputs API
249  // --------------------------------------------------------------------- //
250  /// @{
251 
252  /// Returns the "surface" output associated with the material.
253  USDRI_API
255 
256  /// Returns the "displacement" output associated with the material.
257  USDRI_API
259 
260  /// Returns the "volume" output associated with the material.
261  USDRI_API
263 
264  /// @}
265 
266  // --------------------------------------------------------------------- //
267  /// \name API for setting sources of outputs
268  // --------------------------------------------------------------------- //
269  /// @{
270 
271  USDRI_API
272  bool SetSurfaceSource(const SdfPath &surfacePath) const;
273 
274  USDRI_API
275  bool SetDisplacementSource(const SdfPath &displacementPath) const;
276 
277  USDRI_API
278  bool SetVolumeSource(const SdfPath &volumePath) const;
279 
280  /// @}
281 
282  // --------------------------------------------------------------------- //
283  /// \name Shaders API
284  // --------------------------------------------------------------------- //
285  /// @{
286 
287  /// Returns a valid shader object if the "surface" output on the
288  /// material is connected to one.
289  ///
290  /// If \p ignoreBaseMaterial is true and if the "surface" shader source
291  /// is specified in the base-material of this material, then this
292  /// returns an invalid shader object.
293  USDRI_API
294  UsdShadeShader GetSurface(bool ignoreBaseMaterial=false) const;
295 
296  /// Returns a valid shader object if the "displacement" output on the
297  /// material is connected to one.
298  ///
299  /// If \p ignoreBaseMaterial is true and if the "displacement" shader source
300  /// is specified in the base-material of this material, then this
301  /// returns an invalid shader object.
302  USDRI_API
303  UsdShadeShader GetDisplacement(bool ignoreBaseMaterial=false) const;
304 
305  /// Returns a valid shader object if the "volume" output on the
306  /// material is connected to one.
307  ///
308  /// If \p ignoreBaseMaterial is true and if the "volume" shader source
309  /// is specified in the base-material of this material, then this
310  /// returns an invalid shader object.
311  USDRI_API
312  UsdShadeShader GetVolume(bool ignoreBaseMaterial=false) const;
313 
314  /// @}
315 
316 
317  /// Walks the namespace subtree below the material and computes a map
318  /// containing the list of all inputs on the material and the associated
319  /// vector of consumers of their values. The consumers can be inputs on
320  /// shaders within the material or on node-graphs under it.
321  USDRI_API
324  bool computeTransitiveConsumers=false) const;
325 
326  /// @}
327 
328 private:
329  UsdShadeShader _GetSourceShaderObject(const UsdShadeOutput &output,
330  bool ignoreBaseMaterial) const;
331 
332  // Helper method to get the deprecated 'bxdf' output.
333  UsdShadeOutput _GetBxdfOutput(const UsdPrim &materialPrim) const;
334 };
335 
337 
338 #endif
std::unordered_map< UsdShadeInput, std::vector< UsdShadeInput >, UsdShadeInput::Hash > InterfaceInputConsumersMap
Definition: nodeGraph.h:338
USDRI_API UsdShadeShader GetDisplacement(bool ignoreBaseMaterial=false) const
USDRI_API UsdSchemaKind _GetSchemaKind() const override
Single Apply API schema.
USDRI_API UsdAttribute GetVolumeAttr() const
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USDRI_API UsdShadeShader GetSurface(bool ignoreBaseMaterial=false) const
UsdRiMaterialAPI(const UsdPrim &prim=UsdPrim())
Definition: materialAPI.h:67
static const UsdSchemaKind schemaKind
Definition: materialAPI.h:61
USDRI_API UsdAttribute GetSurfaceAttr() const
virtual USDRI_API ~UsdRiMaterialAPI()
Destructor.
static USDRI_API bool CanApply(const UsdPrim &prim, std::string *whyNot=nullptr)
USDRI_API bool SetDisplacementSource(const SdfPath &displacementPath) const
USDRI_API UsdAttribute CreateSurfaceAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDRI_API UsdAttribute CreateVolumeAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDRI_API UsdShadeShader GetVolume(bool ignoreBaseMaterial=false) const
static USDRI_API UsdRiMaterialAPI Get(const UsdStagePtr &stage, const SdfPath &path)
Definition: prim.h:116
static USDRI_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
USDRI_API UsdAttribute GetDisplacementAttr() const
#define USDRI_API
Definition: api.h:23
Definition: path.h:273
UsdRiMaterialAPI(const UsdSchemaBase &schemaObj)
Definition: materialAPI.h:75
USDRI_API UsdShadeOutput GetDisplacementOutput() const
Returns the "displacement" output associated with the material.
USDRI_API UsdShadeOutput GetSurfaceOutput() const
Returns the "surface" output associated with the material.
USDRI_API UsdShadeOutput GetVolumeOutput() const
Returns the "volume" output associated with the material.
UsdSchemaKind
Definition: common.h:112
UsdRiMaterialAPI(const UsdShadeMaterial &material)
A constructor for creating a MaterialAPI object from a material prim.
Definition: materialAPI.h:242
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
USDRI_API UsdAttribute CreateDisplacementAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static USDRI_API UsdRiMaterialAPI Apply(const UsdPrim &prim)
USDRI_API UsdShadeNodeGraph::InterfaceInputConsumersMap ComputeInterfaceInputConsumersMap(bool computeTransitiveConsumers=false) const
Definition: type.h:47
USDRI_API bool SetVolumeSource(const SdfPath &volumePath) const
UsdPrim GetPrim() const
Return this schema object's held prim.
Definition: schemaBase.h:103
USDRI_API bool SetSurfaceSource(const SdfPath &surfacePath) const
Definition: value.h:146