meshadj.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003     FILE: meshadj.h
00004 
00005     DESCRIPTION: Adjacency list for meshes.
00006 
00007     CREATED BY: Rolf Berteig
00008 
00009     HISTORY:    Extended for Shiva by: Steve Anderson
00010 
00011  *> Copyright (c) 1994, All Rights Reserved.
00012  **********************************************************************/
00013 
00014 #pragma once
00015 #include <WTypes.h>
00016 #include "maxheap.h"
00017 #include "export.h"
00018 #include "point3.h"
00019 #include "TabTypes.h"
00020 #include "mesh.h"
00021 
00022 // forward declarations
00023 class Face;
00024 class AdjFaceList;
00025 class BitArray;
00026 class Mesh;
00027 
00028 #ifndef UNDEFINED
00029 #define UNDEFINED   0xffffffff
00030 #endif
00031 
00032 
00033 
00046 class MEdge: public MaxHeapOperators {
00047 public:
00048     DWORD f[2];
00049     DWORD v[2];
00050 
00063     DllExport int EdgeIndex(Face *faces,int side);
00071     DllExport BOOL Selected (Face *faces,BitArray &esel);
00077     DllExport BOOL Visible (Face *faces);
00083     DllExport BOOL Hidden (Face *faces);
00088     DllExport Point3 Center(Point3* verts);
00094     DllExport BOOL AFaceSelected(BitArray &fsel);
00103     DllExport Point3 ButterFlySubdivide (Mesh *mesh,AdjFaceList *af,float tens);
00124     DllExport UVVert ButterFlyMapSubdivide (Mesh *mesh,AdjFaceList *af,float tens, int mp, bool & seam, UVVert & side2);
00129     DWORD OtherVert (DWORD vv) { return (v[0] == vv) ? v[1] : v[0]; }
00134     DWORD OtherFace (DWORD ff) { return (f[0] == ff) ? f[1] : f[0]; }
00135 };
00136 
00153 class AdjEdgeList: public MaxHeapOperators {
00154 public:
00155     DWORDTab *list;     // 1 DWORDTab per vertex. The Tab is a list of indices into the edge list, 1 for each edge adjacent to the vertex
00156     Tab<MEdge> edges;   // Table of edges
00157     int nverts;         // size of 'list'.
00158 
00165     DllExport AdjEdgeList(Mesh& amesh);
00167     DllExport ~AdjEdgeList();
00168 
00172     DllExport void AddEdge( DWORD fi, DWORD v1, DWORD v2 );
00174     DWORDTab& operator[](int i) { return list[i]; }
00181     DllExport int FindEdge(DWORD v0, DWORD v1);
00184     DllExport int FindEdge(DWORDTab& vmap,DWORD v0, DWORD v1);      
00187     DllExport void TransferEdges(DWORD from,DWORD to,DWORD except1,DWORD except2,DWORD del);
00190     DllExport void RemoveEdge(DWORD from,DWORD e);
00195     DllExport void OrderAllEdges (Face *faces); // only affects order in each vert's list.
00209     DllExport void OrderVertEdges (DWORD v, Face *faces, Tab<DWORD> *flist=NULL);
00217     DllExport void GetFaceList (DWORD v, Tab<DWORD> & flist);
00218 
00219     DllExport void MyDebugPrint ();
00220 
00227     void AddEdgeToVertex(DWORD v,DWORD e) { list[v].Append (1, &e); }
00228 };
00229 
00237 class AdjFace: public MaxHeapOperators {
00238 public:
00239     DWORD f[3];
00241     AdjFace() {f[0] = f[1] = f[2] = UNDEFINED;}
00242 };
00243 
00254 class AdjFaceList: public MaxHeapOperators {
00255 public:
00256     Tab<AdjFace> list;
00257 
00260     AdjFace& operator[](int i) {return list[i];}
00263     DllExport AdjFaceList(Mesh& mesh,AdjEdgeList& el);
00264 };
00265 
00282 class FaceElementList: public MaxHeapOperators {
00283 public:
00284     // For each face, which element is it in
00285     DWORDTab elem;
00286     DWORD count;
00295     DllExport FaceElementList(Mesh &mesh,AdjFaceList& af);
00297     DWORD operator[](int i) {return elem[i];}
00298 };
00299 
00322 class FaceClusterList: public MaxHeapOperators {
00323 public:
00324     // Cluster #, one for each face - non-selected faces have UNDEFINED for their id.
00325     DWORDTab clust;
00326     DWORD count;
00327 
00328     // This version separates cluster also using a minimum angle and optionally the selection set
00352     DllExport FaceClusterList(Mesh *mesh, AdjFaceList& adj,float angle,BOOL useSel=TRUE);       
00353     // Uses selection set
00371     DllExport FaceClusterList (BitArray& fsel, AdjFaceList& adj);       
00373     DWORD operator[](int i) { return clust[i]; }
00389     DllExport void MakeVertCluster(Mesh &mesh, Tab<DWORD> & vclust);
00405     DllExport void GetNormalsCenters (Mesh &mesh, Tab<Point3> & norm, Tab<Point3> & ctr);
00430     DllExport void GetBorder (DWORD clustID, AdjFaceList & af, Tab<DWORD> & cbord);
00460     DllExport void GetOutlineVectors (Mesh & m, AdjFaceList & af, Tab<Point3> & cnorms, Tab<Point3> & odir);
00461 };
00462 
00483 class EdgeClusterList: public MaxHeapOperators {
00484 public:
00485     DWORDTab clust;
00486     DWORD count;
00487 
00498     DllExport EdgeClusterList(Mesh &mesh,BitArray &esel,AdjEdgeList &adj);
00505     DWORD ID(int f, int e) {return clust[f*3+e];}
00508     DWORD operator[](int i) {return clust[i];}
00519     DllExport void MakeVertCluster (Mesh &mesh, Tab<DWORD> & vclust);
00534     DllExport void GetNormalsCenters (Mesh &mesh, Tab<Point3> & norm, Tab<Point3> & ctr);
00535 };
00536 
00563 class MeshChamferData: public MaxHeapOperators {
00564     Tab<UVVert> hmdir[NUM_HIDDENMAPS];
00565 public:
00566     Tab<Point3> vdir;
00567     Tab<float> vmax;
00568     Tab<UVVert> *mdir;
00569 
00571     MeshChamferData () { mdir=NULL; }
00577     MeshChamferData (const Mesh & m) { mdir=NULL; InitToMesh(m); }
00579     DllExport ~MeshChamferData ();
00580 
00586     DllExport void InitToMesh (const Mesh & m);
00600     DllExport void setNumVerts (int nv, bool keep=TRUE, int resizer=0);
00601     Tab<UVVert> & MDir (int mp) { return (mp<0) ? hmdir[-1-mp] : mdir[mp]; }
00602 };
00603 
00604 // The following function has been added
00605 // in 3ds max 4.2.  If your plugin utilizes this new
00606 // mechanism, be sure that your clients are aware that they
00607 // must run your plugin with 3ds max version 4.2 or higher.
00619 DllExport void MeshChamferDataDebugPrint (MeshChamferData & mcd, int mapNum);
00620 // End of 3ds max 4.2 Extension
00621 
00622 // following is never saved: it's a collection of all the temporary data you might want to cache about a mesh.
00623 // Extrusion types:
00624 #define MESH_EXTRUDE_CLUSTER 1
00625 #define MESH_EXTRUDE_LOCAL 2
00626 
00669 class MeshTempData : public BaseInterfaceServer {
00670 private:
00671     AdjEdgeList *adjEList;
00672     AdjFaceList *adjFList;
00673     EdgeClusterList *edgeCluster;
00674     FaceClusterList *faceCluster;
00675     Tab<DWORD> *vertCluster;
00676     Tab<Point3> *normals;
00677     Tab<Point3> *centers;
00678     Tab<Point3> *vnormals;
00679     Tab<Tab<float> *> *clustDist;
00680     Tab<float> *selDist;
00681     Tab<float> *vsWeight;
00682     MeshChamferData *chamData;
00683 
00684     Tab<Point3> *extDir;
00685     Tab<Point3> *outlineDir;
00686 
00687     Mesh *mesh;
00688 
00689     //this is used to keep track of the selDist data.  We used to compute all the seldist data which
00690     //was really slow.  We now only track the selDist that fall within  this limit which can make things
00691     //much faster.
00692     float mFalloffLimit;
00693 
00694 public:
00696     DllExport MeshTempData ();
00702     DllExport MeshTempData (Mesh *m);
00704     DllExport ~MeshTempData ();
00705 
00710     void SetMesh (Mesh *m) { mesh = m; }
00711 
00715     DllExport AdjEdgeList *AdjEList ();
00719     DllExport AdjFaceList *AdjFList ();
00724     DllExport FaceClusterList *FaceClusters ();
00729     DllExport EdgeClusterList *EdgeClusters ();
00742     DllExport Tab<DWORD> *VertexClusters (DWORD sl);
00755     DllExport Tab<Point3> *ClusterNormals (DWORD sl);
00767     DllExport Tab<Point3> *ClusterCenters (DWORD sl);
00777     DllExport Matrix3 ClusterTM (int clust);
00785     DllExport Tab<Point3> *VertexNormals ();
00822     DllExport Tab<float> *VSWeight (BOOL useEdgeDist, int edgeIts,
00823                                     BOOL ignoreBack, float falloff, float pinch, float bubble);
00824 
00826 
00845     DllExport Tab<float> *SelectionDist (BOOL useEdgeDist, int edgeIts, float falloffLimit = -1.0f);
00870     DllExport Tab<float> *ClusterDist (DWORD sl, int clustId, BOOL useEdgeDist, int edgeIts);
00887     DllExport Tab<Point3> *EdgeExtDir (Tab<Point3> *edir, int extrusionType);
00901     DllExport Tab<Point3> *FaceExtDir (int extrusionType);
00907     Tab<Point3> *CurrentExtDir () { return extDir; }
00917     DllExport Tab<Point3> *OutlineDir (int extrusionType);
00918 
00929     DllExport MeshChamferData *ChamferData();
00930 
00972     DllExport void Invalidate (DWORD part);
00975     DllExport void InvalidateDistances ();
00979     DllExport void InvalidateAffectRegion ();
00982     DllExport void freeClusterDist ();
00984     DllExport void freeBevelInfo ();
00986     DllExport void freeChamferData();
00988     DllExport void freeAll ();
00989 };
00990 
00991 // CAL-04/30/01: soft selection parameters.
00992 #define SOFTSEL_MIN_FALLOFF     0.0f
00993 #define SOFTSEL_MAX_FALLOFF     999999.0f
00994 #define SOFTSEL_DEFAULT_FALLOFF 20.0f
00995 
00996 #define SOFTSEL_MIN_PINCH       -1000.0f
00997 #define SOFTSEL_MAX_PINCH       1000.0f
00998 #define SOFTSEL_DEFAULT_PINCH   0.0f
00999 
01000 #define SOFTSEL_MIN_BUBBLE      -1000.0f
01001 #define SOFTSEL_MAX_BUBBLE      1000.0f
01002 #define SOFTSEL_DEFAULT_BUBBLE  0.0f
01003 
01039 DllExport float AffectRegionFunction (float dist, float falloff, float pinch, float bubble);
01040 DllExport Point3 SoftSelectionColor (float selAmount);
01049 DllExport void MatrixFromNormal (Point3& normal, Matrix3& mat);
01059 DllExport void AverageVertexNormals (Mesh & mesh, Tab<Point3> & vnormals);
01067 DllExport Point3 AverageSelVertNormal (Mesh& mesh);
01075 DllExport Point3 AverageSelVertCenter (Mesh& mesh);
01081 DllExport void DeselectHiddenFaces (Mesh &mesh);
01088 DllExport void DeselectHiddenEdges (Mesh &mesh);
01101 DllExport void HiddenFacesToVerts (Mesh &mesh, BitArray alsoHide);
01116 DllExport void SelectionDistance (Mesh & mesh, float *selDist, float falloffLimit = -1.0f);
01151 DllExport void SelectionDistance (Mesh & mesh, float *selDist, int iters, AdjEdgeList *ae=NULL);
01180 DllExport void ClustDistances (Mesh & mesh, DWORD numClusts, DWORD *vclust,
01181                                Tab<float> **clustDist);
01217 DllExport void ClustDistances (Mesh & mesh, DWORD numClusts, DWORD *vclust,
01218                                Tab<float> **clustDist, int iters, AdjEdgeList *ae=NULL);
01219 
01220 // Mesh Selection Converter Interface - by Steve Anderson, October 2002
01221 // For accurate selections of polygons and elements in Meshes in window region selections,
01222 // (as well as correct by-vertex selections of edges and faces in window regions)
01223 // we need to know not only which components were selected, but also which were culled,
01224 // for instance by virtue of being back-facing.  We want to select only elements in which
01225 // all faces were in the selection region, but we shouldn't eliminate elements just because 
01226 // some of their faces were culled.
01227 
01228 // So we provide this Mesh Selection Converter interface, which automatically stores culling
01229 // information in a BitArray when Mesh::SubObjectHitTest is called.  Then this can be used
01230 // to handle level conversions in Editable Mesh, Edit Mesh, and Mesh Select 
01231 // SelectSubComponent routines.
01232 
01233 #define MESHSELECTCONVERT_INTERFACE Interface_ID(0x3da7dd5, 0x7ecf0391)
01234 
01235 // Selection converter flags
01236 #define MESH_SELCONV_REQUIRE_ALL 0x01   // Set during Mesh hit-testing (with window region)
01237 
01238 class MeshSelectionConverter : public BaseInterface {
01239 public:
01240     DllExport MeshSelectionConverter ();
01241 
01242     // Our interesting methods:
01261     DllExport void FaceToElement (Mesh & mesh, AdjFaceList *af, BitArray & faceSel, BitArray & elementSel);
01287     DllExport void FaceToPolygon (Mesh & mesh, AdjFaceList *af, BitArray & faceSel, BitArray & polygonSel,
01288         float faceThresh, bool ignoreVisEdge=false);
01305     DllExport void VertexToEdge (Mesh & mesh, BitArray & vertexSel, BitArray & edgeSel);
01306     DllExport void VertexToFace (Mesh & mesh, BitArray & vertexSel, BitArray & faceSel);
01307 
01308     // Note - we can't just combine VertexToFace and FaceToPolygon, because we won't have accurate Face culling info.
01338     DllExport void VertexToPolygon (Mesh & mesh, AdjFaceList *af, BitArray & vertexSel, BitArray & polygonSel,
01339         float faceThresh, bool ignoreVisEdge=false);
01362     DllExport void VertexToElement (Mesh & mesh, AdjFaceList *af, BitArray & vertexSel, BitArray & elementSel);
01363 
01364     // Access which subobject components were culled in last Mesh hit-testing.
01372     BitArray & GetCull () { return mCull; }
01373 
01374     void SetFlag (DWORD f, bool value=true) { if (value) mFlags |= f; else mFlags &= ~f; }
01375     void ClearFlag(DWORD f) { mFlags &= ~f; }
01376     bool GetFlag (DWORD f) { return (mFlags&f) ? true : false; }
01377 
01378     // From BaseInterface:
01379     Interface_ID GetID() {return MESHSELECTCONVERT_INTERFACE;}
01380     DllExport void DeleteInterface();
01381     DllExport BaseInterface* GetInterface(Interface_ID id);
01382     DllExport BaseInterface* CloneInterface(void* remapDir = NULL);
01383 
01384 private:
01385     DWORD mFlags;
01386     BitArray mCull;
01387     DWORD mCullLevel;
01388 };
01389 
01390