-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadFromStl.cpp
53 lines (41 loc) · 1.47 KB
/
LoadFromStl.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
#include "LoadFromStl.h"
void LoadFromStl::load(const std::string &filePath,
const Material &material,
Scene &scene) {
std::ifstream fileStream(filePath);
if (!fileStream.good()) {
throw "file opening error";
}
std::string currentToken;
fileStream >> currentToken; // facet or endsolid
fileStream >> currentToken; // facet or endsolid
while (true) {
fileStream >> currentToken; // facet or endsolid
if (currentToken == "endsolid") {
break;
}
else if (currentToken == "") {
continue;
}
double nX, nY, nZ;
fileStream >> currentToken; // normal
fileStream >> nX >> nY >> nZ;
fileStream >> currentToken; // outer
fileStream >> currentToken; // loop
double v1X, v1Y, v1Z;
fileStream >> currentToken; // vertex
fileStream >> v1X >> v1Y >> v1Z;
double v2X, v2Y, v2Z;
fileStream >> currentToken; // vertex
fileStream >> v2X >> v2Y >> v2Z;
double v3X, v3Y, v3Z;
fileStream >> currentToken; // vertex
fileStream >> v3X >> v3Y >> v3Z;
fileStream >> currentToken; // endloop
fileStream >> currentToken; // endfacet
scene.addObject(
new Triangle(Point(v1X, v1Y, v1Z), Point(v2X, v2Y, v2Z), Point(v3X, v3Y, v3Z), Vector(nX, nY, nZ),
material));
}
fileStream.close();
}