Ejemplo n.º 1
0
        private void CreateBuildings(List <ICompleteOsmGeo> buildings, List <LatLon> centroids,
                                     Dictionary <LatLon, double?> elevations, Point offset, string outputDir)
        {
            UpdateProgress(0);
            UpdateProgressMessage("[Buildings] Generating building models");

            var bldOutputAbsolute = Path.Combine(outputDir, bldOutput);

            Utils.DeleteDirectoryContents(bldOutputAbsolute);

            var modelSii    = new SiiFile();
            var modelSiiIdx = 0;

            int progressReportInterval = 32;

            for (int i = 0; i < buildings.Count; i++)
            {
                var building = (CompleteWay)buildings[i];

                var modelName     = "generated_bld_" + building.Id;
                var bldOutputFile = $"/{bldOutput}/{modelName}.{pmdExtension}";

                var projCentroid   = projection.Project(centroids[i].Latitude, centroids[i].Longitude);
                var offsetCentroid = new Vector3((float)(projCentroid.X - offset.X),
                                                 0, (float)((projCentroid.Y - offset.Y) * -1));
                var nodes = Utils.ProjectWay(building, offset, projection, elevation, false);
                GenerateModel(building, nodes, offsetCentroid, modelName, bldOutputAbsolute);

                // create model.sii entry
                var unitName = new Token($"g__{modelSiiIdx}");
                var unit     = new Unit("model_def", $"model.{unitName}");
                modelSiiIdx++;
                unit.Attributes.Add("model_desc", bldOutputFile);
                unit.Attributes.Add("category", "osm_proto_generated");
                modelSii.Units.Add(unit);

                // add the model to the map
                var modelMapPos     = offsetCentroid;
                var elevationLatLon = GetCentroid(building);
                modelMapPos.Y = (float)(elevations[elevationLatLon] ?? 0);
                var modelMapItem = Model.Add(map, modelMapPos, 0, unitName, "default", "default");
                modelMapItem.ViewDistance = 950;

                if (i % progressReportInterval == 0)
                {
                    UpdateProgress((float)(i + 1) / buildings.Count);
                }
            }

            Directory.CreateDirectory(Path.Combine(outputDir, "def/world"));
            var modelSiiPath = Path.Combine(outputDir, "def/world/model.osm_proto.sii");

            modelSii.Serialize(modelSiiPath);

            UpdateProgress(1);
        }
Ejemplo n.º 2
0
        private List <Terrain> CreateTerrains(BBox <Point> projBounds)
        {
            UpdateProgressMessage("[Terrain] Creating terrain items and materials");
            UpdateProgress(0);

            var stepSize = StepSize.Meters16;

            var terrains  = new List <Terrain>();
            var satMatSii = new SiiFile();
            var satMatIdx = 1;

            int i      = 0;
            int totalX = (int)Math.Ceiling((projBounds.Max.X - projBounds.Min.X) / XSize);
            int totalY = (int)Math.Ceiling((projBounds.Max.Y - projBounds.Min.Y) / YSize);

            int progressReportInterval = 5;

            for (double y = projBounds.Min.Y; y < projBounds.Max.Y; y += YSize)
            {
                for (double x = projBounds.Min.X; x < projBounds.Max.X; x += XSize)
                {
                    // create terrain item
                    var tPos = new Vector3((float)(x - offset.X), 0, (float)(y - offset.Y));
                    var trn  = AddTerrainGrid(stepSize, TerrainCols, TerrainRows, tPos);
                    trn.ViewDistance = 1500;
                    terrains.Add(trn);

                    LoadAndApplySatelliteImage(trn, satMatIdx++, satMatSii);

                    i++;
                    if (i % progressReportInterval == 0)
                    {
                        UpdateProgress((float)i / (totalX * totalY));
                    }
                }
            }

            var satMatSiiDir = Path.Combine(modDir, "def/world/");

            Directory.CreateDirectory(satMatSiiDir);
            satMatSii.Serialize(Path.Combine(satMatSiiDir, "terrain_material.osm_proto.sii"));

            UpdateProgress(1);

            return(terrains);
        }