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