forked from autodesk-forks/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLook.cpp
125 lines (105 loc) · 4.77 KB
/
Look.cpp
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
//
// TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
// All rights reserved. See LICENSE.txt for license.
//
#include <MaterialXTest/Catch/catch.hpp>
#include <MaterialXCore/Document.h>
namespace mx = MaterialX;
TEST_CASE("Look", "[look]")
{
mx::DocumentPtr doc = mx::createDocument();
// Create a material and look.
mx::MaterialPtr material = doc->addMaterial();
material->addShaderRef();
mx::LookPtr look = doc->addLook();
REQUIRE(doc->getMaterials().size() == 1);
REQUIRE(doc->getLooks().size() == 1);
// Bind the material to a geometry string.
mx::MaterialAssignPtr matAssign1 = look->addMaterialAssign("matAssign1", material->getName());
matAssign1->setGeom("/robot1");
REQUIRE(matAssign1->getReferencedMaterial() == material);
REQUIRE(material->getGeometryBindings("/robot1").size() == 1);
REQUIRE(material->getGeometryBindings("/robot2").size() == 0);
// Bind the material to a geometric collection.
mx::MaterialAssignPtr matAssign2 = look->addMaterialAssign("matAssign2", material->getName());
mx::CollectionPtr collection = doc->addCollection();
collection->setIncludeGeom("/robot2");
collection->setExcludeGeom("/robot2/left_arm");
matAssign2->setCollection(collection);
REQUIRE(material->getGeometryBindings("/robot2").size() == 1);
REQUIRE(material->getGeometryBindings("/robot2/right_arm").size() == 1);
REQUIRE(material->getGeometryBindings("/robot2/left_arm").size() == 0);
// Create a property assignment.
mx::PropertyAssignPtr propertyAssign = look->addPropertyAssign();
propertyAssign->setProperty("twosided");
propertyAssign->setGeom("/robot1");
propertyAssign->setValue(true);
REQUIRE(propertyAssign->getProperty() == "twosided");
REQUIRE(propertyAssign->getGeom() == "/robot1");
REQUIRE(propertyAssign->getValue()->isA<bool>());
REQUIRE(propertyAssign->getValue()->asA<bool>() == true);
// Create a property set assignment.
mx::PropertySetPtr propertySet = doc->addPropertySet();
propertySet->setPropertyValue("matte", false);
REQUIRE(propertySet->getPropertyValue("matte")->isA<bool>());
REQUIRE(propertySet->getPropertyValue("matte")->asA<bool>() == false);
mx::PropertySetAssignPtr propertySetAssign = look->addPropertySetAssign();
propertySetAssign->setPropertySet(propertySet);
propertySetAssign->setGeom("/robot1");
REQUIRE(propertySetAssign->getPropertySet() == propertySet);
REQUIRE(propertySetAssign->getGeom() == "/robot1");
// Create a variant set.
mx::VariantSetPtr variantSet = doc->addVariantSet("damageVars");
variantSet->addVariant("original");
variantSet->addVariant("damaged");
REQUIRE(variantSet->getVariants().size() == 2);
// Create a visibility element.
mx::VisibilityPtr visibility = look->addVisibility();
REQUIRE(visibility->getVisible() == false);
visibility->setVisible(true);
REQUIRE(visibility->getVisible() == true);
visibility->setGeom("/robot2");
REQUIRE(visibility->getGeom() == "/robot2");
visibility->setCollection(collection);
REQUIRE(visibility->getCollection() == collection);
// Create an inherited look.
mx::LookPtr look2 = doc->addLook();
look2->setInheritsFrom(look);
REQUIRE(look2->getActiveMaterialAssigns().size() == 2);
REQUIRE(look2->getActivePropertySetAssigns().size() == 1);
REQUIRE(look2->getActiveVisibilities().size() == 1);
// Create and detect an inheritance cycle.
look->setInheritsFrom(look2);
REQUIRE(!doc->validate());
look->setInheritsFrom(nullptr);
REQUIRE(doc->validate());
// Disconnect the inherited look.
look2->setInheritsFrom(nullptr);
REQUIRE(look2->getActiveMaterialAssigns().empty());
REQUIRE(look2->getActivePropertySetAssigns().empty());
REQUIRE(look2->getActiveVisibilities().empty());
}
TEST_CASE("LookGroup", "[look]")
{
mx::DocumentPtr doc = mx::createDocument();
mx::LookGroupPtr lookGroup = doc->addLookGroup("lookgroup1");
std::vector<mx::LookGroupPtr> lookGroups = doc->getLookGroups();
REQUIRE(lookGroups.size() == 1);
const std::string looks = "look1,look2,look3,look4,look5";
mx::StringVec looksVec = mx::splitString(looks, ",");
for (const std::string& lookName : looksVec)
{
mx::LookPtr look = doc->addLook(lookName);
REQUIRE(look != nullptr);
}
lookGroup->setLooks(looks);
const std::string& looks2 = lookGroup->getLooks();
mx::StringVec looksVec2 = mx::splitString(looks2, ",");
REQUIRE(looksVec.size() == looksVec2.size());
REQUIRE(lookGroup->getActiveLook().empty());
lookGroup->setActiveLook("look1");
REQUIRE(lookGroup->getActiveLook() == "look1");
doc->removeLookGroup("lookgroup1");
lookGroups = doc->getLookGroups();
REQUIRE(lookGroups.size() == 0);
}