public ResourcePackager clone() { ResourcePackager copy = new ResourcePackager(); copy.setArchive(archive.get()); copy.setOutputLocation(output_location); copy.setCompressTextures(compress_textures); copy.setMaxTextureSize(max_tex_size); copy.setInlineTextures(inline_textures); copy.setFixMipmaps(fix_mipmaps); return copy; }
public ResourcePackager clone() { ResourcePackager copy = new ResourcePackager(); copy.setArchive(archive.get()); copy.setOutputLocation(output_location); copy.setCompressTextures(compress_textures); copy.setMaxTextureSize(max_tex_size); copy.setInlineTextures(inline_textures); copy.setFixMipmaps(fix_mipmaps); return(copy); }
/** * Assigns an optional resource packager to the compiler. The resource packager will * prepare referenced resources (like texture skins and external models) and copy them * to the output location. * * @param packager * Packager to use with this compiler. */ public void setResourcePackager(ResourcePackager value) { resource_packager = value; }
/** * Pushes source data onto the level of detail queue. Levels of detail are * interpreted from front to back. * * @param layer * Feature layer from which to read source data * @param graph * Filter graph to use to build scene graph * @param min_range * Minimum visibility range of this level of detail * @param max_range * Maximum visibility range of this level of detail * @param replace * If true, this detail level will replace the ones before it. If false, it * will join the scene graph without removing the previous levels. * @param depth * Level of detail depth (0 = top level) * @param user_data * User-defined data to pass to the cell compiler */ public void push(FeatureLayer layer, FilterGraph graph, Properties env_props, ResourcePackager packager, float min_range, float max_range, bool replace, uint depth, object user_data) { if (layer != null) { // update the automatic AOI: if (!aoi_auto.isValid()) aoi_auto = layer.getExtent(); else aoi_auto.expandToInclude(layer.getExtent()); // store the LOD definition: levels.Add(new MapLayerLevelOfDetail( layer, graph, env_props, packager, min_range, max_range, replace, depth, user_data)); grid_valid = false; } }
/*** Class methods ***************************************************/ bool Builder.addSlicesToMapLayer(BuildLayerSliceList slices, Properties env_properties, MapLayer map_layer, ResourcePackager default_packager, uint depth, Session session, Source parent_source) { foreach (BuildLayerSlice i in slices) { BuildLayerSlice slice = i; if (slice.getSource() != null && !build(slice.getSource(), session)) { // osgGIS.warn() // << "Unable to build source \"" << slice.getSource().getName() << "\" or one of its dependencies." // << std.endl; return false; } Source slice_source = slice.getSource() != null ? slice.getSource() : parent_source; ResourcePackager packager = default_packager ? default_packager.clone() : null; if (packager != null) { packager.setMaxTextureSize( slice.getProperties().getIntValue("max_texture_size", default_packager.getMaxTextureSize())); packager.setCompressTextures( slice.getProperties().getBoolValue("compress_textures", default_packager.getCompressTextures())); packager.setInlineTextures( slice.getProperties().getBoolValue("inline_textures", default_packager.getInlineTextures())); } if (slice_source != null) { FeatureLayer feature_layer = Registry.instance().createFeatureLayer( slice_source.getAbsoluteURI()); if (feature_layer == null) { //osgGIS.warn() << "Cannot access source \"" << slice_source.getName() << std.endl; return false; } map_layer.push( feature_layer, slice.getFilterGraph(), env_properties, packager.get(), slice.getMinRange(), slice.getMaxRange(), true, depth, null); } // now add any sub-slice children: if (!addSlicesToMapLayer(slice.getSubSlices(), env_properties, map_layer, packager.get(), depth + 1, session, slice_source)) { return false; } } return true; }
private bool addSlicesToMapLayer( BuildLayerSliceList slices, Properties env_props, MapLayer map_layer, ResourcePackager default_packager, uint lod, Session session, Source source);
protected bool build(BuildLayer layer) { string work_dir_name = project.getAbsoluteWorkingDirectory(); if ( string.IsNullOrEmpty(work_dir_name) ) work_dir_name = "work_" + project.getName(); string work_dir = PathUtils.combinePaths( project.getBaseURI(), work_dir_name ); if ( osgDB.makeDirectory( work_dir ) ) { Registry.instance().setWorkDirectory( work_dir ); } //osgGIS.notice() << "Building layer \"" << layer.getName() << "\"." << std.endl; // first create and initialize a Session that will share data across the build. Session session = new Session(); // add shared scripts to the session: foreach( Script i in project.getScripts()) session.addScript( i ); // add shared resources to the session: foreach( Resource i in project.getResources() ) session.getResources().addResource( i ); // now establish the source data record form this layer and open a feature layer // that connects to that source. Source source = layer.getSource(); // default source.. may be overriden in slices //if ( !source ) //{ // //TODO: log error // osgGIS.notify( osg.WARN ) // << "No source specified for layer \"" << layer.getName() << "\"." << std.endl; // return false; //} // recursively build any sources that need building. if ( source && !build( source, session.get() ) ) { // osgGIS.warn() // << "Unable to build source \"" << source.getName() << "\" or one of its dependencies." // << std.endl; return false; } FeatureLayer feature_layer; if ( source != null) { feature_layer = Registry.instance().createFeatureLayer( source.getAbsoluteURI() ); if ( feature_layer == null ) { //TODO: log error //osgGIS.warn() // << "Cannot access source \"" << source.getName() // << "\" for layer \"" << layer.getName() << "\"." << std.endl; return false; } } // The reference terrain: osg.Node terrain_node; SpatialReference terrain_srs; GeoExtent terrain_extent; Terrain terrain = layer.getTerrain(); if ( !getTerrainData( terrain, terrain_node, terrain_srs, terrain_extent ) ) return false; // output file: string output_file = layer.getAbsoluteTargetPath(); osgDB.makeDirectoryForFile( output_file ); if ( !osgDB.fileExists( osgDB.getFilePath( output_file ) ) ) { //osgGIS.warn() // << "Unable to establish target location for layer \"" // << layer.getName() << "\" at \"" << output_file << "\"." // << std.endl; return false; } // whether to include textures in IVE files: bool inline_ive_textures = layer.getProperties().getBoolValue( "inline_textures", false ); // TODO: deprecate this as we move towards the ResourcePackager... osgDB.ReaderWriter.Options options; if ( inline_ive_textures ) { options = new osgDB.ReaderWriter.Options( "noWriteExternalReferenceFiles useOriginalExternalReferences" ); } else { options = new osgDB.ReaderWriter.Options( "noTexturesInIVEFile noWriteExternalReferenceFiles useOriginalExternalReferences" ); } osgDB.Registry.instance().setOptions( options ); osgDB.Archive archive; string archive_file = output_file; if ( osgDB.getLowerCaseFileExtension( output_file ) == "osga" ) { archive = osgDB.openArchive( output_file, osgDB.Archive.CREATE, 4096 ); output_file = "out.ive"; // since there's no way to set the master file name...fake it out osg.Group dummy = new osg.Group(); archive.writeNode( dummy , output_file ); } // intialize a task manager if necessary: TaskManager manager = num_threads > 1? new TaskManager( num_threads ) : num_threads < 1? new TaskManager() : null; // prep the map layer definition: MapLayer map_layer = new MapLayer(); // a resource packager if necessary will copy ext-ref files to the output location: ResourcePackager packager = new ResourcePackager(); packager.setArchive( archive.get() ); packager.setOutputLocation( osgDB.getFilePath( output_file ) ); if ( layer.getProperties().getBoolValue( "localize_resources", false ) ) { packager.setMaxTextureSize( layer.getProperties().getIntValue( "max_texture_size", 0 ) ); packager.setCompressTextures( layer.getProperties().getBoolValue( "compress_textures", false ) ); packager.setInlineTextures( layer.getProperties().getBoolValue( "inline_textures", false ) ); } if ( !addSlicesToMapLayer( layer.getSlices(), layer.getEnvProperties(), map_layer, packager, 0, session, source ) ) { //osgGIS.warn() << "Failed to add all slices to layer " << layer.getName() << std.endl; return false; } // calculate the grid cell size: double col_size = layer.getProperties().getDoubleValue( "col_size", -1.0 ); double row_size = layer.getProperties().getDoubleValue( "row_size", -1.0 ); if ( col_size <= 0.0 || row_size <= 0.0 ) { int num_cols = Math.Max( 1, layer.getProperties().getIntValue( "num_cols", 1 ) ); int num_rows = Math.Max(1, layer.getProperties().getIntValue("num_rows", 1)); col_size = map_layer.getAreaOfInterest().getWidth() / (double)num_cols; row_size = map_layer.getAreaOfInterest().getHeight() / (double)num_rows; } map_layer.setCellWidth( col_size ); map_layer.setCellHeight( row_size ); map_layer.setEncodeCellRadius( layer.getProperties().getBoolValue( "encode_cell_radius", true ) ); MapLayerCompiler compiler; // figure out which compiler to use: if ( layer.getType() == BuildLayer.LayerType.TYPE_QUADTREE ) { compiler = new QuadTreeMapLayerCompiler( map_layer, session ); } else if (layer.getType() == BuildLayer.LayerType.TYPE_GRIDDED) { compiler = new GriddedMapLayerCompiler( map_layer.get(), session. ); } else if (layer.getType() == BuildLayer.LayerType.TYPE_SIMPLE) { compiler = new SimpleMapLayerCompiler( map_layer, session ); } if ( compiler.get() ) { compiler.setAbsoluteOutputURI( output_file ); compiler.setPaged( layer.getProperties().getBoolValue( "paged", true ) ); compiler.setTerrain( terrain_node.get(), terrain_srs, terrain_extent ); compiler.setArchive( archive.get(), archive_file ); compiler.setResourcePackager( packager.get() ); // build the layer and write the root file to output: osg.Group result = compiler.compile( manager.get() ); if ( result != null ) { packager.packageNode( result.get(), output_file ); } } if ( archive != null ) { archive.close(); } //osgGIS.notice() << "Done building layer \"" << layer.getName() << "\"." << std.endl; return true; }