forked from autodesk-forks/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeom.cpp
105 lines (87 loc) · 4.34 KB
/
Geom.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
//
// 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("Geom strings", "[geom]")
{
// Test for overlapping paths.
REQUIRE(mx::geomStringsMatch("/", "/robot1"));
REQUIRE(mx::geomStringsMatch("/robot1", "/robot1/left_arm"));
REQUIRE(mx::geomStringsMatch("/robot1, /robot2", "/robot2/left_arm"));
REQUIRE(!mx::geomStringsMatch("", "/robot1"));
REQUIRE(!mx::geomStringsMatch("/robot1", "/robot2"));
REQUIRE(!mx::geomStringsMatch("/robot1, /robot2", "/robot3"));
// Test that one path contains another.
REQUIRE(mx::geomStringsMatch("/", "/robot1", true));
REQUIRE(!mx::geomStringsMatch("/robot1", "/", true));
}
TEST_CASE("Geom elements", "[geom]")
{
mx::DocumentPtr doc = mx::createDocument();
// Add geominfos and tokens
mx::GeomInfoPtr geominfo1 = doc->addGeomInfo("geominfo1", "/robot1, /robot2");
geominfo1->setTokenValue("asset", std::string("robot"));
mx::GeomInfoPtr geominfo2 = doc->addGeomInfo("geominfo2", "/robot1");
geominfo2->setTokenValue("id", std::string("01"));
mx::GeomInfoPtr geominfo3 = doc->addGeomInfo("geominfo3", "/robot2");
geominfo3->setTokenValue("id", std::string("02"));
REQUIRE_THROWS_AS(doc->addGeomInfo("geominfo1"), mx::Exception&);
// Create a node graph with a single image node.
mx::NodeGraphPtr nodeGraph = doc->addNodeGraph();
nodeGraph->setFilePrefix("folder/");
REQUIRE_THROWS_AS(doc->addNodeGraph(nodeGraph->getName()), mx::Exception&);
mx::NodePtr image = nodeGraph->addNode("image");
image->setParameterValue("file", "<asset><id>_diffuse_<UDIM>.tif", mx::FILENAME_TYPE_STRING);
// Test filename string substitutions.
mx::ParameterPtr fileParam = image->getParameter("file");
mx::StringResolverPtr resolver1 = image->createStringResolver("/robot1");
resolver1->setUdimString("1001");
mx::StringResolverPtr resolver2 = image->createStringResolver("/robot2");
resolver2->setUdimString("1002");
REQUIRE(fileParam->getResolvedValue(resolver1)->asA<std::string>() == "folder/robot01_diffuse_1001.tif");
REQUIRE(fileParam->getResolvedValue(resolver2)->asA<std::string>() == "folder/robot02_diffuse_1002.tif");
// Create a geominfo with an attribute.
mx::GeomInfoPtr geominfo4 = doc->addGeomInfo("geominfo4", "/robot1");
mx::StringVec udimSet = {"1001", "1002", "1003", "1004"};
geominfo4->setGeomPropValue("udimset", udimSet);
REQUIRE(doc->getGeomPropValue("udimset", "/robot1")->asA<mx::StringVec>() == udimSet);
REQUIRE(doc->getGeomPropValue("udimset", "/robot2") == nullptr);
// Create a base collection.
mx::CollectionPtr collection1 = doc->addCollection("collection1");
collection1->setIncludeGeom("/scene1");
collection1->setExcludeGeom("/scene1/sphere2");
REQUIRE(collection1->matchesGeomString("/scene1/sphere1"));
REQUIRE(!collection1->matchesGeomString("/scene1/sphere2"));
// Create a derived collection.
mx::CollectionPtr collection2 = doc->addCollection("collection2");
collection2->setIncludeCollection(collection1);
REQUIRE(collection2->matchesGeomString("/scene1/sphere1"));
REQUIRE(!collection2->matchesGeomString("/scene1/sphere2"));
// Create and test an include cycle.
collection1->setIncludeCollection(collection2);
REQUIRE(!doc->validate());
collection1->setIncludeCollection(nullptr);
REQUIRE(doc->validate());
// Test geometry string substitutions.
collection1->setGeomPrefix("/root");
REQUIRE(collection1->matchesGeomString("/root/scene1"));
REQUIRE(!collection1->matchesGeomString("/root/scene2"));
}
TEST_CASE("GeomPropDef", "[geom]")
{
mx::DocumentPtr doc = mx::createDocument();
// Declare a GeomPropDef for world-space normal.
mx::GeomPropDefPtr worldNormal = doc->addGeomPropDef("Nworld", "normal");
worldNormal->setSpace("world");
// Create a NodeDef with an input that defaults to the declared world-space
// normal property.
doc->addNodeDef("ND_foo", "color3", "foo");
mx::InputPtr input = doc->addInput("input1", "vector3");
input->setDefaultGeomPropString(worldNormal->getName());
// Validate connections.
REQUIRE(input->getDefaultGeomProp() == worldNormal);
REQUIRE(doc->validate());
}