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