Loading...
Searching...
No Matches
materialBindingAPI.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_MATERIALBINDINGAPI_H
25#define USDSHADE_GENERATED_MATERIALBINDINGAPI_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
39#include <tbb/concurrent_unordered_map.h>
40
41#include "pxr/base/vt/value.h"
42
43#include "pxr/base/gf/vec3d.h"
44#include "pxr/base/gf/vec3f.h"
46
47#include "pxr/base/tf/token.h"
48#include "pxr/base/tf/type.h"
49
50PXR_NAMESPACE_OPEN_SCOPE
51
52class SdfAssetPath;
53
54// -------------------------------------------------------------------------- //
55// MATERIALBINDINGAPI //
56// -------------------------------------------------------------------------- //
57
152{
153public:
157 static const UsdSchemaKind schemaKind = UsdSchemaKind::SingleApplyAPI;
158
164 : UsdAPISchemaBase(prim)
165 {
166 }
167
171 explicit UsdShadeMaterialBindingAPI(const UsdSchemaBase& schemaObj)
172 : UsdAPISchemaBase(schemaObj)
173 {
174 }
175
177 USDSHADE_API
179
183 USDSHADE_API
184 static const TfTokenVector &
185 GetSchemaAttributeNames(bool includeInherited=true);
186
196 USDSHADE_API
198 Get(const UsdStagePtr &stage, const SdfPath &path);
199
200
217 USDSHADE_API
218 static bool
219 CanApply(const UsdPrim &prim, std::string *whyNot=nullptr);
220
236 USDSHADE_API
238 Apply(const UsdPrim &prim);
239
240protected:
244 USDSHADE_API
246
247private:
248 // needs to invoke _GetStaticTfType.
249 friend class UsdSchemaRegistry;
250 USDSHADE_API
251 static const TfType &_GetStaticTfType();
252
253 static bool _IsTypedSchema();
254
255 // override SchemaBase virtuals.
256 USDSHADE_API
257 const TfType &_GetTfType() const override;
258
259public:
260 // ===================================================================== //
261 // Feel free to add custom code below this line, it will be preserved by
262 // the code generator.
263 //
264 // Just remember to:
265 // - Close the class declaration with };
266 // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
267 // - Close the include guard with #endif
268 // ===================================================================== //
269 // --(BEGIN CUSTOM CODE)--
270
278
284 USDSHADE_API
286 const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
287
294 USDSHADE_API
296 const TfToken &bindingName,
297 const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
298
307 USDSHADE_API
308 std::vector<UsdRelationship> GetCollectionBindingRels(
309 const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
310
314 public:
318 {}
319
320 USDSHADE_API
321 explicit DirectBinding(const UsdRelationship &bindingRel);
322
324 USDSHADE_API
326
329 const SdfPath &GetMaterialPath() const {
330 return _materialPath;
331 }
332
336 return _bindingRel;
337 }
338
341 return _materialPurpose;
342 }
343
348 bool IsBound() const {
349 return _isBound;
350 }
351
352 private:
353 // The path to the material that is bound to.
354 SdfPath _materialPath;
355
356 // The binding relationship.
357 UsdRelationship _bindingRel;
358
359 // The purpose of the material binding.
360 TfToken _materialPurpose;
361
362 // Store if there was a binding here. This allows us to distinguish if
363 // a direct binding is purposefully empty.
364 bool _isBound;
365 };
366
371 public:
375 {}
376
381 USDSHADE_API
382 explicit CollectionBinding(const UsdRelationship &collBindingRel);
383
386 USDSHADE_API
388
391 USDSHADE_API
393
395 USDSHADE_API
396 static bool IsCollectionBindingRel(const UsdRelationship &bindingRel);
397
400 bool IsValid() const {
402 && !GetMaterialPath().IsEmpty();
403 }
405 const SdfPath &GetCollectionPath() const {
406 return _collectionPath;
407 }
408
410 const SdfPath &GetMaterialPath() const {
411 return _materialPath;
412 }
413
417 return _bindingRel;
418 }
419
420 private:
421 // The collection being bound.
422 SdfPath _collectionPath;
423
424 // The material that is bound to.
425 SdfPath _materialPath;
426
427 // The relationship that binds the collection to the material.
428 UsdRelationship _bindingRel;
429 };
430
431 using CollectionBindingVector = std::vector<CollectionBinding>;
432
443 USDSHADE_API
445 const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
446
468 USDSHADE_API
469 CollectionBindingVector GetCollectionBindings(
470 const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
471
478 USDSHADE_API
480 const UsdRelationship &bindingRel);
481
491
495 USDSHADE_API
497 const UsdRelationship &bindingRel,
498 const TfToken &bindingStrength);
499
501
509
529 USDSHADE_API
530 bool Bind(
531 const UsdShadeMaterial &material,
532 const TfToken &bindingStrength=UsdShadeTokens->fallbackStrength,
533 const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
534
569 USDSHADE_API
570 bool Bind(
571 const UsdCollectionAPI &collection,
572 const UsdShadeMaterial &material,
573 const TfToken &bindingName=TfToken(),
574 const TfToken &bindingStrength=UsdShadeTokens->fallbackStrength,
575 const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
576
582 USDSHADE_API
584 const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
585
596 USDSHADE_API
598 const TfToken &bindingName,
599 const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
600
602 USDSHADE_API
603 bool UnbindAllBindings() const;
604
618 USDSHADE_API
620 const UsdPrim &prim,
621 const TfToken &bindingName,
622 const TfToken &materialPurpose) const;
623
635 USDSHADE_API
637 const UsdPrim &prim,
638 const TfToken &bindingName,
639 const TfToken &materialPurpose) const;
640
642
689
695 tbb::concurrent_unordered_map<SdfPath,
696 std::unique_ptr<UsdCollectionAPI::MembershipQuery>, SdfPath::Hash>;
697
699 using DirectBindingPtr = std::unique_ptr<DirectBinding>;
700
701 struct BindingsAtPrim {
711 USDSHADE_API
712 BindingsAtPrim(const UsdPrim &prim, const TfToken &materialPurpose,
713 bool supportLegacyBindings);
714
718 DirectBindingPtr directBinding;
719
722 CollectionBindingVector restrictedPurposeCollBindings;
723
725 CollectionBindingVector allPurposeCollBindings;
726 };
727
729 friend struct BindingsAtPrim;
730
735 using BindingsCache = tbb::concurrent_unordered_map<SdfPath,
736 std::unique_ptr<BindingsAtPrim>, SdfPath::Hash>;
737
739 USDSHADE_API
741
743 USDSHADE_API
745 const UsdRelationship &bindingRel);
746
804 USDSHADE_API
806 BindingsCache *bindingsCache,
807 CollectionQueryCache *collectionQueryCache,
808 const TfToken &materialPurpose=UsdShadeTokens->allPurpose,
809 UsdRelationship *bindingRel=nullptr,
810 bool supportLegacyBindings=true) const;
811
836 USDSHADE_API
838 const TfToken &materialPurpose=UsdShadeTokens->allPurpose,
839 UsdRelationship *bindingRel=nullptr,
840 bool supportLegacyBindings=true) const;
841
864 USDSHADE_API
865 static std::vector<UsdShadeMaterial> ComputeBoundMaterials(
866 const std::vector<UsdPrim> &prims,
867 const TfToken &materialPurpose=UsdShadeTokens->allPurpose,
868 std::vector<UsdRelationship> *bindingRels=nullptr,
869 bool supportLegacyBindings=true);
870
872
873 // --------------------------------------------------------------------- //
925
940 USDSHADE_API
942 const TfToken &subsetName,
943 const VtIntArray &indices,
944 const TfToken &elementType=UsdGeomTokens->face);
945
948 USDSHADE_API
949 std::vector<UsdGeomSubset> GetMaterialBindSubsets();
950
964 USDSHADE_API
966
975 USDSHADE_API
977
980 USDSHADE_API
981 static bool CanContainPropertyName(const TfToken &name);
982
984
985private:
986
987 UsdRelationship _CreateDirectBindingRel(
988 const TfToken &materialPurpose) const;
989
990 UsdRelationship _CreateCollectionBindingRel(
991 const TfToken &bindingName,
992 const TfToken &materialPurpose) const;
993
994 // Helper method for getting collection bindings when the set of all
995 // collection binding relationship names for the required purpose is
996 // known.
997 CollectionBindingVector _GetCollectionBindings(
998 const TfTokenVector &collBindingPropertyNames) const;
999};
1000
1001PXR_NAMESPACE_CLOSE_SCOPE
1002
1003#endif
Contains an asset path and an optional resolved path.
Definition: assetPath.h:47
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
Definition: path.h:414
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
TfType represents a dynamic runtime type.
Definition: type.h:65
The base class for all API schemas.
This is a general purpose API schema, used to describe a collection of heterogeneous objects within t...
Encodes a subset of a piece of geometry (i.e.
Definition: subset.h:87
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:134
A UsdRelationship creates dependencies between scenegraph objects by allowing a prim to target other ...
Definition: relationship.h:128
The base class for all schema types in Usd.
Definition: schemaBase.h:56
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:113
UsdSchemaKind
An enum representing which kind of schema a given schema class belongs to.
Definition: common.h:129
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:457
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.