00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __GU_Brush__
00020 #define __GU_Brush__
00021
00022 #include "GU_API.h"
00023 #include <UT/UT_Color.h>
00024 #include <UT/UT_BitArray.h>
00025 #include <UT/UT_Vector3Array.h>
00026 #include <UT/UT_PtrArray.h>
00027 #include <UT/UT_IntArray.h>
00028 #include <UT/UT_FloatArray.h>
00029 #include <UT/UT_RefArray.h>
00030
00031 #include <GEO/GEO_Delta.h>
00032 #include <GEO/GEO_Detail.h>
00033
00034 class GB_PrimitiveGroup;
00035 class GB_PointGroup;
00036 class GEO_Delta;
00037 class GU_Detail;
00038 class GEO_Primitive;
00039 class GEO_Point;
00040 class GEO_PointTree;
00041 class GEO_Vertex;
00042 class GEO_Hull;
00043
00044 class GU_API GU_StencilPixel
00045 {
00046 public:
00047 int idx;
00048 float val;
00049 };
00050
00051
00052 enum GU_BrushStencilMode {
00053 GU_BRUSHMERGEMODE_NONE,
00054 GU_BRUSHMERGEMODE_POINT,
00055 GU_BRUSHMERGEMODE_VERTEX
00056 };
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 class GU_API GU_BrushStencil
00068 {
00069 public:
00070 GU_BrushStencil();
00071 virtual ~GU_BrushStencil();
00072
00073 void clearStencil();
00074 bool isEmpty() const;
00075
00076
00077 void setVertexMode();
00078 void setPointMode();
00079 bool isVertexMode() const;
00080 bool isPointMode() const;
00081
00082 void setPointVal(int ptidx, float val, float alpha);
00083 void setVertexVal(int vtxidx, float val, float alpha);
00084
00085 void setPointVal(int ptidx, float val,
00086 const UT_Vector3 &colour, float alpha);
00087 void setVertexVal(int vtxidx, float val,
00088 const UT_Vector3 &colour, float alpha);
00089
00090 void startPointIterate();
00091 bool iteratePoint(int &ptidx, float &alpha);
00092 bool iteratePoint(int &ptidx, float &alpha, UT_Vector3 &color);
00093
00094 void startVertexIterate();
00095 bool iterateVertex(int &vtxidx, float &alpha);
00096 bool iterateVertex(int &vtxidx, float &alpha, UT_Vector3 &color);
00097
00098
00099
00100 void setVtxTables(UT_PtrArray<UT_IntArray *> *pt2vtx,
00101 UT_PtrArray<const GEO_Vertex *> *vtx,
00102 const GU_Detail *gdp);
00103
00104 protected:
00105
00106 UT_RefArray<GU_StencilPixel> myEntries;
00107
00108
00109
00110 UT_IntArray myStencilRef;
00111
00112
00113
00114 UT_IntArray myPointPass;
00115
00116
00117 UT_Vector3Array myColours;
00118
00119 UT_PtrArray<UT_IntArray *> *myPt2Vtx;
00120 UT_PtrArray<const GEO_Vertex *> *myVtx;
00121 const GU_Detail *myGdp;
00122
00123
00124 GU_BrushStencilMode myMode;
00125
00126
00127 int myCurPixel, myCurSubIdx;
00128 int myCurIteratePass;
00129 bool myCurIsVertexIterate;
00130 };
00131
00132 typedef void (*GU_BrushMergeModeCallback)(GEO_Point *pt, GEO_Vertex *vtx,
00133 UT_Vector3 &result,
00134 const UT_Vector3 &cd, const UT_Vector3 &orig, void *data);
00135
00136 typedef void (*GU_BrushCallback)(GEO_Point *pt,
00137 const UT_PtrArray<const GEO_Point *> *ptneighbour,
00138 GEO_Vertex *vtx,
00139 const UT_PtrArray<const GEO_Vertex *> *vtxneighbour,
00140 GEO_Primitive *vtx_prim, int prim_vtx_idx,
00141 float alpha, GEO_Delta *delta, void *data);
00142
00143
00144 enum GU_BrushMergeMode {
00145 GU_BRUSHMERGEMODE_REPLACE,
00146 GU_BRUSHMERGEMODE_ADD,
00147 GU_BRUSHMERGEMODE_SUB,
00148 GU_BRUSHMERGEMODE_MULT,
00149 GU_BRUSHMERGEMODE_SCREEN,
00150 GU_BRUSHMERGEMODE_HUE,
00151 GU_BRUSHMERGEMODE_SAT,
00152 GU_BRUSHMERGEMODE_LIGHT,
00153 GU_BRUSHMERGEMODE_RED,
00154 GU_BRUSHMERGEMODE_GREEN,
00155 GU_BRUSHMERGEMODE_BLUE,
00156 GU_BRUSHMERGEMODE_INVERT,
00157 GU_BRUSHMERGEMODE_CALLBACK
00158 };
00159
00160 class GU_BrushNib;
00161
00162 class GU_API GU_Brush
00163 {
00164 public:
00165 GU_Brush();
00166 virtual ~GU_Brush();
00167
00168
00169
00170 void buildCaches(GU_Detail *gdp, const GU_Detail *isectgdp,
00171 const GB_PrimitiveGroup *group,
00172 const GB_PointGroup *ptgroup,
00173 int usevisibility);
00174
00175 void buildVertexClasses();
00176 void clearCaches();
00177
00178 bool hasValidCache() { return myPointTree ? true : false; }
00179
00180
00181
00182
00183 bool overrideColour(const char *name);
00184 bool overrideAlpha(const char *name);
00185 bool overrideNml(const char *name);
00186
00187
00188 void useCaptureRegion(int captureidx, int normalizeweight,
00189 GEO_Detail::CaptureType capturetype
00190 = GEO_Detail::CAPTURE_BONE);
00191
00192
00193
00194 int defaultColour(bool create = 0);
00195 int defaultAlpha(bool create = 0);
00196 int defaultNormal(bool create = 0);
00197 int defaultTexture(bool create = 0);
00198
00199
00200
00201 void visualizeColor(float low, float high,
00202 UT_ColorRamp mode);
00203 int doVisualize() const { return myVisualizeOffset >= 0; }
00204 void setVisualizeCd(GEO_Point *pt, const UT_Vector3 &cd);
00205 void clearVisualize() { myVisualizeOffset = -1; }
00206 void applyVisualize(GU_Detail *gdp);
00207 void applyVisualizeStencil(GU_Detail *gdp);
00208
00209
00210 void getPointCd(const GEO_Point *pt, UT_Vector3 &cd) const;
00211 void getVertexCd(const GEO_Vertex *vtx, UT_Vector3 &cd) const;
00212
00213
00214
00215 void addPrimPoints(const GEO_Primitive *prim,
00216 UT_BitArray &ptused,
00217 UT_Vector3Array &pts, UT_IntArray &idxlist);
00218 void buildTrees(int usevisibility);
00219 void addUVPrimPoints(const GEO_Primitive *prim,
00220 int uvoffset,
00221 UT_BitArray &ptused,
00222 UT_Vector3Array &uvpts, UT_IntArray &idxlist);
00223 void buildUVTrees(int usevisibility);
00224 void destroyTrees();
00225 GEO_PointTree *getPointTree() { return myPointTree; }
00226 GEO_PointTree *getUVPointTree() { return myUVPointTree; }
00227
00228
00229 void connectRingPts(const GEO_Point *pt1,
00230 const GEO_Point *pt2,
00231 bool doublevalence = false);
00232 void connectRingVtx(int vtxnum,
00233 const GEO_Vertex *vtx2,
00234 bool doublevalence = false);
00235 void addToRingCache(GEO_Primitive *prim);
00236 void buildRingCache(int usevisibility);
00237 void clearRingCache();
00238
00239
00240
00241
00242 void setWriteAlpha(int val) { myWriteAlpha = val; }
00243 int getWriteAlpha() const { return myWriteAlpha; }
00244
00245 int hasStencil() const;
00246
00247 void clearStencil();
00248
00249 void setMergeModeCallback(GU_BrushMergeModeCallback cb,
00250 void *data)
00251 {
00252 myMergeModeCallback = cb;
00253 myMergeModeCallbackData = data;
00254 }
00255
00256 void applyMergeMode(GEO_Point *pt, GEO_Vertex *vtx,
00257 UT_Vector3 &result,
00258 const UT_Vector3 &src, const UT_Vector3 &dst,
00259 GU_BrushMergeMode mergemode);
00260
00261 void setStencil(float val, int usevisibility);
00262
00263 void colourStencil(GEO_Delta *delta, const UT_Vector3 &cd,
00264 GU_BrushMergeMode mergemode);
00265
00266 void stampColourStencil(GEO_Delta *delta,
00267 GU_BrushMergeMode mergemode);
00268
00269 void callbackStencil(GEO_Delta *delta,
00270 GU_BrushCallback cb, void *data);
00271
00272
00273
00274 void combNormals(GEO_Delta *delta, const UT_Vector3 &dir,
00275 float lift, int preservenmllen);
00276
00277 void dragTexture(GEO_Delta *delta, const UT_Vector3 &dir);
00278 void scaleTexture(GEO_Delta *delat, float scale,
00279 const UT_Vector3 &orig);
00280
00281
00282 void displaceNormals(GEO_Delta *delta, float amt);
00283
00284 void displaceVector(GEO_Delta *delta,
00285 const UT_Vector3 &dir, float amt);
00286
00287 void smoothPoints(GEO_Delta *delta);
00288
00289 void smoothAttribute(GEO_Delta *delta);
00290
00291 void smoothNormals(GEO_Delta *delta, int preservenmllen);
00292
00293 void smoothTexture(GEO_Delta *delta);
00294
00295
00296
00297 void eraseAttributes(GEO_Delta *old, GEO_Delta *change);
00298 void erasePositions(GEO_Delta *old, GEO_Delta *change);
00299 void eraseCapture(GEO_Delta *old, GEO_Delta *change);
00300
00301
00302
00303 int findUVSeedPtNum(const UT_Vector3 &orig);
00304
00305
00306
00307 void applyDab(GU_BrushNib *nib, float stencil_val,
00308 const UT_Vector3 &orig, const UT_Vector3 &dir,
00309 float rad,
00310 const GEO_Primitive *seed,
00311 const GEO_Point *seedpt,
00312 bool useconnectivity,
00313 bool inuv);
00314
00315
00316 void getNormal(int primidx, UT_Vector3 &nml);
00317
00318 void getPtNormal(int ptidx, UT_Vector3 &nml);
00319
00320 void clearNormalCache();
00321
00322 private:
00323 #ifdef INTEL_COMPILER
00324 GU_Brush(const GU_Brush& ) { }
00325 #endif
00326
00327 protected:
00328 int testPrimitive(const GEO_Primitive *test,
00329 const UT_Vector3 &orig, const UT_Vector3 &dir,
00330 float radius2, int seeddir);
00331 int testPoint(int ptnum,
00332 const UT_Vector3 &orig, const UT_Vector3 &dir,
00333 float radius2, int seeddir);
00334 void evaluateHullsNormal(const GEO_Hull *hull);
00335 bool isPointEditable(int ptnum);
00336
00337 const GB_PrimitiveGroup *myGroup;
00338 const GB_PointGroup *myPointGroup;
00339 GU_Detail *myGdp;
00340 const GU_Detail *myIsectGdp;
00341
00342 UT_BitArray myNmlSet;
00343 UT_Vector3Array myNmlCache;
00344 UT_BitArray myPtNmlSet;
00345 UT_Vector3Array myPtNmlCache;
00346
00347 GEO_PointTree *myPointTree;
00348 GEO_PointTree *myUVPointTree;
00349 UT_Vector3Array myPointPos;
00350 UT_Vector3Array myUVPointPos;
00351
00352 UT_PtrArray<UT_PtrArray<const GEO_Primitive *> *> myPt2Prim;
00353 UT_PtrArray<const GEO_Vertex *> myIsectVtx;
00354 UT_PtrArray<GEO_Vertex *> myGeoVtx;
00355 UT_PtrArray<GEO_Primitive *> myVtx2Prim;
00356 UT_IntArray myVtx2PrimIdx;
00357 UT_PtrArray<UT_IntArray *> myPt2Vtx;
00358
00359
00360
00361
00362
00363 UT_IntArray myVtxClass;
00364
00365
00366 UT_PtrArray<UT_PtrArray<const GEO_Point *> *> myRingZero;
00367
00368
00369
00370 UT_IntArray myRingValence;
00371
00372 UT_PtrArray<UT_PtrArray<const GEO_Vertex *> *> myVtxRingZero;
00373 UT_PtrArray<UT_IntArray *> myVtxRingClass;
00374
00375 int myColorOffset;
00376 int myColorSize;
00377 bool myColorVertex;
00378 int myAlphaOffset;
00379 bool myAlphaVertex;
00380 int myTextureOffset;
00381 int myTextureSize;
00382 bool myTextureVertex;
00383 int myNormalOffset;
00384 int myVisualizeOffset;
00385 float myVisLow, myVisHigh;
00386 UT_ColorRamp myVisMode;
00387 int myWriteAlpha;
00388 int myCaptureOffset, myCaptureIdx, myNormalizeWeight;
00389 GEO_Detail::CaptureType myCaptureType;
00390 bool myUseVisibility;
00391
00392 GU_BrushMergeModeCallback myMergeModeCallback;
00393 void *myMergeModeCallbackData;
00394
00395 private:
00396 GU_BrushStencil myStencil;
00397 };
00398
00399 #endif
00400