6#ifndef MATERIALX_GEOM_H
7#define MATERIALX_GEOM_H
16MATERIALX_NAMESPACE_BEGIN
18extern MX_CORE_API
const string GEOM_PATH_SEPARATOR;
19extern MX_CORE_API
const string UNIVERSAL_GEOM_NAME;
20extern MX_CORE_API
const string UDIM_TOKEN;
21extern MX_CORE_API
const string UV_TILE_TOKEN;
22extern MX_CORE_API
const string UDIM_SET_PROPERTY;
30class CollectionRemove;
69 bool operator==(
const GeomPath& rhs)
const
71 return _vec == rhs._vec &&
74 bool operator!=(
const GeomPath& rhs)
const
76 return !(*
this == rhs);
81 _vec(splitString(geom, GEOM_PATH_SEPARATOR)),
87 operator string()
const
91 return _empty ? EMPTY_STRING : UNIVERSAL_GEOM_NAME;
94 for (
size_t i = 0; i < _vec.size(); i++)
97 if (i + 1 < _vec.size())
99 geom += GEOM_PATH_SEPARATOR;
111 if (_empty || rhs._empty)
115 if (contains && _vec.size() > rhs._vec.size())
119 size_t minSize = std::min(_vec.size(), rhs._vec.size());
120 for (
size_t i = 0; i < minSize; i++)
122 if (_vec[i] != rhs._vec[i])
141 return _vec.empty() && !_empty;
156 Element(parent, category, name)
169 setAttribute(GEOM_ATTRIBUTE, geom);
175 return hasAttribute(GEOM_ATTRIBUTE);
181 return getAttribute(GEOM_ATTRIBUTE);
189 createStringResolver()->resolve(getGeom(), GEOMNAME_TYPE_STRING) :
200 setAttribute(COLLECTION_ATTRIBUTE, collection);
206 return hasAttribute(COLLECTION_ATTRIBUTE);
212 return getAttribute(COLLECTION_ATTRIBUTE);
227 bool validate(
string* message =
nullptr)
const override;
232 static const string GEOM_ATTRIBUTE;
233 static const string COLLECTION_ATTRIBUTE;
257 return addChild<GeomProp>(name);
263 return getChildOfType<GeomProp>(name);
269 return getChildrenOfType<GeomProp>();
275 removeChildOfType<GeomProp>(name);
289 return addChild<Token>(name);
295 return getChildOfType<Token>(name);
301 return getChildrenOfType<Token>();
307 removeChildOfType<Token>(name);
316 template <
class T>
GeomPropPtr setGeomPropValue(
const string& name,
318 const string& type = EMPTY_STRING);
326 token = addToken(name);
327 token->setValue<
string>(value);
334 static const string CATEGORY;
349 static const string CATEGORY;
375 setAttribute(GEOM_PROP_ATTRIBUTE, node);
381 return hasAttribute(GEOM_PROP_ATTRIBUTE);
387 return getAttribute(GEOM_PROP_ATTRIBUTE);
397 setAttribute(SPACE_ATTRIBUTE, space);
403 return hasAttribute(SPACE_ATTRIBUTE);
409 return getAttribute(SPACE_ATTRIBUTE);
419 setAttribute(INDEX_ATTRIBUTE, space);
425 return hasAttribute(INDEX_ATTRIBUTE);
431 return getAttribute(INDEX_ATTRIBUTE);
437 static const string CATEGORY;
438 static const string GEOM_PROP_ATTRIBUTE;
439 static const string SPACE_ATTRIBUTE;
440 static const string INDEX_ATTRIBUTE;
449 Element(parent, CATEGORY, name)
460 setAttribute(INCLUDE_GEOM_ATTRIBUTE, geom);
466 return hasAttribute(INCLUDE_GEOM_ATTRIBUTE);
472 return getAttribute(INCLUDE_GEOM_ATTRIBUTE);
479 return hasIncludeGeom() ?
480 createStringResolver()->resolve(getIncludeGeom(), GEOMNAME_TYPE_STRING) :
491 setAttribute(EXCLUDE_GEOM_ATTRIBUTE, geom);
497 return hasAttribute(EXCLUDE_GEOM_ATTRIBUTE);
503 return getAttribute(EXCLUDE_GEOM_ATTRIBUTE);
510 return hasExcludeGeom() ?
511 createStringResolver()->resolve(getExcludeGeom(), GEOMNAME_TYPE_STRING) :
522 setAttribute(INCLUDE_COLLECTION_ATTRIBUTE, collection);
528 return hasAttribute(INCLUDE_COLLECTION_ATTRIBUTE);
534 return getAttribute(INCLUDE_COLLECTION_ATTRIBUTE);
542 void setIncludeCollections(
const vector<ConstCollectionPtr>& collections);
546 vector<CollectionPtr> getIncludeCollections()
const;
549 bool hasIncludeCycle()
const;
558 bool matchesGeomString(
const string& geom)
const;
566 bool validate(
string* message =
nullptr)
const override;
571 static const string CATEGORY;
572 static const string INCLUDE_GEOM_ATTRIBUTE;
573 static const string EXCLUDE_GEOM_ATTRIBUTE;
574 static const string INCLUDE_COLLECTION_ATTRIBUTE;
581 GeomPropPtr geomProp = getChildOfType<GeomProp>(name);
584 geomProp->setValue(value, type);
598MX_CORE_API
bool geomStringsMatch(
const string& geom1,
const string& geom2,
bool contains =
false);
600MATERIALX_NAMESPACE_END
Base and generic element classes.
shared_ptr< Token > TokenPtr
A shared pointer to a Token.
Definition: Element.h:46
shared_ptr< Element > ElementPtr
A shared pointer to an Element.
Definition: Element.h:31
shared_ptr< GeomInfo > GeomInfoPtr
A shared pointer to a GeomInfo.
Definition: Geom.h:38
shared_ptr< GeomElement > GeomElementPtr
A shared pointer to a GeomElement.
Definition: Geom.h:33
shared_ptr< GeomProp > GeomPropPtr
A shared pointer to a GeomProp.
Definition: Geom.h:43
shared_ptr< const GeomProp > ConstGeomPropPtr
A shared pointer to a const GeomProp.
Definition: Geom.h:45
shared_ptr< const GeomElement > ConstGeomElementPtr
A shared pointer to a const GeomElement.
Definition: Geom.h:35
shared_ptr< const Collection > ConstCollectionPtr
A shared pointer to a const Collection.
Definition: Geom.h:55
MX_CORE_API bool geomStringsMatch(const string &geom1, const string &geom2, bool contains=false)
Given two geometry strings, each containing an array of geom names, return true if they have any geom...
Definition: Geom.cpp:27
shared_ptr< Collection > CollectionPtr
A shared pointer to a Collection.
Definition: Geom.h:53
shared_ptr< const GeomPropDef > ConstGeomPropDefPtr
A shared pointer to a const GeomPropDef.
Definition: Geom.h:50
shared_ptr< const GeomInfo > ConstGeomInfoPtr
A shared pointer to a const GeomInfo.
Definition: Geom.h:40
shared_ptr< GeomPropDef > GeomPropDefPtr
A shared pointer to a GeomPropDef.
Definition: Geom.h:48
Import and export declarations for the Core library.
vector< string > StringVec
A vector of strings.
Definition: Library.h:57
A collection element within a Document.
Definition: Geom.h:446
bool hasIncludeCollectionString() const
Return true if this element has an include collection string.
Definition: Geom.h:526
void setExcludeGeom(const string &geom)
Set the exclude geometry string of this element.
Definition: Geom.h:489
string getActiveExcludeGeom() const
Return the active exclude geometry string of this element, taking all geometry string substitutions a...
Definition: Geom.h:508
const string & getExcludeGeom() const
Return the exclude geometry string of this element.
Definition: Geom.h:501
void setIncludeCollectionString(const string &collection)
Set the include collection string of this element.
Definition: Geom.h:520
const string & getIncludeCollectionString() const
Return the include collection string of this element.
Definition: Geom.h:532
string getActiveIncludeGeom() const
Return the active include geometry string of this element, taking all geometry string substitutions a...
Definition: Geom.h:477
bool hasIncludeGeom() const
Return true if this element has an include geometry string.
Definition: Geom.h:464
void setIncludeGeom(const string &geom)
Set the include geometry string of this element.
Definition: Geom.h:458
const string & getIncludeGeom() const
Return the include geometry string of this element.
Definition: Geom.h:470
bool hasExcludeGeom() const
Return true if this element has an exclude geometry string.
Definition: Geom.h:495
The base class for MaterialX elements.
Definition: Element.h:80
The base class for geometric elements, which support bindings to geometries and geometric collections...
Definition: Geom.h:153
const string & getGeom() const
Return the geometry string of this element.
Definition: Geom.h:179
const string & getCollectionString() const
Return the collection string of this element.
Definition: Geom.h:210
void setGeom(const string &geom)
Set the geometry string of this element.
Definition: Geom.h:167
bool hasCollectionString() const
Return true if this element has a collection string.
Definition: Geom.h:204
bool hasGeom() const
Return true if this element has a geometry string.
Definition: Geom.h:173
string getActiveGeom() const
Return the active geometry string of this element, taking all geometry string substitutions at this s...
Definition: Geom.h:186
void setCollectionString(const string &collection)
Set the collection string of this element.
Definition: Geom.h:198
A geometry info element within a Document.
Definition: Geom.h:239
vector< GeomPropPtr > getGeomProps() const
Return a vector of all GeomProp elements.
Definition: Geom.h:267
TokenPtr getToken(const string &name) const
Return the Token, if any, with the given name.
Definition: Geom.h:293
GeomPropPtr getGeomProp(const string &name) const
Return the GeomProp, if any, with the given name.
Definition: Geom.h:261
vector< TokenPtr > getTokens() const
Return a vector of all Token elements.
Definition: Geom.h:299
GeomPropPtr addGeomProp(const string &name=EMPTY_STRING)
Add a GeomProp to this element.
Definition: Geom.h:255
TokenPtr setTokenValue(const string &name, const string &value)
Set the string value of a Token by its name, creating a child element to hold the Token if needed.
Definition: Geom.h:322
TokenPtr addToken(const string &name=EMPTY_STRING)
Add a Token to this element.
Definition: Geom.h:287
void removeGeomProp(const string &name)
Remove the GeomProp, if any, with the given name.
Definition: Geom.h:273
void removeToken(const string &name)
Remove the Token, if any, with the given name.
Definition: Geom.h:305
GeomPropPtr setGeomPropValue(const string &name, const T &value, const string &type=EMPTY_STRING)
Set the value of a GeomProp by its name, creating a child element to hold the GeomProp if needed.
Definition: Geom.h:577
A MaterialX geometry path, representing the hierarchical location expressed by a geometry name.
Definition: Geom.h:61
bool isUniversal() const
Return true if this geometry path is universal.
Definition: Geom.h:139
GeomPath(const string &geom)
Construct a path from a geometry name string.
Definition: Geom.h:80
bool isEmpty() const
Return true if this geometry path is empty.
Definition: Geom.h:132
bool isMatching(const GeomPath &rhs, bool contains=false) const
Return true if there is any geometry in common between the two paths.
Definition: Geom.h:109
An element representing a declaration of geometric property data.
Definition: Geom.h:361
bool hasIndex() const
Return true if this element has an index string.
Definition: Geom.h:423
bool hasSpace() const
Return true if this element has a geometric space string.
Definition: Geom.h:401
void setGeomProp(const string &node)
Set the geometric property string of this element.
Definition: Geom.h:373
const string & getSpace() const
Return the geometric space string of this element.
Definition: Geom.h:407
void setIndex(const string &space)
Set the index string of this element.
Definition: Geom.h:417
const string & getGeomProp() const
Return the geometric property string of this element.
Definition: Geom.h:385
const string & getIndex() const
Return the index string of this element.
Definition: Geom.h:429
void setSpace(const string &space)
Set the geometric space string of this element.
Definition: Geom.h:395
bool hasGeomProp() const
Return true if this element has a geometric property string.
Definition: Geom.h:379
A geometric property element within a GeomInfo.
Definition: Geom.h:340
The base class for typed elements.
Definition: Element.h:837
The base class for elements that support typed values.
Definition: Element.h:895