/** * Gets the OSG state set associated with a skin resource, creating it * anew if necessary * * @param skin * Skin for which to create the state set * @return * An OSG state set containing a texture */ public Material getStateSet(SkinResource skin) { Material result = null; if (skin != null) { if (!skin_state_sets.ContainsKey(skin)) { result = skin.createStateSet(); skin_state_sets[skin] = result; //skin_state_sets[skin] = result; } else { if (skin_state_sets[skin] == null) // null state set.. { result = skin.createStateSet(); skin_state_sets[skin] = result; } else { result = skin_state_sets[skin]; } } } return(result); }
/** * Adds a hand-built skin resource directly to the cache. * For single-use (e.g. unique to the FilterEnv) skins, it is better (and * usually necessary for memory-usage purposes) to add them directly to the * local cache (versus the Resource Library) so that they don't sit around * using up memory for an entire compilation. */ //void addSkin( osg::Image* image ); public SkinResource addSkin(Material state_set) { SkinResource skin = new SkinResource(); skin_state_sets[skin] = state_set; return(skin); }
/** * Add a new resource instance to the library. * * @param resource * Resource to add to the library */ public void addResource(Resource resource) { if (resource != null) { lock (sincronizeFlag) { #if TODO_PH if (resource is SkinResource) { SkinResource skin = (SkinResource)resource; skins.Add(skin); //osgGIS::Notify(osg::INFO)<<"ResourceLibrary: added skin" <<skin->getAbsoluteURI()<<std::endl; } else if (resource is ModelResource) { ModelResource model = (ModelResource)resource; models.Add(model); //osgGIS::Notify(osg::INFO)<<"ResourceLibrary: added model" <<skin->getAbsoulteURI()<<std::endl; //osgDB::Registry::instance()->getDataFilePathList().push_back(osgDB::getFilePath (model->getAbsoluteURI) } else if (resource is RasterResource) { RasterResource raster = (RasterResource)resource; rasters.Add(raster); //osgGIS::notify(osg::INFO)<<"ResourceLibrary: added raster"<<raster->getAbsoluteURI()<<std::endl; } else if (resource is FeatureLayerResource) { FeatureLayerResource flr = (FeatureLayerResource)resource; featureLayers.Add(flr); //osgGIS::notify(osg::INFO)<<"ResourceLibrary: added feature layer "<<flr->getAbsoluteURI()<<std::endl; } else #endif if (resource is SRSResource) { SRSResource srsr = (SRSResource)resource; srsList.Add(srsr); //osgGIS::notify(osg::INFO)<<"ResourceLibrary: added SRS" << srsr->getName()<<std::endl; } #if TODO_PH else if (resource is PathResource) { PathResource pr = (PathResource)resource; paths.Add(pr); //osgGIS::notify(osg::INFO)<<"ResourceLibrary: added path" << pr->getAbsoluteURI()<<std::endl; } #endif resource.SincronizedFlag = sincronizeFlag; } } }
void LayerCompiler.localizeResources(string output_folder) { // collect the resources marked as used. ResourceList resources_to_localize = getSession().getResourcesUsed(true); osgDB.ReaderWriter.Options local_options = new osgDB.ReaderWriter.Options(); foreach (Resource i in resources_to_localize) { Resource resource = i; // if we are localizing resources, attempt to copy each one to the output folder: if (getLocalizeResources()) { if (resource is SkinResource) { SkinResource skin = (SkinResource)resource; /******/ Image image = null; //skin.getImage(); if (image != null) { string filename = osgDB.getSimpleFileName(image.getFileName()); Image output_image = image.get(); if (getCompressTextures()) { output_image = ImageUtils.convertRGBAtoDDS(image.get()); filename = osgDB.getNameLessExtension(filename) + ".dds"; output_image.setFileName(filename); } if (getArchive() && !getArchive().fileExists(filename)) { osgDB.ReaderWriter.WriteResult r = getArchive().writeImage(*(output_image.get()), filename, local_options.get()); if (r.error()) { //TODO osgGIS.notify( osg.WARN ) << " Failure to copy image " << filename << " into the archive" << std.endl; } } else { if (osgDB.fileExists(output_folder)) { if (!osgDB.writeImageFile(*(output_image.get()), PathUtils.combinePaths(output_folder, filename), local_options.get())) { //TODO osgGIS.notify( osg.WARN ) << " FAILED to copy image " << filename << " into the folder " << output_folder << std.endl; } } else { //TODO osgGIS.notify( osg.WARN ) << " FAILD to localize image " << filename << ", folder " << output_folder << " not found" << std.endl; } } } } else if (resource is ModelResource) { ModelResource model = (ModelResource)resource; osg.Node node = osgDB.readNodeFile(model.getAbsoluteURI()); if (node.valid()) { string filename = osgDB.getSimpleFileName(model.getAbsoluteURI()); if (getArchive() != null) { osgDB.ReaderWriter.WriteResult r = getArchive().writeNode(*(node.get()), filename, local_options.get()); if (r.error()) { //TODO osgGIS.notify( osg.WARN ) << " Failure to copy model " << filename << " into the archive" << std.endl; } } else { if (osgDB.fileExists(output_folder)) { if (!osgDB.writeNodeFile(*(node.get()), osgDB.concatPaths(output_folder, filename), local_options.get())) { //TODO osgGIS.notify( osg.WARN ) << " FAILED to copy model " << filename << " into the folder " << output_folder << std.endl; } } else { //TODO osgGIS.notify( osg.WARN ) << " FAILD to localize model " << filename << ", folder " << output_folder << " not found" << std.endl; } } } } } // now remove any single-use (i.e. non-shared) resources (whether we are localizing them or not) if (resource.isSingleUse()) { getSession().getResources().removeResource(resource); } } }