HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HUSD_BindMaterial.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Side Effects Software Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #ifndef __HUSD_BindMaterial__
19 #define __HUSD_BindMaterial__
20 
21 #include "HUSD_API.h"
22 #include "HUSD_DataHandle.h"
23 #include "HUSD_Path.h"
24 #include "HUSD_TimeCode.h"
25 #include <SYS/SYS_Types.h>
26 
27 
28 template <typename T> class UT_Array;
29 
30 
32 {
33 public:
34  /// Standard constructor.
36 
37  /// Assigns the given material to the given geometry primitive(s).
38  bool bind(const UT_StringRef &mat_prim_path,
39  const UT_StringRef &geo_prim_path) const;
40  bool bind(const UT_StringRef &mat_prim_path,
41  const HUSD_FindPrims &find_geo_prims) const;
42 
43  /// Performs a collection based binding with explicit values for the
44  /// collection path, binding prim path, and binding name. The bind
45  /// method and bind prim path set on this object are ignored.
46  bool bindAsCollection(const UT_StringRef &mat_prim_path,
47  const UT_StringRef &collection_path,
48  const UT_StringRef &binding_prim_path,
49  const UT_StringRef &binding_name) const;
50 
51  /// Assigns the given material to a subset of the geometry primitive. This
52  /// method creates the geometry subset. If a geometry subset already
53  /// exists, it can be bound using the regular bind methods above.
54  bool bindSubset(const UT_StringRef &mat_prim_path,
55  const UT_StringRef &geo_prim_path,
56  const UT_Array<exint> *face_indices,
57  const HUSD_TimeCode &tc = HUSD_TimeCode()) const;
58 
59  /// Creates a geometry subset for material binding, but does not actually
60  /// bind any material to the prim.
61  HUSD_Path createSubset(const UT_StringRef &subset_name,
62  const UT_StringRef &geo_prim_path,
63  const UT_Array<exint> &face_indices,
64  const HUSD_TimeCode &tc = HUSD_TimeCode()) const;
65 
66  /// Makes sure the primitives are not bound to any material.
67  /// I.e, if there is any direct material binding (on the given prim
68  /// or its ancestor), authors a binding block on the given prim,
69  /// and if there is any collection-based assignment on the prim or ancestor,
70  /// removes the given prim from the collection.
71  bool unbindAll( const HUSD_FindPrims &find_prims ) const;
72 
73  /// Removes the material binding from the geometry primitive(s).
74  /// The @p unbind_limit determines how many material bindings are blocked.
75  //
76  /// The binding limit of 1 unassigns the currently bound material,
77  /// allowing any other candidate moaterial to take over.
78  ///
79  /// The binding limit of 2 unassigns the currently bound material (if any),
80  /// and the second candidate material (if any), allowing the next candidate
81  /// material to take effect.
82  bool unbind( const HUSD_FindPrims &find_prims,
83  const UT_StringHolder &purpose,
84  int unbind_limit = 1) const;
85 
86  /// Looks for the specified attrname on any prims in the named layer.
87  /// This string attribute is turned into an SdfPath that is bound as the
88  /// material to the primitive with the attribute. If the attribute string
89  /// points to a geometry primitive, we assign the material bound to that
90  /// geometry primitive. Return false if the operation fails in an
91  /// unrecoverable way. An error will have been added to the error scope
92  /// to explain the failure. Warnings may also be generated for more minor
93  /// issues such as invalid material paths.
94  bool assignMaterialsFromAttribute(
95  const UT_StringRef &layername,
97  const UT_StringRef &primpath,
98  const UT_StringRef &refprimpath,
99  const UT_StringRef &attrname,
100  bool remove_attr,
101  bool create_empty_materials) const;
102 
103  /// Enumeration of the ways in which a binding can be performed.
104  enum class BindMethod
105  {
106  DIRECT, // direct binding
107  COLLECTION // collection-based binding
108  };
109 
110  /// Sets the method of defining bindings.
111  void setBindMethod( BindMethod method )
112  { myBindMethod = method; }
114  { return myBindMethod; }
115 
116  /// Sets the collection expansion option when defining collections.
117  void setBindCollectionExpand( bool expand )
118  { myBindCollectionExpand = expand; }
120  { return myBindCollectionExpand; }
121 
122  /// For collection-based bindings, sets the USD primitive path on which the
123  /// collection-based binding is defined.
125  { myBindPrimPath = p; }
127  { return myBindPrimPath; }
128 
129  /// For collection-based bindings, sets the USD binding name.
130  /// (If not set explicitly, the material name will be used).
131  void setBindName( const UT_StringRef &n)
132  { myBindName = n; }
133  const UT_StringHolder & getBindName() const
134  { return myBindName; }
135 
136  /// Enumeration of the material binding strength.
137  enum class Strength
138  {
139  DEFAULT, // fallback
140  STRONG, // stronger than descendants
141  WEAK // weaker than descendants
142  };
143 
144  /// Sets the strength preference for material assignments.
145  void setStrength( Strength strength )
146  { myStrength = strength; }
148  { return myStrength; }
149 
150  /// Sets the purpose for material assignments.
151  void setPurpose( const UT_StringHolder &purpose )
152  { myPurpose = purpose; }
153  const UT_StringHolder & getPurpose() const
154  { return myPurpose; }
155 
156 
157 private:
158  HUSD_AutoWriteLock & myWriteLock;
159  BindMethod myBindMethod; // Collection based?
160  bool myBindCollectionExpand; // Expand collections
161  Strength myStrength; // Binding strength
162  UT_StringHolder myPurpose; // Binding purpose
163  UT_StringHolder myBindPrimPath; // Collection location
164  UT_StringHolder myBindName; // Collection bind name
165 };
166 
167 #endif
168 
const UT_StringHolder & getBindPrimPath() const
BindMethod getBindMethod() const
#define HUSD_API
Definition: HUSD_API.h:32
const UT_StringHolder & getPurpose() const
void setBindCollectionExpand(bool expand)
Sets the collection expansion option when defining collections.
GLdouble n
Definition: glcorearb.h:2008
const UT_StringHolder & getBindName() const
void setPurpose(const UT_StringHolder &purpose)
Sets the purpose for material assignments.
simple inheritance: W = L * pW
BindMethod
Enumeration of the ways in which a binding can be performed.
void setBindPrimPath(const UT_StringRef &p)
Strength
Enumeration of the material binding strength.
void setBindMethod(BindMethod method)
Sets the method of defining bindings.
void setStrength(Strength strength)
Sets the strength preference for material assignments.
void setBindName(const UT_StringRef &n)
**If you just want to fire and args
Definition: thread.h:609
bool getBindCollectionExpand() const
Strength getStrength() const