diff options
Diffstat (limited to 'OpenSim/Region/Physics/Meshing/SculptMesh.cs')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/SculptMesh.cs | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/OpenSim/Region/Physics/Meshing/SculptMesh.cs b/OpenSim/Region/Physics/Meshing/SculptMesh.cs index f1dd586..4dc6e2e 100644 --- a/OpenSim/Region/Physics/Meshing/SculptMesh.cs +++ b/OpenSim/Region/Physics/Meshing/SculptMesh.cs | |||
@@ -25,12 +25,18 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | // to build without references to System.Drawing, comment this out | ||
29 | #define SYSTEM_DRAWING | ||
30 | |||
28 | using System; | 31 | using System; |
29 | using System.Collections.Generic; | 32 | using System.Collections.Generic; |
30 | using System.Text; | 33 | using System.Text; |
31 | using System.IO; | 34 | using System.IO; |
35 | |||
36 | #if SYSTEM_DRAWING | ||
32 | using System.Drawing; | 37 | using System.Drawing; |
33 | using System.Drawing.Imaging; | 38 | using System.Drawing.Imaging; |
39 | #endif | ||
34 | 40 | ||
35 | namespace PrimMesher | 41 | namespace PrimMesher |
36 | { | 42 | { |
@@ -46,6 +52,7 @@ namespace PrimMesher | |||
46 | 52 | ||
47 | public enum SculptType { sphere = 1, torus = 2, plane = 3, cylinder = 4 }; | 53 | public enum SculptType { sphere = 1, torus = 2, plane = 3, cylinder = 4 }; |
48 | 54 | ||
55 | #if SYSTEM_DRAWING | ||
49 | // private Bitmap ScaleImage(Bitmap srcImage, float scale) | 56 | // private Bitmap ScaleImage(Bitmap srcImage, float scale) |
50 | // { | 57 | // { |
51 | // int sourceWidth = srcImage.Width; | 58 | // int sourceWidth = srcImage.Width; |
@@ -83,6 +90,7 @@ namespace PrimMesher | |||
83 | // return scaledImage; | 90 | // return scaledImage; |
84 | // } | 91 | // } |
85 | 92 | ||
93 | |||
86 | public SculptMesh SculptMeshFromFile(string fileName, SculptType sculptType, int lod, bool viewerMode) | 94 | public SculptMesh SculptMeshFromFile(string fileName, SculptType sculptType, int lod, bool viewerMode) |
87 | { | 95 | { |
88 | Bitmap bitmap = (Bitmap)Bitmap.FromFile(fileName); | 96 | Bitmap bitmap = (Bitmap)Bitmap.FromFile(fileName); |
@@ -97,6 +105,7 @@ namespace PrimMesher | |||
97 | _SculptMesh(bitmap, (SculptType)sculptType, lod, viewerMode != 0, mirror != 0, invert != 0); | 105 | _SculptMesh(bitmap, (SculptType)sculptType, lod, viewerMode != 0, mirror != 0, invert != 0); |
98 | bitmap.Dispose(); | 106 | bitmap.Dispose(); |
99 | } | 107 | } |
108 | #endif | ||
100 | 109 | ||
101 | /// <summary> | 110 | /// <summary> |
102 | /// ** Experimental ** May disappear from future versions ** not recommeneded for use in applications | 111 | /// ** Experimental ** May disappear from future versions ** not recommeneded for use in applications |
@@ -201,6 +210,7 @@ namespace PrimMesher | |||
201 | calcVertexNormals(SculptType.plane, numXElements, numYElements); | 210 | calcVertexNormals(SculptType.plane, numXElements, numYElements); |
202 | } | 211 | } |
203 | 212 | ||
213 | #if SYSTEM_DRAWING | ||
204 | public SculptMesh(Bitmap sculptBitmap, SculptType sculptType, int lod, bool viewerMode) | 214 | public SculptMesh(Bitmap sculptBitmap, SculptType sculptType, int lod, bool viewerMode) |
205 | { | 215 | { |
206 | _SculptMesh(sculptBitmap, sculptType, lod, viewerMode, false, false); | 216 | _SculptMesh(sculptBitmap, sculptType, lod, viewerMode, false, false); |
@@ -210,9 +220,16 @@ namespace PrimMesher | |||
210 | { | 220 | { |
211 | _SculptMesh(sculptBitmap, sculptType, lod, viewerMode, mirror, invert); | 221 | _SculptMesh(sculptBitmap, sculptType, lod, viewerMode, mirror, invert); |
212 | } | 222 | } |
223 | #endif | ||
224 | |||
225 | public SculptMesh(List<List<Coord>> rows, SculptType sculptType, bool viewerMode, bool mirror, bool invert) | ||
226 | { | ||
227 | _SculptMesh(rows, sculptType, viewerMode, mirror, invert); | ||
228 | } | ||
213 | 229 | ||
230 | #if SYSTEM_DRAWING | ||
214 | /// <summary> | 231 | /// <summary> |
215 | /// converts a bitmap to a list lists of coords, while scaling the image. | 232 | /// converts a bitmap to a list of lists of coords, while scaling the image. |
216 | /// the scaling is done in floating point so as to allow for reduced vertex position | 233 | /// the scaling is done in floating point so as to allow for reduced vertex position |
217 | /// quantization as the position will be averaged between pixel values. this routine will | 234 | /// quantization as the position will be averaged between pixel values. this routine will |
218 | /// likely fail if the bitmap width and height are not powers of 2. | 235 | /// likely fail if the bitmap width and height are not powers of 2. |
@@ -267,6 +284,7 @@ namespace PrimMesher | |||
267 | return rows; | 284 | return rows; |
268 | } | 285 | } |
269 | 286 | ||
287 | |||
270 | void _SculptMesh(Bitmap sculptBitmap, SculptType sculptType, int lod, bool viewerMode, bool mirror, bool invert) | 288 | void _SculptMesh(Bitmap sculptBitmap, SculptType sculptType, int lod, bool viewerMode, bool mirror, bool invert) |
271 | { | 289 | { |
272 | coords = new List<Coord>(); | 290 | coords = new List<Coord>(); |
@@ -285,12 +303,27 @@ namespace PrimMesher | |||
285 | int scale = (int)(1.0f / sourceScaleFactor); | 303 | int scale = (int)(1.0f / sourceScaleFactor); |
286 | if (scale < 1) scale = 1; | 304 | if (scale < 1) scale = 1; |
287 | 305 | ||
288 | List<List<Coord>> rows = bitmap2Coords(sculptBitmap, scale, mirror); | 306 | _SculptMesh(bitmap2Coords(sculptBitmap, scale, mirror), sculptType, viewerMode, mirror, invert); |
307 | } | ||
308 | #endif | ||
309 | |||
310 | |||
311 | void _SculptMesh(List<List<Coord>> rows, SculptType sculptType, bool viewerMode, bool mirror, bool invert) | ||
312 | { | ||
313 | coords = new List<Coord>(); | ||
314 | faces = new List<Face>(); | ||
315 | normals = new List<Coord>(); | ||
316 | uvs = new List<UVCoord>(); | ||
317 | |||
318 | sculptType = (SculptType)(((int)sculptType) & 0x07); | ||
319 | |||
320 | if (mirror) | ||
321 | if (sculptType == SculptType.plane) | ||
322 | invert = !invert; | ||
289 | 323 | ||
290 | viewerFaces = new List<ViewerFace>(); | 324 | viewerFaces = new List<ViewerFace>(); |
291 | 325 | ||
292 | int width = sculptBitmap.Width / scale; | 326 | int width = rows[0].Count; |
293 | // int height = sculptBitmap.Height / scale; | ||
294 | 327 | ||
295 | int p1, p2, p3, p4; | 328 | int p1, p2, p3, p4; |
296 | 329 | ||