00001
00002
00003
00004
00005
00006
00007
00008
00009 #pragma once
00010
00011 #include "maxheap.h"
00012 #include "shphier.h"
00013 #include "captypes.h"
00014 #include "shpsels.h"
00015 #include "templt.h"
00016 #include "maxtypes.h"
00017 #include "channels.h"
00018 #include "TabTypes.h"
00019 #include "GraphicsConstants.h"
00020
00021
00022 class GraphicsWindow;
00023 class Material;
00024 class HitRegion;
00025 struct SnapInfo;
00026 class IPoint2;
00027
00028
00030
00031 #define PSHAPE_SNAP_IGNORELAST (1<<0)
00032 #define PSHAPE_SNAP_NOEDGES (1<<1)
00033
00034
00035
00037
00039 #define POLYSHP_INTERP_SIMPLE 0 //!< Parameter space based on segments
00040 #define POLYSHP_INTERP_NORMALIZED 1 //!< Parameter space normalized to curve length
00041
00042
00043
00044
00045 class Spline3D;
00046
00047
00048
00049
00051
00052 #define CAPVERT_VISEDGE (1<<0)
00053
00054
00055 class CapVert: public MaxHeapOperators {
00056 public:
00057 int vert;
00058 DWORD flags;
00059 float ang;
00060 CapVert *prev,*next;
00061 CapVert *smaller,*bigger;
00062 CapVert() { vert=0; flags = 0; ang = 0.0f; prev=next=smaller=bigger = NULL; }
00063 };
00064
00065
00081 #define POLYPT_KNOT (1<<8)
00082
00087 #define POLYPT_INTERPOLATED (1<<9)
00088
00098 #define POLYPT_SMOOTH (1<<10)
00099
00103 #define POLYPT_SEG_SELECTED (1<<11)
00104
00105 #define POLYPT_BRIDGE (1<<16) //!< \internal Span between two polygons. Used internally by capping code.
00106 #define POLYPT_SPLICE (1<<17) //!< \internal Point is endpoint of a bridge. Used internally by capping code.
00107 #define POLYPT_VISEDGE (1<<18) //!< \internal Segment should be visible on mesh. Used internally by capping code.
00108 #define POLYPT_NO_SPLICE (1<<19) //!< \internal Don't allow a bridge at this point. Used internally by capping code.
00109 #define POLYPT_INVIS_EDGE (1<<20) //!< \internal Force segment to be invisible on capping. Used internally by capping code
00110 #define POLYPT_NO_SNAP (1<<21) //!< \internal Suppress snapping when set. Used internally by capping code.
00111
00112
00116 #define POLYPT_MATID_SHIFT 16
00117 #define POLYPT_MATID_MASK 0xFFFF
00118
00119
00120
00124 class PolyPt: public MaxHeapOperators {
00125 public:
00126 Point3 p;
00127 DWORD flags;
00128 DWORD flags2;
00129 int aux;
00130
00132 PolyPt() { p = Point3(0,0,0); flags = 0; flags2 = 0; aux = 0; }
00133
00135 PolyPt(Point3 ip, DWORD f=0, int a=0, DWORD f2=0) { p = ip; flags = f; aux = a; flags2 = f2;}
00136
00139 inline MtlID GetMatID() {return (int)((flags2>>POLYPT_MATID_SHIFT)&POLYPT_MATID_MASK);}
00140
00144 inline void SetMatID(MtlID id) {flags2 &= 0xFFFF; flags2 |= (DWORD)(id<<POLYPT_MATID_SHIFT);}
00145 };
00146
00147
00149
00150 #define CAP3DS_OPT_CLOSEST_BRIDGE (1<<0) //!< Bridge polys at closest point
00151
00152
00153
00155
00156
00157 #define POLYLINE_CLOSED (1<<0)
00158
00162 #define POLYLINE_NO_SELF_INT (1<<1)
00163
00164
00170 class PolyLine: public MaxHeapOperators {
00171 public:
00172 int numPts;
00173 PolyPt *pts;
00174 DWORD flags;
00175 Box3 bdgBox;
00176 float cachedLength;
00177 float *lengths;
00178 float *percents;
00179 BOOL cacheValid;
00180
00184 CoreExport PolyLine();
00185
00187 CoreExport PolyLine(PolyLine& from);
00188
00190 CoreExport ~PolyLine();
00191
00195 CoreExport void Init();
00196
00198 void Close() { flags |= POLYLINE_CLOSED; }
00199
00202 CoreExport BOOL IsClosed();
00203
00205 void Open() { flags &= ~POLYLINE_CLOSED; }
00206
00209 CoreExport BOOL IsOpen();
00210
00212 void SetNoSelfInt() { flags |= POLYLINE_NO_SELF_INT; }
00213
00215 BOOL IsNoSelfInt() { return (flags & POLYLINE_NO_SELF_INT) ? TRUE : FALSE; }
00216
00218 int Verts() { return numPts; }
00219
00221 CoreExport int Segments();
00222
00228 CoreExport BOOL SetNumPts(int count, BOOL keep = TRUE);
00229
00233 CoreExport void Append(PolyPt& p);
00234
00238 CoreExport void Insert(int where, PolyPt& p);
00239
00242 CoreExport void Delete(int where);
00243
00252 CoreExport void Reverse(BOOL keepZero=FALSE);
00253
00255 CoreExport PolyLine& operator=(PolyLine& from);
00258 CoreExport PolyLine& operator=(Spline3D& from);
00261 CoreExport PolyPt& operator[](int index) { return pts[index]; }
00262
00265 CoreExport void BuildBoundingBox(void);
00266
00271 CoreExport void InvalidateGeomCache();
00272
00277 CoreExport Box3 GetBoundingBox(Matrix3 *tm=NULL);
00278
00280 CoreExport void Render(GraphicsWindow* gw, Material* ma, RECT *rp, int compFlags, int numMat);
00281
00295 CoreExport void Render(GraphicsWindow* gw, Material* ma, int numMat, BOOL colorSegs, BitArray &segsel, BOOL useStartSegments = TRUE);
00296
00298 CoreExport BOOL Select(GraphicsWindow* gw, Material* ma, HitRegion* hr, int abortOnHit = FALSE);
00299
00301 CoreExport void Snap(GraphicsWindow* gw, SnapInfo* snap, IPoint2* p, Matrix3 &tm, DWORD flags);
00302
00305 CoreExport void Transform(Matrix3 &tm);
00306
00311 CoreExport void Dump(MCHAR *title = NULL);
00312
00315 CoreExport void SpliceLine(int where, PolyLine &source, int splicePoint);
00316
00326 CoreExport BOOL HitsSegment(Point2 p1, Point2 p2, BOOL findAll = FALSE, IntersectionCallback3D *cb = NULL);
00327
00329 CoreExport int Cap3DS(CapVert *capverts, MeshCapInfo &capInfo, DWORD options = 0);
00330
00339 CoreExport BOOL HitsPolyLine(PolyLine &line, BOOL findAll = FALSE, IntersectionCallback3D *cb = NULL);
00340
00345 CoreExport BOOL SurroundsPoint(Point2 &point);
00346
00352 CoreExport Point3 InterpPiece3D(int segment, float t);
00353
00361 CoreExport Point3 InterpCurve3D(float u, int ptype=POLYSHP_INTERP_SIMPLE);
00362
00368 CoreExport Point3 TangentPiece3D(int segment, float t);
00369
00376 CoreExport Point3 TangentCurve3D(float u, int ptype=POLYSHP_INTERP_SIMPLE);
00377
00380 CoreExport MtlID GetMatID(int segment);
00382 CoreExport float CurveLength();
00383
00387 CoreExport BOOL IsClockWise();
00388
00395 CoreExport BOOL SelfIntersects(BOOL findAll = FALSE, IntersectionCallback3D *cb = NULL);
00396
00397 CoreExport void GetSmoothingMap(IntTab& map);
00398
00399 CoreExport IOResult Save(ISave* isave);
00400 CoreExport IOResult Load(ILoad* iload);
00401
00407 CoreExport void Swap(PolyLine& line);
00408 };
00409
00410 #define CAPFACE_AB (1<<0)
00411 #define CAPFACE_BC (1<<1)
00412 #define CAPFACE_CA (1<<2)
00413
00414 class ShapeObject;
00415
00428 class PolyShape: public MaxHeapOperators {
00429 public:
00430 int numLines;
00431 PolyLine *lines;
00432 DWORD flags;
00433 Box3 bdgBox;
00434
00436
00437 ShapeVSel vertSel;
00438 ShapeSSel segSel;
00439 ShapePSel polySel;
00440
00441
00445 DWORD selLevel;
00446
00453 DWORD dispFlags;
00454
00456
00457 MeshCapInfo morphCap;
00458 BOOL morphCapCacheValid;
00459 MeshCapInfo gridCap;
00460 BOOL gridCapCacheValid;
00461 PatchCapInfo patchCap;
00462 BOOL patchCapCacheValid;
00463 ShapeHierarchy cachedHier;
00464 BOOL hierCacheValid;
00465
00466
00471 CoreExport PolyShape();
00472
00475 CoreExport PolyShape(PolyShape& from);
00476
00478 CoreExport ~PolyShape();
00479
00483 CoreExport void Init();
00484
00488 CoreExport void NewShape();
00489
00495 CoreExport BOOL SetNumLines(int count, BOOL keep = TRUE);
00496
00500 CoreExport PolyLine* NewLine();
00501
00505 CoreExport void Append(PolyLine &l);
00506
00511 CoreExport void Insert(int where, PolyLine& l);
00512
00516 CoreExport void Delete(int where);
00517
00519 CoreExport PolyShape& operator=(PolyShape& from);
00520
00526 CoreExport PolyShape& operator=(BezierShape& from);
00527
00531 CoreExport void BuildBoundingBox(void);
00532
00537 CoreExport void InvalidateGeomCache(BOOL unused);
00538
00540 CoreExport void InvalidateCapCache();
00541
00548 CoreExport Box3 GetBoundingBox(Matrix3 *tm=NULL);
00549
00557 CoreExport void GetDeformBBox(TimeValue t, Box3& box, Matrix3 *tm, BOOL useSel );
00558
00560 CoreExport void Render(GraphicsWindow* gw, Material* ma, RECT *rp, int compFlags, int numMat);
00561
00563 CoreExport BOOL Select(GraphicsWindow* gw, Material* ma, HitRegion* hr, int abortOnHit = FALSE);
00564
00566 CoreExport void Snap(GraphicsWindow* gw, SnapInfo* snap, IPoint2* p, Matrix3 &tm);
00567
00569 CoreExport void Snap(GraphicsWindow* gw, SnapInfo* snap, IPoint2* p, Matrix3 &tm, DWORD flags);
00570
00574 CoreExport void Transform(Matrix3 &tm);
00575
00587 CoreExport int MakeCap(TimeValue t, MeshCapInfo &capInfo, int capType);
00588
00601 CoreExport int MakeCap(TimeValue t, PatchCapInfo &capInfo);
00602
00604 CoreExport int Make3DSCap(MeshCapInfo &capInfo, DWORD options = 0);
00605
00607 CoreExport int MakeGridCap(MeshCapInfo &capInfo);
00608
00614 CoreExport void Dump(MCHAR *title = NULL);
00615
00617 CoreExport void UpdateCachedHierarchy();
00618
00627 CoreExport ShapeHierarchy &OrganizeCurves(TimeValue t, ShapeHierarchy *hier = NULL);
00628
00637 CoreExport void UpdateSels();
00638
00647 CoreExport void Reverse(int poly, BOOL keepZero=FALSE);
00648
00661 CoreExport void Reverse(BitArray &reverse, BOOL keepZero=FALSE);
00662
00667 CoreExport MtlID GetMatID(int poly, int piece);
00674 CoreExport BitArray VertexTempSel(int poly);
00675
00677 CoreExport void ShallowCopy(PolyShape* ashape, ChannelMask channels);
00678
00680 CoreExport void DeepCopy(PolyShape* ashape, ChannelMask channels);
00681
00683 CoreExport void NewAndCopyChannels(ChannelMask channels);
00684
00686 CoreExport void FreeChannels(ChannelMask channels, int zeroOthers=1);
00687
00688
00690 CoreExport IOResult Save(ISave *isave);
00691
00693 CoreExport IOResult Load(ILoad *iload);
00694
00707 CoreExport bool Delete(const unsigned int* indices, unsigned int n);
00708
00716 CoreExport void Append(PolyLine* lines, unsigned int n, bool useSwap = false);
00717 };
00718