// *************************************************************************** void CAnimationSet::preloadSSSShapes(IDriver &drv, CShapeBank &shapeBank) { const std::string shapeCacheName= "SSS_PreLoad"; // Create the Animation Set Shape cache if do not exist if(!shapeBank.isShapeCache(shapeCacheName)) { // allow "inifinite" number of preloaded shapes shapeBank.addShapeCache(shapeCacheName); shapeBank.setShapeCacheSize(shapeCacheName, 1000000); } // For all files std::set<std::string>::iterator it; for(it=_SSSShapes.begin();it!=_SSSShapes.end();it++) { string fileName= toLower(*it); // link the shape to the shapeCache shapeBank.linkShapeToShapeCache(fileName, shapeCacheName); // If !present in the shapeBank if( shapeBank.getPresentState(fileName)==CShapeBank::NotPresent ) { // Don't load it if no more space in the cache if( shapeBank.getShapeCacheFreeSpace(shapeCacheName)>0 ) { // load it. shapeBank.load(fileName); // If success if( shapeBank.getPresentState(fileName)==CShapeBank::Present ) { // When a shape is first added to the bank, it is not in the cache. // add it and release it to force it to be in the cache. IShape *shp= shapeBank.addRef(fileName); if(shp) { //nlinfo("Loading %s", CPath::lookup(fileName.c_str(), false, false).c_str()); shp->flushTextures(drv, 0); shapeBank.release(shp); } } } } } }
void CResourceManager::loadChildren(const std::string &filename) { string ext = CFile::getExtension(filename); if(ext == "shape") { // need to get texture inside the shape NL3D::registerSerial3d(); CShapeStream ss; NLMISC::CIFile i(CPath::lookup(filename, false).c_str()); i.serial(ss); i.close(); CMesh *m = (CMesh*)ss.getShapePointer(); uint nbm = m->getNbMaterial(); for(uint i = 0; i < nbm; i++) { CMaterial &mat = m->getMaterial(i); for(uint j = 0; j < IDRV_MAT_MAXTEXTURES; j++) { ITexture *t = mat.getTexture(j); if(t) { CTextureFile *tf = dynamic_cast<CTextureFile *>(t); if(tf) { get(tf->getFileName()); } else { CTextureMultiFile *tmf = dynamic_cast<CTextureMultiFile *>(t); if(tmf) { for(uint t = 0; t < tmf->getNumFileName(); t++) get(tmf->getFileName(t)); } } } } } } else if(ext == "ps") { // need to get texture inside the shape NL3D::registerSerial3d(); string fn = CFile::getFilename(filename); CShapeBank *bank = new CShapeBank; string shapeCache("mtptShapeCache"); bank->addShapeCache(shapeCache); bank->setShapeCacheSize(shapeCache,1024*1024); std::vector<std::string> filelist; filelist.push_back(filename); CDriverUser *drv = (CDriverUser *)(&C3DTask::getInstance().driver()); bank->preLoadShapes(shapeCache,filelist,string("*.ps"),NULL,true,drv->getDriver()); bool b = bank->isShapeWaiting(); IShape *is = bank->getShape(fn); //bank->load(filename) CParticleSystemShape *ps = (CParticleSystemShape *)is; uint numTexture = ps->getNumCachedTextures(); nlinfo("loadchildren(%s) : num texture = %d",filename.c_str(),numTexture); for(uint i=0;i<numTexture;i++) { ITexture *tex = ps->getCachedTexture(i); CTextureFile *utex = (CTextureFile *)tex; nlinfo("loadchildren(%s) : texture = %s",filename.c_str(),utex->getFileName().c_str()); get(utex->getFileName()); } bank->reset(); delete bank; } }