some improvements to sculptmap alpha handling and LOD
parent
4b81393274
commit
1d14cf8c3f
|
@ -53,42 +53,49 @@ namespace PrimMesher
|
||||||
public enum SculptType { sphere = 1, torus = 2, plane = 3, cylinder = 4 };
|
public enum SculptType { sphere = 1, torus = 2, plane = 3, cylinder = 4 };
|
||||||
|
|
||||||
#if SYSTEM_DRAWING
|
#if SYSTEM_DRAWING
|
||||||
// private Bitmap ScaleImage(Bitmap srcImage, float scale)
|
private Bitmap ScaleImage(Bitmap srcImage, float scale, bool removeAlpha)
|
||||||
// {
|
{
|
||||||
// int sourceWidth = srcImage.Width;
|
int sourceWidth = srcImage.Width;
|
||||||
// int sourceHeight = srcImage.Height;
|
int sourceHeight = srcImage.Height;
|
||||||
// int sourceX = 0;
|
int sourceX = 0;
|
||||||
// int sourceY = 0;
|
int sourceY = 0;
|
||||||
|
|
||||||
// int destX = 0;
|
int destX = 0;
|
||||||
// int destY = 0;
|
int destY = 0;
|
||||||
// int destWidth = (int)(srcImage.Width * scale);
|
int destWidth = (int)(srcImage.Width * scale);
|
||||||
// int destHeight = (int)(srcImage.Height * scale);
|
int destHeight = (int)(srcImage.Height * scale);
|
||||||
|
|
||||||
// if (srcImage.PixelFormat == PixelFormat.Format32bppArgb)
|
Bitmap scaledImage;
|
||||||
// for (int y = 0; y < srcImage.Height; y++)
|
|
||||||
// for (int x = 0; x < srcImage.Width; x++)
|
|
||||||
// {
|
|
||||||
// Color c = srcImage.GetPixel(x, y);
|
|
||||||
// srcImage.SetPixel(x, y, Color.FromArgb(255, c.R, c.G, c.B));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Bitmap scaledImage = new Bitmap(destWidth, destHeight,
|
if (removeAlpha)
|
||||||
// PixelFormat.Format24bppRgb);
|
{
|
||||||
|
if (srcImage.PixelFormat == PixelFormat.Format32bppArgb)
|
||||||
|
for (int y = 0; y < srcImage.Height; y++)
|
||||||
|
for (int x = 0; x < srcImage.Width; x++)
|
||||||
|
{
|
||||||
|
Color c = srcImage.GetPixel(x, y);
|
||||||
|
srcImage.SetPixel(x, y, Color.FromArgb(255, c.R, c.G, c.B));
|
||||||
|
}
|
||||||
|
|
||||||
// scaledImage.SetResolution(96.0f, 96.0f);
|
scaledImage = new Bitmap(destWidth, destHeight,
|
||||||
|
PixelFormat.Format24bppRgb);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
scaledImage = new Bitmap(srcImage, destWidth, destHeight);
|
||||||
|
|
||||||
// Graphics grPhoto = Graphics.FromImage(scaledImage);
|
scaledImage.SetResolution(96.0f, 96.0f);
|
||||||
// grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;
|
|
||||||
|
|
||||||
// grPhoto.DrawImage(srcImage,
|
Graphics grPhoto = Graphics.FromImage(scaledImage);
|
||||||
// new Rectangle(destX, destY, destWidth, destHeight),
|
grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;
|
||||||
// new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
|
|
||||||
// GraphicsUnit.Pixel);
|
|
||||||
|
|
||||||
// grPhoto.Dispose();
|
grPhoto.DrawImage(srcImage,
|
||||||
// return scaledImage;
|
new Rectangle(destX, destY, destWidth, destHeight),
|
||||||
// }
|
new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
|
||||||
|
GraphicsUnit.Pixel);
|
||||||
|
|
||||||
|
grPhoto.Dispose();
|
||||||
|
return scaledImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public SculptMesh SculptMeshFromFile(string fileName, SculptType sculptType, int lod, bool viewerMode)
|
public SculptMesh SculptMeshFromFile(string fileName, SculptType sculptType, int lod, bool viewerMode)
|
||||||
|
@ -268,6 +275,11 @@ namespace PrimMesher
|
||||||
for (imageY = imageYStart; imageY < imageYEnd; imageY++)
|
for (imageY = imageYStart; imageY < imageYEnd; imageY++)
|
||||||
{
|
{
|
||||||
Color c = bitmap.GetPixel(imageX, imageY);
|
Color c = bitmap.GetPixel(imageX, imageY);
|
||||||
|
if (c.A != 255)
|
||||||
|
{
|
||||||
|
bitmap.SetPixel(imageX, imageY, Color.FromArgb(255, c.R, c.G, c.B));
|
||||||
|
c = bitmap.GetPixel(imageX, imageY);
|
||||||
|
}
|
||||||
rSum += c.R;
|
rSum += c.R;
|
||||||
gSum += c.G;
|
gSum += c.G;
|
||||||
bSum += c.B;
|
bSum += c.B;
|
||||||
|
@ -298,12 +310,18 @@ namespace PrimMesher
|
||||||
if (sculptType == SculptType.plane)
|
if (sculptType == SculptType.plane)
|
||||||
invert = !invert;
|
invert = !invert;
|
||||||
|
|
||||||
float sourceScaleFactor = (float)(lod) / (float)Math.Sqrt(sculptBitmap.Width * sculptBitmap.Height);
|
float sculptBitmapLod = (float)Math.Sqrt(sculptBitmap.Width * sculptBitmap.Height);
|
||||||
|
|
||||||
int scale = (int)(1.0f / sourceScaleFactor);
|
float sourceScaleFactor = (float)(lod) / sculptBitmapLod;
|
||||||
if (scale < 1) scale = 1;
|
|
||||||
|
|
||||||
_SculptMesh(bitmap2Coords(sculptBitmap, scale, mirror), sculptType, viewerMode, mirror, invert);
|
float fScale = 1.0f / sourceScaleFactor;
|
||||||
|
|
||||||
|
int iScale = (int)fScale;
|
||||||
|
if (iScale < 1) iScale = 1;
|
||||||
|
if (iScale > 2 && iScale % 2 == 0)
|
||||||
|
_SculptMesh(bitmap2Coords(ScaleImage(sculptBitmap, 64.0f / sculptBitmapLod, true), 64 / lod, mirror), sculptType, viewerMode, mirror, invert);
|
||||||
|
else
|
||||||
|
_SculptMesh(bitmap2Coords(sculptBitmap, iScale, mirror), sculptType, viewerMode, mirror, invert);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue