Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
0
        protected void setCenterAndRadius(osg.Node node, GeoExtent cell_extent, SmartReadCallback reader)
        {
            SpatialReference srs = map_layer.getOutputSRS(getSession(), getTerrainSRS());
            // first get the output srs centroid:
            GeoPoint centroid = srs.transform(cell_extent.getCentroid());
            GeoPoint sw       = srs.transform(cell_extent.getSouthwest());

            double radius = map_layer.getEncodeCellRadius() ?
                            (centroid - sw).length() :
                            -1.0;

            if (terrain_node.valid() && terrain_srs != null)
            {
                GeoPoint clamped;
                for (int t = 0; t < 5; t++)
                {
                    clamped = GeomUtils.clampToTerrain(centroid, terrain_node.get(), terrain_srs, reader);
                    if (!clamped.isValid())
                    {
                        // if the clamp failed, it's due to the geocentric intersection bug in which the isect
                        // fails when coplanar with a tile boundary/skirt. Fudge the centroid and try again.
                        double fudge = 0.001 * ((double)(1 + (Random.Rand() % 10)));
                        centroid.X += fudge;
                        centroid.Y -= fudge;
                        centroid.Z += fudge * fudge;
                    }
                    else
                    {
                        break;
                    }
                }

                if (!clamped.isValid())
                {
                    SpatialReference geo    = srs.getGeographicSRS();
                    GeoPoint         latlon = geo.transform(centroid);
                    //osgGIS.warn() << "*** UNABLE TO CLAMP CENTROID: ***" << latlon.toString() << std.endl;
                }
                else
                {
                    centroid = clamped;
                }
            }
            else
            {
                //osgGIS.warn() << "*** Failed to clamp Center/Radius for cell" << std.endl;
            }

            if (node is osg.LOD)
            {
                osg.LOD plod = (osg.LOD)node;
                plod.setCenter(centroid);
                plod.setRadius(radius);
            }
            else if (node is osg.ProxyNode)
            {
                osg.ProxyNode proxy = (osg.ProxyNode)node;
                proxy.setCenter(centroid);
                proxy.setRadius(radius);
            }
        }