-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathrender-config.cc
128 lines (109 loc) · 3.41 KB
/
render-config.cc
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
#include "render-config.h"
#include "picojson.h"
#include <fstream>
#include <istream>
namespace example {
bool LoadRenderConfig(example::RenderConfig* config, const char* filename) {
std::ifstream is(filename);
if (is.fail()) {
std::cerr << "Cannot open " << filename << std::endl;
return false;
}
std::istream_iterator<char> input(is);
std::string err;
picojson::value v;
input = picojson::parse(v, input, std::istream_iterator<char>(), &err);
if (!err.empty()) {
std::cerr << err << std::endl;
}
if (!v.is<picojson::object>()) {
std::cerr << "Not a JSON object" << std::endl;
return false;
}
picojson::object o = v.get<picojson::object>();
if (o.find("obj_filename") != o.end()) {
if (o["obj_filename"].is<std::string>()) {
config->obj_filename = o["obj_filename"].get<std::string>();
}
}
if (o.find("ptex_filename") != o.end()) {
if (o["ptex_filename"].is<std::string>()) {
config->ptex_filename = o["ptex_filename"].get<std::string>();
}
}
config->scene_scale = 1.0f;
if (o.find("scene_scale") != o.end()) {
if (o["scene_scale"].is<double>()) {
config->scene_scale = static_cast<float>(o["scene_scale"].get<double>());
}
}
config->eye[0] = 0.0f;
config->eye[1] = 0.0f;
config->eye[2] = 5.0f;
if (o.find("eye") != o.end()) {
if (o["eye"].is<picojson::array>()) {
picojson::array arr = o["eye"].get<picojson::array>();
if (arr.size() == 3) {
config->eye[0] = static_cast<float>(arr[0].get<double>());
config->eye[1] = static_cast<float>(arr[1].get<double>());
config->eye[2] = static_cast<float>(arr[2].get<double>());
}
}
}
config->up[0] = 0.0f;
config->up[1] = 1.0f;
config->up[2] = 0.0f;
if (o.find("up") != o.end()) {
if (o["up"].is<picojson::array>()) {
picojson::array arr = o["up"].get<picojson::array>();
if (arr.size() == 3) {
config->up[0] = static_cast<float>(arr[0].get<double>());
config->up[1] = static_cast<float>(arr[1].get<double>());
config->up[2] = static_cast<float>(arr[2].get<double>());
}
}
}
config->look_at[0] = 0.0f;
config->look_at[1] = 0.0f;
config->look_at[2] = 0.0f;
if (o.find("look_at") != o.end()) {
if (o["look_at"].is<picojson::array>()) {
picojson::array arr = o["look_at"].get<picojson::array>();
if (arr.size() == 3) {
config->look_at[0] = static_cast<float>(arr[0].get<double>());
config->look_at[1] = static_cast<float>(arr[1].get<double>());
config->look_at[2] = static_cast<float>(arr[2].get<double>());
}
}
}
config->fov = 45.0f;
if (o.find("fov") != o.end()) {
if (o["fov"].is<double>()) {
config->fov = static_cast<float>(o["fov"].get<double>());
}
}
config->width = 512;
if (o.find("width") != o.end()) {
if (o["width"].is<double>()) {
config->width = static_cast<int>(o["width"].get<double>());
}
}
config->height = 512;
if (o.find("height") != o.end()) {
if (o["height"].is<double>()) {
config->height = static_cast<int>(o["height"].get<double>());
}
}
if (o.find("ptex_filter") != o.end()) {
if (o["ptex_filter"].is<double>()) {
config->ptex_filter = static_cast<int>(o["ptex_filter"].get<double>());
}
}
if (o.find("dump_ptex") != o.end()) {
if (o["dump_ptex"].is<bool>()) {
config->dump_ptex = o["dump_ptex"].get<bool>();
}
}
return true;
}
}