Skip to content

Commit

Permalink
Texture tiling fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NanoBob committed Feb 27, 2023
1 parent 50de78d commit ffe2441
Showing 1 changed file with 6 additions and 45 deletions.
51 changes: 6 additions & 45 deletions RenderWarePreviewer/Helpers/MeshHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ public static DiffuseMaterial GetMaterial(SixLabors.ImageSharp.Image<Rgba32>? im
};
if (image != null)
{
material.Brush = new ImageBrush(GetBitMap(image));
material.Brush = new ImageBrush(GetBitMap(image))
{
TileMode = TileMode.Tile,
ViewportUnits = BrushMappingMode.Absolute
};
}
else
{
Expand Down Expand Up @@ -139,54 +143,11 @@ public static MeshGeometry3D GetMesh(RenderWareIo.Structs.Dff.Geometry geometry,

foreach (var uv in geometry.TexCoords)
{
mesh.TextureCoordinates.Add(SanitzeUv(uv));
mesh.TextureCoordinates.Add(new Point(uv.X, uv.Y));
}
return mesh;
}

private static Point SanitzeUv(Uv uv)
{
//return new Point(uv.X, uv.Y);
//return new Point((uv.X + 100f) % 1, (uv.Y + 100) % 1f);
//return new Point(
// uv.X < 0 ? uv.X + MathF.Round(MathF.Abs(uv.X) + 0.5f) :
// uv.X > 1 ? uv.X % 1f :
// uv.X,
// uv.Y < 0 ? uv.Y + MathF.Round(MathF.Abs(uv.Y) + 0.5f) :
// uv.Y > 1 ? uv.Y % 1f :
// uv.Y
//);

//return new Point(
// uv.X < -1 ? -(MathF.Abs(uv.X) % 1f) + MathF.Round(MathF.Abs(-(MathF.Abs(uv.X) % 1f)) + 0.5f) :
// uv.X < 0 ? uv.X + MathF.Round(MathF.Abs(uv.X) + 0.5f) :
// uv.X > 1 ? uv.X % 1f :
// uv.X,
// uv.Y < -1 ? -(MathF.Abs(uv.Y) % 1f) + MathF.Round(MathF.Abs(-(MathF.Abs(uv.Y) % 1f)) + 0.5f) :
// uv.Y < 0 ? uv.Y + MathF.Round(MathF.Abs(uv.Y) + 0.5f) :
// uv.Y > 1 ? uv.Y % 1f :
// uv.Y
//);


if (uv.X < -1)
uv.X = -(MathF.Abs(uv.X) % 1f);
if (uv.Y < -1)
uv.Y = -(MathF.Abs(uv.Y) % 1f);

if (uv.X < 0)
uv.X = (uv.X + 100);
if (uv.Y < 0)
uv.Y = (uv.Y + 100);

if (uv.X > 1)
uv.X = uv.X % 1.0f;
if (uv.Y > 1)
uv.Y = uv.Y % 1.0f;

return new Point(uv.X, uv.Y);
}

private static BitmapSource GetBitMap(SixLabors.ImageSharp.Image<Rgba32> image)
{
Rgba32[] rgbaArray = new Rgba32[image.Width * image.Height];
Expand Down

0 comments on commit ffe2441

Please sign in to comment.