shape.h

Go to the documentation of this file.
00001 //**************************************************************************/
00002 // Copyright (c) 1998-2006 Autodesk, Inc.
00003 // All rights reserved.
00004 // 
00005 // These coded instructions, statements, and computer programs contain
00006 // unpublished proprietary information written by Autodesk, Inc., and are
00007 // protected by Federal copyright law. They may not be disclosed to third
00008 // parties or copied or duplicated in any form, in whole or in part, without
00009 // the prior written consent of Autodesk, Inc.
00010 //**************************************************************************/
00011 // FILE:        shape.h
00012 // DESCRIPTION: Defines Basic BezierShape Object
00013 // AUTHOR:      Tom Hudson
00014 // HISTORY:     created 23 February 1995
00015 //**************************************************************************/
00016 
00017 #pragma once
00018 
00019 #include "maxheap.h"
00020 #include "shphier.h"
00021 #include "spline3d.h"
00022 #include "shpsels.h"    // Shape selection classes
00023 #include "hitdata.h"
00024 #include "TabTypes.h"
00025 #include "GraphicsConstants.h"
00026 
00027 // forward declarations
00028 class BezierShape;
00029 class ModContext;
00030 
00031 // Parameters for BezierShape::PerformTrimOrExtend
00032 #define SHAPE_TRIM 0
00033 #define SHAPE_EXTEND 1
00034 
00035 //watje class contains the data for the bind points
00036 class bindShape: public MaxHeapOperators
00037 {
00038 public:
00039     int pointSplineIndex;      // spline that is to be bound
00040     int segSplineIndex;        // spline that contains the segment to bind to
00041     int seg;                    // seg that the point is bound to
00042     Point3 bindPoint,segPoint;  // posiiton in space of the start seg point and the bind point
00043     BOOL isEnd;                 // is the bound point the end or beginning of the spline
00044 };
00045 
00046 
00062 class ShapeSubHitRec: public MaxHeapOperators {
00063     private:
00064         ShapeSubHitRec *next;
00065     public:
00066         DWORD   dist;
00067         BezierShape*    shape;
00068         int     poly;
00069         int     index;
00072         ShapeSubHitRec( DWORD dist, BezierShape *shape, int poly, int index, ShapeSubHitRec *next )
00073             { this->dist = dist; this->shape = shape; this->poly = poly; this->index = index; this->next = next; }
00074 
00076         ShapeSubHitRec *Next() { return next; }
00077     };
00078 
00084 class SubShapeHitList: public MaxHeapOperators {
00085     private:
00086         ShapeSubHitRec *first;
00087     public:
00089         SubShapeHitList() { first = NULL; }
00091         CoreExport ~SubShapeHitList();  
00092 
00094         ShapeSubHitRec *First() { return first; }
00108         CoreExport void AddHit( DWORD dist, BezierShape *shape, int poly, int index );  
00109         int Count() {
00110             int count = 0;
00111             ShapeSubHitRec *ptr = first;
00112             while(ptr) {
00113                 count++;
00114                 ptr = ptr->Next();
00115                 }
00116             return count;
00117             }
00118     };
00119 
00120 // Special storage class for hit records so we can know which object was hit
00133 class ShapeHitData : public HitData {
00134     public:
00135         BezierShape *shape;
00136         int poly;
00137         int index;
00140         ShapeHitData(BezierShape *shape, int poly, int index)
00141             { this->shape = shape; this->poly = poly; this->index = index; }
00142         ~ShapeHitData() {}
00143     };
00144 
00145 
00146 // Callback used for retrieving other shapes in the current editing context
00154 class ShapeContextCallback: public MaxHeapOperators {
00155     public:
00165         virtual BezierShape *GetShapeContext(ModContext* context) = 0;
00166     };
00167 
00168 class ShapeObject;
00169 
00185 class BezierShapeTopology: public MaxHeapOperators {
00186     public:
00187         BOOL ready;
00188         IntTab kcount;
00189         BitArray closed;
00193         BezierShapeTopology() { ready = FALSE; }
00198         CoreExport void Build(BezierShape &shape);
00200         CoreExport int operator==(const BezierShapeTopology& t);
00202         CoreExport IOResult Save(ISave *isave);
00204         CoreExport IOResult Load(ILoad *iload);
00205     };
00206 
00207 // The following {class, member, macro, flag} has been added
00208 // in 3ds max 4.2.  If your plugin utilizes this new
00209 // mechanism, be sure that your clients are aware that they
00210 // must run your plugin with 3ds max version 4.2 or higher.
00211 
00212 // CAL-04/12/01: Use area selection to jump between splines in soft selection
00213 // To be merged into BezierShape in the future.
00214 // Two public data members, mUseAreaSelect & mAreaSelect, in the interface extension class.
00215 // Set mUseAreaSelect to TRUE to enable the use of area selection to jump between splines
00216 // when doing soft selection with edge distance enabled. mAreaSelect is the distance
00217 // allowed to jump from one node in a spline to another node in another spline.
00218 #define BEZIER_SHAPE_INTERFACE_EX41 Interface_ID(0x23526cd1, 0x695d7e4e)
00219 #define GET_BEZIER_SHAPE_INTERFACE_EX41() \
00220     (BezierShapeInterface_Ex41*) GetInterface(BEZIER_SHAPE_INTERFACE_EX41)
00221 
00238 class BezierShapeInterface_Ex41 : public BaseInterface
00239 {
00240 public:
00241     BOOL mUseAreaSelect;        // TRUE if use area selection
00242     float mAreaSelect;          // Radius of area selection
00243 
00251     BaseInterface*  GetInterface(Interface_ID id) { if (id == BEZIER_SHAPE_INTERFACE_EX41) return (BaseInterface*)this; else return NULL; }
00254     Interface_ID    GetID() { return BEZIER_SHAPE_INTERFACE_EX41; }
00257     void            DeleteInterface();
00258 };
00259 // End of 3ds max 4.2 Extension
00260 
00307 class BezierShape : public BaseInterfaceServer {
00308         Box3            bdgBox;         // object space--depends on geom+topo
00309         static int shapeCount;          // Number of shape objects in the system!
00310         PolyShape pShape;               // PolyShape cache
00311         int pShapeSteps;                // Number of steps in the cache
00312         BOOL pShapeOptimize;            // TRUE if cache is optimized
00313         BOOL pShapeCacheValid;          // TRUE if the cache is current
00314         int *vertBase;                  // Cache giving vert start index for each spline
00315         int totalShapeVerts;            // Total number of verts in the shape (cached)
00316         int *knotBase;                  // Cache giving knot start index for each spline
00317         int totalShapeKnots;            // Total number of knots in the shape (cached)
00318         BOOL topoCacheValid;            // TRUE if topology cache is valid
00319         BezierShapeTopology topology;   // Topology cache
00320         
00321         // CAL-03/25/01: use area selection to jump between splines in soft selection
00322         //               Make new APIs to access these in the future.
00323         // BOOL mUseAreaSelect;         // TRUE if use area selection
00324         // float mAreaSelect;               // Radius of area selection
00325 
00326         // CAL-04/12/01: move the above two private data members into interface extension
00327         //               and use the following private methods to access them
00328         BOOL UseAreaSelect();
00329         void SetUseAreaSelect( BOOL useAreaSelect );
00330 
00331         float AreaSelect();
00332         void SetAreaSelect( float aresSelect );
00333 
00334         // CAL-03/25/01: Remove these friend declaration once their access to area selection
00335         //               variables are replaced by the new APIs.
00336         friend INT_PTR CALLBACK SplineSelectDlgProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam );
00337 
00338     public:
00339         
00340         // Patch capping cache (mesh capping and hierarchy caches stored in PolyShape cache)
00341         PatchCapInfo patchCap;
00342         BOOL patchCapCacheValid;
00343 
00344         // The list of splines
00345         Spline3D **splines;
00346         int splineCount;
00347 
00348         int steps;                      // Number of steps (-1 = adaptive)
00349         BOOL optimize;                  // TRUE optimizes linear segments
00350 
00351         // Selection
00352         ShapeVSel   vertSel;        // selected vertices
00353         ShapeSSel   segSel;         // selected segments
00354         ShapePSel   polySel;        // selected polygons
00355 
00356         // If hit bezier vector, this is its info:
00357         int bezVecPoly;
00358         int bezVecVert;
00359 
00360         // Selection level
00361         DWORD       selLevel;
00362 
00363         // Display attribute flags
00364         DWORD       dispFlags;
00365 
00379         CoreExport BezierShape();
00382         CoreExport BezierShape(BezierShape& fromShape);
00383 
00398         CoreExport void     Init();
00399 
00401         CoreExport ~BezierShape();
00402 
00404         CoreExport BezierShape&         operator=(BezierShape& fromShape);
00406         CoreExport BezierShape&         operator=(PolyShape& fromShape);
00414         CoreExport Point3   GetVert(int poly, int i);
00424         CoreExport void     SetVert(int poly, int i, const Point3 &xyz);
00425         
00427         CoreExport void     Render(GraphicsWindow *gw, Material *ma, RECT *rp, int compFlags, int numMat);
00428         CoreExport void     RenderGizmo(GraphicsWindow *gw);
00430         CoreExport BOOL     Select(GraphicsWindow *gw, Material *ma, HitRegion *hr, int abortOnHit = FALSE);
00432         CoreExport void     Snap(GraphicsWindow *gw, SnapInfo *snap, IPoint2 *p, Matrix3 &tm);
00433         // See polyshp.h for snap flags
00435         CoreExport void     Snap(GraphicsWindow *gw, SnapInfo *snap, IPoint2 *p, Matrix3 &tm, DWORD flags);
00438         CoreExport BOOL     SubObjectHitTest(GraphicsWindow *gw, Material *ma, HitRegion *hr,
00439                                 DWORD flags, SubShapeHitList& hitList );
00440 
00444         CoreExport void     BuildBoundingBox(void);
00452         CoreExport Box3     GetBoundingBox(Matrix3 *tm=NULL); // RB: optional TM allows the box to be calculated in any space.
00453                                                               // NOTE: this will be slower becuase all the points must be transformed.
00454         
00458         CoreExport void     InvalidateGeomCache();
00460         CoreExport void     InvalidateCapCache();
00461                 
00462         // functions for use in data flow evaluation
00464         CoreExport void     ShallowCopy(BezierShape *ashape, ChannelMask channels);
00466         CoreExport void     DeepCopy(BezierShape *ashape, ChannelMask channels);
00468         CoreExport void NewAndCopyChannels(ChannelMask channels);
00470         CoreExport void     FreeChannels(ChannelMask channels, int zeroOthers=1);
00471 
00472         // Display flags
00479         CoreExport void     SetDispFlag(DWORD f);
00486         CoreExport DWORD    GetDispFlag(DWORD f);
00493         CoreExport void     ClearDispFlag(DWORD f);
00509         CoreExport BitArray VertexTempSel(int poly, int level = -1);
00510         // Constructs a vertex selection list for all polys based on the current selection level
00511         // This is a bitarray with a bit for each vertex in each poly in the shape.  If
00512         // includeVecs is set, it will set the bits for vectors associated with selected knots.
00513         // Specify a poly number or -1 for all.  Can specify selection level optionally
00545         CoreExport BitArray VertexTempSelAll(int poly = -1, BOOL includeVecs = FALSE, int level = 0, BOOL forceSel = FALSE);
00546 
00548 
00553         CoreExport BitArray VertexFlagSel(int poly, DWORD flag);
00554 
00556         CoreExport IOResult Save(ISave* isave);
00558         CoreExport IOResult Load(ILoad* iload);
00559 
00560         // BezierShape-specific methods
00561 
00563         inline int SplineCount() { return splineCount; }
00570         CoreExport Spline3D* GetSpline(int index);
00586         CoreExport Spline3D* NewSpline(int itype = KTYPE_CORNER,int dtype = KTYPE_BEZIER,int ptype = PARM_UNIFORM);
00595         CoreExport Spline3D* AddSpline(Spline3D* spline);
00601         CoreExport int DeleteSpline(int index);
00611         CoreExport int InsertSpline(Spline3D* spline, int index);
00613         CoreExport void NewShape();
00616         CoreExport int GetNumVerts();
00619         CoreExport int GetNumSegs();
00632         CoreExport void GetDeformBBox(TimeValue t, Box3& box, Matrix3 *tm, BOOL useSel );
00645         CoreExport void UpdateSels(BOOL save=FALSE);
00652         CoreExport void GetClosures(BitArray& array);
00658         CoreExport void SetClosures(BitArray& array);
00681         CoreExport float FindSegmentPoint(int poly, int segment, GraphicsWindow *gw, Material *ma, HitRegion *hr, int ptype = PARAM_SIMPLE);
00692         CoreExport void Reverse(int poly, BOOL keepZero = FALSE);
00705         CoreExport void Reverse(BitArray &reverse, BOOL keepZero = FALSE);
00717         CoreExport ShapeHierarchy &OrganizeCurves(TimeValue t, ShapeHierarchy *hier = NULL);
00727         CoreExport void MakePolyShape(PolyShape &pshp, int steps = -1, BOOL optimize = FALSE);
00736         CoreExport void MakeFirst(int poly, int vertex);
00742         CoreExport void Transform(Matrix3 &tm);
00744         CoreExport BezierShape& operator+=(BezierShape& from);
00756         CoreExport void AddAndWeld(BezierShape &from, float weldThreshold);
00758         CoreExport void ReadyCachedPolyShape();
00769         CoreExport int MakeCap(TimeValue t, MeshCapInfo &capInfo, int capType);
00779         CoreExport int MakeCap(TimeValue t, PatchCapInfo &capInfo);
00787         CoreExport int ReadyPatchCap();
00788         
00789         // The following copies the shapes, selection sets and any caches from the source object.
00790         // It does NOT copy selection level info or display info.
00797         CoreExport void CopyShapeDataFrom(BezierShape &fromShape);
00798 
00799         // The following methods provide an easy way to derive a simple index for any
00800         // vert in any spline in the shape, and turn that index back into a poly/vert pair
00802         CoreExport void PrepVertBaseIndex();    // Used internally automatically
00811         CoreExport int GetVertIndex(int poly, int vert);
00821         CoreExport void GetPolyAndVert(int index, int &polyOut, int &vertOut);
00823         CoreExport int GetTotalVerts(); // Total number of verts in the shape
00824         CoreExport Point3   GetVert( int index ); // returns a point using global indexing scheme
00825         CoreExport void     SetVert( int index , const Point3 &xyz); // sets a point using global indexing scheme
00826 
00827         // The following methods provide an easy way to derive a simple index for any
00828         // knot in any spline in the shape, and turn that index back into a poly/knot pair
00830         CoreExport void PrepKnotBaseIndex();    // Used internally automatically
00839         CoreExport int GetKnotIndex(int poly, int knot);
00849         CoreExport void GetPolyAndKnot(int index, int &polyOut, int &knotOut);
00851         CoreExport int GetTotalKnots(); // Total number of knots in the shape
00852 
00853         // The following functions delete the selected items, returning TRUE if any were
00854         // deleted, or FALSE if none were deleted.
00861         CoreExport BOOL DeleteSelVerts(int poly);   // For single poly
00868         CoreExport BOOL DeleteSelSegs(int poly);    // For single poly
00871         CoreExport BOOL DeleteSelectedVerts();  // For all polys
00874         CoreExport BOOL DeleteSelectedSegs();
00877         CoreExport BOOL DeleteSelectedPolys();
00878 
00879         // Copy the selected geometry (segments or polys), reversing if needed.
00880         // Returns TRUE if anything was copied
00887         CoreExport BOOL CloneSelectedParts(BOOL reverse=FALSE);
00888 
00889         // Tag the points in the spline components to record our topology (This stores
00890         // identifying values in the Spline3D's Knot::aux fields for each control point)
00891         // This info can be used after topology-changing operations to remap information
00892         // tied to control points.
00893         // Returns FALSE if > 32767 knots or polys (can't record that many)
00894         // 
00895         // MAXr3: Optional channel added.  0=aux2, 1=aux3
00909         CoreExport BOOL RecordTopologyTags(int channel=0);
00910 
00911         // Support for interpolating along the shape's splines
00927         CoreExport Point3 InterpCurve3D(int poly, float param, int ptype=PARAM_SIMPLE);
00942         CoreExport Point3 TangentCurve3D(int poly, float param, int ptype=PARAM_SIMPLE);
00962         CoreExport Point3 InterpPiece3D(int poly, int piece, float param, int ptype=PARAM_SIMPLE);
00977         CoreExport Point3 TangentPiece3D(int poly, int piece, float param, int ptype=PARAM_SIMPLE);
00987         CoreExport MtlID GetMatID(int poly, int piece);
00992         CoreExport float LengthOfCurve(int poly);
00993 
00994         // Get information on shape topology
01002         CoreExport void GetTopology(BezierShapeTopology &topo);
01003 
01004         // Perform a trim or extend
01034         CoreExport BOOL PerformTrimOrExtend(IObjParam *ip, ViewExp *vpt, ShapeHitData *hit, IPoint2 &m, ShapeContextCallback &cb, int trimType, int trimInfinite);
01035 
01036         CoreExport BOOL SelVertsSameType(); // Are all selected vertices the same type?
01037         CoreExport BOOL SelSegsSameType();  // Are all selected segments the same type?
01038         CoreExport BOOL SelSplinesSameType();   // Are all segments in selected splines the same type?
01039 
01040 //watje 1-10-98 additonal changes
01041 
01042         Tab<bindShape> bindList;        //list of bind points
01058         CoreExport void BindKnot(BOOL isEnd, int segIndex, int splineSegID, int splinePointID); // binds a knot to a seg ment
01065         CoreExport BOOL UnbindKnot(int splineID, BOOL isEnd);  //unbind a knot 
01081         CoreExport void UpdateBindList(BOOL useGeometricTracking = FALSE);  //when topology changes this needs to be called to update the bind list
01084         CoreExport BOOL HideSelectedSegs();  // hide selected segs
01087         CoreExport BOOL HideSelectedVerts(); // hide segs attached to selected verts
01090         CoreExport BOOL HideSelectedSplines(); // hide segs attached to selected splines
01093         CoreExport BOOL UnhideSegs();          //unhide all segs
01094 
01095         CoreExport int  UnselectHiddenVerts();
01096         CoreExport int  UnselectHiddenSegs();
01097         CoreExport int  UnselectHiddenSplines();
01098 
01099         float * mpVertexWeights;
01100         int numVertexWeights;
01101         int   * mpVertexEdgeDists;
01102         float * mpVertexDists;
01103 
01104         public:
01105         CoreExport void  SetVertexWeightCount( int i ); // destroys existing weights, sets all weights = 0.0.
01106         CoreExport void  SetVertexWeight( int i, float w ) { assert( mpVertexWeights ); if ( i >= numVertexWeights ) return; mpVertexWeights[i] = w; }
01107         CoreExport float VertexWeight( int i ) { if ( !mpVertexWeights ) return 0.0f; if ( i >= numVertexWeights ) return 0.0f; return mpVertexWeights[i]; }
01108         CoreExport bool  VertexWeightSupport() { if ( mpVertexWeights ) return true; return false; }
01109         CoreExport float *GetVSelectionWeights() { return mpVertexWeights; }
01110         CoreExport void SupportVSelectionWeights();     // Allocate a weight table if none 
01111 
01112         float mFalloff, mPinch, mBubble;
01113         int   mEdgeDist, mUseEdgeDist, mAffectBackface, mUseSoftSelections;
01114 
01115         CoreExport int  UseEdgeDists( );
01116         CoreExport void SetUseEdgeDists( int edgeDist );
01117 
01118         CoreExport int  EdgeDist( );
01119         CoreExport void SetEdgeDist( int edgeDist );
01120 
01121         CoreExport int  UseSoftSelections();
01122         CoreExport void SetUseSoftSelections( int useSoftSelections );
01123 
01124         CoreExport int AffectBackface( );
01125         CoreExport void SetAffectBackface( int affectBackface );
01126 
01127         CoreExport float Falloff( );
01128         CoreExport void SetFalloff( float falloff );
01129 
01130         CoreExport float Pinch( );
01131         CoreExport void SetPinch( float pinch );
01132 
01133         CoreExport float Bubble( );
01134         CoreExport void SetBubble( float bubble );
01135 
01136         CoreExport void InvalidateVertexWeights();
01137 
01138         CoreExport void UpdateVertexDists();
01139         CoreExport void UpdateEdgeDists( );
01140         CoreExport void UpdateVertexWeights();
01141 
01143 
01149         CoreExport bool DeleteSplines(const unsigned int* indices, unsigned int n);
01150     };
01151