aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/Meshing/SculptMesh.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/Meshing/SculptMesh.cs')
-rw-r--r--OpenSim/Region/Physics/Meshing/SculptMesh.cs149
1 files changed, 84 insertions, 65 deletions
diff --git a/OpenSim/Region/Physics/Meshing/SculptMesh.cs b/OpenSim/Region/Physics/Meshing/SculptMesh.cs
index 4dc6e2e..4a7f3ad 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>();
@@ -318,8 +310,7 @@ namespace PrimMesher
318 sculptType = (SculptType)(((int)sculptType) & 0x07); 310 sculptType = (SculptType)(((int)sculptType) & 0x07);
319 311
320 if (mirror) 312 if (mirror)
321 if (sculptType == SculptType.plane) 313 invert = !invert;
322 invert = !invert;
323 314
324 viewerFaces = new List<ViewerFace>(); 315 viewerFaces = new List<ViewerFace>();
325 316
@@ -331,8 +322,18 @@ namespace PrimMesher
331 322
332 if (sculptType != SculptType.plane) 323 if (sculptType != SculptType.plane)
333 { 324 {
334 for (int rowNdx = 0; rowNdx < rows.Count; rowNdx++) 325 if (rows.Count % 2 == 0)
335 rows[rowNdx].Add(rows[rowNdx][0]); 326 {
327 for (int rowNdx = 0; rowNdx < rows.Count; rowNdx++)
328 rows[rowNdx].Add(rows[rowNdx][0]);
329 }
330 else
331 {
332 int lastIndex = rows[0].Count - 1;
333
334 for (int i = 0; i < rows.Count; i++)
335 rows[i][0] = rows[i][lastIndex];
336 }
336 } 337 }
337 338
338 Coord topPole = rows[0][width / 2]; 339 Coord topPole = rows[0][width / 2];
@@ -340,23 +341,41 @@ namespace PrimMesher
340 341
341 if (sculptType == SculptType.sphere) 342 if (sculptType == SculptType.sphere)
342 { 343 {
343 int count = rows[0].Count; 344 if (rows.Count % 2 == 0)
344 List<Coord> topPoleRow = new List<Coord>(count); 345 {
345 List<Coord> bottomPoleRow = new List<Coord>(count); 346 int count = rows[0].Count;
347 List<Coord> topPoleRow = new List<Coord>(count);
348 List<Coord> bottomPoleRow = new List<Coord>(count);
346 349
347 for (int i = 0; i < count; i++) 350 for (int i = 0; i < count; i++)
351 {
352 topPoleRow.Add(topPole);
353 bottomPoleRow.Add(bottomPole);
354 }
355 rows.Insert(0, topPoleRow);
356 rows.Add(bottomPoleRow);
357 }
358 else
348 { 359 {
349 topPoleRow.Add(topPole); 360 int count = rows[0].Count;
350 bottomPoleRow.Add(bottomPole); 361
362 List<Coord> topPoleRow = rows[0];
363 List<Coord> bottomPoleRow = rows[rows.Count - 1];
364
365 for (int i = 0; i < count; i++)
366 {
367 topPoleRow[i] = topPole;
368 bottomPoleRow[i] = bottomPole;
369 }
351 } 370 }
352 rows.Insert(0, topPoleRow);
353 rows.Add(bottomPoleRow);
354 } 371 }
355 else if (sculptType == SculptType.torus) 372
373 if (sculptType == SculptType.torus)
356 rows.Add(rows[0]); 374 rows.Add(rows[0]);
357 375
358 int coordsDown = rows.Count; 376 int coordsDown = rows.Count;
359 int coordsAcross = rows[0].Count; 377 int coordsAcross = rows[0].Count;
378// int lastColumn = coordsAcross - 1;
360 379
361 float widthUnit = 1.0f / (coordsAcross - 1); 380 float widthUnit = 1.0f / (coordsAcross - 1);
362 float heightUnit = 1.0f / (coordsDown - 1); 381 float heightUnit = 1.0f / (coordsDown - 1);