1 | #include "SceneGraph.h"
|
---|
2 | #include "Polygon3.h"
|
---|
3 | #include "Mesh.h"
|
---|
4 | #include "ObjExporter.h"
|
---|
5 |
|
---|
6 |
|
---|
7 | using namespace std;
|
---|
8 |
|
---|
9 | namespace GtpVisibilityPreprocessor {
|
---|
10 |
|
---|
11 | ObjExporter::ObjExporter(const string filename):Exporter(filename)
|
---|
12 | {
|
---|
13 | stream.open(mFilename.c_str());
|
---|
14 | stream<<"#File exported by GTP visibility preprocessor"<<endl;
|
---|
15 | vertexIndex = 1;
|
---|
16 | }
|
---|
17 |
|
---|
18 |
|
---|
19 | ObjExporter::~ObjExporter()
|
---|
20 | {
|
---|
21 | stream<<"# export finished"<<endl;
|
---|
22 | stream.close();
|
---|
23 | }
|
---|
24 |
|
---|
25 | void
|
---|
26 | ObjExporter::ExportSceneNode(SceneGraphNode *node)
|
---|
27 | {
|
---|
28 | if (!node->IsLeaf())
|
---|
29 | {
|
---|
30 | SceneGraphInterior *interior = static_cast<SceneGraphInterior *>(node);
|
---|
31 |
|
---|
32 | SceneGraphNodeContainer::iterator ni = interior->mChildren.begin();
|
---|
33 |
|
---|
34 | for (; ni != interior->mChildren.end(); ni++)
|
---|
35 | ExportSceneNode(*ni);
|
---|
36 | }
|
---|
37 | else
|
---|
38 | {
|
---|
39 |
|
---|
40 | SceneGraphLeaf *leaf = static_cast<SceneGraphLeaf *>(node);
|
---|
41 |
|
---|
42 | ObjectContainer::const_iterator mi = leaf->mGeometry.begin();
|
---|
43 |
|
---|
44 | for (; mi != leaf->mGeometry.end(); mi++)
|
---|
45 | { // export the transform ...
|
---|
46 | ExportIntersectable(*mi);
|
---|
47 | }
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | void
|
---|
52 | ObjExporter::ExportMesh(Mesh *mesh)
|
---|
53 | {
|
---|
54 | int vertexOffset = vertexIndex;
|
---|
55 |
|
---|
56 | VertexContainer::const_iterator vi = mesh->mVertices.begin();
|
---|
57 | for (; vi != mesh->mVertices.end(); vi++) {
|
---|
58 | stream<<"v "<<(*vi).x<<" "<<(*vi).y<<" "<<(*vi).z<<endl;
|
---|
59 | vertexIndex ++;
|
---|
60 | }
|
---|
61 |
|
---|
62 | FaceContainer::const_iterator fi = mesh->mFaces.begin();
|
---|
63 | for (; fi != mesh->mFaces.end(); fi++) {
|
---|
64 | Face *face = *fi;
|
---|
65 | VertexIndexContainer::const_iterator vi = face->mVertexIndices.begin();
|
---|
66 | stream<<"f ";
|
---|
67 | for (; vi != face->mVertexIndices.end(); vi++)
|
---|
68 | stream<<vertexOffset + *vi<<" ";
|
---|
69 | stream<<endl;
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 | void
|
---|
75 | ObjExporter::ExportPolygon(Polygon3 *poly)
|
---|
76 | {
|
---|
77 | int vertexOffset = vertexIndex;
|
---|
78 |
|
---|
79 | VertexContainer::const_iterator vi = poly->mVertices.begin();
|
---|
80 | for (; vi != poly->mVertices.end(); vi++) {
|
---|
81 | stream<<"v "<<(*vi).x<<" "<<(*vi).y<<" "<<(*vi).z<<endl;
|
---|
82 | vertexIndex ++;
|
---|
83 | }
|
---|
84 |
|
---|
85 | stream<<"f ";
|
---|
86 | int i = vertexOffset;
|
---|
87 | vi = poly->mVertices.begin();
|
---|
88 | for (; vi != poly->mVertices.end(); vi++, i++)
|
---|
89 | stream<<i<<" ";
|
---|
90 | stream<<endl;
|
---|
91 |
|
---|
92 | }
|
---|
93 |
|
---|
94 | }
|
---|