All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"
31 #include "pxr/usd/usd/apiSchemaBase.h"
32 #include "pxr/usd/usd/prim.h"
33 #include "pxr/usd/usd/stage.h"
34 #include "pxr/usd/usdShade/tokens.h"
35 
36 #include "pxr/usd/usd/collectionAPI.h"
37 #include "pxr/usd/usdGeom/subset.h"
38 #include "pxr/usd/usdShade/material.h"
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"
45 #include "pxr/base/gf/matrix4d.h"
46 
47 #include "pxr/base/tf/token.h"
48 #include "pxr/base/tf/type.h"
49 
50 PXR_NAMESPACE_OPEN_SCOPE
51 
52 class SdfAssetPath;
53 
54 // -------------------------------------------------------------------------- //
55 // MATERIALBINDINGAPI //
56 // -------------------------------------------------------------------------- //
57 
152 {
153 public:
158 
164  : UsdAPISchemaBase(prim)
165  {
166  }
167 
171  explicit UsdShadeMaterialBindingAPI(const UsdSchemaBase& schemaObj)
172  : UsdAPISchemaBase(schemaObj)
173  {
174  }
175 
177  USDSHADE_API
178  virtual ~UsdShadeMaterialBindingAPI();
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 
215  USDSHADE_API
217  Apply(const UsdPrim &prim);
218 
219 protected:
223  USDSHADE_API
224  UsdSchemaType _GetSchemaType() const override;
225 
226 private:
227  // needs to invoke _GetStaticTfType.
228  friend class UsdSchemaRegistry;
229  USDSHADE_API
230  static const TfType &_GetStaticTfType();
231 
232  static bool _IsTypedSchema();
233 
234  // override SchemaBase virtuals.
235  USDSHADE_API
236  const TfType &_GetTfType() const override;
237 
238 public:
239  // ===================================================================== //
240  // Feel free to add custom code below this line, it will be preserved by
241  // the code generator.
242  //
243  // Just remember to:
244  // - Close the class declaration with };
245  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
246  // - Close the include guard with #endif
247  // ===================================================================== //
248  // --(BEGIN CUSTOM CODE)--
249 
257 
263  USDSHADE_API
265  const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
266 
273  USDSHADE_API
275  const TfToken &bindingName,
276  const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
277 
286  USDSHADE_API
287  std::vector<UsdRelationship> GetCollectionBindingRels(
288  const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
289 
293  public:
297  {}
298 
299  USDSHADE_API
300  explicit DirectBinding(const UsdRelationship &bindingRel);
301 
303  USDSHADE_API
305 
308  const SdfPath &GetMaterialPath() const {
309  return _materialPath;
310  }
311 
315  return _bindingRel;
316  }
317 
319  const TfToken &GetMaterialPurpose() const {
320  return _materialPurpose;
321  }
322 
323  private:
324  // The path to the material that is bound to.
325  SdfPath _materialPath;
326 
327  // The binding relationship.
328  UsdRelationship _bindingRel;
329 
330  // The purpose of the material binding.
331  TfToken _materialPurpose;
332  };
333 
338  public:
342  {}
343 
348  USDSHADE_API
349  explicit CollectionBinding(const UsdRelationship &collBindingRel);
350 
353  USDSHADE_API
355 
358  USDSHADE_API
360 
363  bool IsValid() const {
364  return GetCollection() && GetMaterial();
365  }
367  const SdfPath &GetCollectionPath() const {
368  return _collectionPath;
369  }
370 
372  const SdfPath &GetMaterialPath() const {
373  return _materialPath;
374  }
375 
379  return _bindingRel;
380  }
381 
382  private:
383  // The collection being bound.
384  SdfPath _collectionPath;
385 
386  // The material that is bound to.
387  SdfPath _materialPath;
388 
389  // The relationship that binds the collection to the material.
390  UsdRelationship _bindingRel;
391  };
392 
393  using CollectionBindingVector = std::vector<CollectionBinding>;
394 
405  USDSHADE_API
406  DirectBinding GetDirectBinding(
407  const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
408 
430  USDSHADE_API
431  CollectionBindingVector GetCollectionBindings(
432  const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
433 
440  USDSHADE_API
442  const UsdRelationship &bindingRel);
443 
453 
457  USDSHADE_API
458  static bool SetMaterialBindingStrength(
459  const UsdRelationship &bindingRel,
460  const TfToken &bindingStrength);
461 
463 
471 
485  USDSHADE_API
486  bool Bind(
487  const UsdShadeMaterial &material,
488  const TfToken &bindingStrength=UsdShadeTokens->fallbackStrength,
489  const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
490 
519  USDSHADE_API
520  bool Bind(
521  const UsdCollectionAPI &collection,
522  const UsdShadeMaterial &material,
523  const TfToken &bindingName=TfToken(),
524  const TfToken &bindingStrength=UsdShadeTokens->fallbackStrength,
525  const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
526 
530  USDSHADE_API
531  bool UnbindDirectBinding(
532  const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
533 
538  USDSHADE_API
540  const TfToken &bindingName,
541  const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
542 
544  USDSHADE_API
545  bool UnbindAllBindings() const;
546 
560  USDSHADE_API
562  const UsdPrim &prim,
563  const TfToken &bindingName,
564  const TfToken &materialPurpose) const;
565 
577  USDSHADE_API
579  const UsdPrim &prim,
580  const TfToken &bindingName,
581  const TfToken &materialPurpose) const;
582 
584 
631 
636  using CollectionQueryCache =
637  tbb::concurrent_unordered_map<SdfPath,
638  std::unique_ptr<UsdCollectionAPI::MembershipQuery>, SdfPath::Hash>;
639 
641  using DirectBindingPtr = std::unique_ptr<DirectBinding>;
642 
643  struct BindingsAtPrim {
647  USDSHADE_API
648  BindingsAtPrim(const UsdPrim &prim, const TfToken &materialPurpose);
649 
653  DirectBindingPtr directBinding;
654 
657  CollectionBindingVector restrictedPurposeCollBindings;
658 
660  CollectionBindingVector allPurposeCollBindings;
661  };
662 
664  friend struct BindingsAtPrim;
665 
670  using BindingsCache = tbb::concurrent_unordered_map<SdfPath,
671  std::unique_ptr<BindingsAtPrim>, SdfPath::Hash>;
672 
713  USDSHADE_API
715  BindingsCache *bindingsCache,
716  CollectionQueryCache *collectionQueryCache,
717  const TfToken &materialPurpose=UsdShadeTokens->allPurpose,
718  UsdRelationship *bindingRel=nullptr) const;
719 
736  USDSHADE_API
738  const TfToken &materialPurpose=UsdShadeTokens->allPurpose,
739  UsdRelationship *bindingRel=nullptr) const;
740 
755  USDSHADE_API
756  static std::vector<UsdShadeMaterial> ComputeBoundMaterials(
757  const std::vector<UsdPrim> &prims,
758  const TfToken &materialPurpose=UsdShadeTokens->allPurpose,
759  std::vector<UsdRelationship> *bindingRels=nullptr);
760 
762 
763  // --------------------------------------------------------------------- //
815 
830  USDSHADE_API
832  const TfToken &subsetName,
833  const VtIntArray &indices,
834  const TfToken &elementType=UsdGeomTokens->face);
835 
838  USDSHADE_API
839  std::vector<UsdGeomSubset> GetMaterialBindSubsets();
840 
854  USDSHADE_API
855  bool SetMaterialBindSubsetsFamilyType(const TfToken &familyType);
856 
865  USDSHADE_API
867 
870  USDSHADE_API
871  static bool CanContainPropertyName(const TfToken &name);
872 
874 
875 private:
876 
877  UsdRelationship _CreateDirectBindingRel(
878  const TfToken &materialPurpose) const;
879 
880  UsdRelationship _CreateCollectionBindingRel(
881  const TfToken &bindingName,
882  const TfToken &materialPurpose) const;
883 
884  // Helper method for getting collection bindings when the set of all
885  // collection binding relationship names for the required purpose is
886  // known.
887  CollectionBindingVector _GetCollectionBindings(
888  const TfTokenVector &collBindingPropertyNames) const;
889 };
890 
891 PXR_NAMESPACE_CLOSE_SCOPE
892 
893 #endif
USDSHADE_API UsdShadeMaterial GetMaterial() const
Constructs and returns the material object that this collection-based binding binds to...
USDSHADE_API UsdSchemaType _GetSchemaType() const override
Returns the type of schema this class belongs to.
USDSHADE_API std::vector< UsdGeomSubset > GetMaterialBindSubsets()
Returns all the existing GeomSubsets with familyName=UsdShadeTokens-&gt;materialBind below this prim...
static USDSHADE_API bool SetMaterialBindingStrength(const UsdRelationship &bindingRel, const TfToken &bindingStrength)
Sets the &#39;bindMaterialAs&#39; token-valued metadata on the given binding relationship.
const SdfPath & GetCollectionPath() const
Returns the path to the collection that is bound by this binding.
USDSHADE_API DirectBinding GetDirectBinding(const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const
Computes and returns the direct binding for the given material purpose on this prim.
This struct is used to represent a collection-based material binding, which contains two objects - a ...
tbb::concurrent_unordered_map< SdfPath, std::unique_ptr< UsdCollectionAPI::MembershipQuery >, SdfPath::Hash > CollectionQueryCache
An unordered list of collection paths mapped to the associated collection&#39;s MembershipQuery object...
static USDSHADE_API std::vector< UsdShadeMaterial > ComputeBoundMaterials(const std::vector< UsdPrim > &prims, const TfToken &materialPurpose=UsdShadeTokens->allPurpose, std::vector< UsdRelationship > *bindingRels=nullptr)
Static API for efficiently and concurrently computing the resolved material bindings for a vector of ...
static USDSHADE_API TfToken GetMaterialBindingStrength(const UsdRelationship &bindingRel)
Resolves the &#39;bindMaterialAs&#39; token-valued metadata on the given binding relationship and returns it...
USDSHADE_API UsdCollectionAPI GetCollection() const
Constructs and returns the CollectionAPI object for the collection that is bound by this collection-b...
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 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 ...
The base class for all API schemas.
USDSHADE_API UsdRelationship GetDirectBindingRel(const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const
Returns the direct material-binding relationship on this prim for the given material purpose...
USDSHADE_API bool UnbindAllBindings() const
Unbinds all direct and collection-based bindings on this prim.
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...
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...
DirectBinding()
Default constructor initializes a DirectBinding object with invalid material and bindingRel data memb...
UsdShadeMaterialBindingAPI is an API schema that provides an interface for binding materials to prims...
const TfToken & GetMaterialPurpose() const
Returns the purpose of the direct binding.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
USDSHADE_API UsdShadeMaterial ComputeBoundMaterial(BindingsCache *bindingsCache, CollectionQueryCache *collectionQueryCache, const TfToken &materialPurpose=UsdShadeTokens->allPurpose, UsdRelationship *bindingRel=nullptr) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
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 TfStaticData< UsdShadeTokensType > UsdShadeTokens
A global variable with static, efficient TfTokens for use in all public USD API.
This is a general purpose API schema, used to describe a collection of heterogeneous objects within t...
USDGEOM_API TfStaticData< UsdGeomTokensType > UsdGeomTokens
A global variable with static, efficient TfTokens for use in all public USD API.
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 UsdShadeMaterialBindingAPI Get(const UsdStagePtr &stage, const SdfPath &path)
Return a UsdShadeMaterialBindingAPI holding the prim adhering to this schema at path on stage...
USDSHADE_API bool SetMaterialBindSubsetsFamilyType(const TfToken &familyType)
Author the familyType of the &quot;materialBind&quot; family of GeomSubsets on this prim.
UsdSchemaType
An enum representing which type of schema a given schema class belongs to.
Definition: common.h:127
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.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:132
const SdfPath & GetMaterialPath() const
Returns the path to the material that is bound to by this binding.
static const UsdSchemaType schemaType
Compile time constant representing what kind of schema this class is.
static USDSHADE_API UsdShadeMaterialBindingAPI Apply(const UsdPrim &prim)
Applies this single-apply API schema to the given prim.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
Single Apply API schema.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:288
std::unique_ptr< DirectBinding > DirectBindingPtr
Alias for a unique_ptr to a DirectBinding object.
CollectionBinding()
Default constructor initializes a CollectionBinding object with invalid collection, material and bindingRel data members.
const UsdRelationship & GetBindingRel() const
Returns the binding-relationship that represents this collection- based binding.
A UsdRelationship creates dependencies between scenegraph objects by allowing a prim to target other ...
Definition: relationship.h:128
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...
const UsdRelationship & GetBindingRel() const
Returns the binding-relationship that represents this direct binding.
virtual USDSHADE_API ~UsdShadeMaterialBindingAPI()
Destructor.
bool IsValid() const
Returns true if the CollectionBinding points to a valid material and collection.
Contains an asset path and an optional resolved path.
Definition: assetPath.h:43
Encodes a subset of a piece of geometry (i.e.
Definition: subset.h:85
USDSHADE_API UsdShadeMaterial GetMaterial() const
Gets the material object that this direct binding binds to.
UsdShadeMaterialBindingAPI(const UsdSchemaBase &schemaObj)
Construct a UsdShadeMaterialBindingAPI on the prim held by schemaObj .
friend struct BindingsAtPrim
BindingsAtPrim needs to invoke private _GetCollectionBindings().
TfType represents a dynamic runtime type.
Definition: type.h:64
const SdfPath & GetMaterialPath() const
Returns the path to the material that is bound to by this direct binding.
Singleton registry that provides access to schema type information and the prim definitions for regis...
A Material provides a container into which multiple &quot;render targets&quot; can add data that defines a &quot;sha...
Definition: material.h:111
UsdShadeMaterialBindingAPI(const UsdPrim &prim=UsdPrim())
Construct a UsdShadeMaterialBindingAPI on UsdPrim prim .
The base class for all schema types in Usd.
Definition: schemaBase.h:56
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...
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 TfToken GetMaterialBindSubsetsFamilyType()
Returns the familyType of the family of &quot;materialBind&quot; GeomSubsets on this prim.
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...
static USDSHADE_API bool CanContainPropertyName(const TfToken &name)
Test whether a given name contains the &quot;material:binding:&quot; prefix.
This class represents a direct material binding.