From 3e22bb24f5aa75f568485ed35e644c6a5c37dfe3 Mon Sep 17 00:00:00 2001 From: dahlia Date: Mon, 9 Nov 2009 18:43:09 -0800 Subject: add an overload to _SculptMesh for meshing from a list of coordinates add conditional compilation for System.Drawing dependency --- OpenSim/Region/Physics/Meshing/SculptMesh.cs | 49 ++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/Meshing/SculptMesh.cs b/OpenSim/Region/Physics/Meshing/SculptMesh.cs index f1dd586..281ba12 100644 --- a/OpenSim/Region/Physics/Meshing/SculptMesh.cs +++ b/OpenSim/Region/Physics/Meshing/SculptMesh.cs @@ -25,12 +25,18 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +// to build without references to System.Drawing, comment this out +#define SYSTEM_DRAWING + using System; using System.Collections.Generic; using System.Text; using System.IO; + +#if SYSTEM_DRAWING using System.Drawing; using System.Drawing.Imaging; +#endif namespace PrimMesher { @@ -83,6 +89,7 @@ namespace PrimMesher // return scaledImage; // } +#if SYSTEM_DRAWING public SculptMesh SculptMeshFromFile(string fileName, SculptType sculptType, int lod, bool viewerMode) { Bitmap bitmap = (Bitmap)Bitmap.FromFile(fileName); @@ -97,6 +104,7 @@ namespace PrimMesher _SculptMesh(bitmap, (SculptType)sculptType, lod, viewerMode != 0, mirror != 0, invert != 0); bitmap.Dispose(); } +#endif /// /// ** Experimental ** May disappear from future versions ** not recommeneded for use in applications @@ -201,6 +209,7 @@ namespace PrimMesher calcVertexNormals(SculptType.plane, numXElements, numYElements); } +#if SYSTEM_DRAWING public SculptMesh(Bitmap sculptBitmap, SculptType sculptType, int lod, bool viewerMode) { _SculptMesh(sculptBitmap, sculptType, lod, viewerMode, false, false); @@ -210,9 +219,16 @@ namespace PrimMesher { _SculptMesh(sculptBitmap, sculptType, lod, viewerMode, mirror, invert); } +#endif + + public SculptMesh(List> rows, SculptType sculptType, bool viewerMode, bool mirror, bool invert) + { + _SculptMesh(rows, sculptType, viewerMode, mirror, invert); + } +#if SYSTEM_DRAWING /// - /// converts a bitmap to a list lists of coords, while scaling the image. + /// converts a bitmap to a list of lists of coords, while scaling the image. /// the scaling is done in floating point so as to allow for reduced vertex position /// quantization as the position will be averaged between pixel values. this routine will /// likely fail if the bitmap width and height are not powers of 2. @@ -267,6 +283,7 @@ namespace PrimMesher return rows; } + void _SculptMesh(Bitmap sculptBitmap, SculptType sculptType, int lod, bool viewerMode, bool mirror, bool invert) { coords = new List(); @@ -285,13 +302,39 @@ namespace PrimMesher int scale = (int)(1.0f / sourceScaleFactor); if (scale < 1) scale = 1; - List> rows = bitmap2Coords(sculptBitmap, scale, mirror); + _SculptMesh(bitmap2Coords(sculptBitmap, scale, mirror), sculptType, viewerMode, mirror, invert); + } +#endif + + + void _SculptMesh(List> rows, SculptType sculptType, bool viewerMode, bool mirror, bool invert) + { + coords = new List(); + faces = new List(); + normals = new List(); + uvs = new List(); + + sculptType = (SculptType)(((int)sculptType) & 0x07); + + if (mirror) + if (sculptType == SculptType.plane) + invert = !invert; + + //float sourceScaleFactor = (float)(lod) / (float)Math.Sqrt(sculptBitmap.Width * sculptBitmap.Height); + + //int scale = (int)(1.0f / sourceScaleFactor); + //if (scale < 1) scale = 1; + + //List> rows = bitmap2Coords(sculptBitmap, scale, mirror); viewerFaces = new List(); - int width = sculptBitmap.Width / scale; + //int width = sculptBitmap.Width / scale; // int height = sculptBitmap.Height / scale; + int width = rows[0].Count; + int height = rows.Count; + int p1, p2, p3, p4; int imageX, imageY; -- cgit v1.1