/// <summary> /// /// </summary> /// <param name="options">options obtained when convert b3dm data</param> /// <returns></returns> public static SingleTileset Create(TilesetCreationOptions options) { if (options == null) { options = new TilesetCreationOptions(); } var longitude = options.Longitude; var latitude = options.Latitude; var minHeight = options.MinHeight; var maxHeight = options.MaxHeight; var transHeight = options.TransHeight; var tileWidth = options.TileWidth; var tileHeight = options.TileHeight; var offsetX = options.OffsetX; var offsetY = options.OffsetY; var upAxis = options.GltfUpAxis ?? "Y"; // properties var geometricError = options.GeometricError; var transformArray = options.Transfrom; if (transformArray == null || transformArray.Length == 0) { transformArray = GisUtil.Wgs84Transform( longitude, latitude, transHeight).ToArray(); } var height = maxHeight - minHeight; if (!(options.UseRegion || options.UseBox || options.UseSphere)) { options.UseRegion = true; } BoundingVolume boundingVolume = null; if (options.UseRegion) { var longitudeExtent = GisUtil.MetersToLongitude(tileWidth, latitude); var latitudeExtent = GisUtil.MetersToLatituide(tileHeight); var west = longitude - longitudeExtent / 2 + offsetX / tileWidth * longitudeExtent; var south = latitude - latitudeExtent / 2 - offsetY / tileHeight * latitudeExtent; var east = longitude + longitudeExtent / 2 + offsetX / tileWidth * longitudeExtent; var north = latitude + latitudeExtent / 2 - offsetY / tileHeight * latitudeExtent; boundingVolume = new BoundingVolume { Region = new double[] { west, south, east, north, minHeight, maxHeight } }; } else if (options.UseBox) { boundingVolume = new BoundingVolume { Box = new double[] { offsetX, -offsetY, height / 2 + minHeight, // center tileWidth / 2, 0, 0, // width 0, tileHeight / 2, 0, // depth 0, 0, height / 2 // height } }; } else if (options.UseSphere) { boundingVolume = new BoundingVolume { Sphere = new double[] { offsetX, -offsetY, height / 2 + minHeight, Math.Sqrt(tileWidth * tileWidth / 4 + tileHeight * tileHeight / 4 + height * height / 4) } }; } return(new SingleTileset { Asset = new TilesetAsset { GltfUpAxis = upAxis }, //Properties GeometricError = geometricError, Root = new Tile { Transform = transformArray, BoundingVolume = boundingVolume, Content = new TileContent { Url = options.TileName }, OriginalX = options.OriginalX, OriginalY = options.OriginalY, OriginalZ = options.OriginalZ } }); }
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); }