Exemplo 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);
        }
Exemplo 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);
        }
Exemplo n.º 3
0
        private void LoadAndApplySatelliteImage(Terrain trn, int satMatIdx, SiiFile satMatSii)
        {
            // get lat/lon of backward node.
            var latLonBw = MapPosToLatLon(trn.Node.Position);

            // get lat/lon of opposite corner
            var max = MapPosToLatLon(trn.Node.Position + new Vector3(XSize, 0, YSize));

            var satFileName    = $"generated_sat_{satMatIdx}";
            var satTexturePath = Path.Combine(satAbsoluteOutputDir, satFileName + "." + ddsExtension);

            var img = ir.RetrieveMaxResolution(latLonBw.Latitude, latLonBw.Longitude,
                                               max.Latitude, max.Longitude, bingMaxLevel);
            var geo = new MagickGeometry
            {
                IgnoreAspectRatio = true,
                Width             = NextMultipleOf4(img.Width),
                Height            = NextMultipleOf4(img.Height),
            };

            img.Scale(geo);
            img.Write(satTexturePath, writeDefines);

            // add tobj and mat for it
            var satMatPath = $"/{satOutputDir}/{satFileName}.mat";

            satTobj.TexturePaths[0] = $"/{satOutputDir}/{satFileName}.{ddsExtension}";
            satTobj.Save(Path.Combine(satAbsoluteOutputDir, satFileName + ".tobj"));
            satMat.Attributes["texture"] = satFileName + ".tobj";
            satMat.Serialize(Path.Combine(satAbsoluteOutputDir, satFileName + ".mat"));

            // add it to a sii file
            var unitName = "g__" + satMatIdx.ToString();
            var unit     = new Unit("material_def", "terrain_mat." + unitName);

            unit.Attributes.Add("path", satMatPath);
            satMatSii.Units.Add(unit);

            // assign it to the item
            trn.Right.Terrain.QuadData.Material = unitName;
Exemplo n.º 4
0
 public void Sii()
 {
     var ssi = SiiFile.Load(@"D:\Temp\ntfs\sds2\$Sii");
     //ss..Count.Should().Be(41);
 }