History: Loading Meshes From Any Path
Preview of version: 2
Usually the paths of resources - including meshes - should be defined in the resource.cfg file. However, sometimes we need to load mesh files just like "open file" from any local path, which is not predefined in the resource file.
The following code snippet shows to accomplish that:
Copy to clipboard
Ogre::String source; FILE* pFile = fopen( source.c_str(), "rb" ); if (!pFile) OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND,"File " + source + " not found.", "OgreMeshLoaded"); struct stat tagStat; stat( source.c_str(), &tagStat ); MemoryDataStream* memstream = new MemoryDataStream(source, tagStat.st_size, true); fread( (void*)memstream->getPtr(), tagStat.st_size, 1, pFile ); fclose( pFile ); MeshPtr pMesh = MeshManager::getSingleton().createManua("LocalMesh",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); MeshSerializer meshSerializer; DataStreamPtr stream(memstream); meshSerializer.importMesh(stream, pMesh.getPointer()); Entity* pF35_1 = m_pSceneMgr->createEntity("LocalMesh_Ent", "LocalMesh");