add an overload to _SculptMesh for meshing from a list of coordinates

add conditional compilation for System.Drawing dependency
0.6.8-post-fixes
dahlia 2009-11-09 18:43:09 -08:00
parent 5145dfa53c
commit 3e22bb24f5
1 changed files with 46 additions and 3 deletions

View File

@ -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
/// <summary>
/// ** 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<List<Coord>> rows, SculptType sculptType, bool viewerMode, bool mirror, bool invert)
{
_SculptMesh(rows, sculptType, viewerMode, mirror, invert);
}
#if SYSTEM_DRAWING
/// <summary>
/// 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<Coord>();
@ -285,13 +302,39 @@ namespace PrimMesher
int scale = (int)(1.0f / sourceScaleFactor);
if (scale < 1) scale = 1;
List<List<Coord>> rows = bitmap2Coords(sculptBitmap, scale, mirror);
_SculptMesh(bitmap2Coords(sculptBitmap, scale, mirror), sculptType, viewerMode, mirror, invert);
}
#endif
void _SculptMesh(List<List<Coord>> rows, SculptType sculptType, bool viewerMode, bool mirror, bool invert)
{
coords = new List<Coord>();
faces = new List<Face>();
normals = new List<Coord>();
uvs = new List<UVCoord>();
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<List<Coord>> rows = bitmap2Coords(sculptBitmap, scale, mirror);
viewerFaces = new List<ViewerFace>();
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;