Esempio n. 1
0
        private static void WriteTilesetJsonFile(string jsonFilepath, SingleTileset singleTileset)
        {
            var tilesetJson = JsonConvert.SerializeObject(singleTileset, new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                Formatting        = Formatting.Indented
            });

            File.WriteAllText(jsonFilepath, tilesetJson, Encoding.UTF8);
        }
Esempio n. 2
0
        /// <summary>
        /// when converted, generate tileset
        /// </summary>
        /// <param name="objFile">obj file path</param>
        /// <param name="outputPath">output folder</param>
        /// <param name="gisPosition">where the obj model positioned</param>
        /// <returns></returns>
        internal static SingleTileset WriteTileset(string objFile, string outputPath, GisPosition gisPosition)
        {
            var fileName       = Path.GetFileNameWithoutExtension(objFile);
            var b3dmFile       = Path.Combine(outputPath, fileName + ".b3dm");
            var tilesetOptions = WriteB3dm(objFile, b3dmFile);

            //tilesetOptions.TransHeight = 0;
            //tilesetOptions.MinHeight = 0;
            //tilesetOptions.MaxHeight = 40;
            //tilesetOptions.TileWidth = 200;
            //tilesetOptions.TileHeight = 200;
            tilesetOptions.SetPosition(gisPosition);
            tilesetOptions.UseRegion = true;
            var singleTileset = SingleTileset.Create(tilesetOptions);

            return(singleTileset);
        }
Esempio n. 3
0
        internal static SingleTileset WriteTileset(ObjModel objModel,
                                                   string objFolder, string outputPath, GisPosition gisPosition)
        {
            var modelName = objModel.Name;
            var b3dmFile  = Path.Combine(outputPath, modelName + ".b3dm");
            var converter = new Converter(objModel, objFolder,
                                          new GltfOptions {
                Binary = true, Name = modelName, WithBatchTable = true
            });
            var tilesetOptions = WriteB3dm(converter, b3dmFile);

            //tilesetOptions.TransHeight = 0;
            //tilesetOptions.MinHeight = 0;
            //tilesetOptions.MaxHeight = 40;
            //tilesetOptions.TileWidth = 200;
            //tilesetOptions.TileHeight = 200;
            tilesetOptions.SetPosition(gisPosition);
            tilesetOptions.UseRegion = true;
            var singleTileset = SingleTileset.Create(tilesetOptions);

            return(singleTileset);
        }
Esempio n. 4
0
        internal static string CombineTilesets(string outputFolder, GisPosition gisPosition,
                                               params Task <string>[] waitedTasks)
        {
            var west      = double.MaxValue;
            var south     = double.MaxValue;
            var north     = double.MinValue;
            var east      = double.MinValue;
            var minheight = double.MaxValue;
            var maxheight = double.MinValue;

            var outputTileset = Path.Combine(outputFolder, "tileset.json");

            var tiles          = new List <Tile>();
            var geometricError = 500.0;

            foreach (var t in waitedTasks)
            {
                var jsonFile = t.Result;
                var json     = JsonConvert.DeserializeObject <SingleTileset>(
                    File.ReadAllText(jsonFile, Encoding.UTF8));
                if (json.Root == null)
                {
                    continue;
                }
                var boundingVolume = json.Root.BoundingVolume;
                if (boundingVolume == null)
                {
                    continue;
                }
                var geometricError0 = json.GeometricError;
                if (boundingVolume.Region != null &&
                    boundingVolume.Region.Length >= 6)
                {
                    west      = Math.Min(west, boundingVolume.Region[0]);
                    south     = Math.Min(south, boundingVolume.Region[1]);
                    east      = Math.Max(east, boundingVolume.Region[2]);
                    north     = Math.Max(north, boundingVolume.Region[3]);
                    minheight = Math.Min(minheight, boundingVolume.Region[4]);
                    maxheight = Math.Max(maxheight, boundingVolume.Region[5]);
                }

                tiles.Add(new Tile
                {
                    BoundingVolume = boundingVolume,
                    GeometricError = geometricError0,
                    Refine         = json.Root.Refine,
                    Content        = new TileContent
                    {
                        Url = jsonFile.Substring(outputFolder.Length).TrimStart(new char[] { '\\', '/' }).Replace('\\', '/')
                    }
                });
            }

            var allTileset = new SingleTileset
            {
                Asset = new TilesetAsset
                {
                    Version        = "0.0",
                    TilesetVersion = "1.0.0-arctron"
                },
                GeometricError = geometricError,
                Root           = new Tile
                {
                    BoundingVolume = new BoundingVolume
                    {
                        Region = new double[] {
                            west, south,
                            east, north,
                            minheight, maxheight
                        }
                    },
                    Refine         = "ADD",
                    GeometricError = geometricError,
                    Children       = tiles
                }
            };
            var tilesetJsonPath = Path.Combine(outputFolder, "tileset.json");

            File.WriteAllText(tilesetJsonPath,
                              JsonConvert.SerializeObject(allTileset,
                                                          new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                Formatting        = Formatting.Indented
            }));
            return(tilesetJsonPath);
        }
Esempio n. 5
0
        internal static string MergeTilesets(string outputFolder, GisPosition gisPosition, bool lod, bool writeChildTilesetJson, params Task <SingleTileset>[] waitedTasks)
        {
            var west      = double.MaxValue;
            var south     = double.MaxValue;
            var north     = double.MinValue;
            var east      = double.MinValue;
            var minheight = double.MaxValue;
            var maxheight = double.MinValue;

            var outputTileset = Path.Combine(outputFolder, "tileset.json");
            var outputPath    = GenerateBatchedPath(outputFolder);

            var tilesetList = new List <SingleTileset>();

            var tiles          = new List <Tile>();
            var geometricError = 500.0;

            foreach (var t in waitedTasks)
            {
                var json = t.Result;
                tilesetList.Add(json);
                if (json.Root == null)
                {
                    continue;
                }
                var boundingVolume = json.Root.BoundingVolume;
                if (boundingVolume == null)
                {
                    continue;
                }
                var geometricError0 = json.GeometricError;
                if (boundingVolume.Region != null &&
                    boundingVolume.Region.Length >= 6)
                {
                    west      = Math.Min(west, boundingVolume.Region[0]);
                    south     = Math.Min(south, boundingVolume.Region[1]);
                    east      = Math.Max(east, boundingVolume.Region[2]);
                    north     = Math.Max(north, boundingVolume.Region[3]);
                    minheight = Math.Min(minheight, boundingVolume.Region[4]);
                    maxheight = Math.Max(maxheight, boundingVolume.Region[5]);
                }
                var contentName = Path.GetFileNameWithoutExtension(json.Root.Content.Url);
                if (!lod)
                {
                    var err = geometricError0 / 4.0;
                    if (json.Root != null)
                    {
                        double?err0 = null;
                        if (json.Root.OriginalX != null && json.Root.OriginalX.IsValid())
                        {
                            var errX = (json.Root.OriginalX.Max - json.Root.OriginalX.Min) / 10;
                            err0 = errX;
                        }
                        if (json.Root.OriginalY != null && json.Root.OriginalY.IsValid())
                        {
                            var errY = (json.Root.OriginalY.Max - json.Root.OriginalY.Min) / 10;
                            if (!err0.HasValue)
                            {
                                err0 = errY;
                            }
                            else if (err0.Value < errY)
                            {
                                err0 = errY;
                            }
                        }
                        if (json.Root.OriginalZ != null && json.Root.OriginalZ.IsValid())
                        {
                            var errZ = (json.Root.OriginalZ.Max - json.Root.OriginalZ.Min) / 10;
                            if (!err0.HasValue)
                            {
                                err0 = errZ;
                            }
                            else if (err0.Value < errZ)
                            {
                                err0 = errZ;
                            }
                        }
                        if (err0.HasValue)
                        {
                            err = err0.Value;
                        }
                    }
                    tiles.Add(new Tile
                    {
                        BoundingVolume = boundingVolume,
                        GeometricError = 0.0,
                        Refine         = null,
                        Content        = new TileContent
                        {
                            Url            = DataFolderName + "/" + json.Root.Content.Url,
                            BoundingVolume = boundingVolume
                        }
                    });
                }
                if (writeChildTilesetJson)
                {
                    var jsonFilepath = Path.Combine(outputPath, contentName + ".json");
                    WriteTilesetJsonFile(jsonFilepath, json);
                }
            }
            if (lod)
            {
                tiles = TilesetRegionComparer.SortTrees(tilesetList, DataFolderName);
            }

            var longitude      = gisPosition.Longitude;
            var latitude       = gisPosition.Latitude;
            var transHeight    = gisPosition.TransHeight.HasValue ? gisPosition.TransHeight.Value : 0.0;
            var transformArray = GisUtil.Wgs84Transform(
                longitude, latitude, transHeight).ToArray();

            var allTileset = new SingleTileset
            {
                Asset = new TilesetAsset
                {
                    Version        = "0.0",
                    TilesetVersion = "1.0.0-arctron"
                },
                GeometricError = geometricError,
                Root           = new Tile
                {
                    BoundingVolume = new BoundingVolume
                    {
                        Region = new double[] {
                            west, south,
                            east, north,
                            minheight, maxheight
                        }
                    },
                    Refine         = "ADD",
                    GeometricError = geometricError / 2.0,
                    Children       = tiles,
                    Transform      = transformArray
                }
            };


            allTileset.ResetGeometricErrors(); //TODO:

            var tilesetJsonPath = Path.Combine(outputFolder, "tileset.json");

            File.WriteAllText(tilesetJsonPath,
                              JsonConvert.SerializeObject(allTileset,
                                                          new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
                                    //,Formatting = Formatting.Indented
            }));
            return(tilesetJsonPath);
        }