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