diff options
Diffstat (limited to 'OpenSim/Region/Physics/Meshing/SculptMesh.cs')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/SculptMesh.cs | 146 |
1 files changed, 83 insertions, 63 deletions
diff --git a/OpenSim/Region/Physics/Meshing/SculptMesh.cs b/OpenSim/Region/Physics/Meshing/SculptMesh.cs index 4dc6e2e..6aa8fe4 100644 --- a/OpenSim/Region/Physics/Meshing/SculptMesh.cs +++ b/OpenSim/Region/Physics/Meshing/SculptMesh.cs | |||
@@ -53,43 +53,6 @@ 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) | ||
57 | // { | ||
58 | // int sourceWidth = srcImage.Width; | ||
59 | // int sourceHeight = srcImage.Height; | ||
60 | // int sourceX = 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); | ||
67 | |||
68 | // if (srcImage.PixelFormat == PixelFormat.Format32bppArgb) | ||
69 | // for (int y = 0; y < srcImage.Height; y++) | ||
70 | // for (int x = 0; x < srcImage.Width; x++) | ||
71 | // { | ||
72 | // Color c = srcImage.GetPixel(x, y); | ||
73 | // srcImage.SetPixel(x, y, Color.FromArgb(255, c.R, c.G, c.B)); | ||
74 | // } | ||
75 | |||
76 | // Bitmap scaledImage = new Bitmap(destWidth, destHeight, | ||
77 | // PixelFormat.Format24bppRgb); | ||
78 | |||
79 | // scaledImage.SetResolution(96.0f, 96.0f); | ||
80 | |||
81 | // Graphics grPhoto = Graphics.FromImage(scaledImage); | ||
82 | // grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low; | ||
83 | |||
84 | // grPhoto.DrawImage(srcImage, | ||
85 | // new Rectangle(destX, destY, destWidth, destHeight), | ||
86 | // new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), | ||
87 | // GraphicsUnit.Pixel); | ||
88 | |||
89 | // grPhoto.Dispose(); | ||
90 | // return scaledImage; | ||
91 | // } | ||
92 | |||
93 | 56 | ||
94 | public SculptMesh SculptMeshFromFile(string fileName, SculptType sculptType, int lod, bool viewerMode) | 57 | public SculptMesh SculptMeshFromFile(string fileName, SculptType sculptType, int lod, bool viewerMode) |
95 | { | 58 | { |
@@ -99,6 +62,7 @@ namespace PrimMesher | |||
99 | return sculptMesh; | 62 | return sculptMesh; |
100 | } | 63 | } |
101 | 64 | ||
65 | |||
102 | public SculptMesh(string fileName, int sculptType, int lod, int viewerMode, int mirror, int invert) | 66 | public SculptMesh(string fileName, int sculptType, int lod, int viewerMode, int mirror, int invert) |
103 | { | 67 | { |
104 | Bitmap bitmap = (Bitmap)Bitmap.FromFile(fileName); | 68 | Bitmap bitmap = (Bitmap)Bitmap.FromFile(fileName); |
@@ -268,6 +232,11 @@ namespace PrimMesher | |||
268 | for (imageY = imageYStart; imageY < imageYEnd; imageY++) | 232 | for (imageY = imageYStart; imageY < imageYEnd; imageY++) |
269 | { | 233 | { |
270 | Color c = bitmap.GetPixel(imageX, imageY); | 234 | Color c = bitmap.GetPixel(imageX, imageY); |
235 | if (c.A != 255) | ||
236 | { | ||
237 | bitmap.SetPixel(imageX, imageY, Color.FromArgb(255, c.R, c.G, c.B)); | ||
238 | c = bitmap.GetPixel(imageX, imageY); | ||
239 | } | ||
271 | rSum += c.R; | 240 | rSum += c.R; |
272 | gSum += c.G; | 241 | gSum += c.G; |
273 | bSum += c.B; | 242 | bSum += c.B; |
@@ -284,30 +253,53 @@ namespace PrimMesher | |||
284 | return rows; | 253 | return rows; |
285 | } | 254 | } |
286 | 255 | ||
287 | 256 | private List<List<Coord>> bitmap2CoordsSampled(Bitmap bitmap, int scale, bool mirror) | |
288 | void _SculptMesh(Bitmap sculptBitmap, SculptType sculptType, int lod, bool viewerMode, bool mirror, bool invert) | ||
289 | { | 257 | { |
290 | coords = new List<Coord>(); | 258 | int numRows = bitmap.Height / scale; |
291 | faces = new List<Face>(); | 259 | int numCols = bitmap.Width / scale; |
292 | normals = new List<Coord>(); | 260 | List<List<Coord>> rows = new List<List<Coord>>(numRows); |
293 | uvs = new List<UVCoord>(); | ||
294 | 261 | ||
295 | sculptType = (SculptType)(((int)sculptType) & 0x07); | 262 | float pixScale = 1.0f / 256.0f; |
296 | 263 | ||
297 | if (mirror) | 264 | int imageX, imageY = 0; |
298 | if (sculptType == SculptType.plane) | 265 | |
299 | invert = !invert; | 266 | int rowNdx, colNdx; |
267 | |||
268 | for (rowNdx = 0; rowNdx <= numRows; rowNdx++) | ||
269 | { | ||
270 | List<Coord> row = new List<Coord>(numCols); | ||
271 | imageY = rowNdx * scale; | ||
272 | if (rowNdx == numRows) imageY--; | ||
273 | for (colNdx = 0; colNdx <= numCols; colNdx++) | ||
274 | { | ||
275 | imageX = colNdx * scale; | ||
276 | if (colNdx == numCols) imageX--; | ||
300 | 277 | ||
301 | float sourceScaleFactor = (float)(lod) / (float)Math.Sqrt(sculptBitmap.Width * sculptBitmap.Height); | 278 | Color c = bitmap.GetPixel(imageX, imageY); |
279 | if (c.A != 255) | ||
280 | { | ||
281 | bitmap.SetPixel(imageX, imageY, Color.FromArgb(255, c.R, c.G, c.B)); | ||
282 | c = bitmap.GetPixel(imageX, imageY); | ||
283 | } | ||
302 | 284 | ||
303 | int scale = (int)(1.0f / sourceScaleFactor); | 285 | if (mirror) |
304 | if (scale < 1) scale = 1; | 286 | row.Add(new Coord(-(c.R * pixScale - 0.5f), c.G * pixScale - 0.5f, c.B * pixScale - 0.5f)); |
287 | else | ||
288 | row.Add(new Coord(c.R * pixScale - 0.5f, c.G * pixScale - 0.5f, c.B * pixScale - 0.5f)); | ||
305 | 289 | ||
306 | _SculptMesh(bitmap2Coords(sculptBitmap, scale, mirror), sculptType, viewerMode, mirror, invert); | 290 | } |
291 | rows.Add(row); | ||
292 | } | ||
293 | return rows; | ||
307 | } | 294 | } |
308 | #endif | ||
309 | 295 | ||
310 | 296 | ||
297 | void _SculptMesh(Bitmap sculptBitmap, SculptType sculptType, int lod, bool viewerMode, bool mirror, bool invert) | ||
298 | { | ||
299 | _SculptMesh(new SculptMap(sculptBitmap, lod).ToRows(mirror), sculptType, viewerMode, mirror, invert); | ||
300 | } | ||
301 | #endif | ||
302 | |||
311 | void _SculptMesh(List<List<Coord>> rows, SculptType sculptType, bool viewerMode, bool mirror, bool invert) | 303 | void _SculptMesh(List<List<Coord>> rows, SculptType sculptType, bool viewerMode, bool mirror, bool invert) |
312 | { | 304 | { |
313 | coords = new List<Coord>(); | 305 | coords = new List<Coord>(); |
@@ -331,8 +323,18 @@ namespace PrimMesher | |||
331 | 323 | ||
332 | if (sculptType != SculptType.plane) | 324 | if (sculptType != SculptType.plane) |
333 | { | 325 | { |
334 | for (int rowNdx = 0; rowNdx < rows.Count; rowNdx++) | 326 | if (rows.Count % 2 == 0) |
335 | rows[rowNdx].Add(rows[rowNdx][0]); | 327 | { |
328 | for (int rowNdx = 0; rowNdx < rows.Count; rowNdx++) | ||
329 | rows[rowNdx].Add(rows[rowNdx][0]); | ||
330 | } | ||
331 | else | ||
332 | { | ||
333 | int lastIndex = rows[0].Count - 1; | ||
334 | |||
335 | for (int i = 0; i < rows.Count; i++) | ||
336 | rows[i][0] = rows[i][lastIndex]; | ||
337 | } | ||
336 | } | 338 | } |
337 | 339 | ||
338 | Coord topPole = rows[0][width / 2]; | 340 | Coord topPole = rows[0][width / 2]; |
@@ -340,23 +342,41 @@ namespace PrimMesher | |||
340 | 342 | ||
341 | if (sculptType == SculptType.sphere) | 343 | if (sculptType == SculptType.sphere) |
342 | { | 344 | { |
343 | int count = rows[0].Count; | 345 | if (rows.Count % 2 == 0) |
344 | List<Coord> topPoleRow = new List<Coord>(count); | 346 | { |
345 | List<Coord> bottomPoleRow = new List<Coord>(count); | 347 | int count = rows[0].Count; |
348 | List<Coord> topPoleRow = new List<Coord>(count); | ||
349 | List<Coord> bottomPoleRow = new List<Coord>(count); | ||
346 | 350 | ||
347 | for (int i = 0; i < count; i++) | 351 | for (int i = 0; i < count; i++) |
352 | { | ||
353 | topPoleRow.Add(topPole); | ||
354 | bottomPoleRow.Add(bottomPole); | ||
355 | } | ||
356 | rows.Insert(0, topPoleRow); | ||
357 | rows.Add(bottomPoleRow); | ||
358 | } | ||
359 | else | ||
348 | { | 360 | { |
349 | topPoleRow.Add(topPole); | 361 | int count = rows[0].Count; |
350 | bottomPoleRow.Add(bottomPole); | 362 | |
363 | List<Coord> topPoleRow = rows[0]; | ||
364 | List<Coord> bottomPoleRow = rows[rows.Count - 1]; | ||
365 | |||
366 | for (int i = 0; i < count; i++) | ||
367 | { | ||
368 | topPoleRow[i] = topPole; | ||
369 | bottomPoleRow[i] = bottomPole; | ||
370 | } | ||
351 | } | 371 | } |
352 | rows.Insert(0, topPoleRow); | ||
353 | rows.Add(bottomPoleRow); | ||
354 | } | 372 | } |
355 | else if (sculptType == SculptType.torus) | 373 | |
374 | if (sculptType == SculptType.torus) | ||
356 | rows.Add(rows[0]); | 375 | rows.Add(rows[0]); |
357 | 376 | ||
358 | int coordsDown = rows.Count; | 377 | int coordsDown = rows.Count; |
359 | int coordsAcross = rows[0].Count; | 378 | int coordsAcross = rows[0].Count; |
379 | int lastColumn = coordsAcross - 1; | ||
360 | 380 | ||
361 | float widthUnit = 1.0f / (coordsAcross - 1); | 381 | float widthUnit = 1.0f / (coordsAcross - 1); |
362 | float heightUnit = 1.0f / (coordsDown - 1); | 382 | float heightUnit = 1.0f / (coordsDown - 1); |