HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Look.h
Go to the documentation of this file.
1 //
2 // TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
3 // All rights reserved. See LICENSE.txt for license.
4 //
5 
6 #ifndef MATERIALX_LOOK_H
7 #define MATERIALX_LOOK_H
8 
9 /// @file
10 /// Look element subclasses
11 
12 #include <MaterialXCore/Export.h>
13 
14 #include <MaterialXCore/Material.h>
15 #include <MaterialXCore/Property.h>
16 #include <MaterialXCore/Variant.h>
17 
19 
20 class Look;
21 class LookGroup;
22 class LookInherit;
23 class MaterialAssign;
24 class Visibility;
25 
26 /// A shared pointer to a Look
27 using LookPtr = shared_ptr<Look>;
28 /// A shared pointer to a const Look
29 using ConstLookPtr = shared_ptr<const Look>;
30 
31 /// A shared pointer to a LookGroup
32 using LookGroupPtr = shared_ptr<LookGroup>;
33 /// A shared pointer to a const LookGroup
34 using ConstLookGroupPtr = shared_ptr<const LookGroup>;
35 
36 /// A shared pointer to a MaterialAssign
37 using MaterialAssignPtr = shared_ptr<MaterialAssign>;
38 /// A shared pointer to a const MaterialAssign
39 using ConstMaterialAssignPtr = shared_ptr<const MaterialAssign>;
40 
41 /// A shared pointer to a Visibility
42 using VisibilityPtr = shared_ptr<Visibility>;
43 /// A shared pointer to a const Visibility
44 using ConstVisibilityPtr = shared_ptr<const Visibility>;
45 
46 /// @class Look
47 /// A look element within a Document.
48 class MX_CORE_API Look : public Element
49 {
50  public:
51  Look(ElementPtr parent, const string& name) :
52  Element(parent, CATEGORY, name)
53  {
54  }
55  virtual ~Look() { }
56 
57  /// @name MaterialAssign Elements
58  /// @{
59 
60  /// Add a MaterialAssign to the look.
61  /// @param name The name of the new MaterialAssign.
62  /// If no name is specified, then a unique name will automatically be
63  /// generated.
64  /// @param material An optional material string, which should match the
65  /// name of the material node to be assigned.
66  /// @return A shared pointer to the new MaterialAssign.
67  MaterialAssignPtr addMaterialAssign(const string& name = EMPTY_STRING,
68  const string& material = EMPTY_STRING);
69 
70  /// Return the MaterialAssign, if any, with the given name.
72  {
73  return getChildOfType<MaterialAssign>(name);
74  }
75 
76  /// Return a vector of all MaterialAssign elements in the look.
77  vector<MaterialAssignPtr> getMaterialAssigns() const
78  {
79  return getChildrenOfType<MaterialAssign>();
80  }
81 
82  /// Return a vector of all MaterialAssign elements that belong to this look,
83  /// taking look inheritance into account.
84  vector<MaterialAssignPtr> getActiveMaterialAssigns() const;
85 
86  /// Remove the MaterialAssign, if any, with the given name.
87  void removeMaterialAssign(const string& name)
88  {
89  removeChildOfType<MaterialAssign>(name);
90  }
91 
92  /// @}
93  /// @name PropertyAssign Elements
94  /// @{
95 
96  /// Add a PropertyAssign to the look.
97  /// @param name The name of the new PropertyAssign.
98  /// If no name is specified, then a unique name will automatically be
99  /// generated.
100  /// @return A shared pointer to the new PropertyAssign.
102  {
103  return addChild<PropertyAssign>(name);
104  }
105 
106  /// Return the PropertyAssign, if any, with the given name.
108  {
109  return getChildOfType<PropertyAssign>(name);
110  }
111 
112  /// Return a vector of all PropertyAssign elements in the look.
113  vector<PropertyAssignPtr> getPropertyAssigns() const
114  {
115  return getChildrenOfType<PropertyAssign>();
116  }
117 
118  /// Return a vector of all PropertyAssign elements that belong to this look,
119  /// taking look inheritance into account.
120  vector<PropertyAssignPtr> getActivePropertyAssigns() const;
121 
122  /// Remove the PropertyAssign, if any, with the given name.
123  void removePropertyAssign(const string& name)
124  {
125  removeChildOfType<PropertyAssign>(name);
126  }
127 
128  /// @}
129  /// @name PropertySetAssign Elements
130  /// @{
131 
132  /// Add a PropertySetAssign to the look.
133  /// @param name The name of the new PropertySetAssign.
134  /// If no name is specified, then a unique name will automatically be
135  /// generated.
136  /// @return A shared pointer to the new PropertySetAssign.
138  {
139  return addChild<PropertySetAssign>(name);
140  }
141 
142  /// Return the PropertySetAssign, if any, with the given name.
144  {
145  return getChildOfType<PropertySetAssign>(name);
146  }
147 
148  /// Return a vector of all PropertySetAssign elements in the look.
149  vector<PropertySetAssignPtr> getPropertySetAssigns() const
150  {
151  return getChildrenOfType<PropertySetAssign>();
152  }
153 
154  /// Return a vector of all PropertySetAssign elements that belong to this look,
155  /// taking look inheritance into account.
156  vector<PropertySetAssignPtr> getActivePropertySetAssigns() const;
157 
158  /// Remove the PropertySetAssign, if any, with the given name.
159  void removePropertySetAssign(const string& name)
160  {
161  removeChildOfType<PropertySetAssign>(name);
162  }
163 
164  /// @}
165  /// @name VariantAssign Elements
166  /// @{
167 
168  /// Add a VariantAssign to the look.
169  /// @param name The name of the new VariantAssign.
170  /// If no name is specified, then a unique name will automatically be
171  /// generated.
172  /// @return A shared pointer to the new VariantAssign.
174  {
175  return addChild<VariantAssign>(name);
176  }
177 
178  /// Return the VariantAssign, if any, with the given name.
180  {
181  return getChildOfType<VariantAssign>(name);
182  }
183 
184  /// Return a vector of all VariantAssign elements in the look.
185  vector<VariantAssignPtr> getVariantAssigns() const
186  {
187  return getChildrenOfType<VariantAssign>();
188  }
189 
190  /// Return a vector of all VariantAssign elements that belong to this look,
191  /// taking look inheritance into account.
192  vector<VariantAssignPtr> getActiveVariantAssigns() const;
193 
194  /// Remove the VariantAssign, if any, with the given name.
195  void removeVariantAssign(const string& name)
196  {
197  removeChildOfType<VariantAssign>(name);
198  }
199 
200  /// @}
201  /// @name Visibility Elements
202  /// @{
203 
204  /// Add a Visibility to the look.
205  /// @param name The name of the new Visibility.
206  /// If no name is specified, then a unique name will automatically be
207  /// generated.
208  /// @return A shared pointer to the new Visibility.
210  {
211  return addChild<Visibility>(name);
212  }
213 
214  /// Return the Visibility, if any, with the given name.
215  VisibilityPtr getVisibility(const string& name) const
216  {
217  return getChildOfType<Visibility>(name);
218  }
219 
220  /// Return a vector of all Visibility elements in the look.
221  vector<VisibilityPtr> getVisibilities() const
222  {
223  return getChildrenOfType<Visibility>();
224  }
225 
226  /// Return a vector of all Visibility elements that belong to this look,
227  /// taking look inheritance into account.
228  vector<VisibilityPtr> getActiveVisibilities() const;
229 
230  /// Remove the Visibility, if any, with the given name.
231  void removeVisibility(const string& name)
232  {
233  removeChildOfType<Visibility>(name);
234  }
235 
236  /// @}
237 
238  public:
239  static const string CATEGORY;
240 };
241 
242 /// @class LookGroup
243 /// A look group element within a Document.
245 {
246  public:
247  LookGroup(ElementPtr parent, const string& name) :
248  Element(parent, CATEGORY, name)
249  {
250  }
251  virtual ~LookGroup() { }
252 
253  /// Set comma-separated list of looks.
254  void setLooks(const string& looks)
255  {
256  setAttribute(LOOKS_ATTRIBUTE, looks);
257  }
258 
259  /// Get comma-separated list of looks.
260  const string& getLooks() const
261  {
262  return getAttribute(LOOKS_ATTRIBUTE);
263  }
264 
265  /// Set the active look.
266  void setActiveLook(const string& look)
267  {
268  setAttribute(ACTIVE_ATTRIBUTE, look);
269  }
270 
271  /// Return the active look, if any.
272  const string& getActiveLook() const
273  {
274  return getAttribute(ACTIVE_ATTRIBUTE);
275  }
276 
277  public:
278  static const string CATEGORY;
279  static const string LOOKS_ATTRIBUTE;
280  static const string ACTIVE_ATTRIBUTE;
281 };
282 
283 /// @class MaterialAssign
284 /// A material assignment element within a Look.
286 {
287  public:
288  MaterialAssign(ElementPtr parent, const string& name) :
289  GeomElement(parent, CATEGORY, name)
290  {
291  }
292  virtual ~MaterialAssign() { }
293 
294  /// @name Material String
295  /// @{
296 
297  /// Set the material string for the MaterialAssign.
298  void setMaterial(const string& material)
299  {
300  setAttribute(MATERIAL_ATTRIBUTE, material);
301  }
302 
303  /// Return true if the given MaterialAssign has a material string.
304  bool hasMaterial() const
305  {
306  return hasAttribute(MATERIAL_ATTRIBUTE);
307  }
308 
309  /// Return the material string for the MaterialAssign.
310  const string& getMaterial() const
311  {
312  return getAttribute(MATERIAL_ATTRIBUTE);
313  }
314 
315  /// Return the outputs on any referenced material
316  vector<OutputPtr> getMaterialOutputs() const;
317 
318  /// @}
319  /// @name Exclusive
320  /// @{
321 
322  /// Set the exclusive boolean for the MaterialAssign.
323  void setExclusive(bool value)
324  {
325  setTypedAttribute<bool>(EXCLUSIVE_ATTRIBUTE, value);
326  }
327 
328  /// Return the exclusive boolean for the MaterialAssign.
329  bool getExclusive() const
330  {
331  return getTypedAttribute<bool>(EXCLUSIVE_ATTRIBUTE);
332  }
333 
334  /// @}
335  /// @name Material References
336  /// @{
337 
338  /// Return the material node, if any, referenced by the MaterialAssign.
339  NodePtr getReferencedMaterial() const;
340 
341  /// @}
342  /// @name VariantAssign Elements
343  /// @{
344 
345  /// Add a VariantAssign to the look.
346  /// @param name The name of the new VariantAssign.
347  /// If no name is specified, then a unique name will automatically be
348  /// generated.
349  /// @return A shared pointer to the new VariantAssign.
351  {
352  return addChild<VariantAssign>(name);
353  }
354 
355  /// Return the VariantAssign, if any, with the given name.
357  {
358  return getChildOfType<VariantAssign>(name);
359  }
360 
361  /// Return a vector of all VariantAssign elements in the look.
362  vector<VariantAssignPtr> getVariantAssigns() const
363  {
364  return getChildrenOfType<VariantAssign>();
365  }
366 
367  /// Return a vector of all VariantAssign elements that belong to this look,
368  /// taking look inheritance into account.
369  vector<VariantAssignPtr> getActiveVariantAssigns() const;
370 
371  /// Remove the VariantAssign, if any, with the given name.
372  void removeVariantAssign(const string& name)
373  {
374  removeChildOfType<VariantAssign>(name);
375  }
376 
377  public:
378  static const string CATEGORY;
379  static const string MATERIAL_ATTRIBUTE;
380  static const string EXCLUSIVE_ATTRIBUTE;
381 };
382 
383 /// @class Visibility
384 /// A visibility element within a Look.
385 ///
386 /// A Visibility describes the visibility relationship between two geometries
387 /// or geometric collections.
388 ///
389 /// @todo Add a Look::geomIsVisible method that computes the visibility between
390 /// two geometries in the context of a specific Look.
392 {
393  public:
394  Visibility(ElementPtr parent, const string& name) :
395  GeomElement(parent, CATEGORY, name)
396  {
397  }
398  virtual ~Visibility() { }
399 
400  /// @name Viewer Geom
401  /// @{
402 
403  /// Set the viewer geom string of the element.
404  void setViewerGeom(const string& geom)
405  {
406  setAttribute(VIEWER_GEOM_ATTRIBUTE, geom);
407  }
408 
409  /// Return true if the given element has a viewer geom string.
410  bool hasViewerGeom() const
411  {
412  return hasAttribute(VIEWER_GEOM_ATTRIBUTE);
413  }
414 
415  /// Return the viewer geom string of the element.
416  const string& getViewerGeom() const
417  {
418  return getAttribute(VIEWER_GEOM_ATTRIBUTE);
419  }
420 
421  /// @}
422  /// @name Viewer Collection
423  /// @{
424 
425  /// Set the viewer geom string of the element.
426  void setViewerCollection(const string& collection)
427  {
428  setAttribute(VIEWER_COLLECTION_ATTRIBUTE, collection);
429  }
430 
431  /// Return true if the given element has a viewer collection string.
432  bool hasViewerCollection() const
433  {
434  return hasAttribute(VIEWER_COLLECTION_ATTRIBUTE);
435  }
436 
437  /// Return the viewer collection string of the element.
438  const string& getViewerCollection() const
439  {
440  return getAttribute(VIEWER_COLLECTION_ATTRIBUTE);
441  }
442 
443  /// @}
444  /// @name Visibility Type
445  /// @{
446 
447  /// Set the visibility type string of the element.
448  void setVisibilityType(const string& type)
449  {
450  setAttribute(VISIBILITY_TYPE_ATTRIBUTE, type);
451  }
452 
453  /// Return true if the given element has a visibility type string.
454  bool hasVisibilityType() const
455  {
456  return hasAttribute(VISIBILITY_TYPE_ATTRIBUTE);
457  }
458 
459  /// Return the visibility type string of the element.
460  const string& getVisibilityType() const
461  {
462  return getAttribute(VISIBILITY_TYPE_ATTRIBUTE);
463  }
464 
465  /// @}
466  /// @name Visible
467  /// @{
468 
469  /// Set the visible boolean of the element.
470  void setVisible(bool visible)
471  {
472  setTypedAttribute<bool>(VISIBLE_ATTRIBUTE, visible);
473  }
474 
475  /// Return the visible boolean of the element.
476  bool getVisible() const
477  {
478  return getTypedAttribute<bool>(VISIBLE_ATTRIBUTE);
479  }
480 
481  /// @}
482 
483  public:
484  static const string CATEGORY;
485  static const string VIEWER_GEOM_ATTRIBUTE;
486  static const string VIEWER_COLLECTION_ATTRIBUTE;
487  static const string VISIBILITY_TYPE_ATTRIBUTE;
488  static const string VISIBLE_ATTRIBUTE;
489 };
490 
491 /// Return a vector of all MaterialAssign elements that bind this material node
492 /// to the given geometry string
493 /// @param materialNode Node to examine
494 /// @param geom The geometry for which material bindings should be returned.
495 /// By default, this argument is the universal geometry string "/",
496 /// and all material bindings are returned.
497 /// @return Vector of MaterialAssign elements
498 MX_CORE_API vector<MaterialAssignPtr> getGeometryBindings(ConstNodePtr materialNode, const string& geom = UNIVERSAL_GEOM_NAME);
499 
501 
502 #endif
VariantAssignPtr addVariantAssign(const string &name=EMPTY_STRING)
Definition: Look.h:350
virtual ~Look()
Definition: Look.h:55
shared_ptr< PropertySetAssign > PropertySetAssignPtr
A shared pointer to a PropertySetAssign.
Definition: Property.h:39
VisibilityPtr getVisibility(const string &name) const
Return the Visibility, if any, with the given name.
Definition: Look.h:215
void removeVariantAssign(const string &name)
Remove the VariantAssign, if any, with the given name.
Definition: Look.h:372
const string & getViewerCollection() const
Return the viewer collection string of the element.
Definition: Look.h:438
shared_ptr< MaterialAssign > MaterialAssignPtr
A shared pointer to a MaterialAssign.
Definition: Look.h:37
vector< VariantAssignPtr > getVariantAssigns() const
Return a vector of all VariantAssign elements in the look.
Definition: Look.h:185
LookGroup(ElementPtr parent, const string &name)
Definition: Look.h:247
static const string CATEGORY
Definition: Look.h:239
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:23
shared_ptr< const Look > ConstLookPtr
A shared pointer to a const Look.
Definition: Look.h:29
void setLooks(const string &looks)
Set comma-separated list of looks.
Definition: Look.h:254
shared_ptr< const Visibility > ConstVisibilityPtr
A shared pointer to a const Visibility.
Definition: Look.h:44
MX_CORE_API vector< MaterialAssignPtr > getGeometryBindings(ConstNodePtr materialNode, const string &geom=UNIVERSAL_GEOM_NAME)
MATERIALX_NAMESPACE_BEGIN MX_CORE_API const string EMPTY_STRING
shared_ptr< Look > LookPtr
A shared pointer to a Look.
Definition: Look.h:27
bool getExclusive() const
Return the exclusive boolean for the MaterialAssign.
Definition: Look.h:329
const string & getViewerGeom() const
Return the viewer geom string of the element.
Definition: Look.h:416
const string & getActiveLook() const
Return the active look, if any.
Definition: Look.h:272
shared_ptr< const Node > ConstNodePtr
A shared pointer to a const Node.
Definition: Node.h:26
void setMaterial(const string &material)
Set the material string for the MaterialAssign.
Definition: Look.h:298
const string & getAttribute(const string &attrib) const
Definition: Element.h:498
void setActiveLook(const string &look)
Set the active look.
Definition: Look.h:266
const string & getVisibilityType() const
Return the visibility type string of the element.
Definition: Look.h:460
MaterialAssign(ElementPtr parent, const string &name)
Definition: Look.h:288
virtual ~LookGroup()
Definition: Look.h:251
GLuint const GLchar * name
Definition: glcorearb.h:786
#define MX_CORE_API
Definition: Export.h:18
static const string MATERIAL_ATTRIBUTE
Definition: Look.h:379
virtual ~MaterialAssign()
Definition: Look.h:292
static const string ACTIVE_ATTRIBUTE
Definition: Look.h:280
PropertyAssignPtr addPropertyAssign(const string &name=EMPTY_STRING)
Definition: Look.h:101
static const string LOOKS_ATTRIBUTE
Definition: Look.h:279
const string & getLooks() const
Get comma-separated list of looks.
Definition: Look.h:260
VisibilityPtr addVisibility(const string &name=EMPTY_STRING)
Definition: Look.h:209
shared_ptr< Visibility > VisibilityPtr
A shared pointer to a Visibility.
Definition: Look.h:42
static const string EXCLUSIVE_ATTRIBUTE
Definition: Look.h:380
void setExclusive(bool value)
Set the exclusive boolean for the MaterialAssign.
Definition: Look.h:323
void removeMaterialAssign(const string &name)
Remove the MaterialAssign, if any, with the given name.
Definition: Look.h:87
shared_ptr< LookGroup > LookGroupPtr
A shared pointer to a LookGroup.
Definition: Look.h:32
Look(ElementPtr parent, const string &name)
Definition: Look.h:51
void setVisibilityType(const string &type)
Set the visibility type string of the element.
Definition: Look.h:448
PropertySetAssignPtr addPropertySetAssign(const string &name=EMPTY_STRING)
Definition: Look.h:137
static const string CATEGORY
Definition: Look.h:378
MaterialAssignPtr getMaterialAssign(const string &name) const
Return the MaterialAssign, if any, with the given name.
Definition: Look.h:71
MX_CORE_API const string UNIVERSAL_GEOM_NAME
shared_ptr< VariantAssign > VariantAssignPtr
A shared pointer to a VariantAssign.
Definition: Variant.h:33
Visibility(ElementPtr parent, const string &name)
Definition: Look.h:394
Definition: Look.h:48
vector< MaterialAssignPtr > getMaterialAssigns() const
Return a vector of all MaterialAssign elements in the look.
Definition: Look.h:77
static const string VISIBILITY_TYPE_ATTRIBUTE
Definition: Look.h:487
shared_ptr< PropertyAssign > PropertyAssignPtr
A shared pointer to a PropertyAssign.
Definition: Property.h:29
VariantAssignPtr addVariantAssign(const string &name=EMPTY_STRING)
Definition: Look.h:173
VariantAssignPtr getVariantAssign(const string &name) const
Return the VariantAssign, if any, with the given name.
Definition: Look.h:356
static const string VISIBLE_ATTRIBUTE
Definition: Look.h:488
void removePropertySetAssign(const string &name)
Remove the PropertySetAssign, if any, with the given name.
Definition: Look.h:159
PropertyAssignPtr getPropertyAssign(const string &name) const
Return the PropertyAssign, if any, with the given name.
Definition: Look.h:107
VariantAssignPtr getVariantAssign(const string &name) const
Return the VariantAssign, if any, with the given name.
Definition: Look.h:179
vector< PropertySetAssignPtr > getPropertySetAssigns() const
Return a vector of all PropertySetAssign elements in the look.
Definition: Look.h:149
PropertySetAssignPtr getPropertySetAssign(const string &name) const
Return the PropertySetAssign, if any, with the given name.
Definition: Look.h:143
void setAttribute(const string &attrib, const string &value)
Set the value string of the given attribute.
void removePropertyAssign(const string &name)
Remove the PropertyAssign, if any, with the given name.
Definition: Look.h:123
void removeVisibility(const string &name)
Remove the Visibility, if any, with the given name.
Definition: Look.h:231
const string & getMaterial() const
Return the material string for the MaterialAssign.
Definition: Look.h:310
bool hasAttribute(const string &attrib) const
Return true if the given attribute is present.
Definition: Element.h:491
bool hasMaterial() const
Return true if the given MaterialAssign has a material string.
Definition: Look.h:304
static const string VIEWER_GEOM_ATTRIBUTE
Definition: Look.h:485
static const string CATEGORY
Definition: Look.h:484
void setViewerGeom(const string &geom)
Set the viewer geom string of the element.
Definition: Look.h:404
void setViewerCollection(const string &collection)
Set the viewer geom string of the element.
Definition: Look.h:426
GLsizei const GLfloat * value
Definition: glcorearb.h:824
bool hasVisibilityType() const
Return true if the given element has a visibility type string.
Definition: Look.h:454
bool getVisible() const
Return the visible boolean of the element.
Definition: Look.h:476
bool hasViewerGeom() const
Return true if the given element has a viewer geom string.
Definition: Look.h:410
void removeVariantAssign(const string &name)
Remove the VariantAssign, if any, with the given name.
Definition: Look.h:195
Definition: core.h:1131
shared_ptr< Element > ElementPtr
A shared pointer to an Element.
Definition: Element.h:30
vector< VariantAssignPtr > getVariantAssigns() const
Return a vector of all VariantAssign elements in the look.
Definition: Look.h:362
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:24
void setVisible(bool visible)
Set the visible boolean of the element.
Definition: Look.h:470
vector< VisibilityPtr > getVisibilities() const
Return a vector of all Visibility elements in the look.
Definition: Look.h:221
shared_ptr< const MaterialAssign > ConstMaterialAssignPtr
A shared pointer to a const MaterialAssign.
Definition: Look.h:39
vector< PropertyAssignPtr > getPropertyAssigns() const
Return a vector of all PropertyAssign elements in the look.
Definition: Look.h:113
shared_ptr< const LookGroup > ConstLookGroupPtr
A shared pointer to a const LookGroup.
Definition: Look.h:34
type
Definition: core.h:1059
bool hasViewerCollection() const
Return true if the given element has a viewer collection string.
Definition: Look.h:432
static const string CATEGORY
Definition: Look.h:278
static const string VIEWER_COLLECTION_ATTRIBUTE
Definition: Look.h:486
shared_ptr< Node > NodePtr
A shared pointer to a Node.
Definition: Node.h:24
virtual ~Visibility()
Definition: Look.h:398