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 
213  USDSHADE_API
215  Apply(const UsdPrim &prim);
216 
217 protected:
221  USDSHADE_API
222  UsdSchemaType _GetSchemaType() const override;
223 
224 private:
225  // needs to invoke _GetStaticTfType.
226  friend class UsdSchemaRegistry;
227  USDSHADE_API
228  static const TfType &_GetStaticTfType();
229 
230  static bool _IsTypedSchema();
231 
232  // override SchemaBase virtuals.
233  USDSHADE_API
234  const TfType &_GetTfType() const override;
235 
236 public:
237  // ===================================================================== //
238  // Feel free to add custom code below this line, it will be preserved by
239  // the code generator.
240  //
241  // Just remember to:
242  // - Close the class declaration with };
243  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
244  // - Close the include guard with #endif
245  // ===================================================================== //
246  // --(BEGIN CUSTOM CODE)--
247 
255 
261  USDSHADE_API
263  const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
264 
271  USDSHADE_API
273  const TfToken &bindingName,
274  const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
275 
284  USDSHADE_API
285  std::vector<UsdRelationship> GetCollectionBindingRels(
286  const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
287 
291  public:
295  {}
296 
297  USDSHADE_API
298  explicit DirectBinding(const UsdRelationship &bindingRel);
299 
301  USDSHADE_API
303 
306  const SdfPath &GetMaterialPath() const {
307  return _materialPath;
308  }
309 
313  return _bindingRel;
314  }
315 
317  const TfToken &GetMaterialPurpose() const {
318  return _materialPurpose;
319  }
320 
321  private:
322  // The path to the material that is bound to.
323  SdfPath _materialPath;
324 
325  // The binding relationship.
326  UsdRelationship _bindingRel;
327 
328  // The purpose of the material binding.
329  TfToken _materialPurpose;
330  };
331 
336  public:
340  {}
341 
346  USDSHADE_API
347  explicit CollectionBinding(const UsdRelationship &collBindingRel);
348 
351  USDSHADE_API
353 
356  USDSHADE_API
358 
361  bool IsValid() const {
362  return GetCollection() && GetMaterial();
363  }
365  const SdfPath &GetCollectionPath() const {
366  return _collectionPath;
367  }
368 
370  const SdfPath &GetMaterialPath() const {
371  return _materialPath;
372  }
373 
377  return _bindingRel;
378  }
379 
380  private:
381  // The collection being bound.
382  SdfPath _collectionPath;
383 
384  // The material that is bound to.
385  SdfPath _materialPath;
386 
387  // The relationship that binds the collection to the material.
388  UsdRelationship _bindingRel;
389  };
390 
391  using CollectionBindingVector = std::vector<CollectionBinding>;
392 
403  USDSHADE_API
404  DirectBinding GetDirectBinding(
405  const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
406 
428  USDSHADE_API
429  CollectionBindingVector GetCollectionBindings(
430  const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
431 
438  USDSHADE_API
440  const UsdRelationship &bindingRel);
441 
451 
455  USDSHADE_API
456  static bool SetMaterialBindingStrength(
457  const UsdRelationship &bindingRel,
458  const TfToken &bindingStrength);
459 
461 
469 
483  USDSHADE_API
484  bool Bind(
485  const UsdShadeMaterial &material,
486  const TfToken &bindingStrength=UsdShadeTokens->fallbackStrength,
487  const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
488 
517  USDSHADE_API
518  bool Bind(
519  const UsdCollectionAPI &collection,
520  const UsdShadeMaterial &material,
521  const TfToken &bindingName=TfToken(),
522  const TfToken &bindingStrength=UsdShadeTokens->fallbackStrength,
523  const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
524 
528  USDSHADE_API
529  bool UnbindDirectBinding(
530  const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
531 
536  USDSHADE_API
538  const TfToken &bindingName,
539  const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
540 
542  USDSHADE_API
543  bool UnbindAllBindings() const;
544 
558  USDSHADE_API
560  const UsdPrim &prim,
561  const TfToken &bindingName,
562  const TfToken &materialPurpose) const;
563 
575  USDSHADE_API
577  const UsdPrim &prim,
578  const TfToken &bindingName,
579  const TfToken &materialPurpose) const;
580 
582 
629 
634  using CollectionQueryCache =
635  tbb::concurrent_unordered_map<SdfPath,
636  std::unique_ptr<UsdCollectionAPI::MembershipQuery>, SdfPath::Hash>;
637 
639  using DirectBindingPtr = std::unique_ptr<DirectBinding>;
640 
641  struct BindingsAtPrim {
645  USDSHADE_API
646  BindingsAtPrim(const UsdPrim &prim, const TfToken &materialPurpose);
647 
651  DirectBindingPtr directBinding;
652 
655  CollectionBindingVector restrictedPurposeCollBindings;
656 
658  CollectionBindingVector allPurposeCollBindings;
659  };
660 
662  friend struct BindingsAtPrim;
663 
668  using BindingsCache = tbb::concurrent_unordered_map<SdfPath,
669  std::unique_ptr<BindingsAtPrim>, SdfPath::Hash>;
670 
711  USDSHADE_API
713  BindingsCache *bindingsCache,
714  CollectionQueryCache *collectionQueryCache,
715  const TfToken &materialPurpose=UsdShadeTokens->allPurpose,
716  UsdRelationship *bindingRel=nullptr) const;
717 
734  USDSHADE_API
736  const TfToken &materialPurpose=UsdShadeTokens->allPurpose,
737  UsdRelationship *bindingRel=nullptr) const;
738 
753  USDSHADE_API
754  static std::vector<UsdShadeMaterial> ComputeBoundMaterials(
755  const std::vector<UsdPrim> &prims,
756  const TfToken &materialPurpose=UsdShadeTokens->allPurpose,
757  std::vector<UsdRelationship> *bindingRels=nullptr);
758 
760 
761  // --------------------------------------------------------------------- //
813 
828  USDSHADE_API
830  const TfToken &subsetName,
831  const VtIntArray &indices,
832  const TfToken &elementType=UsdGeomTokens->face);
833 
836  USDSHADE_API
837  std::vector<UsdGeomSubset> GetMaterialBindSubsets();
838 
852  USDSHADE_API
853  bool SetMaterialBindSubsetsFamilyType(const TfToken &familyType);
854 
863  USDSHADE_API
865 
867 
868 private:
869 
870  UsdRelationship _CreateDirectBindingRel(
871  const TfToken &materialPurpose) const;
872 
873  UsdRelationship _CreateCollectionBindingRel(
874  const TfToken &bindingName,
875  const TfToken &materialPurpose) const;
876 
877  // Helper method for getting collection bindings when the set of all
878  // collection binding relationship names for the required purpose is
879  // known.
880  CollectionBindingVector _GetCollectionBindings(
881  const TfTokenVector &collBindingPropertyNames) const;
882 };
883 
884 PXR_NAMESPACE_CLOSE_SCOPE
885 
886 #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:89
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:149
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:131
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:438
Single Apply API schema.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
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:70
const SdfPath & GetMaterialPath() const
Returns the path to the material that is bound to by this direct binding.
Singleton registry that provides access to prim and property definition information for registered Us...
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...
This class represents a direct material binding.