Loading...
Searching...
No Matches
materialBindingAPI.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 USDSHADE_GENERATED_MATERIALBINDINGAPI_H
8#define USDSHADE_GENERATED_MATERIALBINDINGAPI_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usd/usdShade/api.h"
15#include "pxr/usd/usd/prim.h"
16#include "pxr/usd/usd/stage.h"
18
22#include <tbb/concurrent_unordered_map.h>
23
24#include "pxr/base/vt/value.h"
25
26#include "pxr/base/gf/vec3d.h"
27#include "pxr/base/gf/vec3f.h"
29
30#include "pxr/base/tf/token.h"
31#include "pxr/base/tf/type.h"
32
33PXR_NAMESPACE_OPEN_SCOPE
34
35class SdfAssetPath;
36
37// -------------------------------------------------------------------------- //
38// MATERIALBINDINGAPI //
39// -------------------------------------------------------------------------- //
40
135{
136public:
140 static const UsdSchemaKind schemaKind = UsdSchemaKind::SingleApplyAPI;
141
147 : UsdAPISchemaBase(prim)
148 {
149 }
150
154 explicit UsdShadeMaterialBindingAPI(const UsdSchemaBase& schemaObj)
155 : UsdAPISchemaBase(schemaObj)
156 {
157 }
158
160 USDSHADE_API
162
166 USDSHADE_API
167 static const TfTokenVector &
168 GetSchemaAttributeNames(bool includeInherited=true);
169
179 USDSHADE_API
181 Get(const UsdStagePtr &stage, const SdfPath &path);
182
183
200 USDSHADE_API
201 static bool
202 CanApply(const UsdPrim &prim, std::string *whyNot=nullptr);
203
219 USDSHADE_API
221 Apply(const UsdPrim &prim);
222
223protected:
227 USDSHADE_API
229
230private:
231 // needs to invoke _GetStaticTfType.
232 friend class UsdSchemaRegistry;
233 USDSHADE_API
234 static const TfType &_GetStaticTfType();
235
236 static bool _IsTypedSchema();
237
238 // override SchemaBase virtuals.
239 USDSHADE_API
240 const TfType &_GetTfType() const override;
241
242public:
243 // ===================================================================== //
244 // Feel free to add custom code below this line, it will be preserved by
245 // the code generator.
246 //
247 // Just remember to:
248 // - Close the class declaration with };
249 // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
250 // - Close the include guard with #endif
251 // ===================================================================== //
252 // --(BEGIN CUSTOM CODE)--
253
261
267 USDSHADE_API
269 const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
270
277 USDSHADE_API
279 const TfToken &bindingName,
280 const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
281
290 USDSHADE_API
291 std::vector<UsdRelationship> GetCollectionBindingRels(
292 const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
293
297 public:
301 {}
302
303 USDSHADE_API
304 explicit DirectBinding(const UsdRelationship &bindingRel);
305
307 USDSHADE_API
309
312 const SdfPath &GetMaterialPath() const {
313 return _materialPath;
314 }
315
319 return _bindingRel;
320 }
321
324 return _materialPurpose;
325 }
326
331 bool IsBound() const {
332 return _isBound;
333 }
334
335 private:
336 // The path to the material that is bound to.
337 SdfPath _materialPath;
338
339 // The binding relationship.
340 UsdRelationship _bindingRel;
341
342 // The purpose of the material binding.
343 TfToken _materialPurpose;
344
345 // Store if there was a binding here. This allows us to distinguish if
346 // a direct binding is purposefully empty.
347 bool _isBound;
348 };
349
354 public:
358 {}
359
364 USDSHADE_API
365 explicit CollectionBinding(const UsdRelationship &collBindingRel);
366
369 USDSHADE_API
371
374 USDSHADE_API
376
378 USDSHADE_API
379 static bool IsCollectionBindingRel(const UsdRelationship &bindingRel);
380
383 bool IsValid() const {
385 && !GetMaterialPath().IsEmpty();
386 }
388 const SdfPath &GetCollectionPath() const {
389 return _collectionPath;
390 }
391
393 const SdfPath &GetMaterialPath() const {
394 return _materialPath;
395 }
396
400 return _bindingRel;
401 }
402
403 private:
404 // The collection being bound.
405 SdfPath _collectionPath;
406
407 // The material that is bound to.
408 SdfPath _materialPath;
409
410 // The relationship that binds the collection to the material.
411 UsdRelationship _bindingRel;
412 };
413
414 using CollectionBindingVector = std::vector<CollectionBinding>;
415
426 USDSHADE_API
428 const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
429
451 USDSHADE_API
452 CollectionBindingVector GetCollectionBindings(
453 const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
454
461 USDSHADE_API
463 const UsdRelationship &bindingRel);
464
474
478 USDSHADE_API
480 const UsdRelationship &bindingRel,
481 const TfToken &bindingStrength);
482
484
492
512 USDSHADE_API
513 bool Bind(
514 const UsdShadeMaterial &material,
515 const TfToken &bindingStrength=UsdShadeTokens->fallbackStrength,
516 const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
517
552 USDSHADE_API
553 bool Bind(
554 const UsdCollectionAPI &collection,
555 const UsdShadeMaterial &material,
556 const TfToken &bindingName=TfToken(),
557 const TfToken &bindingStrength=UsdShadeTokens->fallbackStrength,
558 const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
559
565 USDSHADE_API
567 const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
568
579 USDSHADE_API
581 const TfToken &bindingName,
582 const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
583
585 USDSHADE_API
586 bool UnbindAllBindings() const;
587
601 USDSHADE_API
603 const UsdPrim &prim,
604 const TfToken &bindingName,
605 const TfToken &materialPurpose) const;
606
618 USDSHADE_API
620 const UsdPrim &prim,
621 const TfToken &bindingName,
622 const TfToken &materialPurpose) const;
623
625
672
678 tbb::concurrent_unordered_map<SdfPath,
679 std::unique_ptr<UsdCollectionAPI::MembershipQuery>, SdfPath::Hash>;
680
682 using DirectBindingPtr = std::unique_ptr<DirectBinding>;
683
684 struct BindingsAtPrim {
694 USDSHADE_API
695 BindingsAtPrim(const UsdPrim &prim, const TfToken &materialPurpose,
696 bool supportLegacyBindings);
697
701 DirectBindingPtr directBinding;
702
705 CollectionBindingVector restrictedPurposeCollBindings;
706
708 CollectionBindingVector allPurposeCollBindings;
709 };
710
712 friend struct BindingsAtPrim;
713
718 using BindingsCache = tbb::concurrent_unordered_map<SdfPath,
719 std::unique_ptr<BindingsAtPrim>, SdfPath::Hash>;
720
722 USDSHADE_API
724
726 USDSHADE_API
728 const UsdRelationship &bindingRel);
729
787 USDSHADE_API
789 BindingsCache *bindingsCache,
790 CollectionQueryCache *collectionQueryCache,
791 const TfToken &materialPurpose=UsdShadeTokens->allPurpose,
792 UsdRelationship *bindingRel=nullptr,
793 bool supportLegacyBindings=true) const;
794
819 USDSHADE_API
821 const TfToken &materialPurpose=UsdShadeTokens->allPurpose,
822 UsdRelationship *bindingRel=nullptr,
823 bool supportLegacyBindings=true) const;
824
847 USDSHADE_API
848 static std::vector<UsdShadeMaterial> ComputeBoundMaterials(
849 const std::vector<UsdPrim> &prims,
850 const TfToken &materialPurpose=UsdShadeTokens->allPurpose,
851 std::vector<UsdRelationship> *bindingRels=nullptr,
852 bool supportLegacyBindings=true);
853
855
856 // --------------------------------------------------------------------- //
908
923 USDSHADE_API
925 const TfToken &subsetName,
926 const VtIntArray &indices,
927 const TfToken &elementType=UsdGeomTokens->face);
928
931 USDSHADE_API
932 std::vector<UsdGeomSubset> GetMaterialBindSubsets();
933
947 USDSHADE_API
949
958 USDSHADE_API
960
963 USDSHADE_API
964 static bool CanContainPropertyName(const TfToken &name);
965
967
968private:
969
970 UsdRelationship _CreateDirectBindingRel(
971 const TfToken &materialPurpose) const;
972
973 UsdRelationship _CreateCollectionBindingRel(
974 const TfToken &bindingName,
975 const TfToken &materialPurpose) const;
976
977 // Helper method for getting collection bindings when the set of all
978 // collection binding relationship names for the required purpose is
979 // known.
980 CollectionBindingVector _GetCollectionBindings(
981 const TfTokenVector &collBindingPropertyNames) const;
982};
983
984PXR_NAMESPACE_CLOSE_SCOPE
985
986#endif
Contains an asset path and optional evaluated and resolved paths.
Definition: assetPath.h:78
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
Definition: path.h:398
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
TfType represents a dynamic runtime type.
Definition: type.h:48
The base class for all API schemas.
Definition: apiSchemaBase.h:99
A general purpose API schema used to describe a collection of prims and properties within a scene.
Encodes a subset of a piece of geometry (i.e.
Definition: subset.h:71
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:117
A UsdRelationship creates dependencies between scenegraph objects by allowing a prim to target other ...
Definition: relationship.h:111
The base class for all schema types in Usd.
Definition: schemaBase.h:39
Singleton registry that provides access to schema type information and the prim definitions for regis...
This struct is used to represent a collection-based material binding, which contains two objects - a ...
const SdfPath & GetCollectionPath() const
Returns the path to the collection that is bound by this binding.
const SdfPath & GetMaterialPath() const
Returns the path to the material that is bound to by this binding.
static USDSHADE_API bool IsCollectionBindingRel(const UsdRelationship &bindingRel)
Checks if the bindingRel identifies a collection.
CollectionBinding()
Default constructor initializes a CollectionBinding object with invalid collection,...
USDSHADE_API CollectionBinding(const UsdRelationship &collBindingRel)
Constructs a CollectionBinding object from the given collection- binding relationship.
USDSHADE_API UsdShadeMaterial GetMaterial() const
Constructs and returns the material object that this collection-based binding binds to.
bool IsValid() const
Returns true if the CollectionBinding points to a non-empty material path and collection.
USDSHADE_API UsdCollectionAPI GetCollection() const
Constructs and returns the CollectionAPI object for the collection that is bound by this collection-b...
const UsdRelationship & GetBindingRel() const
Returns the binding-relationship that represents this collection- based binding.
This class represents a direct material binding.
const SdfPath & GetMaterialPath() const
Returns the path to the material that is bound to by this direct binding.
USDSHADE_API UsdShadeMaterial GetMaterial() const
Gets the material object that this direct binding binds to.
DirectBinding()
Default constructor initializes a DirectBinding object with invalid material and bindingRel data memb...
const TfToken & GetMaterialPurpose() const
Returns the purpose of the direct binding.
const UsdRelationship & GetBindingRel() const
Returns the binding-relationship that represents this direct binding.
bool IsBound() const
Returns true if there is a material bound.
UsdShadeMaterialBindingAPI is an API schema that provides an interface for binding materials to prims...
static USDSHADE_API UsdShadeMaterialBindingAPI Get(const UsdStagePtr &stage, const SdfPath &path)
Return a UsdShadeMaterialBindingAPI holding the prim adhering to this schema at path on stage.
static USDSHADE_API TfToken GetMaterialBindingStrength(const UsdRelationship &bindingRel)
Resolves the 'bindMaterialAs' token-valued metadata on the given binding relationship and returns it.
USDSHADE_API DirectBinding GetDirectBinding(const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const
Computes and returns the direct binding for the given material purpose on this prim.
static USDSHADE_API bool SetMaterialBindingStrength(const UsdRelationship &bindingRel, const TfToken &bindingStrength)
Sets the 'bindMaterialAs' token-valued metadata on the given binding relationship.
tbb::concurrent_unordered_map< SdfPath, std::unique_ptr< UsdCollectionAPI::MembershipQuery >, SdfPath::Hash > CollectionQueryCache
An unordered list of collection paths mapped to the associated collection's MembershipQuery object.
USDSHADE_API TfToken GetMaterialBindSubsetsFamilyType()
Returns the familyType of the family of "materialBind" GeomSubsets on this prim.
static USDSHADE_API TfTokenVector GetMaterialPurposes()
Returns a vector of the possible values for the 'material purpose'.
friend struct BindingsAtPrim
BindingsAtPrim needs to invoke private _GetCollectionBindings().
static USDSHADE_API UsdShadeMaterialBindingAPI Apply(const UsdPrim &prim)
Applies this single-apply API schema to the given prim.
USDSHADE_API UsdGeomSubset CreateMaterialBindSubset(const TfToken &subsetName, const VtIntArray &indices, const TfToken &elementType=UsdGeomTokens->face)
Creates a GeomSubset named subsetName with element type, elementType and familyName materialBind belo...
USDSHADE_API std::vector< UsdGeomSubset > GetMaterialBindSubsets()
Returns all the existing GeomSubsets with familyName=UsdShadeTokens->materialBind below this prim.
static const UsdSchemaKind schemaKind
Compile time constant representing what kind of schema this class is.
USDSHADE_API std::vector< UsdRelationship > GetCollectionBindingRels(const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const
Returns the list of collection-based material binding relationships on this prim for the given materi...
USDSHADE_API bool UnbindAllBindings() const
Unbinds all direct and collection-based bindings on this prim.
USDSHADE_API UsdShadeMaterial ComputeBoundMaterial(const TfToken &materialPurpose=UsdShadeTokens->allPurpose, UsdRelationship *bindingRel=nullptr, bool supportLegacyBindings=true) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static USDSHADE_API std::vector< UsdShadeMaterial > ComputeBoundMaterials(const std::vector< UsdPrim > &prims, const TfToken &materialPurpose=UsdShadeTokens->allPurpose, std::vector< UsdRelationship > *bindingRels=nullptr, bool supportLegacyBindings=true)
Static API for efficiently and concurrently computing the resolved material bindings for a vector of ...
USDSHADE_API bool UnbindDirectBinding(const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const
Unbinds the direct binding for the given material purpose (materialPurpose) on this prim.
USDSHADE_API bool Bind(const UsdCollectionAPI &collection, const UsdShadeMaterial &material, const TfToken &bindingName=TfToken(), const TfToken &bindingStrength=UsdShadeTokens->fallbackStrength, const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const
Authors a collection-based binding, which binds the given material to the given collection on this pr...
static USDSHADE_API bool CanApply(const UsdPrim &prim, std::string *whyNot=nullptr)
Returns true if this single-apply API schema can be applied to the given prim.
USDSHADE_API UsdSchemaKind _GetSchemaKind() const override
Returns the kind of schema this class belongs to.
USDSHADE_API bool Bind(const UsdShadeMaterial &material, const TfToken &bindingStrength=UsdShadeTokens->fallbackStrength, const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const
Authors a direct binding to the given material on this prim.
USDSHADE_API UsdRelationship GetCollectionBindingRel(const TfToken &bindingName, const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const
Returns the collection-based material-binding relationship with the given bindingName and materialPur...
static USDSHADE_API bool CanContainPropertyName(const TfToken &name)
Test whether a given name contains the "material:binding:" prefix.
UsdShadeMaterialBindingAPI(const UsdSchemaBase &schemaObj)
Construct a UsdShadeMaterialBindingAPI on the prim held by schemaObj .
USDSHADE_API UsdRelationship GetDirectBindingRel(const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const
Returns the direct material-binding relationship on this prim for the given material purpose.
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...
static USDSHADE_API const SdfPath GetResolvedTargetPathFromBindingRel(const UsdRelationship &bindingRel)
returns the path of the resolved target identified by bindingRel.
tbb::concurrent_unordered_map< SdfPath, std::unique_ptr< BindingsAtPrim >, SdfPath::Hash > BindingsCache
An unordered list of prim-paths mapped to the corresponding set of bindings at the associated prim.
std::unique_ptr< DirectBinding > DirectBindingPtr
Alias for a unique_ptr to a DirectBinding object.
USDSHADE_API bool SetMaterialBindSubsetsFamilyType(const TfToken &familyType)
Author the familyType of the "materialBind" family of GeomSubsets on this prim.
USDSHADE_API bool AddPrimToBindingCollection(const UsdPrim &prim, const TfToken &bindingName, const TfToken &materialPurpose) const
Adds the specified prim to the collection targeted by the binding relationship corresponding to given...
UsdShadeMaterialBindingAPI(const UsdPrim &prim=UsdPrim())
Construct a UsdShadeMaterialBindingAPI on UsdPrim prim .
USDSHADE_API bool RemovePrimFromBindingCollection(const UsdPrim &prim, const TfToken &bindingName, const TfToken &materialPurpose) const
Removes the specified prim from the collection targeted by the binding relationship corresponding to ...
virtual USDSHADE_API ~UsdShadeMaterialBindingAPI()
Destructor.
USDSHADE_API CollectionBindingVector GetCollectionBindings(const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const
Returns all the collection-based bindings on this prim for the given material purpose.
USDSHADE_API bool UnbindCollectionBinding(const TfToken &bindingName, const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const
Unbinds the collection-based binding with the given bindingName, for the given materialPurpose on thi...
USDSHADE_API UsdShadeMaterial ComputeBoundMaterial(BindingsCache *bindingsCache, CollectionQueryCache *collectionQueryCache, const TfToken &materialPurpose=UsdShadeTokens->allPurpose, UsdRelationship *bindingRel=nullptr, bool supportLegacyBindings=true) const
Computes the resolved bound material for this prim, for the given material purpose.
A Material provides a container into which multiple "render contexts" can add data that defines a "sh...
Definition: material.h:96
UsdSchemaKind
An enum representing which kind of schema a given schema class belongs to.
Definition: common.h:112
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
USDGEOM_API TfStaticData< UsdGeomTokensType > UsdGeomTokens
A global variable with static, efficient TfTokens for use in all public USD API.
USDSHADE_API TfStaticData< UsdShadeTokensType > UsdShadeTokens
A global variable with static, efficient TfTokens for use in all public USD API.