00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #pragma once
00011
00012 #include "maxheap.h"
00013 #include "channels.h"
00014 #include "snap.h"
00015 #include "ioapi.h"
00016 #include "export.h"
00017 #include "vedge.h"
00018 #include "utillib.h"
00019 #include "tab.h"
00020 #include "baseinterface.h"
00021 #include "channels.h"
00022 #include "MeshFaceFlagConstants.h"
00023 #include "GraphicsConstants.h"
00024 #include "assert.h"
00025 #include "bitarray.h"
00026 #include "TabTypes.h"
00027 #include "Strip.h"
00028 #include "box3.h"
00029 #include "point3.h"
00030 #include "UVWMapper.h"
00031 #include "UVWMapTypes.h"
00032
00033
00034 class GraphicsWindow;
00035 class Material;
00036 class HitRegion;
00037 class IPoint2;
00038
00042 #define MESH_USE_EXT_CVARRAY (-32767)
00043
00044 #define MESH_MULTI_PROCESSING TRUE //!< TRUE turns on mp vertex transformation
00045
00046 #define MESH_CAGE_BACKFACE_CULLING //!< for "cage" orange gizmo meshes in EMesh, EPoly, Mesh Select, etc.
00047
00048 class ISave;
00049 class ILoad;
00050 class IHardwareShader;
00051 class TriStrip;
00052 class MeshNormalSpec;
00053
00054 #define NEWMESH
00055
00066 class RNormal: public MaxHeapOperators {
00067 public:
00070 RNormal() { smGroup = mtlIndex = 0; }
00073 void setNormal(const Point3 &nor) { normal = nor; }
00076 void addNormal(const Point3 &nor) { normal += nor; }
00078 void normalize(void) { normal = Normalize(normal); }
00080 Point3 & getNormal(void) { return normal; }
00081 inline const Point3& getNormal() const { return normal; }
00084 void setSmGroup(DWORD g) { smGroup = g; }
00088 void addSmGroup(DWORD g) { smGroup |= g; }
00090 DWORD getSmGroup(void) { return smGroup; }
00093 void setMtlIndex(MtlID i){ mtlIndex = i; }
00095 MtlID getMtlIndex(void) { return mtlIndex; }
00098 void setRGB(Point3 &clr) { rgb = clr; };
00100 Point3 & getRGB(void) { return rgb; }
00101 inline const Point3& getRGB() const { return rgb; }
00102
00103 private:
00107 Point3 normal;
00111 DWORD smGroup;
00116 MtlID mtlIndex;
00118 Point3 rgb;
00119 };
00120
00146 class RVertex: public MaxHeapOperators {
00147 public:
00148 enum {
00149 MAX_NUM_NORMALS = 0xff
00150 };
00151
00152 public:
00155 RVertex() { rFlags = 0; ern = NULL; }
00156
00158 DllExport ~RVertex();
00159
00164 DWORD rFlags;
00165
00167 int pos[3];
00169 RNormal rn;
00175 RNormal *ern;
00176 };
00177
00186 class Face: public MaxHeapOperators {
00187 public:
00189 DWORD v[3];
00196 DWORD smGroup;
00197
00205 DWORD flags;
00206
00209 Face() { smGroup = flags = 0; }
00210
00213 MtlID getMatID() { return (int)( ( flags >> FACE_MATID_SHIFT ) & FACE_MATID_MASK); }
00214
00218 void setMatID(MtlID id) {flags &= 0xFFFF; flags |= (DWORD)(id<<FACE_MATID_SHIFT);}
00221 void setSmGroup(DWORD i) { smGroup = i; }
00222
00224 DWORD getSmGroup(void) { return smGroup; }
00225
00229 DllExport void setVerts(DWORD *vrt);
00230
00236 void setVerts(int a, int b, int c) { v[0]=a; v[1]=b; v[2]=c; }
00237
00245 DllExport void setEdgeVis(int edge, int visFlag);
00246
00254 DllExport void setEdgeVisFlags(int va, int vb, int vc);
00255
00260 int getEdgeVis(int edge){ return flags & (VIS_BIT << edge); }
00261
00265 DWORD getVert(int index) { return v[index]; }
00266
00269 DWORD * getAllVerts(void) { return v; }
00270
00273 BOOL Hidden() {return flags&FACE_HIDDEN?TRUE:FALSE;}
00274
00276 void Hide() {flags|=FACE_HIDDEN;}
00277
00279 void Show() {flags&=~FACE_HIDDEN;}
00280
00284 void SetHide(BOOL hide) {if (hide) Hide(); else Show();}
00285
00286 BOOL InForeground() {return flags&FACE_INFOREGROUND?TRUE:FALSE;}
00287 void PushToForeground() {flags|=FACE_INFOREGROUND;}
00288 void PushToBackground() {flags&=~FACE_INFOREGROUND;}
00289 void SetInForegound(BOOL foreground) {if (foreground) PushToForeground(); else PushToBackground();}
00290
00291 BOOL IsBackFacing() {return flags&FACE_BACKFACING?TRUE:FALSE;}
00292 void SetBackFacing() {flags|=FACE_BACKFACING;}
00293 void SetFrontFacing() {flags&=~FACE_BACKFACING;}
00294 void SetBackFacing(BOOL backFacing) {if (backFacing) SetBackFacing(); else SetFrontFacing();}
00295
00296
00297
00303 DllExport DWORD GetOtherIndex (DWORD v0, DWORD v1);
00304
00312 DllExport DWORD GetEdgeIndex (DWORD v0, DWORD v1);
00313
00321 DllExport int Direction (DWORD v0, DWORD v1);
00322
00326 DllExport DWORD GetVertIndex (DWORD v0);
00327
00343 DllExport void OrderVerts (DWORD & v0, DWORD & v1);
00344 };
00345
00346
00347
00353 class TVFace: public MaxHeapOperators {
00354 public:
00356 DWORD t[3];
00357
00359 TVFace() {}
00360
00365 TVFace(DWORD a, DWORD b, DWORD c) {t[0]=a; t[1]=b; t[2]=c;}
00366
00370 DllExport void setTVerts(DWORD *vrt);
00371
00376 void setTVerts(int a, int b, int c) { t[0]=a; t[1]=b; t[2]=c; }
00377
00382 DWORD getTVert(int index) { return t[index]; }
00383
00386 DWORD * getAllTVerts(void) { return t; }
00387
00391 DllExport DWORD GetVertIndex (DWORD v0);
00392
00396 DllExport DWORD GetOtherIndex (DWORD v0, DWORD v1);
00397
00404 DllExport int Direction (DWORD v0, DWORD v1);
00405
00413 DllExport void OrderVerts (DWORD & v0, DWORD & v1);
00414 };
00415
00416
00417
00418
00419 #define MAX_MESHMAPS 100 //!< The higher limit of the mapping channels (map channel can be from 0 to MAX_MESHMAPS - 1)
00420
00422
00423 #define MESHMAP_USED 0x0001 //!< Indicates this mapping channel is actually used (carries mapping information).
00424 #define MESHMAP_TEXTURE 0x0002 //!< Indicates this is a texture mapping channel.
00425 #define MESHMAP_VERTCOLOR 0x0004 //!< Indicates this is a vertex color channel.
00426 #define MESHMAP_USER 0x0100 //!< Indicates the channel is used for a developer purpose
00427
00428
00429
00430
00432
00433
00437 #define NUM_HIDDENMAPS 2
00438
00439 #define MAP_SHADING -1
00440
00441 #define MAP_ALPHA -2
00442
00444
00455 class MeshMap: public MaxHeapOperators {
00456 public:
00458 DWORD flags;
00461 UVVert *tv;
00465 TVFace *tf;
00467 int vnum;
00469 int fnum;
00470
00473 MeshMap () { flags=0x0; tv=NULL; tf=NULL; vnum = fnum = 0; }
00474
00477 DllExport ~MeshMap ();
00478
00480 int getNumVerts () { return vnum; }
00481
00486 DllExport void setNumVerts (int vn, BOOL keep=FALSE);
00487
00489 int getNumFaces () { return fnum; }
00490
00495 DllExport void setNumFaces (int fn, BOOL keep=FALSE, int oldCt=0);
00496
00499 DllExport void Clear ();
00500
00503 DllExport BitArray GetIsoVerts ();
00504
00512 DllExport void DeleteVertSet (BitArray set, BitArray *delFace=NULL);
00513
00523 DllExport void DeleteFaceSet (BitArray set, BitArray *isoVert=NULL);
00524
00527 void SetFlag (DWORD fl) { flags |= fl; }
00528
00531 void ClearFlag (DWORD fl) { flags &= ~fl; }
00532
00536 BOOL GetFlag (DWORD fl) { return (flags & fl) ? TRUE : FALSE; }
00537
00540 BOOL IsUsed () const { return (flags & MESHMAP_USED) ? TRUE : FALSE; }
00541
00546 DllExport void SwapContents (MeshMap & from);
00547
00550 DllExport MeshMap & operator= (MeshMap & from);
00551 };
00552
00553
00559 DllExport DWORD MapChannelID (int mp);
00560
00561
00565 DllExport int MapChannelNum (int mp);
00566
00567
00572 class MapBitArray: public MaxHeapOperators {
00573 private:
00574 bool mTexture, mColor;
00575 BitArray mTextureFlip, mColorFlip;
00576
00577 public:
00578
00580 MapBitArray () : mTexture(false), mColor(false) { }
00581
00582
00584 MapBitArray (bool defaultValue)
00585 : mTexture(defaultValue), mColor(defaultValue) { }
00586
00589 MapBitArray (bool textureDefault, bool colorDefault)
00590 : mTexture(textureDefault), mColor(colorDefault) { }
00591
00594 int Largest() const { return (mTextureFlip.GetSize()>1) ? mTextureFlip.GetSize()-1 : 0; }
00595
00598 int Smallest() const { return (mColorFlip.GetSize()>1) ? 1-mColorFlip.GetSize() : 0; }
00599
00601 DllExport void Set (int mapChannel, bool val=true);
00602
00604 void Clear (int mapChannel) { Set (mapChannel, false); }
00605
00608 DllExport bool Get (int mapChannel) const;
00609
00611 bool TextureDefault () const { return mTexture; }
00612
00614 bool ColorDefault () const { return mColor; }
00615
00617 void InvertTextureChannels () { mTexture=!mTexture; }
00618
00620 void InvertColorChannels () { mColor=!mColor; }
00621
00623 void InvertAll () { mColor = !mColor; mTexture = !mTexture; }
00624
00626 DllExport IOResult Save(ISave* isave);
00627
00629 DllExport IOResult Load(ILoad* iload);
00630
00632 bool operator[](int i) const { return Get(i); }
00633
00635 DllExport BOOL operator==(const MapBitArray& b) const;
00636
00638 BOOL operator!=(const MapBitArray& b) const { return !(*this == b); }
00639
00641 DllExport MapBitArray& operator=(const MapBitArray& b);
00642 };
00643
00644
00645
00646
00647
00648
00649 #define MAX_VERTDATA 100 //!< The maximum channel index for developers' defined data.
00650 #define VDATA_USER 10 //!< Third parties should use this channel or higher.
00651
00658 #define VDATA_SELECT 0 //!< The vertex soft selection data. This is index 0.
00659 #define VDATA_WEIGHT 1 //!< The vertex weight data. This is index 1.
00660 #define VDATA_ALPHA 2 //!< Vertex Alpha values
00661 #define VDATA_CORNER 3 //!< Cornering values for subdivision use
00662
00663
00664
00665 #define MAX_WEIGHT ((float)1e5)
00666 #define MIN_WEIGHT ((float)1e-5)
00667
00673 #define PERDATA_TYPE_FLOAT 0 //!< The floating point data type.
00674
00675
00676
00680 DllExport int VertexDataType (int vdID);
00681
00686 DllExport void *VertexDataDefault (int vdID);
00687
00701 class PerData: public MaxHeapOperators {
00702 public:
00704 int dnum;
00706 int type;
00708 int alloc;
00710 void *data;
00711
00714 PerData () { data=NULL; dnum=0; alloc=0; type=0; }
00720 PerData (int n, int tp) { data=NULL; dnum=0; alloc=0; type=tp; setAlloc (n, FALSE); }
00723 ~PerData () { Clear (); }
00724
00725
00729 DllExport void *AllocData (int num);
00730
00733 DllExport void FreeData (void *addr);
00734
00739 DllExport int DataSize ();
00740
00745 void *Addr (void *ptr, int at) { BYTE *vd=(BYTE *)ptr; return (void *)(vd+at*DataSize()); }
00746
00750 void *Addr (int at) { return Addr(data,at); }
00751
00757 DllExport void CopyData (void *to, void *from, int num=1);
00758
00764 void CopyData ( int to, int from, int num=1) { CopyData (Addr(to), Addr(from), num); }
00765
00776 DllExport void WeightedSum (void *to, void *fr1, float prop1, void *fr2, float prop2);
00777
00790 void WeightedSum (int to, int fr1, float prop1, int fr2, float prop2) { WeightedSum (Addr(to), Addr(fr1), prop1, Addr(fr2), prop2); }
00791
00797 DllExport void setAlloc (int num, BOOL keep=TRUE);
00798
00804 void SetCount (int num, BOOL keep = FALSE) { setAlloc (num, keep); dnum=num; }
00805
00808 void Shrink () { if (alloc>dnum) setAlloc(dnum); }
00809
00811 int Count () { return dnum; }
00812
00815 DllExport void Clear ();
00816
00821 DllExport void DeleteSet (BitArray del);
00822
00827 DllExport void Delete (int at, int num);
00828
00834 DllExport void Insert (int at, int num, void *el);
00835
00839 DllExport void Append (int num, void *el);
00840
00846 DllExport void InsertCopies (int at, int num, void *el);
00847
00852 DllExport void AppendCopies (int num, void *el);
00853
00857 DllExport void SwapContents (PerData & from);
00858
00861 DllExport PerData & operator= (const PerData & from);
00862 DllExport void MyDebugPrint ();
00863 };
00864
00865
00871 #define MESH_EDGE_LIST (1<<1) //!< \deprecated This flag is obsolete.
00872 #define MESH_LOCK_RENDDATA (1<<2) //!< Setting this flag prevents render data from being deleted (except when the mesh is deleted).
00873 #define MESH_SMOOTH_BIT1 (1<<3)
00874 #define MESH_SMOOTH_BIT2 (1<<4)
00875 #define MESH_SMOOTH_BIT3 (1<<5)
00876 #define MESH_SMOOTH_BIT4 (1<<6)
00877 #define MESH_SMOOTH_MASK 0x78 //!< Flag mask for SMOOTH_BIT's 1 thru 4
00878 #define MESH_BEEN_DSP (1<<9) //!< \internal Mesh? flag that marks the mesh as has been drawn I think
00879
00881 #define MESH_SMOOTH_SUBSEL (1<<10)
00882 #define MESH_FACENORMALSINVALID (1<<11) //!< Mesh flag that Signals that face normals should be rebuilt
00883 #define MESH_CACHEINVALID (1<<12) //!< Mesh, vertices and Face flag Signals that the they have changed and RVertices normals should be rebuilt
00884 #define MESH_BACKFACESCOMPUTED (1<<16) //!< Mesh flag to determine whether the back facing attribute on the face list has been computed or not
00885 #define MESH_PARTIALCACHEINVALID (1<<17) //!< Mesh flag that means that the mesh has only set some of the vertices as invalid and not to reprocess the entire mesh just the vertices that changed
00886
00887
00888
00889 #define MESH_TEMP_1 (1<<13)
00890 #define MESH_TEMP_2 (1<<14)
00891 #define MESH_DONTTRISTRIP (1<<15) //!< \internal Mesh flag to determine whether to use tristripping or not
00892
00893 class StripData: public MaxHeapOperators {
00894 public:
00895 int ct;
00896 DWORD f[6];
00897 void AddFace(DWORD face)
00898 { if(ct < 6) f[ct++] = face; }
00899 };
00900
00901 typedef int (*INTRFUNC)();
00902
00903 DllExport void setMeshIntrFunc(INTRFUNC fn);
00904
00905
00910 class MeshSubHitRec: public MaxHeapOperators {
00911 private:
00912 MeshSubHitRec *next;
00913 public:
00918 DWORD dist;
00924 int index;
00926 DWORD flags;
00927
00930 MeshSubHitRec(DWORD dist, int index, MeshSubHitRec *next)
00931 {this->dist = dist; this->index = index; this->next = next;}
00932
00935 MeshSubHitRec(DWORD dist, int index, DWORD flags, MeshSubHitRec *next)
00936 {this->dist = dist; this->index = index; this->next = next;this->flags = flags;}
00937
00939 MeshSubHitRec *Next() { return next; }
00940 };
00941
00945 class SubObjHitList: public MaxHeapOperators {
00946 private:
00947 MeshSubHitRec *first;
00948 public:
00950 SubObjHitList() { first = NULL; }
00951
00953 DllExport ~SubObjHitList();
00954
00956 MeshSubHitRec *First() { return first; }
00957
00961 DllExport void AddHit( DWORD dist, int index );
00962 };
00963
00964
00965
00968
00969
00970 #define SUBHIT_SELONLY (1<<0) //!< Selected only.
00971 #define SUBHIT_UNSELONLY (1<<2) //!< Unselected only.
00972 #define SUBHIT_ABORTONHIT (1<<3) //!< Abort hit testing on the first hit found.
00973
00977 #define SUBHIT_SELSOLID (1<<4)
00978
00979 #define SUBHIT_USEFACESEL (1<<23) //!< When this bit is set, the sel only and unsel only tests will use the faces selection when doing a vertex level hit test
00980 #define SUBHIT_VERTS (1<<24) //!< Hit test vertices.
00981 #define SUBHIT_FACES (1<<25) //!< Hit test faces.
00982 #define SUBHIT_EDGES (1<<26) //!< Hit test edges.
00983 #define SUBHIT_TYPEMASK (SUBHIT_VERTS|SUBHIT_FACES|SUBHIT_EDGES)
00984
00985
00990 #define MESH_OBJECT (1<<0) //!< Object level.
00991 #define MESH_VERTEX (1<<1) //!< Vertex level.
00992 #define MESH_FACE (1<<2) //!< Face level.
00993 #define MESH_EDGE (1<<3) //!< Edge level.
00994
00995
01003 #define MESH_DISP_NO_NORMALS 0 //!< Turn off normal display.
01004 #define MESH_DISP_FACE_NORMALS (1<<0)
01005 #define MESH_DISP_VERTEX_NORMALS (1<<1)
01006
01007
01008
01009 class MeshOpProgress;
01010 class UVWMapper;
01011
01021 class MeshRenderData: public MaxHeapOperators {
01022 public:
01024 virtual ~MeshRenderData() {;}
01025
01027 virtual void DeleteThis()=0;
01028 };
01029
01030 class AdjFaceList;
01031
01032 namespace MaxGraphics {
01033 class IMeshInternal;
01034 }
01035
01047 class Mesh : public BaseInterfaceServer {
01048 friend class Face;
01049 friend class MeshAccess;
01050 friend class HardwareMesh;
01051 friend class MaxGraphics::IMeshInternal;
01052 friend void gfxCleanup(void *data);
01053
01054 private:
01055
01056 #if MESH_MULTI_PROCESSING
01057 static int refCount;
01058 static HANDLE xfmThread;
01059 static HANDLE xfmMutex;
01060 static HANDLE xfmStartEvent;
01061 static HANDLE xfmEndEvent;
01062 friend DWORD WINAPI xfmFunc(LPVOID ptr);
01063 static HANDLE fNorThread;
01064 static HANDLE fNorMutex;
01065 static HANDLE fNorStartEvent;
01066 static HANDLE fNorEndEvent;
01067 friend DWORD WINAPI fNorFunc(LPVOID ptr);
01068
01069 static HANDLE workThread;
01070 static HANDLE workMutex;
01071 static HANDLE workStartEvent;
01072 static HANDLE workEndEvent;
01073 friend DWORD WINAPI workFunc(LPVOID ptr);
01074 #endif
01075
01076 RVertex* rVerts;
01077 GraphicsWindow* cacheGW;
01078 Point3* faceNormal;
01079 Box3 bdgBox;
01080 int numVisEdges;
01081 int edgeListHasAll;
01082 VEdge* visEdge;
01083
01084
01085 int snapVCt;
01086 int snapFCt;
01087 char* snapV;
01088 char* snapF;
01089
01090
01091 Tab<DWORD> mDisplayEdges;
01092
01093 UINT mDXMeshCacheDrawCount;
01094 UINT mRedrawCountFromLoad;
01095
01096
01097
01098 MeshMap hmaps[NUM_HIDDENMAPS];
01099
01100
01101
01102 long flags;
01103
01104 float norScale;
01105
01106
01107
01108
01109
01110
01111
01112 BYTE dspNormals;
01113 BYTE dspAllEdges;
01114 BYTE dspVertTicks;
01115
01116
01120 void DrawOnlySelectedEdges(GraphicsWindow *gw);
01121
01122
01126 void DrawOnlySelectedFaces(GraphicsWindow *gw);
01127
01128 int renderFace(GraphicsWindow *gw, DWORD index, int *custVis=NULL);
01129 int renderEdge(GraphicsWindow *gw, DWORD face, DWORD edge);
01130 int renderFaceVerts(GraphicsWindow *gw, DWORD index);
01131 void renderStrip(GraphicsWindow *gw, Strip *s);
01132 void render3DFace(GraphicsWindow *gw, DWORD index, int *custVis=NULL);
01133 void render3DFaceVerts(GraphicsWindow *gw, DWORD index);
01134 void render3DStrip(GraphicsWindow *gw, Strip *s);
01135 void render3DWireStrip(GraphicsWindow *gw, Strip *s);
01136 BOOL CanDrawStrips(DWORD rndMode, Material *mtl, int numMtls);
01137 BOOL NormalsMatchVerts();
01138 void checkRVertsAlloc(void);
01139 void calcNormal(int i);
01140 void buildFaceNormals();
01141 void setCacheGW(GraphicsWindow *gw) { cacheGW = gw; }
01142 GraphicsWindow *getCacheGW(void) { return cacheGW; }
01143
01144
01145 bool CanDrawTriStrips(DWORD rndMode, int numMtls, Material *mtl);
01146 bool BuildTriStrips(DWORD rndMode, int numMtls, Material *mtl);
01147 void TriStripify(DWORD rndMode, int numTex, TVFace *tvf[], TriStrip *s, StripData *sd, int vtx);
01148 void Draw3DTriStrips(IHardwareShader *phs, int numMat, Material *ma);
01149 void Draw3DWireTriStrips(IHardwareShader *phs, int numMat, Material *ma);
01150 void Draw3DVisEdgeList(IHardwareShader *phs, DWORD flags);
01151 int render3DTriStrips(IHardwareShader *phs, int kmat, int kstrips);
01152 int render3DWireTriStrips(IHardwareShader *phs, int kmat, int kstrips);
01153 int render3DFaces(IHardwareShader *phs, DWORD index, int *custVis=NULL);
01154
01155 void freeVerts();
01156 void freeVertCol();
01157 void freeFaces();
01158 void freeFaceNormals();
01159 void freeRVerts(BOOL forceDelete=FALSE);
01160 void freeTVerts();
01161 void freeTVFaces();
01162 void freeVCFaces();
01163 void freeSnapData();
01164 int buildSnapData(GraphicsWindow *gw,int verts,int edges);
01165 void ComputeBackFaceFlags(GraphicsWindow *gw);
01166
01167
01168 BitArray mInvalidVert;
01169 BitArray mInvalidFace;
01170 Tab<int> mInvalidVertList;
01171 Tab<int> mInvalidFaceList;
01172
01173 void FreeRVert(int index);
01174 void ComputeFaceAngle(int index, float *angles);
01175 void ComputeRVert(int index, float *faceAngles);
01176
01177 public:
01178
01179
01180
01181 int numVerts;
01182 int numFaces;
01183 Face * faces;
01184
01185
01186 Point3 * verts;
01187
01188
01189 int numTVerts;
01190
01194 UVVert * tVerts;
01199 TVFace * tvFace;
01200
01201
01202 int numCVerts;
01203 VertColor * vertCol;
01204 TVFace * vcFace;
01205
01208 int curVCChan;
01212 VertColor * curVCArray;
01213 TVFace * curVCFace;
01214
01218 VertColor * vertColArray;
01219
01223 TVFace * vcFaceData;
01224
01225
01228 int numMaps;
01232 MeshMap *maps;
01233
01234
01238 BitArray vdSupport;
01242 PerData *vData;
01243
01244
01245 MtlID mtlIndex;
01246
01247
01250 BitArray vertSel;
01253 BitArray faceSel;
01257 BitArray edgeSel;
01259 BitArray vertHide;
01260
01271 DWORD dispFlags;
01272
01279 DWORD selLevel;
01280
01281
01282
01283
01284
01286 int normalsBuilt;
01287
01289 MeshRenderData* renderData;
01290
01291
01292 StripTab* stab;
01293 DWTab norInd;
01294 int normalCount;
01295 Point3* gfxNormals;
01296
01297
01298 void BuildGFXNormals();
01299
01300
01301 int numTexCoords[GFX_MAX_TEXTURES];
01302 Point3 * texCoords[GFX_MAX_TEXTURES];
01303
01305 Tab<TriStrip *> *tstab;
01306
01309 DllExport Mesh();
01312 DllExport Mesh(const Mesh& fromMesh);
01315 DllExport ~Mesh();
01319 DllExport void Init();
01323 DllExport void DeleteThis();
01324
01336 DllExport Mesh& operator=(const Mesh& fromMesh);
01337
01347 DllExport BOOL setNumVerts(int ct, BOOL keep=FALSE, BOOL synchSel=TRUE);
01349 int getNumVerts(void) const { return numVerts; }
01350
01359 DllExport BOOL setNumFaces(int ct, BOOL keep=FALSE, BOOL synchSel=TRUE);
01360
01362 int getNumFaces(void) const{ return numFaces; }
01363
01364
01372 DllExport BOOL setNumTVerts(int ct, BOOL keep=FALSE);
01373
01376 int getNumTVerts(void) const { return numTVerts; }
01377
01391 DllExport BOOL setNumTVFaces(int ct, BOOL keep=FALSE, int oldCt=0);
01392
01393
01394
01395
01400 DllExport BOOL setNumVertCol(int ct,BOOL keep=FALSE);
01402 int getNumVertCol() const {return numCVerts;}
01410 DllExport BOOL setNumVCFaces(int ct, BOOL keep=FALSE, int oldCt=0);
01411
01412
01413
01414
01415
01416
01417
01418
01419
01429 DllExport void setVCDisplayData(int mapChan = 0, VertColor *VCArray=NULL, TVFace *VCf=NULL);
01430
01431
01438 DllExport void setNumMaps (int ct, BOOL keep=FALSE);
01439
01441 int getNumMaps () const { return numMaps; }
01442
01446 DllExport BOOL mapSupport (int mp) const;
01447
01451 DllExport void setMapSupport (int mp, BOOL support=TRUE);
01452
01458 DllExport void setNumMapVerts (int mp, int ct, BOOL keep=FALSE);
01459
01463 DllExport int getNumMapVerts (int mp) const;
01469 DllExport void setNumMapFaces (int mp, int ct, BOOL keep=FALSE, int oldCt=0);
01470
01474 DllExport UVVert *mapVerts (int mp) const;
01475
01479 DllExport TVFace *mapFaces (int mp) const;
01480
01486 void setMapVert (int mp, int i, const UVVert&xyz) { if (mapVerts(mp)) mapVerts(mp)[i] = xyz; }
01487
01491 DllExport void MakeMapPlanar (int mp);
01492
01496 DllExport BitArray GetIsoMapVerts (int mp);
01497
01506 DllExport void DeleteMapVertSet (int mp, BitArray set, BitArray *fdel=NULL);
01507
01510 DllExport void DeleteIsoMapVerts ();
01511
01516 DllExport void DeleteIsoMapVerts (int mp);
01517
01521 DllExport void freeMapVerts (int mp);
01522
01526 DllExport void freeMapFaces (int mp);
01527
01531 MeshMap & Map(int mp) { return (mp<0) ? hmaps[-1-mp] : maps[mp]; }
01532
01536 DllExport void setNumVData (int ct, BOOL keep=FALSE);
01537
01539 int getNumVData () const { return vdSupport.GetSize(); }
01540
01544 DllExport BOOL vDataSupport (int vd) const;
01545
01551 DllExport void setVDataSupport (int vd, BOOL support=TRUE);
01552
01557 void *vertexData (int vd) const { return vDataSupport(vd) ? vData[vd].data : NULL; }
01558
01563 float *vertexFloat (int vd) const { return (float *) vertexData (vd); }
01564
01567 DllExport void freeVData (int vd);
01568
01571 DllExport void freeAllVData ();
01572
01573
01575 float *getVertexWeights () { return vertexFloat(VDATA_WEIGHT); }
01576
01579 void SupportVertexWeights () { setVDataSupport (VDATA_WEIGHT); }
01580
01582 void ClearVertexWeights() { setVDataSupport (VDATA_WEIGHT, FALSE); }
01583
01586 void freeVertexWeights () { freeVData (VDATA_WEIGHT); }
01587
01590 float *getVSelectionWeights () { return vertexFloat(VDATA_SELECT); }
01591
01594 void SupportVSelectionWeights () { setVDataSupport (VDATA_SELECT); }
01595
01597 void ClearVSelectionWeights() { setVDataSupport (VDATA_SELECT, FALSE); }
01598
01601 void freeVSelectionWeights () { freeVData (VDATA_SELECT); }
01602
01603
01604
01611 DllExport void setSmoothFlags(int f);
01612
01615 DllExport int getSmoothFlags();
01616
01621 void setVert(int i, const Point3 &xyz) { verts[i] = xyz; }
01622
01632 void setVert(int i, float x, float y, float z) { verts[i].x=x; verts[i].y=y; verts[i].z=z; }
01639 void setTVert(int i, const UVVert &xyz) { tVerts[i] = xyz; }
01650 void setTVert(int i, float x, float y, float z) { tVerts[i].x=x; tVerts[i].y=y; tVerts[i].z=z; }
01651
01660 DllExport void setNormal(int i, const Point3 &xyz);
01661
01667 DllExport Point3 & getNormal(int i) const;
01668
01674 void setFaceNormal(int i, const Point3 &xyz) { faceNormal[i] = xyz; }
01675
01678 Point3 & getFaceNormal(int i) { return faceNormal[i]; }
01679
01682 Point3 & getVert(int i) { return verts[i]; }
01683
01686 Point3 * getVertPtr(int i) { return verts+i; }
01687
01690 UVVert & getTVert(int i) { return tVerts[i]; }
01691
01694 UVVert * getTVertPtr(int i) { return tVerts+i; }
01695
01698 RVertex & getRVert(int i) { return rVerts[i]; }
01699
01702 RVertex * getRVertPtr(int i) { return rVerts+i; }
01703
01704
01706 void setMtlIndex(MtlID i) { mtlIndex = i; }
01707
01709 MtlID getMtlIndex(void) { return mtlIndex; }
01710
01711
01716 DllExport MtlID getFaceMtlIndex(int i);
01717
01722 DllExport void setFaceMtlIndex(int i, MtlID id);
01723
01740 DllExport void buildNormals();
01741
01747 DllExport void buildRenderNormals();
01748
01749
01750
01751
01752
01753
01764 DllExport void checkNormals(BOOL illum);
01765
01820 DllExport void render(GraphicsWindow *gw, Material *ma, RECT *rp, int compFlags, int numMat=1, InterfaceServer *pi = NULL);
01821
01837 DllExport BOOL select(GraphicsWindow *gw, Material *ma, HitRegion *hr, int abortOnHit = FALSE, int numMat=1);
01838
01869 DllExport void snap(GraphicsWindow *gw, SnapInfo *snap, IPoint2 *p, Matrix3 &tm);
01887 DllExport BOOL SubObjectHitTest(GraphicsWindow *gw, Material *ma, HitRegion *hr,
01888 DWORD flags, SubObjHitList& hitList, int numMat=1 );
01889
01890
01903 void displayNormals(int b, float sc)
01904 {
01905 DbgAssert(b <= 0xff);
01906 DbgAssert(b >= 0);
01907 dspNormals = (BYTE)b;
01908 if(sc != 0.0f)
01909 norScale = sc;
01910 }
01917 void displayAllEdges(int b)
01918 {
01919 DbgAssert(b <= 0xff);
01920 DbgAssert(b >= 0);
01921 dspAllEdges = (BYTE)b;
01922 }
01927 DllExport void buildBoundingBox(void);
01928
01934 DllExport Box3 getBoundingBox(Matrix3 *tm=NULL);
01935
01936
01937
01941 DllExport void InvalidateGeomCache();
01942
01946 DllExport void InvalidateTopologyCache();
01947
01951 DllExport void FreeAll();
01952
01953 DllExport void ZeroTopologyCache();
01954
01955
01957 DllExport void EnableEdgeList(int e);
01958
01960 DllExport void BuildVisEdgeList();
01961
01963 DllExport void DrawVisEdgeList(GraphicsWindow *gw, DWORD flags);
01964 DllExport void Draw3DVisEdgeList(GraphicsWindow *gw, DWORD flags);
01965
01967 DllExport void HitTestVisEdgeList(GraphicsWindow *gw, int abortOnHit );
01968
01970 DllExport void InvalidateEdgeList();
01971
01972
01975 DllExport BOOL BuildStrips();
01977 DllExport void Stripify(Strip *s, StripData *sd, int vtx);
01978 DllExport void Stripify(Strip *s, StripData *sd, int vtx, DWTab& v, DWTab& n, DWTab& tv);
01980 DllExport void getStripVertColor(GraphicsWindow *gw, int cv, int flipped, MtlID mID, DWORD smGroup, Point3 &rgb);
01982 DllExport void getStripNormal(int cv, MtlID mID, DWORD smGroup, Point3 &nor);
01983 DllExport int getStripNormalIndex(int cv, MtlID mID, DWORD smGroup);
01985 DllExport BOOL getStripTVert(GraphicsWindow *gw, int cv, int ctv, Point3 &uvw, int texNum = 0);
01987 DllExport void DrawStrips(GraphicsWindow *gw, Material *ma, int numMat);
01989 DllExport void Draw3DStrips(GraphicsWindow *gw, Material *ma, int numMat);
01990 DllExport void Draw3DWireStrips(GraphicsWindow *gw, Material *ma, int numMat);
01991
01993 DllExport void InvalidateStrips();
01994
01999 DllExport void BuildStripsAndEdges();
02000
02001
02009 DllExport void ShallowCopy(Mesh *amesh, ChannelMask channels);
02010
02018 DllExport void DeepCopy(Mesh *amesh, ChannelMask channels);
02019
02024 DllExport void NewAndCopyChannels(ChannelMask channels);
02025
02036 DllExport void FreeChannels(ChannelMask channels, int zeroOthers=1);
02037
02038
02042 void SetFlag(DWORD f) { flags |= f; }
02047 DWORD GetFlag(DWORD f) { return flags & f; }
02051 void ClearFlag(DWORD f) { flags &= ~f; }
02052
02053
02058 void SetDispFlag(DWORD f) { dispFlags |= f; }
02063 DWORD GetDispFlag(DWORD f) { return dispFlags & f; }
02067 void ClearDispFlag(DWORD f) { dispFlags &= ~f; }
02068
02069
02073 BitArray& VertSel() { return vertSel; }
02074
02078 BitArray& FaceSel() { return faceSel; }
02079
02080
02096 DllExport BitArray VertexTempSel();
02097
02098 DllExport IOResult Save(ISave* isave);
02099 DllExport IOResult Load(ILoad* iload);
02100
02101
02114 DllExport int IntersectRay(Ray& ray, float& at, Point3& norm);
02115
02144 DllExport int IntersectRay(Ray& ray, float& at, Point3& norm, DWORD &fi, Point3 &bary);
02145
02146
02153 DllExport Mesh operator+(Mesh &mesh);
02154
02161 DllExport Mesh operator-(Mesh &mesh);
02168 DllExport Mesh operator*(Mesh &mesh);
02169 DllExport void MyDebugPrint ();
02170
02172 DllExport void WeldCollinear(BitArray &set);
02173
02204 DllExport void Optimize(
02205 float normThresh, float edgeThresh,
02206 float bias, float maxEdge, DWORD flags,
02207 MeshOpProgress *prog=NULL);
02208
02240 DllExport void ApplyUVWMap(int type,
02241 float utile, float vtile, float wtile,
02242 int uflip, int vflip, int wflip, int cap,
02243 const Matrix3 &tm, int channel=1);
02244 DllExport void ApplyMapper (UVWMapper & map, int channel=1);
02245
02252 DllExport void FlipNormal(int i);
02257 DllExport void UnifyNormals(BOOL selOnly);
02273 DllExport void AutoSmooth(float angle,BOOL useSel,BOOL preventIndirectSmoothing=FALSE);
02274
02276 DllExport Edge *MakeEdgeList(int *edgeCount, int flagdbls=0);
02277
02281 DllExport int DeleteFlaggedFaces();
02282
02283
02284
02286 DllExport void DeleteSelected();
02287
02288
02292 DllExport void DeleteVertSet(BitArray set);
02293
02294
02295
02296
02297
02305 DllExport void DeleteFaceSet(BitArray set, BitArray *isoVert=NULL);
02306
02307
02317 DllExport BOOL DoesFaceExist(DWORD v0, DWORD v1, DWORD v2);
02318
02319
02320
02323 DllExport BOOL RemoveDegenerateFaces();
02324
02325
02326
02329 DllExport BOOL RemoveIllegalFaces();
02330
02340 DllExport Point3 FaceNormal (DWORD fi, BOOL nrmlize=FALSE);
02346 DllExport Point3 FaceCenter (DWORD fi);
02353 DllExport float AngleBetweenFaces(DWORD f0, DWORD f1);
02354
02355
02356
02368 DllExport Point3 BaryCoords(DWORD face, Point3 p);
02369
02370
02399 DllExport void DivideEdge(DWORD edge, float prop=.5f, bool visDiag1=TRUE,
02400 bool fixNeighbors=TRUE, bool visDiag2=TRUE);
02421 DllExport void DivideFace(DWORD face, DWORD e1, DWORD e2,
02422 float prop1=.5f, float prop2=.5f, bool fixNeighbors=TRUE, bool split=FALSE);
02435 DllExport void TurnEdge (DWORD edge, DWORD *otherEdge=NULL);
02436
02437
02443 DllExport void FaceCenterTessellate(BOOL ignoreSel=FALSE, MeshOpProgress *mop=NULL);
02454 DllExport void EdgeTessellate(float tens,BOOL ignoreSel=FALSE, MeshOpProgress *mop=NULL);
02455
02456
02457
02458
02459
02466 DllExport void ExtrudeFaces(BOOL doFace=TRUE);
02467
02468
02469
02474 DllExport void IndentSelFaces (float amount);
02475
02476
02477
02484 DllExport void BreakVerts(BitArray set);
02485
02486
02489 DllExport BitArray GetIsoVerts ();
02491 DllExport void DeleteIsoVerts ();
02492
02493
02501 DllExport void CloneFaces(BitArray fset);
02525 DllExport void PolyFromFace (DWORD f, BitArray &set, float thresh, BOOL ignoreVisEdges, AdjFaceList *af=NULL);
02539 DllExport void ElementFromFace (DWORD f, BitArray &set, AdjFaceList *af=NULL);
02550 DllExport void FindVertsUsedOnlyByFaces (BitArray & fset, BitArray & vset);
02557 DllExport void FindOpenEdges (BitArray & edges);
02569 DllExport void FindVertexAngles (float *vang, BitArray *set=NULL);
02570
02571
02579 void SetRenderData(MeshRenderData *p) {renderData = p; }
02586 MeshRenderData * GetRenderData() { return renderData; }
02587
02588
02589 DllExport void ClearSpecifiedNormals ();
02590 DllExport MeshNormalSpec *GetSpecifiedNormals ();
02591 DllExport void SpecifyNormals ();
02592
02593
02594 DllExport void CopyBasics (const Mesh & from);
02595
02596
02597 DllExport BaseInterface* GetInterface(Interface_ID id);
02598
02599
02600
02608 DllExport bool isFaceCacheInvalid(int faceIndex);
02609
02610
02619 DllExport void InvalidateVertexCache(int vertex);
02620
02622 long * vFlags;
02623
02624
02629 DllExport void SetStaticMesh(bool staticMesh);
02630
02631
02635 DllExport void ReduceDisplayCaches();
02636
02642 DllExport bool NeedGWCacheRebuilt(GraphicsWindow *gw,Material *ma, int numMat);
02649 DllExport void BuildGWCache(GraphicsWindow *gw,Material *ma, int numMat,BOOL threaded);
02650
02651
02652
02653 };
02654
02655
02656
02658
02659
02660 #define OPTIMIZE_SAVEMATBOUNDRIES (1<<0)
02661
02662 #define OPTIMIZE_SAVESMOOTHBOUNDRIES (1<<1)
02663
02666 #define OPTIMIZE_AUTOEDGE (1<<2)
02667
02668
02670 DllExport void setUseVisEdge(int b);
02672 DllExport int getUseVisEdge();
02673
02674 #define SMALL_VERTEX_DOTS 0
02675 #define LARGE_VERTEX_DOTS 1
02676
02679
02680 #define VERTEX_DOT2 0 //!< equivalent to SMALL_VERTEX_DOTS
02681 #define VERTEX_DOT3 1 //!< equivalent to LARGE_VERTEX_DOTS
02682 #define VERTEX_DOT4 2
02683 #define VERTEX_DOT5 3
02684 #define VERTEX_DOT6 4
02685 #define VERTEX_DOT7 5
02686
02687
02690
02691 #define HANDLE_BOX2 0
02692 #define HANDLE_BOX3 1
02693 #define HANDLE_BOX4 2
02694 #define HANDLE_BOX5 3
02695 #define HANDLE_BOX6 4
02696 #define HANDLE_BOX7 5
02697
02698
02699
02700 #define VERTEX_DOT_MARKER(vtype) (MarkerType)(vtype - VERTEX_DOT2 + DOT2_MRKR)
02701
02702
02703 #define HANDLE_BOX_MARKER(htype) (MarkerType)(htype - HANDLE_BOX2 + BOX2_MRKR)
02704
02705 DllExport void setUseVertexDots(int b);
02706 DllExport int getUseVertexDots();
02707
02708 DllExport void setVertexDotType(int t);
02709 DllExport int getVertexDotType();
02710
02711 DllExport void setHandleBoxType(int t);
02712 DllExport int getHandleBoxType();
02713
02714 DllExport void setDisplayBackFaceVertices(int b);
02715 DllExport int getDisplayBackFaceVertices();
02716
02717
02718
02719
02720
02721
02722 class VertexNormalsCallback: public MaxHeapOperators {
02723 public:
02724 virtual ~VertexNormalsCallback() {;}
02725 virtual void SetUseFaceAngles (bool value) = 0;
02726 };
02727
02728 class VertexNormalsControl: public MaxHeapOperators {
02729 bool mUseFaceAngles;
02730 Tab<VertexNormalsCallback *> mCallbacks;
02731 public:
02732 DllExport VertexNormalsControl () : mUseFaceAngles(true) { }
02733
02734 DllExport void RegisterCallback (VertexNormalsCallback *pCallback);
02735 DllExport void UnregisterCallback (VertexNormalsCallback *pCallback);
02736
02737 DllExport void SetUseFaceAngles (bool value);
02738 DllExport bool GetUseFaceAngles ();
02739 };
02740
02741 DllExport VertexNormalsControl *GetVertexNormalsControl ();
02742
02743
02744
02750 class MeshOpProgress: public MaxHeapOperators {
02751 public:
02753 virtual ~MeshOpProgress() {;}
02754
02755
02759 virtual void Init(int total)=0;
02760
02761
02768 virtual BOOL Progress(int p)=0;
02769 };
02770
02772
02773 #define MESHBOOL_UNION 1
02774 #define MESHBOOL_INTERSECTION 2
02775 #define MESHBOOL_DIFFERENCE 3
02776
02777
02778
02779
02780
02781
02782
02783
02784
02785
02786
02825 DllExport int CalcBoolOp(
02826 Mesh &mesh, Mesh &mesh1, Mesh &mesh2, int op,
02827 MeshOpProgress *prog = NULL,
02828 Matrix3 *tm1 = NULL,
02829 Matrix3 *tm2 = NULL,
02830 int whichInv = 0,
02831 int weld = TRUE);
02832
02833
02834
02835
02855 DllExport void CombineMeshes(
02856 Mesh &mesh,Mesh &mesh1,Mesh &mesh2,
02857 Matrix3 *tm1=NULL, Matrix3 *tm2=NULL, int whichInv=0);
02858
02866 DllExport void SliceMesh (Mesh & mesh,
02867 Point3 N, float off, bool split=FALSE, bool remove=FALSE);
02868
02869
02870
02871 DllExport Mesh * CreateNewMesh();
02872