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

Consider remapping uv range [0, 1] to image pixel range [0, w-1] (or [0, h-1]) in MeshT.BinPackTextures #57

Merged
merged 1 commit into from
Dec 13, 2023
Merged
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
6 changes: 3 additions & 3 deletions Obj2Tiles.Library/Geometry/MeshT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@
var texture =!(material.Texture == null) ? TexturesCache.GetTexture(material.Texture) : null;
var normalMap = !(material.NormalMap == null) ? TexturesCache.GetTexture(material.NormalMap) : null;

var textureWidth = !(material.Texture == null) ? texture.Width : normalMap.Width;

Check warning on line 457 in Obj2Tiles.Library/Geometry/MeshT.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 457 in Obj2Tiles.Library/Geometry/MeshT.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
var textureHeight = !(material.Texture == null) ? texture.Height : normalMap.Height;

Check warning on line 458 in Obj2Tiles.Library/Geometry/MeshT.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 458 in Obj2Tiles.Library/Geometry/MeshT.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
var clustersRects = clusters.Select(GetClusterRect).ToArray();

CalculateMaxMinAreaRect(clustersRects, textureWidth, textureHeight, out var maxWidth, out var maxHeight,
Expand Down Expand Up @@ -491,8 +491,8 @@

Debug.WriteLine("Cluster boundary (percentage): " + clusterBoundary);

var clusterX = (int)Math.Floor(clusterBoundary.Left * textureWidth);
var clusterY = (int)Math.Floor(clusterBoundary.Top * textureHeight);
var clusterX = (int)Math.Floor(clusterBoundary.Left * (textureWidth - 1));
var clusterY = (int)Math.Floor(clusterBoundary.Top * (textureHeight - 1));
var clusterWidth = (int)Math.Max(Math.Ceiling(clusterBoundary.Width * textureWidth), 1);
var clusterHeight = (int)Math.Max(Math.Ceiling(clusterBoundary.Height * textureHeight), 1);

Expand All @@ -510,13 +510,13 @@
normalMapFileName = !(material.NormalMap == null) ? $"{Name}-texture-normal-{material.Name}{Path.GetExtension(material.NormalMap)}" : null;
if(!(material.Texture == null))
{
newPathTexture = Path.Combine(targetFolder, textureFileName);

Check warning on line 513 in Obj2Tiles.Library/Geometry/MeshT.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'path2' in 'string Path.Combine(string path1, string path2)'.
newTexture.Save(newPathTexture);

Check warning on line 514 in Obj2Tiles.Library/Geometry/MeshT.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'source' in 'void ImageExtensions.Save(Image source, string path)'.
newTexture.Dispose();
}
if(!(material.NormalMap == null))
{
newPathNormalMap = Path.Combine(targetFolder, normalMapFileName);

Check warning on line 519 in Obj2Tiles.Library/Geometry/MeshT.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'path2' in 'string Path.Combine(string path1, string path2)'.
newNormalMap.Save(newPathNormalMap);
newNormalMap.Dispose();
}
Expand Down Expand Up @@ -1238,4 +1238,4 @@
Compress,
Repack,
RepackCompressed
}
}
Loading