- Timestamp:
- 02/17/07 22:48:12 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp
r2122 r2123 8 8 #include "PreprocessorFactory.h" 9 9 #include "OgreLogManager.h" 10 #include "ObjManualMeshLoader.h" 10 11 11 12 … … 17 18 18 19 ObjReader::~ObjReader() 19 {} 20 { 21 CLEAR_CONTAINER(mPvsObjects); 22 } 20 23 21 24 … … 31 34 // hack 32 35 preprocessor->mLoadMeshes = false; 33 GtpVisibilityPreprocessor::ObjectContainer pvsObjects;34 36 35 Ogre::LogManager::getSingleton().logMessage("loading obj scene !!");37 Ogre::LogManager::getSingleton().logMessage("loading obj scene"); 36 38 37 39 if (preprocessor->LoadScene(sceneName)) … … 39 41 Ogre::LogManager::getSingleton().logMessage("scene loaded, loading objects"); 40 42 // form objects from the scene triangles 41 if (!preprocessor->LoadObjects(visibilitySolution, pvsObjects, preprocessor->mObjects))43 if (!preprocessor->LoadObjects(visibilitySolution, mPvsObjects, preprocessor->mObjects)) 42 44 { 43 45 Ogre::LogManager::getSingleton().logMessage("objects cannot be loaded"); … … 52 54 53 55 std::stringstream d; 54 d << "successfully loaded " << pvsObjects.size() << " objects from " << preprocessor->mObjects.size() << " preprocessor objects";56 d << "successfully loaded " << mPvsObjects.size() << " objects from " << preprocessor->mObjects.size() << " preprocessor objects"; 55 57 56 58 Ogre::LogManager::getSingleton().logMessage(d.str()); 57 59 58 GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit, oit_end = pvsObjects.end();60 GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit, oit_end = mPvsObjects.end(); 59 61 60 62 int i = 0; 61 for (oit = pvsObjects.begin(); oit != oit_end; ++ oit, ++ i)63 for (oit = mPvsObjects.begin(); oit != oit_end; ++ oit, ++ i) 62 64 { 63 Ogre::LogManager::getSingleton().logMessage("r"); 65 if (i % 5000 == 4999) 66 { 67 d << i << " objects created" << endl; 68 } 69 64 70 const Ogre::String entname = "Object" + Ogre::StringConverter::toString(i); 65 71 66 Ogre::ManualObject *ent = CreateEntity(entname, *oit); 72 #if 0 73 Ogre::ManualObject *ent = CreateManualObject(entname, *oit); 74 #else 75 Ogre::Entity *ent = CreateEntity(entname, *oit); 76 #endif 67 77 68 78 const Ogre::String nodeName = entname + "Node"; … … 70 80 node->attachObject(ent); 71 81 72 if (i > 100)73 82 // problems for too many objects (= vbo)? 83 //if (i > 30000)break; 74 84 } 75 85 … … 89 99 std::string entityName = name + "Entity"; 90 100 91 GtpVisibilityPreprocessor::BvhLeaf *bvhObj =101 GtpVisibilityPreprocessor::BvhLeaf *bvhObj = 92 102 static_cast<GtpVisibilityPreprocessor::BvhLeaf *>(object); 103 93 104 const int vertexCount = (int)bvhObj->mObjects.size() * 3; 94 105 95 106 ManualObject* manual = mSceneManager->createManualObject(entityName); 96 manual->begin("BaseWhite NoLighting", RenderOperation::OT_LINE_STRIP);107 manual->begin("BaseWhite", RenderOperation::OT_TRIANGLE_LIST); 97 108 109 const float red = GtpVisibilityPreprocessor::Random(1.0f); 110 const float green = GtpVisibilityPreprocessor::Random(1.0f); 111 const float blue = GtpVisibilityPreprocessor::Random(1.0f); 112 98 113 // create vertices 99 100 GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit,oit_end = bvhObj->mObjects.end();114 GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit, 115 oit_end = bvhObj->mObjects.end(); 101 116 102 117 for (oit = bvhObj->mObjects.begin(); oit != oit_end; ++ oit) … … 110 125 { 111 126 const GtpVisibilityPreprocessor::Vector3 vtx = tri.mVertices[i]; 127 const GtpVisibilityPreprocessor::Vector3 n = tri.GetNormal(); 128 112 129 manual->position(vtx.x, vtx.y, vtx.z); 113 manual->colour(1.0f, 0.0f, 0.0f); 130 manual->normal(n.x, n.y, n.z); 131 //manual->colour(red, green, blue); 114 132 } 115 133 } 116 134 135 if (0) 117 136 for (int i = 0; i < vertexCount; ++ i) 118 137 { 119 138 manual->index(i); 120 139 } 140 141 manual->end(); 121 142 122 143 return manual; … … 137 158 std::string entityName = name + "Entity"; 138 159 139 MeshPtr mesh = MeshManager::getSingleton().createManual(meshName, "Custom"); 140 SubMesh* submesh = mesh->createSubMesh(); 160 ObjManualMeshLoader *loader = new ObjManualMeshLoader(bvhObj); 141 161 142 const int vertexCount = (int)bvhObj->mObjects.size() * 3; 143 144 // We must create the vertex data, indicating how many vertices there will be 145 submesh->useSharedVertices = false; 146 submesh->vertexData = new VertexData(); 147 submesh->vertexData->vertexStart = 0; 148 submesh->vertexData->vertexCount = vertexCount; 149 150 std::stringstream d; d << "objects: " << bvhObj->mObjects.size() << " vtx: " << submesh->vertexData->vertexCount << endl; 151 Ogre::LogManager::getSingleton().logMessage(d.str()); 152 153 static const unsigned short source = 0; 154 size_t offset = 0; 155 156 VertexDeclaration* declaration = HardwareBufferManager::getSingleton().createVertexDeclaration(); 157 158 offset += declaration->addElement(source, offset, VET_FLOAT3, VES_POSITION).getSize(); 159 //offset += declaration->addElement(source, offset, VET_FLOAT3,VES_NORMAL).getSize(); 160 //offset += declaration->addElement(source, offset, VET_FLOAT2,VES_TEXTURE_COORDINATES).getSize(); 161 162 163 int numVertices = 0; 164 165 HardwareVertexBufferSharedPtr vbuffer = HardwareBufferManager::getSingleton(). 166 createVertexBuffer(declaration->getVertexSize(source), 167 submesh->vertexData->vertexCount, 168 HardwareBuffer::HBU_STATIC_WRITE_ONLY); 169 170 // No we get access to the buffer to fill it. During so we record the bounding box. 171 AxisAlignedBox aabox; 172 173 float* vdata = static_cast<float*>(vbuffer->lock(HardwareBuffer::HBL_DISCARD)); 174 175 GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit, oit_end = bvhObj->mObjects.end(); 176 177 for (oit = bvhObj->mObjects.begin(); oit != oit_end; ++ oit) 178 { 179 GtpVisibilityPreprocessor::TriangleIntersectable *tObj = 180 static_cast<GtpVisibilityPreprocessor::TriangleIntersectable *>(*oit); 181 182 GtpVisibilityPreprocessor::Triangle3 tri = tObj->GetItem(); 183 184 for (int i = 0; i < 3; ++ i) 185 { 186 Vector3 vtx = Vector3(tri.mVertices[i]); 187 188 *vdata ++ = vtx.x; 189 *vdata ++ = vtx.y; 190 *vdata ++ = vtx.z; 191 192 //std::stringstream d; d << vtx; 193 //Ogre::LogManager::getSingleton().logMessage(d.str()); 194 aabox.merge(vtx); 195 } 196 } 197 //Ogre::LogManager::getSingleton().logMessage("***"); 198 vbuffer->unlock(); 199 200 /*Ogre::RenderOperation rop; 201 submesh->_getRenderOperation(rop); 202 rop.useIndexes = false; 203 */ 204 ////// 205 //-- Creates the index data 206 207 submesh->vertexData->vertexBufferBinding->setBinding(source, vbuffer); 208 209 submesh->indexData->indexStart = 0; 210 // we use an index for every vertex 211 submesh->indexData->indexCount = vertexCount; 212 submesh->indexData->indexBuffer = 213 HardwareBufferManager::getSingleton(). 214 createIndexBuffer(HardwareIndexBuffer::IT_16BIT, 215 submesh->indexData->indexCount, 216 HardwareBuffer::HBU_STATIC_WRITE_ONLY); 217 submesh->operationType = RenderOperation::OT_LINE_STRIP; 218 //uint16* idata = static_cast<uint16*>(submesh->indexData->indexBuffer->lock(HardwareBuffer::HBL_DISCARD)); 219 unsigned short* idata = static_cast<unsigned short*>(submesh->indexData->indexBuffer->lock(HardwareBuffer::HBL_DISCARD)); 220 221 for (int j = 0; j < vertexCount; ++ j) 222 { 223 *idata = j; 224 ++ idata; 225 } 226 227 submesh->indexData->indexBuffer->unlock(); 228 229 submesh->setMaterialName("BaseWhiteNoLighting"); 230 231 // We must indicate the bounding box 232 mesh->_setBounds(aabox); 233 mesh->_setBoundingSphereRadius((aabox.getMaximum() - aabox.getMinimum()).length() / 2.0); 234 mesh->load(); 235 mesh->touch(); 162 Mesh* pMesh = MeshManager::getSingleton().createManual(meshName, "ObjGroup", loader).getPointer(); 163 pMesh->load(); 236 164 237 165 // Create an entity with the mesh 238 166 entity = mSceneManager->createEntity(entityName, meshName); 239 167 240 //entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_MAIN); 168 return entity; 169 } 241 170 242 return entity;243 #endif244 }
Note: See TracChangeset
for help on using the changeset viewer.