source: GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp @ 2112

Revision 2112, 2.4 KB checked in by mattausch, 17 years ago (diff)
Line 
1#include "ObjReader.h"
2#include "gzstream.h"
3#include "Triangle3.h"
4#include "IntersectableWrapper.h"
5
6
7ObjReader::ObjReader()
8{}
9
10
11ObjReader::~ObjReader()
12{}
13
14
15bool ObjReader::LoadFile(const string &filename,
16                                                 GtpVisibilityPreprocessor::ObjectContainer &objects) const
17{
18        igzstream samplesIn(filename.c_str());
19       
20        if (!samplesIn.is_open())
21                return false;
22       
23        // read in triangle size
24        int numTriangles;
25
26        samplesIn.read(reinterpret_cast<char *>(&numTriangles), sizeof(int));
27        objects.reserve(numTriangles);
28       
29        while (1)
30        {
31                GtpVisibilityPreprocessor::Triangle3 tri;
32               
33                samplesIn.read(reinterpret_cast<char *>(tri.mVertices + 0),
34                                           sizeof(GtpVisibilityPreprocessor::Vector3));
35                samplesIn.read(reinterpret_cast<char *>(tri.mVertices + 1),
36                                           sizeof(GtpVisibilityPreprocessor::Vector3));
37                samplesIn.read(reinterpret_cast<char *>(tri.mVertices + 2),
38                                           sizeof(GtpVisibilityPreprocessor::Vector3));
39
40                // end of file reached
41                if (samplesIn.eof())
42                        break;
43
44                GtpVisibilityPreprocessor::TriangleIntersectable *obj =
45                        new GtpVisibilityPreprocessor::TriangleIntersectable(tri);
46                objects.push_back(obj);
47        }
48       
49        return true;
50}
51
52
53const std::vector<Ogre::Entity *> &ObjReader::GetObjects() const
54{
55        return mObjects;
56}
57
58
59#if TODO
60
61Ogre::Entity *IVReader::createEntity(Ogre::SceneManager* sceneMgr,
62                                                                         std::string name,
63                                                                         ObjMeshData *mData,
64                                                                         Ogre::Vector3 *translation)
65{
66        using namespace Ogre;
67
68        std::string meshName = name.substr(name.find('/',0), name.length()) + "/Mesh";
69        std::string entityName = name + "/Entity";
70
71        Mesh* pMesh = NULL;
72        if ((pMesh = (Mesh *) MeshManager::getSingleton().getByName(meshName).getPointer()) == NULL)
73        {
74
75                ObjMeshData *data = mData->expand();
76
77                ObjManualMeshLoader *loader     = new ObjManualMeshLoader(data);
78
79                if (translation != NULL) *translation = data->boundingBox->getCenter();
80
81                addMeshToList(meshName, loader);
82
83                Mesh* pMesh = MeshManager::getSingleton().createManual(meshName, "IVGroup", loader).getPointer();
84
85                pMesh->load();
86                pMesh->touch();
87        }
88        else
89        {
90                if (translation != NULL)
91                {
92                        *translation = meshList->getManualMeshLoader(meshName)->getBoundingBox()->getCenter();
93                }
94        }
95
96        Entity *pEntity = sceneMgr->createEntity(entityName, meshName);
97
98
99        if (0) pEntity->setRenderQueueGroup(Ogre::RENDER_QUEUE_MAIN);
100
101        return pEntity;
102}
103
104
105#endif
Note: See TracBrowser for help on using the repository browser.