-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadOBJ.cpp
66 lines (58 loc) · 1.34 KB
/
loadOBJ.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
#include "loadObj.h"
int Obj_Load(string ObjPath, vector<Face> *obj)
{
obj->clear();
char buffer[256];
float f1, f2, f3;
int i1, i2, i0;
fstream objFile;
objFile.open(ObjPath, ios::in);
if (!objFile.is_open())
return 0;
while (!objFile.eof()) {//get vertices,faces,normals
objFile.getline(buffer, 256, '\n');
if (buffer[0] == 'v' && (buffer[1] == ' ' || buffer[1] == 32)){
if (sscanf_s(buffer, "v %f %f %f", &f1, &f2, &f3) == 3){
Vertices.push_back(Vertex(f1, f2, f3));
}
else{
fprintf(stderr, "ERROR: vertex not in wanted format in OBJLoader\n");
exit(0);
}
}
else if (buffer[0] == 'f' && (buffer[1] == ' ' || buffer[1] == 32)){
if (sscanf_s(buffer, "f %d %d %d", &i0, &i1, &i2) == 3){
Indexs.push_back(FaceIndex(i0, i1, i2));
}
else{
fprintf(stderr, "ERROR: FaceIndex not in wanted format in OBJLoader\n");
exit(0);
}
}
}
objFile.close();//close file
int len = Indexs.size();
for (int i = 0; i<len; ++i){
facetemp.set(Vertices, Indexs[i]);
obj->push_back(facetemp);
}
return 1;
}
vector<Face> Obj_Load(string ObjPath)
{
vector<Face> obj;
Obj_Load(ObjPath, &obj);
return obj;
}
void getMaxXYZ(float *x, float *y, float *z)
{
*x = MaxPoint.x;
*y = MaxPoint.y;
*z = MaxPoint.z;
}
void getMinXYZ(float *x, float *y, float *z)
{
*x = MinPoint.x;
*y = MinPoint.y;
*z = MinPoint.z;
}