Changeset 2119 for GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader
- Timestamp:
- 02/15/07 14:45:30 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjReader.h
r2115 r2119 2 2 #define __ObjReader_H__ 3 3 4 //#include <stdlib>5 4 #include <string> 6 5 #include <vector> 7 6 #include <Ogre.h> 8 7 #include "Containers.h" 9 /*#include "ObjNode.h"10 #include "ObjMeshData.h"11 #include "ObjManualMeshLoader.h"12 */13 8 14 15 namespace GtpVisibilityPreprocessor {16 17 struct Triangle3;18 19 }20 21 //typedef std::vector<GtpVisibilityPreprocessor::Triangle3 *> TriangleContainer;22 9 23 10 class __declspec(dllexport) ObjReader 24 11 { 25 12 public: 26 ObjReader( );13 ObjReader(Ogre::SceneManager *sceneManager); 27 14 ~ObjReader(); 28 15 29 bool LoadFile(const std::string &filename, 30 GtpVisibilityPreprocessor::ObjectContainer &objects) const; 16 bool LoadFile(const string &sceneName, 17 const string &visibilitySolution, 18 Ogre::SceneNode *root); 31 19 32 const std::vector<Ogre::Entity *> &GetObjects() const; 33 34 Ogre::Entity *CreateEntity(const std::string &name); 20 Ogre::Entity *CreateEntity(const std::string &name, 21 GtpVisibilityPreprocessor::Intersectable *object); 35 22 36 23 protected: 37 24 38 std::vector<Ogre::Entity *> mObjects;25 Ogre::SceneManager *mSceneManager; 39 26 }; 40 27 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp
r2115 r2119 3 3 #include "Triangle3.h" 4 4 #include "IntersectableWrapper.h" 5 #include "BvHierarchy.h" 6 #include "Preprocessor.h" 7 #include "OgreEntity.h" 8 #include "PreprocessorFactory.h" 9 #include "OgreLogManager.h" 5 10 6 11 7 ObjReader::ObjReader() 12 13 ObjReader::ObjReader(Ogre::SceneManager *sceneManager): 14 mSceneManager(sceneManager) 8 15 {} 9 16 … … 13 20 14 21 15 bool ObjReader::LoadFile(const string &filename, 16 GtpVisibilityPreprocessor::ObjectContainer &objects) const 22 bool ObjReader::LoadFile(const string &sceneName, 23 const string &visibilitySolution, 24 Ogre::SceneNode *root) 17 25 { 18 igzstream samplesIn(filename.c_str()); 19 20 if (!samplesIn.is_open()) 26 GtpVisibilityPreprocessor::Debug.open("debug.log"); 27 // HACK: get any preprocessor to load file 28 GtpVisibilityPreprocessor::Preprocessor *preprocessor = 29 GtpVisibilityPreprocessor::PreprocessorFactory::CreatePreprocessor("vss"); 30 31 // hack 32 preprocessor->mLoadMeshes = false; 33 GtpVisibilityPreprocessor::ObjectContainer pvsObjects; 34 35 Ogre::LogManager::getSingleton().logMessage("loading obj scene!!"); 36 37 if (preprocessor->LoadScene(sceneName)) 38 { 39 Ogre::LogManager::getSingleton().logMessage("scene loaded, loading objects"); 40 // form objects from the scene triangles 41 if (!preprocessor->LoadObjects(visibilitySolution, pvsObjects, preprocessor->mObjects)) 42 { 43 Ogre::LogManager::getSingleton().logMessage("objects cannot be loaded"); 44 return false; 45 } 46 } 47 else 48 { 49 Ogre::LogManager::getSingleton().logMessage("scene cannot be loaded"); 21 50 return false; 22 23 // read in triangle size 24 int numTriangles; 51 } 25 52 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)); 53 std::stringstream d; 54 d << "successfully loaded " << pvsObjects.size() << " objects"; 39 55 40 // end of file reached 41 if (samplesIn.eof()) 42 break; 56 Ogre::LogManager::getSingleton().logMessage(d.str()); 43 57 44 GtpVisibilityPreprocessor::TriangleIntersectable *obj = 45 new GtpVisibilityPreprocessor::TriangleIntersectable(tri); 46 objects.push_back(obj); 58 GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit, oit_end = pvsObjects.end(); 59 60 int i = 0; 61 for (oit = pvsObjects.begin(); oit != oit_end; ++ oit, ++ i) 62 {Ogre::LogManager::getSingleton().logMessage("r"); 63 const Ogre::String entname = "Object" + i; 64 65 Ogre::Entity *ent = CreateEntity(entname, *oit); 66 67 const Ogre::String nodeName = entname + "/Node"; 68 root->createChildSceneNode(nodeName); 47 69 } 48 49 return true; 70 71 delete preprocessor; 72 73 return false; 50 74 } 51 75 52 76 53 const std::vector<Ogre::Entity *> &ObjReader::GetObjects() const 54 { 55 return mObjects; 56 } 57 58 59 Ogre::Entity *ObjReader::CreateEntity(const std::string &name) 60 // ObjMeshData *mData, 61 // Ogre::Vector3 *translation) 77 Ogre::Entity *ObjReader::CreateEntity(const std::string &name, 78 GtpVisibilityPreprocessor::Intersectable *object) 62 79 { 63 80 using namespace Ogre; 81 //using namespace GtpVisibilityPreprocessor; 82 64 83 Entity *entity; 65 84 66 67 std::string meshName = name.substr(name.find('/',0), name.length()) + "/Mesh"; 85 GtpVisibilityPreprocessor::BvhLeaf *bvhObj = 86 static_cast<GtpVisibilityPreprocessor::BvhLeaf *>(object); 87 88 std::string meshName = name + "/Mesh"; 68 89 std::string entityName = name + "/Entity"; 69 90 70 91 MeshPtr mesh = MeshManager::getSingleton().createManual(meshName, "ObjGroup"); 71 92 SubMesh* submesh = mesh->createSubMesh(); 72 int nbVertices = 99992; 93 73 94 // We must create the vertex data, indicating how many vertices there will be 74 95 submesh->useSharedVertices = false; 75 96 submesh->vertexData = new VertexData(); 76 97 submesh->vertexData->vertexStart = 0; 77 submesh->vertexData->vertexCount = nbVertices;98 submesh->vertexData->vertexCount = (int)bvhObj->mObjects.size() * 3; 78 99 79 100 static const unsigned short source = 0; … … 82 103 VertexDeclaration* declaration = HardwareBufferManager::getSingleton().createVertexDeclaration(); 83 104 84 offset += declaration->addElement(source, offset,VET_FLOAT3,VES_POSITION).getSize();105 offset += declaration->addElement(source, offset, VET_FLOAT3,VES_POSITION).getSize(); 85 106 // offset += declaration->addElement(source,offset,VET_FLOAT3,VES_NORMAL).getSize(); 86 107 // offset += declaration->addElement(source,offset,VET_FLOAT2,VES_TEXTURE_COORDINATES).getSize(); … … 89 110 int numVertices = 0; 90 111 91 HardwareVertexBufferSharedPtr vbuffer = 92 HardwareBufferManager::getSingleton().createVertexBuffer(declaration->getVertexSize(source), // size of one whole vertex93 submesh->vertexData->vertexCount, // number of vertices94 HardwareBuffer::HBU_STATIC_WRITE_ONLY, // usage95 false); // no shadow buffer112 HardwareVertexBufferSharedPtr vbuffer = HardwareBufferManager::getSingleton(). 113 createVertexBuffer(declaration->getVertexSize(source), 114 submesh->vertexData->vertexCount, 115 HardwareBuffer::HBU_STATIC_WRITE_ONLY, 116 false); 96 117 97 98 // No we get access to the buffer to fill it. During so we record the bounding box. 118 // No we get access to the buffer to fill it. During so we record the bounding box. 99 119 AxisAlignedBox aabox; 100 120 101 121 float* vdata = static_cast<float*>(vbuffer->lock(HardwareBuffer::HBL_DISCARD)); 102 122 103 for (size_t i = 0; i < nbVertices; ++ i) 123 GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit, oit_end = bvhObj->mObjects.end(); 124 125 for (oit = bvhObj->mObjects.begin(); oit != oit_end; ++ oit) 104 126 { 105 // Position 106 Vector3 position;// = 20.0f*positions[i]; 107 *vdata++ = position.x; 108 *vdata++ = position.y; 109 *vdata++ = position.z; 110 aabox.merge(position); 111 // Normal 112 Vector3 normal = position.normalisedCopy(); 113 *vdata++ = normal.x; 114 *vdata++ = normal.y; 115 *vdata++ = normal.z; 127 GtpVisibilityPreprocessor::TriangleIntersectable *tObj = 128 static_cast<GtpVisibilityPreprocessor::TriangleIntersectable *>(*oit); 129 130 GtpVisibilityPreprocessor::Triangle3 tri = tObj->GetItem(); 116 131 117 // Texture coordinate118 Vector2 tcoordinate;// = tcoordinates[i];119 *vdata ++ = tcoordinate.x;132 for (int i = 0; i < 3; ++ i) 133 { 134 Vector3 vtx(tri.mVertices[i]); 120 135 121 *vdata ++ = tcoordinate.y; 136 *vdata ++ = vtx.x; 137 *vdata ++ = vtx.y; 138 *vdata ++ = vtx.z; 122 139 140 aabox.merge(vtx); 141 } 123 142 } 124 143 … … 126 145 127 146 // We must indicate the bounding box 128 //mesh->_setBounds(aabox);147 mesh->_setBounds(aabox); 129 148 130 //mesh->_setBoundingSphereRadius((aabox.getMaximum()-aabox.getMinimum()).length()/2.0); 131 149 mesh->_setBoundingSphereRadius((aabox.getMaximum()-aabox.getMinimum()).length()/2.0); 132 150 mesh->load(); 133 151 134 152 // Create an entity with the mesh 135 //entity = mSceneManager->createEntity(meshName, entityName);153 entity = mSceneManager->createEntity(meshName, entityName); 136 154 137 155 return entity; -
GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.vcproj
r2112 r2119 73 73 Name="VCCLCompilerTool" 74 74 AdditionalIncludeDirectories=""$(OGRE_PATH)\OgreMain\include";"$(OGRE_PATH)\Dependencies\include";"$(OGRE_PATH)\Samples\Common\include";..\include;..\..\..\Preprocessing\src" 75 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;OBJREADER_EXPORTS;GTP_VISIBILITY_MODIFIED_OGRE;GAMETOOLS_ILLUMINATION_MODULE "75 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;OBJREADER_EXPORTS;GTP_VISIBILITY_MODIFIED_OGRE;GAMETOOLS_ILLUMINATION_MODULE1" 76 76 RuntimeLibrary="2" 77 77 UsePrecompiledHeader="0"
Note: See TracChangeset
for help on using the changeset viewer.