material.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 USDSHADE_GENERATED_MATERIAL_H
25 #define USDSHADE_GENERATED_MATERIAL_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/usdShade/api.h"
32 #include "pxr/usd/usd/prim.h"
33 #include "pxr/usd/usd/stage.h"
35 
36 #include "pxr/usd/usd/variantSets.h"
37 #include "pxr/usd/usdGeom/subset.h"
39 
40 #include "pxr/base/vt/value.h"
41 
42 #include "pxr/base/gf/vec3d.h"
43 #include "pxr/base/gf/vec3f.h"
44 #include "pxr/base/gf/matrix4d.h"
45 
46 #include "pxr/base/tf/token.h"
47 #include "pxr/base/tf/type.h"
48 
49 PXR_NAMESPACE_OPEN_SCOPE
50 
51 class SdfAssetPath;
52 
53 // -------------------------------------------------------------------------- //
54 // MATERIAL //
55 // -------------------------------------------------------------------------- //
56 
112 {
113 public:
118 
123  explicit UsdShadeMaterial(const UsdPrim& prim=UsdPrim())
124  : UsdShadeNodeGraph(prim)
125  {
126  }
127 
131  explicit UsdShadeMaterial(const UsdSchemaBase& schemaObj)
132  : UsdShadeNodeGraph(schemaObj)
133  {
134  }
135 
137  USDSHADE_API
138  virtual ~UsdShadeMaterial();
139 
143  USDSHADE_API
144  static const TfTokenVector &
145  GetSchemaAttributeNames(bool includeInherited=true);
146 
156  USDSHADE_API
157  static UsdShadeMaterial
158  Get(const UsdStagePtr &stage, const SdfPath &path);
159 
182  USDSHADE_API
183  static UsdShadeMaterial
184  Define(const UsdStagePtr &stage, const SdfPath &path);
185 
186 protected:
190  USDSHADE_API
191  UsdSchemaKind _GetSchemaKind() const override;
192 
193 private:
194  // needs to invoke _GetStaticTfType.
195  friend class UsdSchemaRegistry;
196  USDSHADE_API
197  static const TfType &_GetStaticTfType();
198 
199  static bool _IsTypedSchema();
200 
201  // override SchemaBase virtuals.
202  USDSHADE_API
203  const TfType &_GetTfType() const override;
204 
205 public:
206  // --------------------------------------------------------------------- //
207  // SURFACE
208  // --------------------------------------------------------------------- //
217  USDSHADE_API
219 
225  USDSHADE_API
226  UsdAttribute CreateSurfaceAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
227 
228 public:
229  // --------------------------------------------------------------------- //
230  // DISPLACEMENT
231  // --------------------------------------------------------------------- //
240  USDSHADE_API
242 
248  USDSHADE_API
249  UsdAttribute CreateDisplacementAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
250 
251 public:
252  // --------------------------------------------------------------------- //
253  // VOLUME
254  // --------------------------------------------------------------------- //
263  USDSHADE_API
264  UsdAttribute GetVolumeAttr() const;
265 
271  USDSHADE_API
272  UsdAttribute CreateVolumeAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
273 
274 public:
275  // ===================================================================== //
276  // Feel free to add custom code below this line, it will be preserved by
277  // the code generator.
278  //
279  // Just remember to:
280  // - Close the class declaration with };
281  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
282  // - Close the include guard with #endif
283  // ===================================================================== //
284  // --(BEGIN CUSTOM CODE)--
285 
286  // --------------------------------------------------------------------- //
289  // --------------------------------------------------------------------- //
290 
292  typedef std::function<bool (const SdfPath &)> PathPredicate;
293 
295 
296 
297  // --------------------------------------------------------------------- //
316 
323  USDSHADE_API
324  UsdShadeOutput CreateSurfaceOutput(const TfToken &renderContext
325  =UsdShadeTokens->universalRenderContext) const;
326 
335  USDSHADE_API
336  UsdShadeOutput GetSurfaceOutput(const TfToken &renderContext
337  =UsdShadeTokens->universalRenderContext) const;
338 
346  USDSHADE_API
347  std::vector<UsdShadeOutput> GetSurfaceOutputs() const;
348 
350  USDSHADE_API
352  const TfToken &renderContext,
353  TfToken *sourceName=nullptr,
354  UsdShadeAttributeType *sourceType=nullptr) const;
355 
368  USDSHADE_API
370  const TfTokenVector &contextVector={UsdShadeTokens->universalRenderContext},
371  TfToken *sourceName=nullptr,
372  UsdShadeAttributeType *sourceType=nullptr) const;
373 
380  USDSHADE_API
381  UsdShadeOutput CreateDisplacementOutput(const TfToken &renderContext
382  =UsdShadeTokens->universalRenderContext) const;
383 
392  USDSHADE_API
393  UsdShadeOutput GetDisplacementOutput(const TfToken &renderContext
394  =UsdShadeTokens->universalRenderContext) const;
395 
403  USDSHADE_API
404  std::vector<UsdShadeOutput> GetDisplacementOutputs() const;
405 
407  USDSHADE_API
409  const TfToken &renderContext,
410  TfToken *sourceName=nullptr,
411  UsdShadeAttributeType *sourceType=nullptr) const;
412 
425  USDSHADE_API
427  const TfTokenVector &contextVector={UsdShadeTokens->universalRenderContext},
428  TfToken *sourceName=nullptr,
429  UsdShadeAttributeType *sourceType=nullptr) const;
430 
437  USDSHADE_API
438  UsdShadeOutput CreateVolumeOutput(const TfToken &renderContext
439  =UsdShadeTokens->universalRenderContext) const;
440 
449  USDSHADE_API
450  UsdShadeOutput GetVolumeOutput(const TfToken &renderContext
451  =UsdShadeTokens->universalRenderContext) const;
452 
459  USDSHADE_API
460  std::vector<UsdShadeOutput> GetVolumeOutputs() const;
461 
463  USDSHADE_API
465  const TfToken &renderContext,
466  TfToken *sourceName=nullptr,
467  UsdShadeAttributeType *sourceType=nullptr) const;
468 
481  USDSHADE_API
483  const TfTokenVector &contextVector={UsdShadeTokens->universalRenderContext},
484  TfToken *sourceName=nullptr,
485  UsdShadeAttributeType *sourceType=nullptr) const;
486 
488 
489 private:
490  // Helper method to compute the sources of a given output, identified by its
491  // baseName, for the renderContexts in the specified contextVector.
492  UsdShadeAttributeVector _ComputeNamedOutputSources(
493  const TfToken &baseName,
494  const TfTokenVector &contextVector) const;
495 
496  // Helper method to compute the source shader of a given output, identified
497  // by its baseName, for the renderContexts in the specified contextVector.
498  UsdShadeShader _ComputeNamedOutputShader(
499  const TfToken &baseName,
500  const TfTokenVector &contextVector,
501  TfToken *sourceName,
502  UsdShadeAttributeType *sourceType) const;
503 
504  // Helper method to retrieve outputs in all renderContexts that match the
505  // given terminalName.
506  std::vector<UsdShadeOutput> _GetOutputsForTerminalName(
507  const TfToken& terminalName) const;
508 
509 public:
510  // --------------------------------------------------------------------- //
562  // --------------------------------------------------------------------- //
601  USDSHADE_API
602  std::pair<UsdStagePtr, UsdEditTarget>
603  GetEditContextForVariant(const TfToken &MaterialVariantName,
604  const SdfLayerHandle &layer = SdfLayerHandle()) const;
605 
608  USDSHADE_API
610 
639  USDSHADE_API
640  static bool CreateMasterMaterialVariant(
641  const UsdPrim &masterPrim,
642  const std::vector<UsdPrim> &MaterialPrims,
643  const TfToken &masterVariantSetName = TfToken());
644 
646 
647  // --------------------------------------------------------------------- //
655  // --------------------------------------------------------------------- //
656 
659  USDSHADE_API
661 
664  USDSHADE_API
666 
672  USDSHADE_API
674  const PcpPrimIndex & primIndex,
675  const PathPredicate & pathIsMaterialPredicate);
676 
679  USDSHADE_API
680  void SetBaseMaterial(const UsdShadeMaterial& baseMaterial) const;
681 
684  USDSHADE_API
685  void SetBaseMaterialPath(const SdfPath& baseMaterialPath) const;
686 
688  USDSHADE_API
689  void ClearBaseMaterial() const;
690 
691  // Check if this Material has a base Material
692  USDSHADE_API
693  bool HasBaseMaterial() const;
694 
696 
697 };
698 
699 PXR_NAMESPACE_CLOSE_SCOPE
700 
701 #endif
USDSHADE_API void SetBaseMaterial(const UsdShadeMaterial &baseMaterial) const
Set the base Material of this Material.
USDSHADE_API UsdAttribute GetDisplacementAttr() const
Represents the universal "displacement" output terminal of a material.
PcpPrimIndex is an index of the all sites of scene description that contribute opinions to a specific...
Definition: primIndex.h:76
USDSHADE_API UsdAttribute GetVolumeAttr() const
Represents the universal "volume" output terminal of a material.
USDSHADE_API std::pair< UsdStagePtr, UsdEditTarget > GetEditContextForVariant(const TfToken &MaterialVariantName, const SdfLayerHandle &layer=SdfLayerHandle()) const
Helper function for configuring a UsdStage's UsdEditTarget to author Material variations.
UsdShadeMaterial(const UsdSchemaBase &schemaObj)
Construct a UsdShadeMaterial on the prim held by schemaObj .
Definition: material.h:131
This is a small-vector class with local storage optimization, the local storage can be specified via ...
Definition: smallVector.h:177
static const UsdSchemaKind schemaKind
Compile time constant representing what kind of schema this class is.
Definition: material.h:117
USDSHADE_API UsdAttribute CreateSurfaceAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
See GetSurfaceAttr(), and also Create vs Get Property Methods for when to use Get vs Create.
USDSHADE_API UsdAttribute GetSurfaceAttr() const
Represents the universal "surface" output terminal of a material.
USDSHADE_API std::vector< UsdShadeOutput > GetDisplacementOutputs() const
Returns the "displacement" outputs of this material for all available renderContexts.
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:176
USDSHADE_API UsdShadeOutput CreateVolumeOutput(const TfToken &renderContext=UsdShadeTokens->universalRenderContext) const
Creates and returns the "volume" output on this material for the specified renderContext.
USDSHADE_API UsdShadeOutput GetVolumeOutput(const TfToken &renderContext=UsdShadeTokens->universalRenderContext) const
Returns the "volume" output of this material for the specified renderContext.
A node-graph is a container for shading nodes, as well as other node-graphs.
Definition: nodeGraph.h:80
static USDSHADE_API SdfPath FindBaseMaterialPathInPrimIndex(const PcpPrimIndex &primIndex, const PathPredicate &pathIsMaterialPredicate)
Given a PcpPrimIndex, searches it for an arc to a parent material.
UsdSchemaKind
An enum representing which kind of schema a given schema class belongs to.
Definition: common.h:127
USDSHADE_API UsdShadeMaterial GetBaseMaterial() const
Get the path to the base Material of this Material.
USDSHADE_API UsdShadeOutput CreateDisplacementOutput(const TfToken &renderContext=UsdShadeTokens->universalRenderContext) const
Creates and returns the "displacement" output on this material for the specified renderContext.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
USDSHADE_API UsdAttribute CreateVolumeAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
See GetVolumeAttr(), and also Create vs Get Property Methods for when to use Get vs Create.
USDSHADE_API UsdShadeOutput GetDisplacementOutput(const TfToken &renderContext=UsdShadeTokens->universalRenderContext) const
Returns the "displacement" output of this material for the specified renderContext.
static USDSHADE_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
Return a vector of names of all pre-declared attributes for this schema class and all its ancestor cl...
USDSHADE_API UsdShadeShader ComputeVolumeSource(const TfToken &renderContext, TfToken *sourceName=nullptr, UsdShadeAttributeType *sourceType=nullptr) const
USDSHADE_API UsdShadeOutput CreateSurfaceOutput(const TfToken &renderContext=UsdShadeTokens->universalRenderContext) const
Creates and returns the "surface" output on this material for the specified renderContext.
USDSHADE_API void SetBaseMaterialPath(const SdfPath &baseMaterialPath) const
Set the path to the base Material of this Material.
A UsdVariantSet represents a single VariantSet in USD (e.g.
Definition: variantSets.h:56
static USDSHADE_API UsdShadeMaterial Define(const UsdStagePtr &stage, const SdfPath &path)
Attempt to ensure a UsdPrim adhering to this schema at path is defined (according to UsdPrim::IsDefin...
Represents a concrete typed schema.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:135
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
USDSHADE_API TfStaticData< UsdShadeTokensType > UsdShadeTokens
A global variable with static, efficient TfTokens for use in all public USD API.
USDSHADE_API void ClearBaseMaterial() const
Clear the base Material of this Material.
USDSHADE_API SdfPath GetBaseMaterialPath() const
Get the base Material of this Material.
virtual USDSHADE_API ~UsdShadeMaterial()
Destructor.
USDSHADE_API UsdVariantSet GetMaterialVariant() const
Return a UsdVariantSet object for interacting with the Material variant variantSet.
std::function< bool(const SdfPath &)> PathPredicate
A function type that takes a path and returns a bool.
Definition: material.h:292
USDSHADE_API UsdAttribute CreateDisplacementAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
See GetDisplacementAttr(), and also Create vs Get Property Methods for when to use Get vs Create.
Contains an asset path and an optional resolved path.
Definition: assetPath.h:47
USDSHADE_API UsdShadeShader ComputeDisplacementSource(const TfToken &renderContext, TfToken *sourceName=nullptr, UsdShadeAttributeType *sourceType=nullptr) const
Base class for all USD shaders.
Definition: shader.h:85
TfType represents a dynamic runtime type.
Definition: type.h:64
Singleton registry that provides access to schema type information and the prim definitions for regis...
A Material provides a container into which multiple "render targets" can add data that defines a "sha...
Definition: material.h:111
static USDSHADE_API UsdShadeMaterial Get(const UsdStagePtr &stage, const SdfPath &path)
Return a UsdShadeMaterial holding the prim adhering to this schema at path on stage.
USDSHADE_API UsdSchemaKind _GetSchemaKind() const override
Returns the kind of schema this class belongs to.
This class encapsulates a shader or node-graph output, which is a connectable attribute representing ...
Definition: output.h:47
The base class for all schema types in Usd.
Definition: schemaBase.h:56
USDSHADE_API UsdShadeOutput GetSurfaceOutput(const TfToken &renderContext=UsdShadeTokens->universalRenderContext) const
Returns the "surface" output of this material for the specified renderContext.
USDSHADE_API std::vector< UsdShadeOutput > GetSurfaceOutputs() const
Returns the "surface" outputs of this material for all available renderContexts.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:166
USDSHADE_API std::vector< UsdShadeOutput > GetVolumeOutputs() const
Returns the "volume" outputs of this material for all available renderContexts.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
USDSHADE_API UsdShadeShader ComputeSurfaceSource(const TfToken &renderContext, TfToken *sourceName=nullptr, UsdShadeAttributeType *sourceType=nullptr) const
UsdShadeMaterial(const UsdPrim &prim=UsdPrim())
Construct a UsdShadeMaterial on UsdPrim prim .
Definition: material.h:123
static USDSHADE_API bool CreateMasterMaterialVariant(const UsdPrim &masterPrim, const std::vector< UsdPrim > &MaterialPrims, const TfToken &masterVariantSetName=TfToken())
Create a variantSet on masterPrim that will set the MaterialVariant on each of the given MaterialPrim...