diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/SculptMap.cs | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/OpenSim/Region/Physics/Meshing/SculptMap.cs b/OpenSim/Region/Physics/Meshing/SculptMap.cs index 740424e..b3d9cb6 100644 --- a/OpenSim/Region/Physics/Meshing/SculptMap.cs +++ b/OpenSim/Region/Physics/Meshing/SculptMap.cs | |||
@@ -58,28 +58,24 @@ namespace PrimMesher | |||
58 | if (bmW == 0 || bmH == 0) | 58 | if (bmW == 0 || bmH == 0) |
59 | throw new Exception("SculptMap: bitmap has no data"); | 59 | throw new Exception("SculptMap: bitmap has no data"); |
60 | 60 | ||
61 | int numLodPixels = lod * 2 * lod * 2; // (32 * 2)^2 = 64^2 pixels for default sculpt map image | 61 | int numLodPixels = lod * lod; // (32 * 2)^2 = 64^2 pixels for default sculpt map image |
62 | 62 | ||
63 | bool smallMap = bmW * bmH <= numLodPixels; | ||
63 | bool needsScaling = false; | 64 | bool needsScaling = false; |
64 | 65 | ||
65 | bool smallMap = bmW * bmH <= lod * lod; | ||
66 | |||
67 | width = bmW; | 66 | width = bmW; |
68 | height = bmH; | 67 | height = bmH; |
69 | while (width * height > numLodPixels) | 68 | while (width * height > numLodPixels * 4) |
70 | { | 69 | { |
71 | width >>= 1; | 70 | width >>= 1; |
72 | height >>= 1; | 71 | height >>= 1; |
73 | needsScaling = true; | 72 | needsScaling = true; |
74 | } | 73 | } |
75 | 74 | ||
76 | |||
77 | |||
78 | try | 75 | try |
79 | { | 76 | { |
80 | if (needsScaling) | 77 | if (needsScaling) |
81 | bm = ScaleImage(bm, width, height, | 78 | bm = ScaleImage(bm, width, height); |
82 | System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor); | ||
83 | } | 79 | } |
84 | 80 | ||
85 | catch (Exception e) | 81 | catch (Exception e) |
@@ -87,7 +83,7 @@ namespace PrimMesher | |||
87 | throw new Exception("Exception in ScaleImage(): e: " + e.ToString()); | 83 | throw new Exception("Exception in ScaleImage(): e: " + e.ToString()); |
88 | } | 84 | } |
89 | 85 | ||
90 | if (width * height > lod * lod) | 86 | if (width * height > numLodPixels) |
91 | { | 87 | { |
92 | width >>= 1; | 88 | width >>= 1; |
93 | height >>= 1; | 89 | height >>= 1; |
@@ -144,15 +140,17 @@ namespace PrimMesher | |||
144 | int rowNdx, colNdx; | 140 | int rowNdx, colNdx; |
145 | int smNdx = 0; | 141 | int smNdx = 0; |
146 | 142 | ||
143 | |||
147 | for (rowNdx = 0; rowNdx < numRows; rowNdx++) | 144 | for (rowNdx = 0; rowNdx < numRows; rowNdx++) |
148 | { | 145 | { |
149 | List<Coord> row = new List<Coord>(numCols); | 146 | List<Coord> row = new List<Coord>(numCols); |
150 | for (colNdx = 0; colNdx < numCols; colNdx++) | 147 | for (colNdx = 0; colNdx < numCols; colNdx++) |
151 | { | 148 | { |
149 | |||
152 | if (mirror) | 150 | if (mirror) |
153 | row.Add(new Coord(-(redBytes[smNdx] * pixScale - 0.5f), (greenBytes[smNdx] * pixScale - 0.5f), blueBytes[smNdx] * pixScale - 0.5f)); | 151 | row.Add(new Coord(-((float)redBytes[smNdx] * pixScale - 0.5f), ((float)greenBytes[smNdx] * pixScale - 0.5f), (float)blueBytes[smNdx] * pixScale - 0.5f)); |
154 | else | 152 | else |
155 | row.Add(new Coord(redBytes[smNdx] * pixScale - 0.5f, greenBytes[smNdx] * pixScale - 0.5f, blueBytes[smNdx] * pixScale - 0.5f)); | 153 | row.Add(new Coord((float)redBytes[smNdx] * pixScale - 0.5f, (float)greenBytes[smNdx] * pixScale - 0.5f, (float)blueBytes[smNdx] * pixScale - 0.5f)); |
156 | 154 | ||
157 | ++smNdx; | 155 | ++smNdx; |
158 | } | 156 | } |
@@ -161,23 +159,39 @@ namespace PrimMesher | |||
161 | return rows; | 159 | return rows; |
162 | } | 160 | } |
163 | 161 | ||
164 | private Bitmap ScaleImage(Bitmap srcImage, int destWidth, int destHeight, | 162 | private Bitmap ScaleImage(Bitmap srcImage, int destWidth, int destHeight) |
165 | System.Drawing.Drawing2D.InterpolationMode interpMode) | ||
166 | { | 163 | { |
167 | Bitmap scaledImage = new Bitmap(srcImage, destWidth, destHeight); | ||
168 | scaledImage.SetResolution(96.0f, 96.0f); | ||
169 | |||
170 | Graphics grPhoto = Graphics.FromImage(scaledImage); | ||
171 | grPhoto.InterpolationMode = interpMode; | ||
172 | 164 | ||
173 | grPhoto.DrawImage(srcImage, | 165 | Bitmap scaledImage = new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb); |
174 | new Rectangle(0, 0, destWidth, destHeight), | 166 | |
175 | new Rectangle(0, 0, srcImage.Width, srcImage.Height), | 167 | Color c; |
176 | GraphicsUnit.Pixel); | 168 | float xscale = srcImage.Width / destWidth; |
169 | float yscale = srcImage.Height / destHeight; | ||
170 | |||
171 | float sy = 0.5f; | ||
172 | for (int y = 0; y < destHeight; y++) | ||
173 | { | ||
174 | float sx = 0.5f; | ||
175 | for (int x = 0; x < destWidth; x++) | ||
176 | { | ||
177 | try | ||
178 | { | ||
179 | c = srcImage.GetPixel((int)(sx), (int)(sy)); | ||
180 | scaledImage.SetPixel(x, y, Color.FromArgb(c.R, c.G, c.B)); | ||
181 | } | ||
182 | catch (IndexOutOfRangeException) | ||
183 | { | ||
184 | } | ||
177 | 185 | ||
178 | grPhoto.Dispose(); | 186 | sx += xscale; |
187 | } | ||
188 | sy += yscale; | ||
189 | } | ||
190 | srcImage.Dispose(); | ||
179 | return scaledImage; | 191 | return scaledImage; |
180 | } | 192 | } |
193 | |||
194 | } | ||
195 | |||
181 | } | 196 | } |
182 | } | ||
183 | #endif | 197 | #endif |