improve handling of undersize sculpt textures

slimupdates2
dahlia 2010-05-06 23:02:24 -07:00
parent 39c5ddc837
commit eb6d63ab8e
1 changed files with 11 additions and 4 deletions

View File

@ -60,21 +60,23 @@ namespace PrimMesher
int numLodPixels = lod * 2 * lod * 2; // (32 * 2)^2 = 64^2 pixels for default sculpt map image int numLodPixels = lod * 2 * lod * 2; // (32 * 2)^2 = 64^2 pixels for default sculpt map image
bool needsScaling = false;
width = bmW; width = bmW;
height = bmH; height = bmH;
while (width * height > numLodPixels) while (width * height > numLodPixels)
{ {
width >>= 1; width >>= 1;
height >>= 1; height >>= 1;
needsScaling = true;
} }
width >>= 1;
height >>= 1;
try try
{ {
if (!(bmW == width * 2 && bmH == height * 2)) if (needsScaling)
bm = ScaleImage(bm, width * 2, height * 2, bm = ScaleImage(bm, width, height,
System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor); System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor);
} }
@ -83,6 +85,11 @@ namespace PrimMesher
throw new Exception("Exception in ScaleImage(): e: " + e.ToString()); throw new Exception("Exception in ScaleImage(): e: " + e.ToString());
} }
if (width * height > lod * lod)
{
width >>= 1;
height >>= 1;
}
int numBytes = (width + 1) * (height + 1); int numBytes = (width + 1) * (height + 1);
redBytes = new byte[numBytes]; redBytes = new byte[numBytes];