diff --git a/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs b/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs index 88efd6d526..3b1bdfb633 100644 --- a/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs @@ -314,6 +314,9 @@ namespace OpenSim.Region.Physics.Meshing coords[f.v3].X, coords[f.v3].Y, coords[f.v3].Z)); } + coords.Clear(); + faces.Clear(); + return mesh; } diff --git a/OpenSim/Region/Physics/UbitMeshing/SculptMap.cs b/OpenSim/Region/Physics/UbitMeshing/SculptMap.cs index 054caf36cb..1c75db67c5 100644 --- a/OpenSim/Region/Physics/UbitMeshing/SculptMap.cs +++ b/OpenSim/Region/Physics/UbitMeshing/SculptMap.cs @@ -56,11 +56,12 @@ namespace PrimMesher int numLodPixels = lod * lod; // (32 * 2)^2 = 64^2 pixels for default sculpt map image - bool smallMap = bmW * bmH <= numLodPixels; bool needsScaling = false; + bool smallMap = false; width = bmW; height = bmH; + while (width * height > numLodPixels * 4) { width >>= 1; @@ -81,9 +82,12 @@ namespace PrimMesher if (width * height > numLodPixels) { + smallMap = false; width >>= 1; height >>= 1; } + else + smallMap = true; int numBytes = (width + 1) * (height + 1); redBytes = new byte[numBytes]; @@ -91,21 +95,18 @@ namespace PrimMesher blueBytes = new byte[numBytes]; int byteNdx = 0; + Color c; try { for (int y = 0; y <= height; y++) { - for (int x = 0; x <= width; x++) + for (int x = 0; x < width; x++) { - Color c; - if (smallMap) - c = bm.GetPixel(x < width ? x : x - 1, - y < height ? y : y - 1); + c = bm.GetPixel(x, y < height ? y : y - 1); else - c = bm.GetPixel(x < width ? x * 2 : x * 2 - 1, - y < height ? y * 2 : y * 2 - 1); + c = bm.GetPixel(x * 2, y < height ? y * 2 : y * 2 - 1); redBytes[byteNdx] = c.R; greenBytes[byteNdx] = c.G; @@ -113,6 +114,17 @@ namespace PrimMesher ++byteNdx; } + + if (smallMap) + c = bm.GetPixel(width - 1, y < height ? y : y - 1); + else + c = bm.GetPixel(width * 2 - 1, y < height ? y * 2 : y * 2 - 1); + + redBytes[byteNdx] = c.R; + greenBytes[byteNdx] = c.G; + blueBytes[byteNdx] = c.B; + + ++byteNdx; } } catch (Exception e) @@ -160,14 +172,25 @@ namespace PrimMesher Bitmap scaledImage = new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb); Color c; - float xscale = srcImage.Width / destWidth; - float yscale = srcImage.Height / destHeight; + + + // will let last step to be eventually diferent, as seems to be in sl + + float xscale = (float)srcImage.Width / (float)destWidth; + float yscale = (float)srcImage.Height / (float)destHeight; + + int lastsx = srcImage.Width - 1; + int lastsy = srcImage.Height - 1; + int lastdx = destWidth - 1; + int lastdy = destHeight - 1; float sy = 0.5f; - for (int y = 0; y < destHeight; y++) + float sx; + + for (int y = 0; y < lastdy; y++) { - float sx = 0.5f; - for (int x = 0; x < destWidth; x++) + sx = 0.5f; + for (int x = 0; x < lastdx; x++) { try { @@ -177,11 +200,43 @@ namespace PrimMesher catch (IndexOutOfRangeException) { } - sx += xscale; } + try + { + c = srcImage.GetPixel(lastsx, (int)(sy)); + scaledImage.SetPixel(lastdx, y, Color.FromArgb(c.R, c.G, c.B)); + } + catch (IndexOutOfRangeException) + { + } + sy += yscale; } + + sx = 0.5f; + for (int x = 0; x < lastdx; x++) + { + try + { + c = srcImage.GetPixel((int)(sx), lastsy); + scaledImage.SetPixel(x, lastdy, Color.FromArgb(c.R, c.G, c.B)); + } + catch (IndexOutOfRangeException) + { + } + + sx += xscale; + } + try + { + c = srcImage.GetPixel(lastsx, lastsy); + scaledImage.SetPixel(lastdx, lastdy, Color.FromArgb(c.R, c.G, c.B)); + } + catch (IndexOutOfRangeException) + { + } + srcImage.Dispose(); return scaledImage; } diff --git a/OpenSim/Region/Physics/UbitMeshing/SculptMesh.cs b/OpenSim/Region/Physics/UbitMeshing/SculptMesh.cs index 655b3258a3..bc1375bda7 100644 --- a/OpenSim/Region/Physics/UbitMeshing/SculptMesh.cs +++ b/OpenSim/Region/Physics/UbitMeshing/SculptMesh.cs @@ -48,7 +48,12 @@ namespace PrimMesher { if (mirror) invert = !invert; - _SculptMesh(new SculptMap(sculptBitmap, lod).ToRows(mirror), sculptType, invert); + + SculptMap smap = new SculptMap(sculptBitmap, lod); + + List> rows = smap.ToRows(mirror); + + _SculptMesh(rows, sculptType, invert); } private void _SculptMesh(List> rows, SculptType sculptType, bool invert)