source: golgotha/src/maxtool/sdk_inc/polyshp.h @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
  • Property svn:keywords set to Id
File size: 9.5 KB
Line 
1/**********************************************************************
2 *<
3        FILE: polyshp.h
4
5        DESCRIPTION: Polyline shape methods
6
7        CREATED BY: Tom Hudson
8
9        HISTORY: Created 3 October 1995
10
11 *> Copyright (c) 1995, All Rights Reserved.
12 **********************************************************************/
13
14#ifndef __POLYSHP_H_
15
16#define __POLYSHP_H_
17
18#include "shphier.h"
19#include "captypes.h"
20#include "shpsels.h"    // Shape selection classes
21
22// Display flags
23#define DISP_VERTTICKS          (1<<0)
24//#define DISP_BEZHANDLES               (1<<1)
25#define DISP_SELVERTS           (1<<10)
26#define DISP_SELSEGMENTS        (1<<11)
27#define DISP_SELPOLYS           (1<<13)
28
29// Snap flags
30#define PSHAPE_SNAP_IGNORELAST  (1<<0)
31#define PSHAPE_SNAP_NOEDGES             (1<<1)
32
33// Selection level bits.
34#define SHAPE_OBJECT            (1<<0)
35#define SHAPE_SPLINE            (1<<1)
36#define SHAPE_SEGMENT           (1<<2)
37#define SHAPE_VERTEX            (1<<3)
38
39// Flags for sub object hit test
40
41// NOTE: these are the same bits used for object level.
42#define SUBHIT_SHAPE_SELONLY    (1<<0)
43#define SUBHIT_SHAPE_UNSELONLY  (1<<2)
44#define SUBHIT_SHAPE_ABORTONHIT (1<<3)
45#define SUBHIT_SHAPE_SELSOLID   (1<<4)
46
47#define SUBHIT_SHAPE_VERTS              (1<<24)
48#define SUBHIT_SHAPE_SEGMENTS   (1<<25)
49#define SUBHIT_SHAPE_POLYS              (1<<26)
50#define SUBHIT_SHAPE_TYPEMASK   (SUBHIT_SHAPE_VERTS|SUBHIT_SHAPE_SEGMENTS|SUBHIT_SHAPE_POLYS)
51
52class Spline3D;
53
54//--------------------------------------------------------------
55// Capping classes, etc.
56
57// CapVert flags
58#define CAPVERT_VISEDGE (1<<0)
59
60class CapVert {
61        public:
62                int vert;
63                DWORD flags;
64                float ang;
65                CapVert *prev,*next;
66                CapVert *smaller,*bigger;
67                CapVert() { vert=0; flags = 0; ang = 0.0f; prev=next=smaller=bigger = NULL; }
68        };
69
70//--------------------------------------------------------------
71
72// Predefined PolyPt flags
73// Bits 0-7 are available to the user.  Bits 8-31 are reserved for internal use
74
75// Use these to make capping more efficient
76// If your class converts to a PolyLine, use them!
77#define POLYPT_KNOT             (1<<8)  // A control point
78#define POLYPT_INTERPOLATED (1<<9)      // An interpolated point
79
80// If you convert to a PolyLine, use this bit to control smoothing of the resulting shape
81// If this bit is set, it means that any mesh generated will share smoothing across the edge
82#define POLYPT_SMOOTH           (1<<10) // Point is part of a smooth transition
83
84#define POLYPT_SEG_SELECTED     (1<<11) // The segment that starts with this point is selected
85
86// Used internally by capping code
87#define POLYPT_BRIDGE           (1<<16) // Span between two polygons
88#define POLYPT_SPLICE           (1<<17) // Point is endpoint of a bridge
89#define POLYPT_VISEDGE          (1<<18) // Segment should be visible on mesh
90#define POLYPT_NO_SPLICE        (1<<19) // Don't allow a bridge at this point
91
92class PolyPt {
93        public:
94                Point3 p;
95                DWORD flags;    // See above
96                int aux;                // Auxiliary data attached to this point (usually mesh vertex number for capping)
97                PolyPt() { p = Point3(0,0,0); flags = 0; aux = 0; }
98                PolyPt(Point3 ip, DWORD f = 0, int a=0) { p = ip; flags = f; aux = a; }
99        };
100
101// PolyLine::Cap3DS / PolyShape::Make3DSCap options
102#define CAP3DS_OPT_CLOSEST_BRIDGE (1<<0)        // Bridge polys at closest point
103
104// PolyLine flags
105#define POLYLINE_CLOSED                 (1<<0)
106#define POLYLINE_NO_SELF_INT    (1<<1)          // Ignore self-intersections (special!)
107
108class PolyLine {
109        public:
110                int numPts;
111                PolyPt *pts;
112                DWORD flags;
113                Box3 bdgBox;
114                float cachedLength;
115                BOOL cacheValid;
116                CoreExport PolyLine();
117                CoreExport PolyLine(PolyLine& from);
118                CoreExport ~PolyLine();
119                void Init();
120                void Close() { flags |= POLYLINE_CLOSED; }
121                BOOL IsClosed() { return (flags & POLYLINE_CLOSED) ? TRUE : FALSE; }
122                void Open() { flags &= ~POLYLINE_CLOSED; }
123                BOOL IsOpen() { return (flags & POLYLINE_CLOSED) ? FALSE : TRUE; }
124                void SetNoSelfInt() { flags |= POLYLINE_NO_SELF_INT; }
125                BOOL IsNoSelfInt() { return (flags & POLYLINE_NO_SELF_INT) ? TRUE : FALSE; }
126                int Verts() { return numPts; }
127                int Segments() { return numPts - (IsClosed() ? 0 : 1); }
128                CoreExport BOOL SetNumPts(int count, BOOL keep = TRUE);
129                CoreExport void Append(PolyPt& p);
130                CoreExport void Insert(int where, PolyPt& p);
131                CoreExport void Delete(int where);
132                CoreExport void Reverse(BOOL keepZero=FALSE);
133                CoreExport PolyLine& operator=(PolyLine& from);
134                CoreExport PolyLine& operator=(Spline3D& from);
135                CoreExport PolyPt& operator[](int index) { return pts[index]; }
136                CoreExport void BuildBoundingBox(void);
137                CoreExport void InvalidateGeomCache();
138                CoreExport Box3 GetBoundingBox(Matrix3 *tm=NULL); // RB: optional TM allows the box to be calculated in any space.
139                CoreExport void Render(GraphicsWindow *gw, Material *ma, RECT *rp, int compFlags);
140                CoreExport void Render(GraphicsWindow *gw, BOOL colorSegs, BitArray &segsel);
141                CoreExport BOOL Select(GraphicsWindow *gw, Material *ma, HitRegion *hr, int abortOnHit = FALSE);
142                CoreExport void Snap(GraphicsWindow *gw, SnapInfo *snap, IPoint2 *p, Matrix3 &tm, DWORD flags);
143                CoreExport void Transform(Matrix3 &tm);
144                CoreExport void Dump(TCHAR *title = NULL);
145                CoreExport void SpliceLine(int where, PolyLine &source, int splicePoint);
146                CoreExport BOOL HitsSegment(Point2 p1, Point2 p2);
147                CoreExport int Cap3DS(CapVert *capverts, MeshCapInfo &capInfo, DWORD options = 0);
148                CoreExport BOOL HitsPolyLine(PolyLine &line);
149                CoreExport BOOL SurroundsPoint(Point2 &point);
150                CoreExport Point3 InterpPiece3D(int segment, float t);
151                CoreExport Point3 InterpCurve3D(float u);
152                CoreExport Point3 TangentPiece3D(int segment, float t);
153                CoreExport Point3 TangentCurve3D(float u);
154                CoreExport float CurveLength();
155                CoreExport BOOL IsClockWise();                  // 2D!
156                CoreExport BOOL SelfIntersects();               // 2D!
157                // IO
158                CoreExport IOResult Save(ISave *isave);
159                CoreExport IOResult Load(ILoad *iload);
160        };
161
162#define CAPFACE_AB      (1<<0)
163#define CAPFACE_BC      (1<<1)
164#define CAPFACE_CA      (1<<2)
165
166class ShapeObject;
167
168// Options for steps in MakePolyShape (>=0: Use fixed steps)
169// NOTE: DO NOT change these defines -- They're also used by ShapeObject (object.h)
170#define PSHAPE_BUILTIN_STEPS -2         // Use the shape's built-in steps/adaptive settings (default)
171#define PSHAPE_ADAPTIVE_STEPS -1        // Force adaptive steps
172
173class PolyShape {
174        public:
175                ShapeObject *masterObject;              // If this was derived from a ShapeObject, we maintain a pointer to it
176
177                int numLines;
178                PolyLine *lines;
179                DWORD flags;
180                Box3 bdgBox;
181
182                // Selection
183                ShapeVSel       vertSel;                // selected vertices
184                ShapeSSel       segSel;                 // selected segments
185                ShapePSel       polySel;                // selected polygons
186
187                // Selection level
188                DWORD           selLevel;
189
190                // Display attribute flags
191                DWORD           dispFlags;
192
193                // Capping caches
194                MeshCapInfo morphCap;
195                BOOL morphCapCacheValid;
196                MeshCapInfo gridCap;
197                BOOL gridCapCacheValid;
198                PatchCapInfo patchCap;
199                BOOL patchCapCacheValid;
200
201                // Hierarchy cache
202                ShapeHierarchy cachedHier;
203                BOOL hierCacheValid;
204
205                CoreExport PolyShape();
206                CoreExport PolyShape(PolyShape& from);
207                CoreExport ~PolyShape();
208                CoreExport void Init();                 // Used by constructors
209                CoreExport void NewShape();             // Deletes all lines
210                CoreExport BOOL SetNumLines(int count, BOOL keep = TRUE);
211                CoreExport PolyLine* NewLine();
212                CoreExport void Append(PolyLine &l);
213                CoreExport void Insert(int where, PolyLine& l);
214                CoreExport void Delete(int where);
215                CoreExport PolyShape& operator=(PolyShape& from);
216                CoreExport PolyShape& operator=(BezierShape& from);
217                CoreExport void BuildBoundingBox(void);
218                CoreExport void InvalidateGeomCache(BOOL unused);               // Also invalidates capping caches
219                CoreExport void InvalidateCapCache();
220                CoreExport Box3 GetBoundingBox(Matrix3 *tm=NULL); // RB: optional TM allows the box to be calculated in any space.
221                CoreExport void GetDeformBBox(TimeValue t, Box3& box, Matrix3 *tm, BOOL useSel );
222                CoreExport void Render(GraphicsWindow *gw, Material *ma, RECT *rp, int compFlags);
223                CoreExport BOOL Select(GraphicsWindow *gw, Material *ma, HitRegion *hr, int abortOnHit = FALSE);
224                CoreExport void Snap(GraphicsWindow *gw, SnapInfo *snap, IPoint2 *p, Matrix3 &tm);
225                CoreExport void Snap(GraphicsWindow *gw, SnapInfo *snap, IPoint2 *p, Matrix3 &tm, DWORD flags);
226                CoreExport void Transform(Matrix3 &tm);
227                CoreExport int MakeCap(TimeValue t, MeshCapInfo &capInfo, int capType);
228                CoreExport int MakeCap(TimeValue t, PatchCapInfo &capInfo);
229                CoreExport int Make3DSCap(MeshCapInfo &capInfo, DWORD options = 0);
230                CoreExport int MakeGridCap(MeshCapInfo &capInfo);
231                CoreExport void Dump(TCHAR *title = NULL);
232                CoreExport void UpdateCachedHierarchy();
233                CoreExport ShapeHierarchy &OrganizeCurves(TimeValue t, ShapeHierarchy *hier = NULL);
234                CoreExport void UpdateSels();
235                CoreExport void Reverse(int poly, BOOL keepZero=FALSE);
236                CoreExport void Reverse(BitArray &reverse, BOOL keepZero=FALSE);
237                // Constructs a vertex selection list based on the current selection level.
238                CoreExport BitArray     VertexTempSel(int poly);
239                // functions for use in data flow evaluation
240                CoreExport void ShallowCopy(PolyShape *ashape, unsigned long channels);
241                CoreExport void DeepCopy(PolyShape *ashape, unsigned long channels);
242                CoreExport void NewAndCopyChannels(unsigned long channels);
243                CoreExport void FreeChannels( unsigned long channels, int zeroOthers=1);
244                // IO
245                CoreExport IOResult Save(ISave *isave);
246                CoreExport IOResult Load(ILoad *iload);
247
248        };
249
250#endif // __POLYSHP_H_
Note: See TracBrowser for help on using the repository browser.