diff --git a/Obj2Tiles/Options.cs b/Obj2Tiles/Options.cs index 18dfc6b..afa4c9e 100644 --- a/Obj2Tiles/Options.cs +++ b/Obj2Tiles/Options.cs @@ -46,6 +46,9 @@ public sealed class Options [Option("keep-intermediate", Required = false, HelpText = "Keeps the intermediate files (do not cleanup)", Default = false)] public bool KeepIntermediateFiles { get; set; } + + [Option('t',"yuptozup", Required = false, HelpText = "Convert the upward Y-axis to the upward Z-axis, which is used in some situations where the upward axis may be the Y-axis or the Z-axis after the obj is exported.", Default = true)] + public bool YUpToZUp { get; set; } } public enum Stage diff --git a/Obj2Tiles/Program.cs b/Obj2Tiles/Program.cs index eb3d616..9ee33f1 100644 --- a/Obj2Tiles/Program.cs +++ b/Obj2Tiles/Program.cs @@ -34,13 +34,13 @@ private static async Task Run(Options opts) opts.Output = Path.GetFullPath(opts.Output); opts.Input = Path.GetFullPath(opts.Input); - + Directory.CreateDirectory(opts.Output); var pipelineId = Guid.NewGuid().ToString(); var sw = new Stopwatch(); var swg = Stopwatch.StartNew(); - + Func createTempFolder = opts.UseSystemTempFolder ? s => CreateTempFolder(s, Path.GetTempPath()) : s => CreateTempFolder(s, Path.Combine(opts.Output, ".temp")); @@ -50,7 +50,7 @@ private static async Task Run(Options opts) try { - + destFolderDecimation = opts.StopAt == Stage.Decimation ? opts.Output : createTempFolder($"{pipelineId}-obj2tiles-decimation"); @@ -82,7 +82,7 @@ private static async Task Run(Options opts) return; var gpsCoords = opts.Latitude != null && opts.Longitude != null - ? new GpsCoords(opts.Latitude.Value, opts.Longitude.Value, opts.Altitude, opts.Scale) + ? new GpsCoords(opts.Latitude.Value, opts.Longitude.Value, opts.Altitude, opts.Scale, opts.YUpToZUp) : null; Console.WriteLine(); @@ -114,7 +114,7 @@ private static async Task Run(Options opts) { Console.WriteLine( $" ?> Skipping cleanup, intermediate files are in '{tmpFolder}' with pipeline id '{pipelineId}'"); - + Console.WriteLine(" ?> You should delete this folder manually, it is only for debugging purposes"); } else @@ -137,38 +137,38 @@ private static async Task Run(Options opts) } private static bool CheckOptions(Options opts) - { + { if (string.IsNullOrWhiteSpace(opts.Input)) { Console.WriteLine(" !> Input file is required"); return false; } - + if (!File.Exists(opts.Input)) { Console.WriteLine(" !> Input file does not exist"); return false; } - + if (string.IsNullOrWhiteSpace(opts.Output)) { Console.WriteLine(" !> Output folder is required"); return false; } - + if (opts.LODs < 1) { Console.WriteLine(" !> LODs must be at least 1"); return false; } - + if (opts.Divisions < 0) { Console.WriteLine(" !> Divisions must be non-negative"); return false; } - + return true; } diff --git a/Obj2Tiles/Stages/Model/GpsCoords.cs b/Obj2Tiles/Stages/Model/GpsCoords.cs index 3713565..a7a493d 100644 --- a/Obj2Tiles/Stages/Model/GpsCoords.cs +++ b/Obj2Tiles/Stages/Model/GpsCoords.cs @@ -6,13 +6,14 @@ public class GpsCoords public double Longitude { get; set; } public double Altitude { get; set; } public double Scale { get; set; } - - public GpsCoords(double latitude, double longitude, double altitude, double scale) + public bool YUpToZUp { get; set; } + public GpsCoords(double latitude, double longitude, double altitude, double scale, bool yUpToZUp) { Latitude = latitude; Longitude = longitude; Altitude = altitude; Scale = scale; + YUpToZUp = yUpToZUp; } public GpsCoords() @@ -21,6 +22,7 @@ public GpsCoords() Longitude = 0; Altitude = 0; Scale = 1; + YUpToZUp = true; } public double[] ToEcefTransform() @@ -30,8 +32,8 @@ public double[] ToEcefTransform() var lon = Longitude * Math.PI / 180; var alt = Altitude; - var a = 6378137.0/s; - var b = 6356752.3142/s; + var a = 6378137.0 / s; + var b = 6356752.3142 / s; var f = (a - b) / a; var eSq = 2 * f - f * f; @@ -75,8 +77,11 @@ public double[] ToEcefTransform() 0, 0, 0, 1 }; - var mult = MultiplyMatrix(res, rot); - + var mult = res; + if (YUpToZUp) + { + mult = MultiplyMatrix(res, rot); + } return MultiplyMatrix(ConvertToColumnMajorOrder(mult), scale); } @@ -86,7 +91,7 @@ public double[] ToEcefTransform() 0, -1, 0, 0, 0, 0, 0, 1 }; - + public static double[] ConvertToColumnMajorOrder(double[] m) { var res = new double[16];