forked from AcademySoftwareFoundation/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
163 lines (153 loc) · 5.8 KB
/
Main.cpp
File metadata and controls
163 lines (153 loc) · 5.8 KB
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
#include <MaterialXView/Viewer.h>
#include <iostream>
NANOGUI_FORCE_DISCRETE_GPU();
const std::string options =
" Options: \n"
" --library [FILEPATH] Additional library folder location\n"
" --path [FILEPATH] Additional file search path location\n"
" --mesh [FILENAME] Mesh filename\n"
" --material [FILENAME] Material filename\n"
" --envMethod [INTEGER] Environment lighting method (0 = filtered importance sampling, 1 = prefiltered environment maps, Default is 0)\n"
" --envRad [FILENAME] Specify the environment radiance HDR\n"
" --envIrrad [FILENAME] Specify the environment irradiance HDR\n"
" --msaa [INTEGER] Multisampling count for anti-aliasing (0 = disabled, Default is 0)\n"
" --refresh [INTEGER] Refresh period for the viewer in milliseconds (-1 = disabled, Default is 50)\n"
" --remap [TOKEN1:TOKEN2] Remap one token to another when MaterialX document is loaded\n"
" --skip [NAME] Skip elements matching the given name attribute\n"
" --terminator [STRING] Enforce the given terminator string for file prefixes\n"
" --help Print this list\n";
int main(int argc, char* const argv[])
{
std::vector<std::string> tokens;
for (int i = 1; i < argc; i++)
{
tokens.push_back(std::string(argv[i]));
}
mx::StringVec libraryFolders = { "libraries/stdlib", "libraries/pbrlib", "libraries/stdlib/genglsl", "libraries/pbrlib/genglsl",
"libraries/bxdf", "libraries/lights", "libraries/lights/genglsl" };
mx::FileSearchPath searchPath;
std::string meshFilename = "resources/Geometry/shaderball.obj";
std::string materialFilename = "resources/Materials/Examples/StandardSurface/standard_surface_default.mtlx";
std::string envRadiancePath = "resources/Images/san_giuseppe_bridge.hdr";
std::string envIrradiancePath = "resources/Images/san_giuseppe_bridge_diffuse.hdr";
DocumentModifiers modifiers;
int multiSampleCount = 0;
int refresh = 50;
mx::HwSpecularEnvironmentMethod specularEnvironmentMethod = mx::SPECULAR_ENVIRONMENT_FIS;
for (size_t i = 0; i < tokens.size(); i++)
{
const std::string& token = tokens[i];
const std::string& nextToken = i + 1 < tokens.size() ? tokens[i + 1] : mx::EMPTY_STRING;
if (token == "--library" && !nextToken.empty())
{
libraryFolders.push_back(nextToken);
}
if (token == "--path" && !nextToken.empty())
{
searchPath = mx::FileSearchPath(nextToken);
}
if (token == "--mesh" && !nextToken.empty())
{
meshFilename = nextToken;
}
if (token == "--material" && !nextToken.empty())
{
materialFilename = nextToken;
}
if (token == "--envMethod" && !nextToken.empty())
{
if (std::stoi(nextToken) == 1)
{
specularEnvironmentMethod = mx::SPECULAR_ENVIRONMENT_PREFILTER;
}
}
if (token == "--envRad" && !nextToken.empty())
{
envRadiancePath = nextToken;
}
if (token == "--envIrrad" && !nextToken.empty())
{
envIrradiancePath = nextToken;
}
if (token == "--msaa" && !nextToken.empty())
{
multiSampleCount = std::stoi(nextToken);
}
if (token == "--refresh" && !nextToken.empty())
{
refresh = std::stoi(nextToken);
}
if (token == "--remap" && !nextToken.empty())
{
mx::StringVec vec = mx::splitString(nextToken, ":");
if (vec.size() == 2)
{
modifiers.remapElements[vec[0]] = vec[1];
}
}
if (token == "--skip" && !nextToken.empty())
{
modifiers.skipElements.insert(nextToken);
}
if (token == "--terminator" && !nextToken.empty())
{
modifiers.filePrefixTerminator = nextToken;
}
if (token == "--help")
{
std::cout << options << std::endl;
return 0;
}
}
// Search current directory and parent directory if not found.
mx::FilePath currentPath(mx::FilePath::getCurrentPath());
mx::FilePath parentCurrentPath(currentPath);
parentCurrentPath.pop();
std::vector<mx::FilePath> libraryPaths =
{
mx::FilePath("libraries")
};
for (auto libraryPath : libraryPaths)
{
mx::FilePath fullPath(currentPath / libraryPath);
if (!fullPath.exists())
{
fullPath = parentCurrentPath / libraryPath;
if (fullPath.exists())
{
searchPath.append(fullPath);
}
}
else
{
searchPath.append(fullPath);
}
}
searchPath.append(parentCurrentPath);
searchPath.prepend(currentPath);
try
{
ng::init();
{
ng::ref<Viewer> viewer = new Viewer(libraryFolders,
searchPath,
meshFilename,
materialFilename,
modifiers,
specularEnvironmentMethod,
envRadiancePath,
envIrradiancePath,
multiSampleCount);
viewer->setVisible(true);
ng::mainloop(refresh);
}
ng::shutdown();
}
catch (const std::runtime_error& e)
{
std::string error_msg = std::string("Fatal error: ") + std::string(e.what());
std::cerr << error_msg << std::endl;
return -1;
}
return 0;
}