diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 530794c..a6a7827 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -10,11 +10,11 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v5 - name: Setup .NET - uses: actions/setup-dotnet@v2 + uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Restore dependencies run: dotnet restore - name: Build diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b1a2aec..5390837 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,11 +9,11 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v5 - name: Setup .NET - uses: actions/setup-dotnet@v2 + uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Build run: echo ${{ github.sha }} > Release.txt @@ -32,15 +32,15 @@ jobs: run: dotnet publish -p:PublishProfile=osx-x64.pubxml Obj2Tiles - name: Zip win-x64 - run: cd Obj2Tiles/bin/Release/net8.0/publish/win-x64/ && zip -r ../../../../../../Obj2Tiles-Win64.zip * + run: cd Obj2Tiles/bin/Release/net9.0/publish/win-x64/ && zip -r ../../../../../../Obj2Tiles-Win64.zip * - name: Zip win-arm64 - run: cd Obj2Tiles/bin/Release/net8.0/publish/win-arm64/ && zip -r ../../../../../../Obj2Tiles-WinArm64.zip * + run: cd Obj2Tiles/bin/Release/net9.0/publish/win-arm64/ && zip -r ../../../../../../Obj2Tiles-WinArm64.zip * - name: Zip linux-x64 - run: cd Obj2Tiles/bin/Release/net8.0/publish/linux-x64/ && zip -r ../../../../../../Obj2Tiles-Linux64.zip * + run: cd Obj2Tiles/bin/Release/net9.0/publish/linux-x64/ && zip -r ../../../../../../Obj2Tiles-Linux64.zip * - name: Zip linux-arm64 - run: cd Obj2Tiles/bin/Release/net8.0/publish/linux-arm64/ && zip -r ../../../../../../Obj2Tiles-LinuxArm64.zip * + run: cd Obj2Tiles/bin/Release/net9.0/publish/linux-arm64/ && zip -r ../../../../../../Obj2Tiles-LinuxArm64.zip * - name: Zip osx-x64 - run: cd Obj2Tiles/bin/Release/net8.0/publish/osx-x64/ && zip -r ../../../../../../Obj2Tiles-Osx64.zip * + run: cd Obj2Tiles/bin/Release/net9.0/publish/osx-x64/ && zip -r ../../../../../../Obj2Tiles-Osx64.zip * - name: Release uses: softprops/action-gh-release@v1 diff --git a/MeshDecimatorCore/Algorithms/FastQuadricMeshSimplification.cs b/MeshDecimatorCore/Algorithms/FastQuadricMeshSimplification.cs index 2fdd5f5..bc728fa 100644 --- a/MeshDecimatorCore/Algorithms/FastQuadricMeshSimplification.cs +++ b/MeshDecimatorCore/Algorithms/FastQuadricMeshSimplification.cs @@ -1414,7 +1414,7 @@ public override Mesh ToMesh() else { // This mesh doesn't have any triangles left - indices[subMeshIndex] = new int[0]; + indices[subMeshIndex] = []; } } diff --git a/MeshDecimatorCore/Collections/ResizableArray.cs b/MeshDecimatorCore/Collections/ResizableArray.cs index c7cee69..6e3737f 100644 --- a/MeshDecimatorCore/Collections/ResizableArray.cs +++ b/MeshDecimatorCore/Collections/ResizableArray.cs @@ -36,7 +36,7 @@ internal sealed class ResizableArray private T[] items = null; private int length = 0; - private static T[] emptyArr = new T[0]; + private static T[] emptyArr = []; #endregion #region Properties diff --git a/MeshDecimatorCore/Mesh.cs b/MeshDecimatorCore/Mesh.cs index 58ff063..8117237 100644 --- a/MeshDecimatorCore/Mesh.cs +++ b/MeshDecimatorCore/Mesh.cs @@ -51,7 +51,7 @@ public sealed class Mesh private Vector4[] colors = null; private BoneWeight[] boneWeights = null; - private static readonly int[] emptyIndices = new int[0]; + private static readonly int[] emptyIndices = []; #endregion #region Properties diff --git a/MeshDecimatorCore/MeshDecimatorCore.csproj b/MeshDecimatorCore/MeshDecimatorCore.csproj index 8a91831..b903a56 100644 --- a/MeshDecimatorCore/MeshDecimatorCore.csproj +++ b/MeshDecimatorCore/MeshDecimatorCore.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable diff --git a/Obj2Gltf/BufferState.cs b/Obj2Gltf/BufferState.cs index a591763..cb3d238 100644 --- a/Obj2Gltf/BufferState.cs +++ b/Obj2Gltf/BufferState.cs @@ -173,7 +173,7 @@ public int MakeNormalAccessors(string name) Name = "Normals", Buffer = _model.AddBuffer(NormalsBuffer), ByteStride = 12, - //Target = BufferViewTarget.ARRAY_BUFFER + Target = BufferViewTarget.ARRAY_BUFFER }; NormalsBufferViewIndex = _model.AddBufferView(NormalsBufferView); } @@ -203,7 +203,7 @@ internal int MakeUvAccessor(string name) Name = "Uvs", Buffer = _model.AddBuffer(UvsBuffer), ByteStride = 8, - //Target = BufferViewTarget.ARRAY_BUFFER + Target = BufferViewTarget.ARRAY_BUFFER }; UvsBufferViewIndex = _model.AddBufferView(UvsBufferView); } diff --git a/Obj2Gltf/Obj2Gltf.csproj b/Obj2Gltf/Obj2Gltf.csproj index 46796d3..a59f5a0 100644 --- a/Obj2Gltf/Obj2Gltf.csproj +++ b/Obj2Gltf/Obj2Gltf.csproj @@ -11,7 +11,7 @@ Source;Debug;Release true true - net8.0 + net9.0 10 diff --git a/Obj2Tiles.Common/CommonUtils.cs b/Obj2Tiles.Common/CommonUtils.cs index 41c2082..e8f9f12 100644 --- a/Obj2Tiles.Common/CommonUtils.cs +++ b/Obj2Tiles.Common/CommonUtils.cs @@ -52,8 +52,8 @@ public static bool FilesAreEqual(FileInfo first, FileInfo second) for (var i = 0; i < iterations; i++) { - fs1.Read(one, 0, BytesToRead); - fs2.Read(two, 0, BytesToRead); + fs1.ReadExactly(one, 0, BytesToRead); + fs2.ReadExactly(two, 0, BytesToRead); if (BitConverter.ToInt64(one, 0) != BitConverter.ToInt64(two, 0)) return false; @@ -317,7 +317,7 @@ public static string[] SafeTreeDelete(string baseTempFolder, int rounds = 3, int } if (!entries.Any()) - return Array.Empty(); + return []; Thread.Sleep(delay); } @@ -325,8 +325,8 @@ public static string[] SafeTreeDelete(string baseTempFolder, int rounds = 3, int return entries.ToArray(); } - private static readonly HashSet _compressibleMimeTypes = new() - { + private static readonly HashSet _compressibleMimeTypes = + [ "text/html", "text/css", "text/plain", @@ -358,7 +358,7 @@ public static string[] SafeTreeDelete(string baseTempFolder, int rounds = 3, int "font/eot", "font/otf", "font/opentype" - }; + ]; // Credit https://stackoverflow.com/a/11124118 diff --git a/Obj2Tiles.Common/HttpHelper.cs b/Obj2Tiles.Common/HttpHelper.cs index e6c7e86..19d4e4c 100644 --- a/Obj2Tiles.Common/HttpHelper.cs +++ b/Obj2Tiles.Common/HttpHelper.cs @@ -2,14 +2,14 @@ public static class HttpHelper { - private static readonly HttpClient _httpClient = new HttpClient(); + private static readonly HttpClient HttpClient = new(); public static async Task DownloadFileAsync(string uri, string outputPath) { if (!Uri.TryCreate(uri, UriKind.Absolute, out _)) throw new InvalidOperationException("URI is invalid."); - var fileBytes = await _httpClient.GetByteArrayAsync(uri); + var fileBytes = await HttpClient.GetByteArrayAsync(uri); await File.WriteAllBytesAsync(outputPath, fileBytes); } } \ No newline at end of file diff --git a/Obj2Tiles.Common/Obj2Tiles.Common.csproj b/Obj2Tiles.Common/Obj2Tiles.Common.csproj index 8a91831..b903a56 100644 --- a/Obj2Tiles.Common/Obj2Tiles.Common.csproj +++ b/Obj2Tiles.Common/Obj2Tiles.Common.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable diff --git a/Obj2Tiles.Library.Test/Mesh3Tests.cs b/Obj2Tiles.Library.Test/Mesh3Tests.cs index 06a67ff..5dc7bdc 100644 --- a/Obj2Tiles.Library.Test/Mesh3Tests.cs +++ b/Obj2Tiles.Library.Test/Mesh3Tests.cs @@ -2,10 +2,10 @@ using System.IO; using System.Linq; using System.Numerics; -using FluentAssertions; using NUnit.Framework; using Obj2Tiles.Common; using Obj2Tiles.Library.Geometry; +using Shouldly; using SixLabors.ImageSharp; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.PixelFormats; @@ -19,8 +19,7 @@ public class Mesh3Tests private const string TestOutputPath = "TestOutput"; private const string BrightonTexturingTestUrl = "https://github.com/DroneDB/test_data/raw/master/brighton/odm_texturing.zip"; - - private string GetTestOutputPath(string testName) + private static string GetTestOutputPath(string testName) { var folder = Path.Combine(TestOutputPath, testName); if (Directory.Exists(folder)) @@ -262,9 +261,9 @@ public void Orientation_TestOk() var o = Common.Orientation(v1, v2, v3); - o.Z.Should().Be(1); - o.X.Should().Be(0); - o.Y.Should().Be(0); + o.Z.ShouldBe(1); + o.X.ShouldBe(0); + o.Y.ShouldBe(0); } @@ -277,9 +276,9 @@ public void Orientation_TestZero() var o = Common.Orientation(v1, v2, v3); - o.Z.Should().Be(0); - o.X.Should().Be(0); - o.Y.Should().Be(0); + o.Z.ShouldBe(0); + o.X.ShouldBe(0); + o.Y.ShouldBe(0); } [Test] @@ -289,9 +288,9 @@ public void Orientation_TestCubeMesh() var orientation = mesh.GetAverageOrientation(); - orientation.X.Should().Be(0); - orientation.Y.Should().Be(0); - orientation.Z.Should().Be(0); + orientation.X.ShouldBe(0); + orientation.Y.ShouldBe(0); + orientation.Z.ShouldBe(0); } [Test] diff --git a/Obj2Tiles.Library.Test/Obj2Tiles.Library.Test.csproj b/Obj2Tiles.Library.Test/Obj2Tiles.Library.Test.csproj index 7c2adfb..b9b1645 100644 --- a/Obj2Tiles.Library.Test/Obj2Tiles.Library.Test.csproj +++ b/Obj2Tiles.Library.Test/Obj2Tiles.Library.Test.csproj @@ -1,22 +1,22 @@  - net8.0 + net9.0 enable false - - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + + diff --git a/Obj2Tiles.Library/Common.cs b/Obj2Tiles.Library/Common.cs index 6e3ee0e..68c8cf5 100644 --- a/Obj2Tiles.Library/Common.cs +++ b/Obj2Tiles.Library/Common.cs @@ -35,7 +35,7 @@ public static void CopyImage(Image sourceImage, Image dest, int { sourceRowIndex %= sourceRow.Length; } - targetRow[x + destX] = sourceRow[sourceRowIndex];// + targetRow[x + destX] = sourceRow[sourceRowIndex]; } } }); diff --git a/Obj2Tiles.Library/Geometry/Box3.cs b/Obj2Tiles.Library/Geometry/Box3.cs index bd0dcbc..418f985 100644 --- a/Obj2Tiles.Library/Geometry/Box3.cs +++ b/Obj2Tiles.Library/Geometry/Box3.cs @@ -63,21 +63,21 @@ public Box3[] Split(Axis axis, double position) { return axis switch { - Axis.X => new[] - { + Axis.X => + [ new Box3(Min, new Vertex3(position, Max.Y, Max.Z)), new Box3(new Vertex3(position, Min.Y, Min.Z), Max) - }, - Axis.Y => new[] - { + ], + Axis.Y => + [ new Box3(Min, new Vertex3(Max.X, position, Max.Z)), new Box3(new Vertex3(Min.X, position, Min.Z), Max) - }, - Axis.Z => new[] - { + ], + Axis.Z => + [ new Box3(Min, new Vertex3(Max.X, Max.Y, position)), new Box3(new Vertex3(Min.X, Min.Y, position), Max) - }, + ], _ => throw new ArgumentOutOfRangeException(nameof(axis), axis, null) }; } @@ -86,21 +86,21 @@ public Box3[] Split(Axis axis) { return axis switch { - Axis.X => new[] - { + Axis.X => + [ new Box3(Min, new Vertex3(Min.X + Width / 2, Max.Y, Max.Z)), new Box3(new Vertex3(Min.X + Width / 2, Min.Y, Min.Z), Max) - }, - Axis.Y => new[] - { + ], + Axis.Y => + [ new Box3(Min, new Vertex3(Max.X, Min.Y + Height / 2, Max.Z)), new Box3(new Vertex3(Min.X, Min.Y + Height / 2, Min.Z), Max) - }, - Axis.Z => new[] - { + ], + Axis.Z => + [ new Box3(Min, new Vertex3(Max.X, Max.Y, Min.Z + Depth / 2)), new Box3(new Vertex3(Min.X, Min.Y, Min.Z + Depth / 2), Max) - }, + ], _ => throw new ArgumentOutOfRangeException(nameof(axis), axis, null) }; } diff --git a/Obj2Tiles.Library/Geometry/MeshUtils.cs b/Obj2Tiles.Library/Geometry/MeshUtils.cs index d10352d..89b4f38 100644 --- a/Obj2Tiles.Library/Geometry/MeshUtils.cs +++ b/Obj2Tiles.Library/Geometry/MeshUtils.cs @@ -88,6 +88,12 @@ public static IMesh LoadMesh(string fileName, out string[] dependencies) var vt2 = int.Parse(second[1]); var vt3 = int.Parse(third[1]); + var materialIndex = 0; + if (currentMaterial != string.Empty) + { + materialIndex = materialsDict[currentMaterial]; + } + var faceT = new FaceT( v1 - 1, v2 - 1, @@ -95,7 +101,7 @@ public static IMesh LoadMesh(string fileName, out string[] dependencies) vt1 - 1, vt2 - 1, vt3 - 1, - materialsDict[currentMaterial]); + materialIndex); facesT.Add(faceT); } diff --git a/Obj2Tiles.Library/Obj2Tiles.Library.csproj b/Obj2Tiles.Library/Obj2Tiles.Library.csproj index fee2b4b..895cf43 100644 --- a/Obj2Tiles.Library/Obj2Tiles.Library.csproj +++ b/Obj2Tiles.Library/Obj2Tiles.Library.csproj @@ -1,13 +1,13 @@ - net8.0 + net9.0 enable enable - + diff --git a/Obj2Tiles.Test/Obj2Tiles.Test.csproj b/Obj2Tiles.Test/Obj2Tiles.Test.csproj index 50da0d3..645b9f9 100644 --- a/Obj2Tiles.Test/Obj2Tiles.Test.csproj +++ b/Obj2Tiles.Test/Obj2Tiles.Test.csproj @@ -1,20 +1,21 @@ - net8.0 + net9.0 enable false - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Obj2Tiles.Test/StagesTests.cs b/Obj2Tiles.Test/StagesTests.cs index 2f3b2bf..bd4bf2a 100644 --- a/Obj2Tiles.Test/StagesTests.cs +++ b/Obj2Tiles.Test/StagesTests.cs @@ -18,7 +18,7 @@ public class StagesTests private const string TestDataPath = "TestData"; private const string TestOutputPath = "TestOutput"; - private string GetTestOutputPath(string testName) + private static string GetTestOutputPath(string testName) { var folder = Path.Combine(TestOutputPath, testName); if (Directory.Exists(folder)) @@ -47,7 +47,7 @@ public void TilingStage_Tile() Name = Path.GetFileNameWithoutExtension(file) }).ToDictionary(item => item.Name, item => item.Bounds); - StagesFacade.Tile("TestData/Tile1", testPath, 1, 100, new[] { boundsMapper }); + StagesFacade.Tile("TestData/Tile1", testPath, 1, 100, [boundsMapper]); } diff --git a/Obj2Tiles.sln.DotSettings.user b/Obj2Tiles.sln.DotSettings.user index a27c111..feee357 100644 --- a/Obj2Tiles.sln.DotSettings.user +++ b/Obj2Tiles.sln.DotSettings.user @@ -2,7 +2,7 @@ VISIBLE_FILES <SessionState ContinuousTestingMode="0" IsActive="True" Name="Session" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> - <Project Location="D:\repos\Obj2Tiles\Obj2Tiles.Test" Presentation="&lt;Obj2Tiles.Test&gt;" /> + <Project Location="D:\DATA\repos\Obj2Tiles\Obj2Tiles.Library.Test" Presentation="&lt;Obj2Tiles.Library.Test&gt;" /> </SessionState> diff --git a/Obj2Tiles/Obj2Tiles.csproj b/Obj2Tiles/Obj2Tiles.csproj index 970e04b..4989eb2 100644 --- a/Obj2Tiles/Obj2Tiles.csproj +++ b/Obj2Tiles/Obj2Tiles.csproj @@ -2,14 +2,14 @@ Exe - net8.0 + net9.0 enable enable false - 1.0.13 - 1.0.13 + 1.1.0 + 1.1.0 true - 1.0.13 + 1.1.0 diff --git a/Obj2Tiles/Properties/PublishProfiles/linux-arm64.pubxml b/Obj2Tiles/Properties/PublishProfiles/linux-arm64.pubxml index d94e24b..38e2675 100644 --- a/Obj2Tiles/Properties/PublishProfiles/linux-arm64.pubxml +++ b/Obj2Tiles/Properties/PublishProfiles/linux-arm64.pubxml @@ -6,9 +6,9 @@ https://go.microsoft.com/fwlink/?LinkID=208121. Release Any CPU - bin\Release\net8.0\publish\linux-arm64\ + bin\Release\net9.0\publish\linux-arm64\ FileSystem - net8.0 + net9.0 linux-arm64 true True diff --git a/Obj2Tiles/Properties/PublishProfiles/linux-x64.pubxml b/Obj2Tiles/Properties/PublishProfiles/linux-x64.pubxml index edade88..186d4c5 100644 --- a/Obj2Tiles/Properties/PublishProfiles/linux-x64.pubxml +++ b/Obj2Tiles/Properties/PublishProfiles/linux-x64.pubxml @@ -6,9 +6,9 @@ https://go.microsoft.com/fwlink/?LinkID=208121. Release Any CPU - bin\Release\net8.0\publish\linux-x64\ + bin\Release\net9.0\publish\linux-x64\ FileSystem - net8.0 + net9.0 linux-x64 true True diff --git a/Obj2Tiles/Properties/PublishProfiles/osx-x64.pubxml b/Obj2Tiles/Properties/PublishProfiles/osx-x64.pubxml index f9da46f..1419161 100644 --- a/Obj2Tiles/Properties/PublishProfiles/osx-x64.pubxml +++ b/Obj2Tiles/Properties/PublishProfiles/osx-x64.pubxml @@ -6,9 +6,9 @@ https://go.microsoft.com/fwlink/?LinkID=208121. Release Any CPU - bin\Release\net8.0\publish\osx-x64\ + bin\Release\net9.0\publish\osx-x64\ FileSystem - net8.0 + net9.0 osx-x64 true True diff --git a/Obj2Tiles/Properties/PublishProfiles/win-arm64.pubxml b/Obj2Tiles/Properties/PublishProfiles/win-arm64.pubxml index 2a83f90..0b693c0 100644 --- a/Obj2Tiles/Properties/PublishProfiles/win-arm64.pubxml +++ b/Obj2Tiles/Properties/PublishProfiles/win-arm64.pubxml @@ -6,9 +6,9 @@ https://go.microsoft.com/fwlink/?LinkID=208121. Release Any CPU - bin\Release\net8.0\publish\win-arm64\ + bin\Release\net9.0\publish\win-arm64\ FileSystem - net8.0 + net9.0 win-arm64 true True diff --git a/Obj2Tiles/Properties/PublishProfiles/win-x64.pubxml b/Obj2Tiles/Properties/PublishProfiles/win-x64.pubxml index c57f837..5e6d7c9 100644 --- a/Obj2Tiles/Properties/PublishProfiles/win-x64.pubxml +++ b/Obj2Tiles/Properties/PublishProfiles/win-x64.pubxml @@ -6,9 +6,9 @@ https://go.microsoft.com/fwlink/?LinkID=208121. Release Any CPU - bin\Release\net8.0\publish\win-x64\ + bin\Release\net9.0\publish\win-x64\ FileSystem - net8.0 + net9.0 win-x64 true True diff --git a/Obj2Tiles/Stages/DecimationStage.cs b/Obj2Tiles/Stages/DecimationStage.cs index 7e7d40e..2cd1992 100644 --- a/Obj2Tiles/Stages/DecimationStage.cs +++ b/Obj2Tiles/Stages/DecimationStage.cs @@ -76,11 +76,7 @@ private static void InternalDecimate(ObjMesh sourceObjMesh, string destPath, flo sourceMesh.SetUVs(0, sourceTexCoords3D); } - var currentTriangleCount = 0; - for (var i = 0; i < sourceSubMeshIndices.Length; i++) - { - currentTriangleCount += sourceSubMeshIndices[i].Length / 3; - } + var currentTriangleCount = sourceSubMeshIndices.Sum(t => t.Length / 3); var targetTriangleCount = (int)Math.Ceiling(currentTriangleCount * quality); Console.WriteLine(" ?> Input: {0} vertices, {1} triangles (target {2})", @@ -124,11 +120,7 @@ private static void InternalDecimate(ObjMesh sourceObjMesh, string destPath, flo destObjMesh.WriteFile(destPath); - var outputTriangleCount = 0; - for (var i = 0; i < destIndices.Length; i++) - { - outputTriangleCount += (destIndices[i].Length / 3); - } + var outputTriangleCount = destIndices.Sum(t => (t.Length / 3)); var reduction = (float)outputTriangleCount / currentTriangleCount; var timeTaken = (float)stopwatch.Elapsed.TotalSeconds; diff --git a/Obj2Tiles/Stages/Model/ObjMesh.cs b/Obj2Tiles/Stages/Model/ObjMesh.cs index 5a8af24..5d2684a 100644 --- a/Obj2Tiles/Stages/Model/ObjMesh.cs +++ b/Obj2Tiles/Stages/Model/ObjMesh.cs @@ -327,7 +327,7 @@ public void ReadFile(string path) if (line.Length == 0 || line[0] == '#') continue; - string[] lineSplit = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + string[] lineSplit = line.Split([' '], StringSplitOptions.RemoveEmptyEntries); string firstPart = lineSplit[0]; if (string.Equals(firstPart, "v")) { diff --git a/Obj2Tiles/Stages/SplitStage.cs b/Obj2Tiles/Stages/SplitStage.cs index 2fa97fa..89756c7 100644 --- a/Obj2Tiles/Stages/SplitStage.cs +++ b/Obj2Tiles/Stages/SplitStage.cs @@ -103,10 +103,8 @@ public static async Task> Split(string sourcePath, stri sw.Restart(); var ms = meshes.ToArray(); - for (var index = 0; index < ms.Length; index++) + foreach (var m in ms) { - var m = ms[index]; - if (m is MeshT t) t.TexturesStrategy = textureStrategy; diff --git a/Obj2Tiles/Stages/TilingStage.cs b/Obj2Tiles/Stages/TilingStage.cs index c0f4731..3b05098 100644 --- a/Obj2Tiles/Stages/TilingStage.cs +++ b/Obj2Tiles/Stages/TilingStage.cs @@ -16,7 +16,7 @@ public static void Tile(string sourcePath, string destPath, int lods, double bas { Console.WriteLine(" ?> Working on objs conversion"); - + ConvertAllB3dm(sourcePath, destPath, lods); Console.WriteLine(" -> Generating tileset.json"); @@ -26,7 +26,7 @@ public static void Tile(string sourcePath, string destPath, int lods, double bas Console.WriteLine(" ?> Using default coordinates"); coords = DefaultGpsCoords; } - + // Don't ask me why 100, I have no idea but it works // https://github.com/CesiumGS/3d-tiles/issues/162 //const int baseError = 100; @@ -40,9 +40,7 @@ public static void Tile(string sourcePath, string destPath, int lods, double bas { GeometricError = baseError, Refine = "ADD", - Transform = coords.ToEcefTransform(), - Children = new List() } }; @@ -54,17 +52,17 @@ public static void Tile(string sourcePath, string destPath, int lods, double bas var minZ = double.MaxValue; var masterDescriptors = boundsMapper[0].Keys; - + foreach (var descriptor in masterDescriptors) { var currentTileElement = tileset.Root; - + var refBox = boundsMapper[0][descriptor]; for (var lod = lods - 1; lod >= 0; lod--) { - var box3 = boundsMapper[lod][descriptor]; - + if (!boundsMapper[lod].TryGetValue(descriptor, out var box3)) continue; + if (box3.Min.X < minX) minX = box3.Min.X; @@ -87,7 +85,6 @@ public static void Tile(string sourcePath, string destPath, int lods, double bas { GeometricError = lod == 0 ? 0 : CalculateGeometricError(refBox, box3, lod), Refine = "REPLACE", - Children = new List(), Content = new Content { Uri = $"LOD-{lod}/{Path.GetFileNameWithoutExtension(descriptor)}.b3dm" @@ -95,6 +92,7 @@ public static void Tile(string sourcePath, string destPath, int lods, double bas BoundingVolume = box3.ToBoundingVolume() }; + currentTileElement.Children ??= []; currentTileElement.Children.Add(tile); currentTileElement = tile; } @@ -115,7 +113,7 @@ private static double CalculateGeometricError(Box3 refBox, Box3 box, int lod) var dW = Math.Abs(refBox.Width - box.Width) / box.Width + 1; var dH = Math.Abs(refBox.Height - box.Height) / box.Height + 1; var dD = Math.Abs(refBox.Depth - box.Depth) / box.Depth + 1; - + return Math.Pow(dW + dH + dD, lod); } @@ -145,7 +143,7 @@ private static void ConvertAllB3dm(string sourcePath, string destPath, int lods) }); } - // Where is it? + // Duomo of Milan private static readonly GpsCoords DefaultGpsCoords = new() { Altitude = 0, diff --git a/Obj2Tiles/Tiles/B3dm.cs b/Obj2Tiles/Tiles/B3dm.cs index ba7dfdd..42bbb01 100644 --- a/Obj2Tiles/Tiles/B3dm.cs +++ b/Obj2Tiles/Tiles/B3dm.cs @@ -10,8 +10,8 @@ public B3dm() FeatureTableJson = string.Empty; BatchTableJson = string.Empty; FeatureTableJson = "{\"BATCH_LENGTH\":0} "; - FeatureTableBinary = Array.Empty(); - BatchTableBinary = Array.Empty(); + FeatureTableBinary = []; + BatchTableBinary = []; } public B3dm(byte[] glb): this() @@ -35,6 +35,9 @@ public byte[] ToBytes() var featureTableBinary = BufferPadding.AddPadding(FeatureTableBinary); var batchTableBinary = BufferPadding.AddPadding(BatchTableBinary); + // Ensure GLB data is padded to 8-byte alignment + GlbData = BufferPadding.AddPadding(GlbData); + B3dmHeader.ByteLength = GlbData.Length + headerLength + featureTableJson.Length + Encoding.UTF8.GetByteCount(batchTableJson) + batchTableBinary.Length + FeatureTableBinary.Length; B3dmHeader.FeatureTableJsonByteLength = featureTableJson.Length; diff --git a/Obj2Tiles/Utils.cs b/Obj2Tiles/Utils.cs index f0e5b64..72c95e6 100644 --- a/Obj2Tiles/Utils.cs +++ b/Obj2Tiles/Utils.cs @@ -18,10 +18,13 @@ public static IEnumerable GetObjDependencies(string objPath) foreach (var line in objFile) { - if (!line.StartsWith("mtllib")) continue; + var trimmedLine = line.Trim(); + + if (!trimmedLine.StartsWith("mtllib")) continue; - var mtlPath = Path.Combine(folderName, line[7..].Trim()); - dependencies.Add(line[7..].Trim()); + var mtlPath = folderName != null ? Path.Combine(folderName, trimmedLine[7..].Trim()) : trimmedLine[7..].Trim(); + + dependencies.Add(trimmedLine[7..].Trim()); dependencies.AddRange(GetMtlDependencies(mtlPath)); } @@ -29,7 +32,7 @@ public static IEnumerable GetObjDependencies(string objPath) return dependencies; } - private static IList GetMtlDependencies(string mtlPath) + private static List GetMtlDependencies(string mtlPath) { var mtlFile = File.ReadAllLines(mtlPath); @@ -42,70 +45,70 @@ private static IList GetMtlDependencies(string mtlPath) if (trimmedLine.StartsWith("map_Kd")) { - dependencies.Add(line[7..].Trim()); + dependencies.Add(trimmedLine[7..].Trim()); continue; } if (trimmedLine.StartsWith("map_Ka")) { - dependencies.Add(line[7..].Trim()); + dependencies.Add(trimmedLine[7..].Trim()); continue; } if (trimmedLine.StartsWith("norm")) { - dependencies.Add(line[5..].Trim()); + dependencies.Add(trimmedLine[5..].Trim()); continue; } if (trimmedLine.StartsWith("map_Ks")) { - dependencies.Add(line[7..].Trim()); + dependencies.Add(trimmedLine[7..].Trim()); continue; } if (trimmedLine.StartsWith("map_Bump")) { - dependencies.Add(line[8..].Trim()); + dependencies.Add(trimmedLine[8..].Trim()); continue; } if (trimmedLine.StartsWith("map_d")) { - dependencies.Add(line[6..].Trim()); + dependencies.Add(trimmedLine[6..].Trim()); continue; } if (trimmedLine.StartsWith("map_Ns")) { - dependencies.Add(line[7..].Trim()); + dependencies.Add(trimmedLine[7..].Trim()); continue; } if (trimmedLine.StartsWith("bump")) { - dependencies.Add(line[5..].Trim()); + dependencies.Add(trimmedLine[5..].Trim()); continue; } if (trimmedLine.StartsWith("disp")) { - dependencies.Add(line[5..].Trim()); + dependencies.Add(trimmedLine[5..].Trim()); continue; } if (trimmedLine.StartsWith("decal")) { - dependencies.Add(line[6..].Trim()); + dependencies.Add(trimmedLine[6..].Trim()); continue; } @@ -175,4 +178,4 @@ public static void ConvertB3dm(string objPath, string destPath) File.WriteAllBytes(destPath, b3dm.ToBytes()); } -} \ No newline at end of file +}