diff options
Diffstat (limited to 'OpenSim/Region/Physics/Meshing/SculptMesh.cs')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/SculptMesh.cs | 84 |
1 files changed, 51 insertions, 33 deletions
diff --git a/OpenSim/Region/Physics/Meshing/SculptMesh.cs b/OpenSim/Region/Physics/Meshing/SculptMesh.cs index 4dc6e2e..ebc5be6 100644 --- a/OpenSim/Region/Physics/Meshing/SculptMesh.cs +++ b/OpenSim/Region/Physics/Meshing/SculptMesh.cs | |||
@@ -53,42 +53,49 @@ namespace PrimMesher | |||
53 | public enum SculptType { sphere = 1, torus = 2, plane = 3, cylinder = 4 }; | 53 | public enum SculptType { sphere = 1, torus = 2, plane = 3, cylinder = 4 }; |
54 | 54 | ||
55 | #if SYSTEM_DRAWING | 55 | #if SYSTEM_DRAWING |
56 | // private Bitmap ScaleImage(Bitmap srcImage, float scale) | 56 | private Bitmap ScaleImage(Bitmap srcImage, float scale, bool removeAlpha) |
57 | // { | 57 | { |
58 | // int sourceWidth = srcImage.Width; | 58 | int sourceWidth = srcImage.Width; |
59 | // int sourceHeight = srcImage.Height; | 59 | int sourceHeight = srcImage.Height; |
60 | // int sourceX = 0; | 60 | int sourceX = 0; |
61 | // int sourceY = 0; | 61 | int sourceY = 0; |
62 | |||
63 | int destX = 0; | ||
64 | int destY = 0; | ||
65 | int destWidth = (int)(srcImage.Width * scale); | ||
66 | int destHeight = (int)(srcImage.Height * scale); | ||
62 | 67 | ||
63 | // int destX = 0; | 68 | Bitmap scaledImage; |
64 | // int destY = 0; | ||
65 | // int destWidth = (int)(srcImage.Width * scale); | ||
66 | // int destHeight = (int)(srcImage.Height * scale); | ||
67 | 69 | ||
68 | // if (srcImage.PixelFormat == PixelFormat.Format32bppArgb) | 70 | if (removeAlpha) |
69 | // for (int y = 0; y < srcImage.Height; y++) | 71 | { |
70 | // for (int x = 0; x < srcImage.Width; x++) | 72 | if (srcImage.PixelFormat == PixelFormat.Format32bppArgb) |
71 | // { | 73 | for (int y = 0; y < srcImage.Height; y++) |
72 | // Color c = srcImage.GetPixel(x, y); | 74 | for (int x = 0; x < srcImage.Width; x++) |
73 | // srcImage.SetPixel(x, y, Color.FromArgb(255, c.R, c.G, c.B)); | 75 | { |
74 | // } | 76 | Color c = srcImage.GetPixel(x, y); |
77 | srcImage.SetPixel(x, y, Color.FromArgb(255, c.R, c.G, c.B)); | ||
78 | } | ||
75 | 79 | ||
76 | // Bitmap scaledImage = new Bitmap(destWidth, destHeight, | 80 | scaledImage = new Bitmap(destWidth, destHeight, |
77 | // PixelFormat.Format24bppRgb); | 81 | PixelFormat.Format24bppRgb); |
82 | } | ||
83 | else | ||
84 | scaledImage = new Bitmap(srcImage, destWidth, destHeight); | ||
78 | 85 | ||
79 | // scaledImage.SetResolution(96.0f, 96.0f); | 86 | scaledImage.SetResolution(96.0f, 96.0f); |
80 | 87 | ||
81 | // Graphics grPhoto = Graphics.FromImage(scaledImage); | 88 | Graphics grPhoto = Graphics.FromImage(scaledImage); |
82 | // grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low; | 89 | grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low; |
83 | 90 | ||
84 | // grPhoto.DrawImage(srcImage, | 91 | grPhoto.DrawImage(srcImage, |
85 | // new Rectangle(destX, destY, destWidth, destHeight), | 92 | new Rectangle(destX, destY, destWidth, destHeight), |
86 | // new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), | 93 | new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), |
87 | // GraphicsUnit.Pixel); | 94 | GraphicsUnit.Pixel); |
88 | 95 | ||
89 | // grPhoto.Dispose(); | 96 | grPhoto.Dispose(); |
90 | // return scaledImage; | 97 | return scaledImage; |
91 | // } | 98 | } |
92 | 99 | ||
93 | 100 | ||
94 | public SculptMesh SculptMeshFromFile(string fileName, SculptType sculptType, int lod, bool viewerMode) | 101 | public SculptMesh SculptMeshFromFile(string fileName, SculptType sculptType, int lod, bool viewerMode) |
@@ -268,6 +275,11 @@ namespace PrimMesher | |||
268 | for (imageY = imageYStart; imageY < imageYEnd; imageY++) | 275 | for (imageY = imageYStart; imageY < imageYEnd; imageY++) |
269 | { | 276 | { |
270 | Color c = bitmap.GetPixel(imageX, imageY); | 277 | Color c = bitmap.GetPixel(imageX, imageY); |
278 | if (c.A != 255) | ||
279 | { | ||
280 | bitmap.SetPixel(imageX, imageY, Color.FromArgb(255, c.R, c.G, c.B)); | ||
281 | c = bitmap.GetPixel(imageX, imageY); | ||
282 | } | ||
271 | rSum += c.R; | 283 | rSum += c.R; |
272 | gSum += c.G; | 284 | gSum += c.G; |
273 | bSum += c.B; | 285 | bSum += c.B; |
@@ -298,12 +310,18 @@ namespace PrimMesher | |||
298 | if (sculptType == SculptType.plane) | 310 | if (sculptType == SculptType.plane) |
299 | invert = !invert; | 311 | invert = !invert; |
300 | 312 | ||
301 | float sourceScaleFactor = (float)(lod) / (float)Math.Sqrt(sculptBitmap.Width * sculptBitmap.Height); | 313 | float sculptBitmapLod = (float)Math.Sqrt(sculptBitmap.Width * sculptBitmap.Height); |
314 | |||
315 | float sourceScaleFactor = (float)(lod) / sculptBitmapLod; | ||
302 | 316 | ||
303 | int scale = (int)(1.0f / sourceScaleFactor); | 317 | float fScale = 1.0f / sourceScaleFactor; |
304 | if (scale < 1) scale = 1; | ||
305 | 318 | ||
306 | _SculptMesh(bitmap2Coords(sculptBitmap, scale, mirror), sculptType, viewerMode, mirror, invert); | 319 | int iScale = (int)fScale; |
320 | if (iScale < 1) iScale = 1; | ||
321 | if (iScale > 2 && iScale % 2 == 0) | ||
322 | _SculptMesh(bitmap2Coords(ScaleImage(sculptBitmap, 64.0f / sculptBitmapLod, true), 64 / lod, mirror), sculptType, viewerMode, mirror, invert); | ||
323 | else | ||
324 | _SculptMesh(bitmap2Coords(sculptBitmap, iScale, mirror), sculptType, viewerMode, mirror, invert); | ||
307 | } | 325 | } |
308 | #endif | 326 | #endif |
309 | 327 | ||