Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Y up translation #63

Merged
merged 4 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
/_ReSharper.Caches/
.vs/
Binary file removed .vs/Obj2Tiles/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file removed .vs/Obj2Tiles/v17/.suo
Binary file not shown.
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', "y-up-to-z-up", Required = true, 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)]
HeDo88TH marked this conversation as resolved.
Show resolved Hide resolved
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 == true)
: 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
Loading