FileInfoListPtr findResourceFileInfo (const String& _groupName, const String& _pattern, bool _recursive, bool _dirs) { OGRE_LOCK_AUTO_MUTEX // MEMCATEGORY_GENERAL is the only category supported for SharedPtr FileInfoListPtr vec(OGRE_NEW_T(FileInfoList, MEMCATEGORY_GENERAL)(), SPFM_DELETE_T); // Try to find in resource index first ResourceGroup* grp = getResourceGroup(_groupName); if (!grp) { GOTHOGRE_EXCEPT( "Cannot locate a resource group called '" << _groupName << "'"); } OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex // Iterate over the archives LocationList::iterator i, iend; iend = grp->locationList.end(); for (i = grp->locationList.begin(); i != iend; ++i) { FileInfoListPtr lst = (*i)->archive->findFileInfo(_pattern, _recursive, _dirs); vec->insert(vec->end(), lst->begin(), lst->end()); } return vec; }
void MeshSerializerTests::getResourceFullPath(const ResourcePtr& resource, String& outPath) { ResourceGroupManager& resourceGroupMgr = ResourceGroupManager::getSingleton(); String group = resource->getGroup(); String name = resource->getName(); FileInfo* info = NULL; FileInfoListPtr locPtr = resourceGroupMgr.listResourceFileInfo(group); FileInfoList::iterator it, itEnd; it = locPtr->begin(); itEnd = locPtr->end(); for (; it != itEnd; it++) { if (stricmp(name.c_str(), it->filename.c_str()) == 0) { info = &*it; break; } } if(!info) { outPath = name; return; } outPath = info->archive->getName(); if (outPath[outPath .size()-1] != '/' && outPath[outPath .size()-1] != '\\') { outPath += '/'; } outPath += info->path; if (outPath[outPath .size()-1] != '/' && outPath[outPath .size()-1] != '\\') { outPath += '/'; } outPath += info->filename; assert(info->archive->getType() == "FileSystem"); }
//----------------------------------------------------------------------- void PagingLandScapeTexture_InstantBaseTextureEdit::_unloadMaterial() { assert (!mMaterial.isNull() && "PagingLandScapeTexture_InstantBaseTextureEdit::::_unloadMaterial"); if (mIsModified) { const String fname = PagingLandScapeOptions::getSingleton().landscape_filename + ".Base." + StringConverter::toString(mDataZ) + String(".") + StringConverter::toString(mDataX) + "."; const String extname = PagingLandScapeOptions::getSingleton().TextureExtension; FileInfoListPtr finfo = ResourceGroupManager::getSingleton().findResourceFileInfo ( PagingLandScapeOptions::getSingleton().groupName, fname + extname); FileInfoList::iterator it = finfo->begin(); if (it != finfo->end()) { //FileInfo *inf = &(*it); char *olddir = ChangeToDir (const_cast< char * > (((it)->archive->getName()).c_str())); //FileSystemArchive::pushDirectory() mImage.save(fname + "modif." + extname); //FileSystemArchive::pushDirectory(); RetablishDir (olddir); } } // Anyway, they're surely null already, as they're freed by delete page() mBuffer.setNull (); mTexture.setNull (); mImage.loadDynamicImage (0, 0, 0, PF_BYTE_RGB); mBaseData = 0; }
bool Sample_MeshLod::getResourceFullPath(MeshPtr& mesh, String& outPath) { ResourceGroupManager& resourceGroupMgr = ResourceGroupManager::getSingleton(); String group = mesh->getGroup(); String name = mesh->getName(); Ogre::FileInfo* info = NULL; FileInfoListPtr locPtr = resourceGroupMgr.listResourceFileInfo(group); FileInfoList::iterator it, itEnd; it = locPtr->begin(); itEnd = locPtr->end(); for (; it != itEnd; it++) { if (stricmp(name.c_str(), it->filename.c_str()) == 0) { info = &*it; break; } } if(!info) { outPath = name; return false; } outPath = info->archive->getName(); if (outPath[outPath .size()-1] != '/' && outPath[outPath .size()-1] != '\\') { outPath += '/'; } outPath += info->path; if (outPath[outPath .size()-1] != '/' && outPath[outPath .size()-1] != '\\') { outPath += '/'; } outPath += info->filename; return (info->archive->getType() == "FileSystem"); }
//----------------------------------------------------------------------- void PagingLandScapeData2D_HeightFieldTC::_save() { const Real scale = 1.0f / mParent->getOptions()->scale.y; uchar *img = mImage->getData(); unsigned int j = 0; for (unsigned int i = 0; i < mMax - 1; i ++) { img[ i ] = uchar (_encodeTC(mHeightData[j++]) * scale); } const String fname = mParent->getOptions()->LandScape_filename + "." + StringConverter::toString(mPageZ) + "." + StringConverter::toString(mPageX) + "."; const String extname = mParent->getOptions()->LandScape_extension; FileInfoListPtr finfo = ResourceGroupManager::getSingleton().findResourceFileInfo ( mParent->getOptions()->groupName, fname + extname); FileInfoList::iterator it = finfo->begin(); if (it != finfo->end()) { //FileInfo *inf = &(*it); char *olddir = ChangeToDir (const_cast< char * > (((it)->archive->getName()).c_str())); //FileSystemArchive::pushDirectory() mImage->save (fname + "modif." + extname); //FileSystemArchive::pushDirectory(); RetablishDir (olddir); } }
// ------------------------------------------------------------------------- void OgreBulletApplication::setupResources(void) { ExampleApplication::setupResources(); ResourceGroupManager *rsm = ResourceGroupManager::getSingletonPtr(); StringVector groups = rsm->getResourceGroups(); FileInfoListPtr finfo = ResourceGroupManager::getSingleton().findResourceFileInfo ( "Bootstrap", "axes.mesh"); const bool isSDK = (!finfo->empty()) && StringUtil::startsWith (finfo->begin()->archive->getName(), "../../media/packs/ogrecore.zip", true); const String resName ("OgreBullet"); { if (std::find(groups.begin(), groups.end(), resName) == groups.end()) { rsm->createResourceGroup(resName); String baseName; if (isSDK) { baseName = "../../../ogrebullet/"; } else { baseName = "../../../../../ogreaddons/ogrebullet/"; } rsm->addResourceLocation (baseName + "demos/Media","FileSystem", resName); rsm->addResourceLocation (baseName + "demos/Media/textures", "FileSystem", resName); rsm->addResourceLocation (baseName + "demos/Media/overlays", "FileSystem", resName); rsm->addResourceLocation (baseName + "demos/Media/materials", "FileSystem", resName); rsm->addResourceLocation (baseName + "demos/Media/models", "FileSystem", resName); rsm->addResourceLocation (baseName + "demos/Media/gui", "FileSystem", resName); } } }
void MeshObject::postProcess() { loaded=true; if(!sceneNode) return; // important: you need to add the LODs before creating the entity // now find possible LODs, needs to be done before calling createEntity() if(!mesh.isNull()) { String basename, ext; StringUtil::splitBaseFilename(meshName, basename, ext); String group = ResourceGroupManager::getSingleton().findGroupContainingResource(meshName); // the classic LODs FileInfoListPtr files = ResourceGroupManager::getSingleton().findResourceFileInfo(group, basename + "_lod*.mesh"); for (FileInfoList::iterator iterFiles = files->begin(); iterFiles!= files->end(); ++iterFiles) { String format = basename + "_lod%d.mesh"; int i = -1; int r = sscanf(iterFiles->filename.c_str(), format.c_str(), &i); if(r <= 0 || i < 0) continue; float distance = 3; // we need to tune this according to our sightrange float sightrange = PARSEREAL(SSETTING("SightRange")); if(sightrange > 4999) { // unlimited if (i == 1) distance = 200; else if(i == 2) distance = 600; else if(i == 3) distance = 2000; else if(i == 4) distance = 5000; } else { // limited if (i == 1) distance = std::max(20.0f, sightrange * 0.1f); else if(i == 2) distance = std::max(20.0f, sightrange * 0.2f); else if(i == 3) distance = std::max(20.0f, sightrange * 0.3f); else if(i == 4) distance = std::max(20.0f, sightrange * 0.4f); } Ogre::MeshManager::getSingleton().load(iterFiles->filename, mesh->getGroup()); mesh->createManualLodLevel(distance, iterFiles->filename); } // the custom LODs FileInfoListPtr files2 = ResourceGroupManager::getSingleton().findResourceFileInfo(group, basename + "_clod_*.mesh"); for (FileInfoList::iterator iterFiles = files2->begin(); iterFiles!= files2->end(); ++iterFiles) { // and custom LODs String format = basename + "_clod_%d.mesh"; int i = -1; int r = sscanf(iterFiles->filename.c_str(), format.c_str(), &i); if(r <= 0 || i < 0) continue; Ogre::MeshManager::getSingleton().load(iterFiles->filename, mesh->getGroup()); mesh->createManualLodLevel(i, iterFiles->filename); } } // now create an entity around the mesh and attach it to the scene graph try { if(entityName.empty()) ent = smgr->createEntity(meshName); else ent = smgr->createEntity(entityName, meshName); if(ent) sceneNode->attachObject(ent); } catch(Ogre::Exception& e) { LOG("error loading mesh: " + meshName + ": " + e.getFullDescription()); return; } // then modify some things if(enableSimpleMaterial) MaterialFunctionMapper::replaceSimpleMeshMaterials(ent, simpleMatColour); if(skin) skin->replaceMeshMaterials(ent); if(mfm) mfm->replaceMeshMaterials(ent); if(!materialName.empty()) ent->setMaterialName(materialName); // only set it if different from default (true) if(!castshadows && sceneNode && sceneNode->numAttachedObjects() > 0) sceneNode->getAttachedObject(0)->setCastShadows(castshadows); sceneNode->setVisible(visible); }