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

Support texture coordinates greater than1 #62

Merged
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.
19 changes: 16 additions & 3 deletions Obj2Tiles.Library/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,30 @@ public static class Common
public static void CopyImage(Image<Rgba32> sourceImage, Image<Rgba32> dest, int sourceX, int sourceY, int sourceWidth, int sourceHeight, int destX, int destY)
{
var height = sourceHeight;

sourceImage.ProcessPixelRows(dest, (sourceAccessor, targetAccessor) =>
{
var shouldCulaSourceAccessorIndex = sourceY + height > sourceAccessor.Height;

for (var i = 0; i < height; i++)
{
var sourceRow = sourceAccessor.GetRowSpan(sourceY + i);
var sourceAccessorIndex = sourceY + i;
if (shouldCulaSourceAccessorIndex && sourceAccessorIndex >= sourceAccessor.Height)
{
sourceAccessorIndex %= sourceAccessor.Height;
}
var sourceRow = sourceAccessor.GetRowSpan(sourceAccessorIndex);
var targetRow = targetAccessor.GetRowSpan(i + destY);

var shouldCulaSourceRowIndex = sourceX + sourceWidth > sourceRow.Length;
for (var x = 0; x < sourceWidth; x++)
{
targetRow[x + destX] = sourceRow[x + sourceX];
var sourceRowIndex = x + sourceX;
if (shouldCulaSourceRowIndex && sourceRowIndex >= sourceRow.Length)
{
sourceRowIndex %= sourceRow.Length;
}
targetRow[x + destX] = sourceRow[sourceRowIndex];//
}
}
});
Expand Down
9 changes: 6 additions & 3 deletions Obj2Tiles.Library/Geometry/MeshT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,12 @@ 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 = !(material.Texture == null)
? Math.Max(texture.Height - (clusterY + clusterHeight), 0)
: Math.Max(normalMap.Height - (clusterY + clusterHeight), 0);
var height = material.Texture != null ? texture.Height : normalMap.Height;
var adjustedSourceY = height - (clusterY + clusterHeight);
if (adjustedSourceY < 0)
{
adjustedSourceY = (int)Math.Ceiling((double)(clusterY + clusterHeight) / (double)height) * height - (clusterY + clusterHeight);
}
var adjustedDestY = Math.Max(edgeLength - (newTextureClusterRect.Y + clusterHeight), 0);

if (!(material.Texture == null))
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 @@ -50,7 +50,7 @@ public static IMesh LoadMesh(string fileName, out string[] dependencies)
double.Parse(segs[1], CultureInfo.InvariantCulture),
double.Parse(segs[2], CultureInfo.InvariantCulture));

if (vtx.X < 0 || vtx.Y < 0 || vtx.X > 1 || vtx.Y > 1)
if (vtx.X < 0 || vtx.Y < 0)
throw new Exception("Invalid texture coordinates: " + vtx);

textureVertices.Add(vtx);
Expand Down
Loading