Skip to content

Commit

Permalink
Merge pull request #13 from HeDo88TH/master
Browse files Browse the repository at this point in the history
Various fixes and improvements
  • Loading branch information
HeDo88TH authored Jul 19, 2022
2 parents a190bb8 + 4c86477 commit 1f6c065
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
14 changes: 9 additions & 5 deletions Obj2Tiles.Library/Geometry/MeshT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<int>> clusters,
IDictionary<Vertex2, int> newTextureVertices, List<Task> tasks)
IDictionary<Vertex2, int> newTextureVertices, ICollection<Task> tasks)
{
var material = _materials[materialIndex];

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Obj2Tiles.Library/Geometry/MeshUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
{
Expand Down
2 changes: 1 addition & 1 deletion Obj2Tiles.Library/Materials/Material.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static Material[] ReadMtl(string path, out string[] dependencies)
var materials = new List<Material>();
var deps = new List<string>();

var texture = string.Empty;
string texture = null;
var name = string.Empty;
RGB? ambientColor = null, diffuseColor = null, specularColor = null;
double? specularExponent = null, dissolve = null;
Expand Down
4 changes: 2 additions & 2 deletions Obj2Tiles/Obj2Tiles.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<AssemblyVersion>1.0.7</AssemblyVersion>
<FileVersion>1.0.7</FileVersion>
<AssemblyVersion>1.0.8</AssemblyVersion>
<FileVersion>1.0.8</FileVersion>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>

Expand Down
3 changes: 3 additions & 0 deletions Obj2Tiles/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1f6c065

Please sign in to comment.