1 | /**********************************************************************
|
---|
2 | *<
|
---|
3 | FILE: shape.h
|
---|
4 |
|
---|
5 | DESCRIPTION: Defines Basic BezierShape Object
|
---|
6 |
|
---|
7 | CREATED BY: Tom Hudson
|
---|
8 |
|
---|
9 | HISTORY: created 23 February 1995
|
---|
10 |
|
---|
11 | *> Copyright (c) 1995, All Rights Reserved.
|
---|
12 | **********************************************************************/
|
---|
13 |
|
---|
14 | #ifndef __SHAPE__
|
---|
15 |
|
---|
16 | #define __SHAPE__
|
---|
17 |
|
---|
18 | #include "shphier.h"
|
---|
19 | #include "spline3d.h"
|
---|
20 | #include "shpsels.h" // Shape selection classes
|
---|
21 |
|
---|
22 | class BezierShape;
|
---|
23 |
|
---|
24 | class ShapeSubHitRec {
|
---|
25 | private:
|
---|
26 | ShapeSubHitRec *next;
|
---|
27 | public:
|
---|
28 | DWORD dist;
|
---|
29 | BezierShape* shape;
|
---|
30 | int poly;
|
---|
31 | int index;
|
---|
32 | ShapeSubHitRec( DWORD dist, BezierShape *shape, int poly, int index, ShapeSubHitRec *next )
|
---|
33 | { this->dist = dist; this->shape = shape; this->poly = poly; this->index = index; this->next = next; }
|
---|
34 |
|
---|
35 | ShapeSubHitRec *Next() { return next; }
|
---|
36 | };
|
---|
37 |
|
---|
38 | class SubShapeHitList {
|
---|
39 | private:
|
---|
40 | ShapeSubHitRec *first;
|
---|
41 | public:
|
---|
42 | SubShapeHitList() { first = NULL; }
|
---|
43 | ~SubShapeHitList() {
|
---|
44 | ShapeSubHitRec *ptr = first, *fptr;
|
---|
45 | while ( ptr ) {
|
---|
46 | fptr = ptr;
|
---|
47 | ptr = ptr->Next();
|
---|
48 | delete fptr;
|
---|
49 | }
|
---|
50 | first = NULL;
|
---|
51 | }
|
---|
52 |
|
---|
53 | ShapeSubHitRec *First() { return first; }
|
---|
54 | void AddHit( DWORD dist, BezierShape *shape, int poly, int index ) {
|
---|
55 | first = new ShapeSubHitRec(dist,shape,poly,index,first);
|
---|
56 | }
|
---|
57 | };
|
---|
58 |
|
---|
59 | // Special storage class for hit records so we can know which object was hit
|
---|
60 | class ShapeHitData : public HitData {
|
---|
61 | public:
|
---|
62 | BezierShape *shape;
|
---|
63 | int poly;
|
---|
64 | int index;
|
---|
65 | ShapeHitData(BezierShape *shape, int poly, int index)
|
---|
66 | { this->shape = shape; this->poly = poly; this->index = index; }
|
---|
67 | ~ShapeHitData() {}
|
---|
68 | };
|
---|
69 |
|
---|
70 | // Display flags
|
---|
71 | #define DISP_VERTTICKS (1<<0)
|
---|
72 | #define DISP_BEZHANDLES (1<<1)
|
---|
73 | #define DISP_SELVERTS (1<<10)
|
---|
74 | #define DISP_SELSEGMENTS (1<<11)
|
---|
75 | #define DISP_SELPOLYS (1<<13)
|
---|
76 | #define DISP_UNSELECTED (1<<14) // Used by loft -- Shape unselected
|
---|
77 | #define DISP_SELECTED (1<<15) // Used by loft -- Shape selected
|
---|
78 | #define DISP_ATSHAPELEVEL (1<<16) // Used by loft -- Shape at current level
|
---|
79 |
|
---|
80 | // Selection level bits.
|
---|
81 | #define SHAPE_OBJECT (1<<0)
|
---|
82 | #define SHAPE_SPLINE (1<<1)
|
---|
83 | #define SHAPE_SEGMENT (1<<2)
|
---|
84 | #define SHAPE_VERTEX (1<<3)
|
---|
85 |
|
---|
86 | // Flags for sub object hit test
|
---|
87 |
|
---|
88 | // NOTE: these are the same bits used for object level.
|
---|
89 | #define SUBHIT_SHAPE_SELONLY (1<<0)
|
---|
90 | #define SUBHIT_SHAPE_UNSELONLY (1<<2)
|
---|
91 | #define SUBHIT_SHAPE_ABORTONHIT (1<<3)
|
---|
92 | #define SUBHIT_SHAPE_SELSOLID (1<<4)
|
---|
93 |
|
---|
94 | #define SUBHIT_SHAPE_VERTS (1<<24)
|
---|
95 | #define SUBHIT_SHAPE_SEGMENTS (1<<25)
|
---|
96 | #define SUBHIT_SHAPE_POLYS (1<<26)
|
---|
97 | #define SUBHIT_SHAPE_TYPEMASK (SUBHIT_SHAPE_VERTS|SUBHIT_SHAPE_SEGMENTS|SUBHIT_SHAPE_POLYS)
|
---|
98 |
|
---|
99 | class ShapeObject;
|
---|
100 |
|
---|
101 | class BezierShape {
|
---|
102 | Box3 bdgBox; // object space--depends on geom+topo
|
---|
103 | static int shapeCount; // Number of shape objects in the system!
|
---|
104 | PolyShape pShape; // PolyShape cache
|
---|
105 | int pShapeSteps; // Number of steps in the cache
|
---|
106 | BOOL pShapeOptimize; // TRUE if cache is optimized
|
---|
107 | BOOL pShapeCacheValid; // TRUE if the cache is current
|
---|
108 | public:
|
---|
109 | ShapeObject *masterObject; // If this was derived from a ShapeObject, we maintain a pointer to it
|
---|
110 |
|
---|
111 | // Patch capping cache (mesh capping and hierarchy caches stored in PolyShape cache)
|
---|
112 | PatchCapInfo patchCap;
|
---|
113 | BOOL patchCapCacheValid;
|
---|
114 |
|
---|
115 | // The list of splines
|
---|
116 | Spline3D **splines;
|
---|
117 | int splineCount;
|
---|
118 |
|
---|
119 | int steps; // Number of steps (-1 = adaptive)
|
---|
120 | BOOL optimize; // TRUE optimizes linear segments
|
---|
121 |
|
---|
122 | // Selection
|
---|
123 | ShapeVSel vertSel; // selected vertices
|
---|
124 | ShapeSSel segSel; // selected segments
|
---|
125 | ShapePSel polySel; // selected polygons
|
---|
126 |
|
---|
127 | // If hit bezier vector, this is its info:
|
---|
128 | int bezVecPoly;
|
---|
129 | int bezVecVert;
|
---|
130 |
|
---|
131 | // Selection level
|
---|
132 | DWORD selLevel;
|
---|
133 |
|
---|
134 | // Display attribute flags
|
---|
135 | DWORD dispFlags;
|
---|
136 |
|
---|
137 | CoreExport BezierShape();
|
---|
138 | CoreExport BezierShape(BezierShape& fromShape);
|
---|
139 |
|
---|
140 | CoreExport void Init();
|
---|
141 |
|
---|
142 | CoreExport ~BezierShape();
|
---|
143 |
|
---|
144 | CoreExport BezierShape& operator=(BezierShape& fromShape);
|
---|
145 | CoreExport BezierShape& operator=(PolyShape& fromShape);
|
---|
146 |
|
---|
147 | CoreExport Point3& GetVert(int poly, int i);
|
---|
148 | CoreExport void SetVert(int poly, int i, const Point3 &xyz);
|
---|
149 |
|
---|
150 | CoreExport void Render(GraphicsWindow *gw, Material *ma, RECT *rp, int compFlags);
|
---|
151 | CoreExport BOOL Select(GraphicsWindow *gw, Material *ma, HitRegion *hr, int abortOnHit = FALSE);
|
---|
152 | CoreExport void Snap(GraphicsWindow *gw, SnapInfo *snap, IPoint2 *p, Matrix3 &tm);
|
---|
153 | // See polyshp.h for snap flags
|
---|
154 | CoreExport void Snap(GraphicsWindow *gw, SnapInfo *snap, IPoint2 *p, Matrix3 &tm, DWORD flags);
|
---|
155 | CoreExport BOOL SubObjectHitTest(GraphicsWindow *gw, Material *ma, HitRegion *hr,
|
---|
156 | DWORD flags, SubShapeHitList& hitList );
|
---|
157 |
|
---|
158 | CoreExport void BuildBoundingBox(void);
|
---|
159 | CoreExport Box3 GetBoundingBox(Matrix3 *tm=NULL); // RB: optional TM allows the box to be calculated in any space.
|
---|
160 | // NOTE: this will be slower becuase all the points must be transformed.
|
---|
161 |
|
---|
162 | CoreExport void InvalidateGeomCache();
|
---|
163 | CoreExport void InvalidateCapCache();
|
---|
164 | CoreExport void FreeAll(); //DS
|
---|
165 |
|
---|
166 | // functions for use in data flow evaluation
|
---|
167 | CoreExport void ShallowCopy(BezierShape *ashape, unsigned long channels);
|
---|
168 | CoreExport void DeepCopy(BezierShape *ashape, unsigned long channels);
|
---|
169 | CoreExport void NewAndCopyChannels(unsigned long channels);
|
---|
170 | CoreExport void FreeChannels( unsigned long channels, int zeroOthers=1);
|
---|
171 |
|
---|
172 | // Display flags
|
---|
173 | CoreExport void SetDispFlag(DWORD f);
|
---|
174 | CoreExport DWORD GetDispFlag(DWORD f);
|
---|
175 | CoreExport void ClearDispFlag(DWORD f);
|
---|
176 |
|
---|
177 | // Constructs a vertex selection list based on the current selection level.
|
---|
178 | CoreExport BitArray VertexTempSel(int poly);
|
---|
179 |
|
---|
180 | CoreExport IOResult Save(ISave* isave);
|
---|
181 | CoreExport IOResult Load(ILoad* iload);
|
---|
182 |
|
---|
183 | // BezierShape-specific methods
|
---|
184 |
|
---|
185 | inline int SplineCount() { return splineCount; }
|
---|
186 | CoreExport Spline3D* GetSpline(int index);
|
---|
187 | CoreExport Spline3D* NewSpline(int itype = KTYPE_CORNER,int dtype = KTYPE_BEZIER,int ptype = PARM_UNIFORM);
|
---|
188 | CoreExport Spline3D* AddSpline(Spline3D* spline);
|
---|
189 | CoreExport int DeleteSpline(int index);
|
---|
190 | CoreExport int InsertSpline(Spline3D* spline, int index);
|
---|
191 | CoreExport void NewShape();
|
---|
192 | CoreExport int GetNumVerts();
|
---|
193 | CoreExport int GetNumSegs();
|
---|
194 | CoreExport void GetDeformBBox(TimeValue t, Box3& box, Matrix3 *tm, BOOL useSel );
|
---|
195 | CoreExport void UpdateSels();
|
---|
196 | CoreExport void GetClosures(BitArray& array);
|
---|
197 | CoreExport void SetClosures(BitArray& array);
|
---|
198 | CoreExport float FindSegmentPoint(int poly, int segment, GraphicsWindow *gw, Material *ma, HitRegion *hr);
|
---|
199 | CoreExport void Reverse(int poly);
|
---|
200 | CoreExport void Reverse(BitArray &reverse);
|
---|
201 | CoreExport ShapeHierarchy &OrganizeCurves(TimeValue t, ShapeHierarchy *hier = NULL);
|
---|
202 | CoreExport void MakePolyShape(PolyShape &pshp, int steps = -1, BOOL optimize = FALSE);
|
---|
203 | CoreExport void MakeFirst(int poly, int vertex);
|
---|
204 | CoreExport void Transform(Matrix3 &tm);
|
---|
205 | CoreExport BezierShape& operator+=(BezierShape& from);
|
---|
206 | CoreExport void ReadyCachedPolyShape();
|
---|
207 | CoreExport int MakeCap(TimeValue t, MeshCapInfo &capInfo, int capType);
|
---|
208 | CoreExport int MakeCap(TimeValue t, PatchCapInfo &capInfo);
|
---|
209 | CoreExport int ReadyPatchCap();
|
---|
210 | };
|
---|
211 |
|
---|
212 | #endif // __SHAPE__
|
---|