Skip to content

Commit

Permalink
Add a parameter to indicate whether to convert the upward Y-axis to …
Browse files Browse the repository at this point in the history
…the upward Z-axis, as the upward axis may be the Y-axis or the Z-axis after some objs are exported.
  • Loading branch information
dashenxian committed Feb 22, 2024
1 parent ce1041f commit 53f291c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
3 changes: 3 additions & 0 deletions Obj2Tiles/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions Obj2Tiles/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> createTempFolder = opts.UseSystemTempFolder
? s => CreateTempFolder(s, Path.GetTempPath())
: s => CreateTempFolder(s, Path.Combine(opts.Output, ".temp"));
Expand All @@ -50,7 +50,7 @@ private static async Task Run(Options opts)

try
{

destFolderDecimation = opts.StopAt == Stage.Decimation
? opts.Output
: createTempFolder($"{pipelineId}-obj2tiles-decimation");
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
19 changes: 12 additions & 7 deletions Obj2Tiles/Stages/Model/GpsCoords.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -21,6 +22,7 @@ public GpsCoords()
Longitude = 0;
Altitude = 0;
Scale = 1;
YUpToZUp = true;
}

public double[] ToEcefTransform()
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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];
Expand Down

0 comments on commit 53f291c

Please sign in to comment.