void MeshObject::loadMesh() { try { Ogre::String resourceGroup = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME; mesh = static_cast<Ogre::MeshPtr>(Ogre::MeshManager::getSingleton().create(meshName, resourceGroup)); if(backgroundLoading) { mesh->setBackgroundLoaded(true); mesh->addListener(this); ticket = Ogre::ResourceBackgroundQueue::getSingleton().load( Ogre::MeshManager::getSingletonPtr()->getResourceType(), mesh->getName(), resourceGroup, false, 0, 0, 0); // try to load its textures in the background for(int i=0; i<mesh->getNumSubMeshes(); i++) { SubMesh *sm = mesh->getSubMesh(i); String materialName = sm->getMaterialName(); Ogre::MaterialPtr mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(materialName)); //, resourceGroup)); if(mat.isNull()) continue; for(int tn=0; tn<mat->getNumTechniques(); tn++) { Technique *t = mat->getTechnique(tn); for(int pn=0; pn<t->getNumPasses(); pn++) { Pass *p = t->getPass(pn); for(int tun=0; tun<p->getNumTextureUnitStates(); tun++) { TextureUnitState *tu = p->getTextureUnitState(tun); String textureName = tu->getTextureName(); // now add this texture to the background loading queue Ogre::TexturePtr tex = static_cast<Ogre::TexturePtr>(Ogre::TextureManager::getSingleton().create(textureName, resourceGroup)); tex->setBackgroundLoaded(true); tex->addListener(this); ticket = Ogre::ResourceBackgroundQueue::getSingleton().load( Ogre::TextureManager::getSingletonPtr()->getResourceType(), tex->getName(), resourceGroup, false, 0, 0, 0); } } } } } if(!backgroundLoading) postProcess(); } catch (Ogre::Exception* e) { LOG("exception while loading mesh: " + e->getFullDescription()); } }