diff --git a/Obj2Tiles.Library/Geometry/MeshT.cs b/Obj2Tiles.Library/Geometry/MeshT.cs index 9d697bf..97806f3 100644 --- a/Obj2Tiles.Library/Geometry/MeshT.cs +++ b/Obj2Tiles.Library/Geometry/MeshT.cs @@ -431,13 +431,17 @@ private void TrimTextures(string targetFolder) private void LoadTexturesCache() { - Parallel.ForEach(_materials, material => TexturesCache.GetTexture(material.Texture)); + Parallel.ForEach(_materials, material => + { + if (!string.IsNullOrEmpty(material.Texture)) + TexturesCache.GetTexture(material.Texture); + }); } private static readonly JpegEncoder encoder = new JpegEncoder { Quality = 75 }; private void BinPackTextures(string targetFolder, int materialIndex, IReadOnlyList> clusters, - IDictionary newTextureVertices, List tasks) + IDictionary newTextureVertices, ICollection tasks) { var material = _materials[materialIndex]; @@ -528,8 +532,8 @@ private void BinPackTextures(string targetFolder, int materialIndex, IReadOnlyLi Debug.WriteLine("Found place for cluster at " + newTextureClusterRect); // Too long to explain this here, but it works - var adjustedSourceY = texture.Height - (clusterY + clusterHeight); - var adjustedDestY = edgeLength - (newTextureClusterRect.Y + clusterHeight); + var adjustedSourceY = Math.Max(texture.Height - (clusterY + clusterHeight), 0); + var adjustedDestY = Math.Max(edgeLength - (newTextureClusterRect.Y + clusterHeight), 0); Common.CopyImage(texture, newTexture, clusterX, adjustedSourceY, clusterWidth, clusterHeight, newTextureClusterRect.X, adjustedDestY); @@ -1093,7 +1097,7 @@ into g File.Delete(newTexturePath); Console.WriteLine($" -> Compressing texture '{material.Texture}'"); - + using (var image = Image.Load(material.Texture)) { image.SaveAsJpeg(newTexturePath, encoder); diff --git a/Obj2Tiles.Library/Geometry/MeshUtils.cs b/Obj2Tiles.Library/Geometry/MeshUtils.cs index 0197b7c..d4ac4e5 100644 --- a/Obj2Tiles.Library/Geometry/MeshUtils.cs +++ b/Obj2Tiles.Library/Geometry/MeshUtils.cs @@ -34,7 +34,7 @@ public static IMesh LoadMesh(string fileName, out string[] dependencies) if (string.IsNullOrWhiteSpace(line) || line.StartsWith("#")) continue; - var segs = line.Split(' '); + var segs = line.Split(' ', StringSplitOptions.RemoveEmptyEntries); switch (segs[0]) { diff --git a/Obj2Tiles.Library/Materials/Material.cs b/Obj2Tiles.Library/Materials/Material.cs index 246dfe0..64d5286 100644 --- a/Obj2Tiles.Library/Materials/Material.cs +++ b/Obj2Tiles.Library/Materials/Material.cs @@ -56,7 +56,7 @@ public static Material[] ReadMtl(string path, out string[] dependencies) var materials = new List(); var deps = new List(); - var texture = string.Empty; + string texture = null; var name = string.Empty; RGB? ambientColor = null, diffuseColor = null, specularColor = null; double? specularExponent = null, dissolve = null; diff --git a/Obj2Tiles/Obj2Tiles.csproj b/Obj2Tiles/Obj2Tiles.csproj index e4034d8..2257cb4 100644 --- a/Obj2Tiles/Obj2Tiles.csproj +++ b/Obj2Tiles/Obj2Tiles.csproj @@ -6,8 +6,8 @@ enable enable false - 1.0.7 - 1.0.7 + 1.0.8 + 1.0.8 true diff --git a/Obj2Tiles/Program.cs b/Obj2Tiles/Program.cs index 2cef17e..57a51dc 100644 --- a/Obj2Tiles/Program.cs +++ b/Obj2Tiles/Program.cs @@ -32,6 +32,9 @@ private static async Task Run(Options opts) if (!CheckOptions(opts)) return; + opts.Output = Path.GetFullPath(opts.Output); + opts.Input = Path.GetFullPath(opts.Input); + Directory.CreateDirectory(opts.Output); var pipelineId = Guid.NewGuid().ToString(); diff --git a/README.md b/README.md index 7eadf46..326af25 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ ![license](https://img.shields.io/github/license/HeDo88TH/Obj2Tiles) ![commits](https://img.shields.io/github/commit-activity/m/HeDo88TH/Obj2Tiles) ![languages](https://img.shields.io/github/languages/top/HeDo88TH/Obj2Tiles) -[![Build & Test](https://github.com/HeDo88TH/Obj2Tiles/actions/workflows/build-test.yml/badge.svg)](https://github.com/HeDo88TH/Obj2Tiles/actions/workflows/build-test.yml) +[![Build & Test](https://github.com/OpenDroneMap/Obj2Tiles/actions/workflows/build-test.yml/badge.svg)](https://github.com/OpenDroneMap/Obj2Tiles/actions/workflows/build-test.yml) +[![Publish](https://github.com/OpenDroneMap/Obj2Tiles/actions/workflows/publish.yml/badge.svg)](https://github.com/OpenDroneMap/Obj2Tiles/actions/workflows/publish.yml) Obj2Tiles is a fully fledged tool to convert OBJ files to 3D Tiles format. It creates multiple LODs, splits the mesh and repacks the textures.