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
| | #include "rx_model.h"
void ReadOBJ(const string filename, rxPolygons &polys, Vec3 cen, Vec3 ext)
{
if(!polys.vertices.empty()){
polys.vertices.clear();
polys.normals.clear();
polys.faces.clear();
polys.materials.clear();
polys.open = 0;
}
rxOBJ obj;
if(obj.Read(filename, polys.vertices, polys.normals, polys.faces, polys.materials, true)){
cout << filename << " have been read." << endl;
if(polys.normals.empty()){
CalVertexNormals(polys);
}
cout << " the number of vertex : " << polys.vertices.size() << endl;
cout << " the number of normal : " << polys.normals.size() << endl;
cout << " the number of polygon : " << polys.faces.size() << endl;
cout << " the number of material : " << polys.materials.size() << endl;
FitVertices(cen, ext, polys.vertices);
if(!polys.materials.empty()){
rxMTL::iterator iter = polys.materials.begin();
for(; iter != polys.materials.end(); ++iter){
if(iter->second.tex_file.empty()) continue;
cout << iter->first << " : " << iter->second.tex_file;
LoadGLTexture(iter->second.tex_file, iter->second.tex_name, true, false);
cout << " : " << iter->second.tex_name << endl;
}
}
polys.open = 1;
}
}
void SaveOBJ(const string filename, rxPolygons &polys)
{
rxOBJ obj;
if(obj.Save(filename, polys.vertices, polys.normals, polys.faces, polys.materials)){
cout << filename << " have been saved." << endl;
}
}
|