Changeset 2115 for GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src
- Timestamp:
- 02/12/07 19:00:37 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp
r2112 r2115 57 57 58 58 59 #if TODO 60 61 Ogre::Entity *IVReader::createEntity(Ogre::SceneManager* sceneMgr, 62 std::string name, 63 ObjMeshData *mData, 64 Ogre::Vector3 *translation) 59 Ogre::Entity *ObjReader::CreateEntity(const std::string &name) 60 // ObjMeshData *mData, 61 // Ogre::Vector3 *translation) 65 62 { 66 63 using namespace Ogre; 64 Entity *entity; 67 65 66 68 67 std::string meshName = name.substr(name.find('/',0), name.length()) + "/Mesh"; 69 68 std::string entityName = name + "/Entity"; 70 69 71 Mesh* pMesh = NULL; 72 if ((pMesh = (Mesh *) MeshManager::getSingleton().getByName(meshName).getPointer()) == NULL) 70 MeshPtr mesh = MeshManager::getSingleton().createManual(meshName, "ObjGroup"); 71 SubMesh* submesh = mesh->createSubMesh(); 72 int nbVertices = 99992; 73 // We must create the vertex data, indicating how many vertices there will be 74 submesh->useSharedVertices = false; 75 submesh->vertexData = new VertexData(); 76 submesh->vertexData->vertexStart = 0; 77 submesh->vertexData->vertexCount = nbVertices; 78 79 static const unsigned short source = 0; 80 size_t offset = 0; 81 82 VertexDeclaration* declaration = HardwareBufferManager::getSingleton().createVertexDeclaration(); 83 84 offset += declaration->addElement(source,offset,VET_FLOAT3,VES_POSITION).getSize(); 85 // offset += declaration->addElement(source,offset,VET_FLOAT3,VES_NORMAL).getSize(); 86 // offset += declaration->addElement(source,offset,VET_FLOAT2,VES_TEXTURE_COORDINATES).getSize(); 87 88 89 int numVertices = 0; 90 91 HardwareVertexBufferSharedPtr vbuffer = 92 HardwareBufferManager::getSingleton().createVertexBuffer(declaration->getVertexSize(source), // size of one whole vertex 93 submesh->vertexData->vertexCount, // number of vertices 94 HardwareBuffer::HBU_STATIC_WRITE_ONLY, // usage 95 false); // no shadow buffer 96 97 98 // No we get access to the buffer to fill it. During so we record the bounding box. 99 AxisAlignedBox aabox; 100 101 float* vdata = static_cast<float*>(vbuffer->lock(HardwareBuffer::HBL_DISCARD)); 102 103 for (size_t i = 0; i < nbVertices; ++ i) 73 104 { 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; 74 116 75 ObjMeshData *data = mData->expand(); 117 // Texture coordinate 118 Vector2 tcoordinate;// = tcoordinates[i]; 119 *vdata ++ = tcoordinate.x; 76 120 77 ObjManualMeshLoader *loader = new ObjManualMeshLoader(data);121 *vdata ++ = tcoordinate.y; 78 122 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 else89 {90 if (translation != NULL)91 {92 *translation = meshList->getManualMeshLoader(meshName)->getBoundingBox()->getCenter();93 }94 123 } 95 124 96 Entity *pEntity = sceneMgr->createEntity(entityName, meshName);125 vbuffer->unlock(); 97 126 127 // We must indicate the bounding box 128 //mesh->_setBounds(aabox); 98 129 99 if (0) pEntity->setRenderQueueGroup(Ogre::RENDER_QUEUE_MAIN);130 //mesh->_setBoundingSphereRadius((aabox.getMaximum()-aabox.getMinimum()).length()/2.0); 100 131 101 return pEntity; 132 mesh->load(); 133 134 // Create an entity with the mesh 135 //entity = mSceneManager->createEntity(meshName, entityName); 136 137 return entity; 102 138 } 103 104 105 #endif
Note: See TracChangeset
for help on using the changeset viewer.