-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.cpp
More file actions
111 lines (102 loc) · 2.88 KB
/
Copy pathmodel.cpp
File metadata and controls
111 lines (102 loc) · 2.88 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
#include "PAZ_IO"
#include <sstream>
void paz::parse_model(const Bytes& content, std::vector<float>& positions, std::
vector<float>& uvs, std::vector<float>& normals, std::vector<unsigned int>&
materials, std::vector<std::string>& materialNames, std::vector<std::
string>& materialLibs, std::vector<unsigned int>& indices)
{
std::istringstream iss(content.str());
positions.clear();
uvs.clear();
normals.clear();
materials.clear();
materialNames.clear();
materialLibs.clear();
indices.clear();
std::string line;
std::getline(iss, line);
const std::size_t numVerts = std::stoull(line);
positions.resize(4*numVerts);
uvs.resize(2*numVerts);
normals.resize(4*numVerts);
materials.resize(numVerts);
std::getline(iss, line);
{
std::istringstream iss1(line);
while(std::getline(iss1, line, ' '))
{
materialNames.push_back(line);
}
}
std::getline(iss, line);
{
std::istringstream iss1(line);
while(std::getline(iss1, line, ' '))
{
materialLibs.push_back(line);
}
}
for(std::size_t i = 0; i < numVerts; ++i)
{
std::getline(iss, line);
std::istringstream iss1(line);
for(int j = 0; j < 3; ++j)
{
iss1 >> positions[4*i + j];
}
positions[4*i + 3] = 1.;
for(int j = 0; j < 2; ++j)
{
iss1 >> uvs[2*i + j];
}
for(int j = 0; j < 3; ++j)
{
iss1 >> normals[4*i + j];
}
normals[4*i + 3] = 0.;
iss1 >> materials[i];
}
while(std::getline(iss, line))
{
indices.push_back(std::stoull(line));
}
}
paz::Bytes paz::to_model(const std::vector<float>& positions, const std::vector<
float>& uvs, const std::vector<float>& normals, const std::vector<unsigned
int>& materials, const std::vector<std::string>& materialNames, const std::
vector<std::string>& materialLibs, const std::vector<unsigned int>& indices)
{
std::ostringstream oss;
oss << materials.size() << '\n';
for(std::size_t i = 0; i < materialNames.size(); ++i)
{
oss << materialNames[i] << (i + 1 < materialNames.size() ? " " : "");
}
oss << '\n';
for(std::size_t i = 0; i < materialLibs.size(); ++i)
{
oss << materialLibs[i] << (i + 1 < materialLibs.size() ? " " : "");
}
oss << '\n';
for(std::size_t i = 0; i < materials.size(); ++i)
{
for(int j = 0; j < 3; ++j)
{
oss << positions[4*i + j] << ' ';
}
for(int j = 0; j < 2; ++j)
{
oss << uvs[2*i + j] << ' ';
}
for(int j = 0; j < 3; ++j)
{
oss << normals[4*i + j] << ' ';
}
oss << materials[i] << '\n';
}
for(auto n : indices)
{
oss << n << '\n';
}
return oss.str();
}