HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SOP_BrushBase.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: SOP Library (C++)
7  *
8  * COMMENTS: This is the base class for all brushes.
9  *
10  */
11 
12 #ifndef __SOP_BrushBase_h__
13 #define __SOP_BrushBase_h__
14 
15 #include "SOP_GDT.h"
16 
17 #include "SOP_API.h"
19 #include <GU/GU_Brush.h>
20 #include <GA/GA_Names.h>
21 
22 
23 class GEO_PointTree;
24 class GU_RayIntersect;
25 class TIL_TextureMap;
26 class GEO_Primitive;
27 
28 class PRM_MenuEntry;
29 
36 };
37 
60 };
61 
66 };
67 
71 };
72 
76 };
77 
78 #define SOP_BRUSH_NUM_PENS 2
79 
81 {
82 public:
83  SOP_BrushBase(OP_Network *net, const char *name, OP_Operator *entry);
84  virtual ~SOP_BrushBase();
85 
86  virtual OP_ERROR cookInputGroups(OP_Context &context,
87  int alone = 0);
88 
89  // These set functions adjust the brushes current state.
90  // The MSS State will use them to inform the SOP how to recook.
91  virtual void setAccumulateStencil(bool yesno) = 0;
92  virtual void setRayOrigin(const UT_Vector3 &orig, fpreal t) = 0;
93  virtual void setRayOrientation(const UT_Vector3 &orient, fpreal t) = 0;
94  virtual void setHitPrimitive(int primidx, fpreal t) = 0;
95  virtual void setHitPoint(int /* ptidx */, fpreal /* t */) {}
96  virtual void setHitUVW(fpreal u, fpreal v, fpreal w, fpreal t) = 0;
97  virtual void setHitPressure(fpreal pressure, fpreal t) = 0;
98  virtual void setHitInUV(bool inuv, const UT_StringHolder &uvattribname)
99  {
100  myHitInUV = inuv;
101  if (myHitInUV)
102  {
103  UT_ASSERT(uvattribname.isstring());
104  if (uvattribname.isstring())
105  myUVAttribName = uvattribname;
106  else
107  myUVAttribName = GA_Names::uv;
108  }
109  else
110  {
111  myUVAttribName = UT_StringHolder::theEmptyString;
112  }
113  }
114  virtual void setBrushEvent(SOP_BrushEvent event) = 0;
115  virtual void setBrushOp(SOP_BrushOp op) = 0;
116  virtual void setBrushShape(SOP_BrushShape shape) = 0;
117  virtual void setProjectionType(int projtype) = 0;
118  virtual void useForegroundColor(void) = 0;
119  virtual void useBackgroundColor(void) = 0;
120  // These are used to update the current radius.
121  virtual void setRadius(fpreal radius, fpreal t) = 0;
122  virtual void setUVRadius(fpreal radius, fpreal t) = 0;
123 
124  void setCachedOp(int pen, SOP_BrushOp op);
125  SOP_BrushOp getCachedOp(int pen) const { UT_ASSERT(pen < SOP_BRUSH_NUM_PENS); return myCachedBrushOp[pen]; }
126 
127  virtual const GA_PrimitiveGroup *getPrimitiveSelection(void) const
128  {
129  return (const GA_PrimitiveGroup*) myGroup;
130  }
131 
132  // Gets the rayintersector for this current group setup and specified time.
133  // If the checkgeo is true, it will test to see if the intersect geo
134  // has changed. We normally do NOT want to do this as rebuilding the
135  // cache is expensive if it was our own change. However, when locating
136  // or mouse down we should enable this to catch other triggers.
137  // The probeonly, if set to true, will prevent the rebuilding of
138  // the GU_RayIntersect, so may return null. This provides a fast way
139  // to update the flags needed to check if geometry changes and
140  // a rebuild is necessary later.
141  virtual GU_RayIntersect *getRayIntersect(
142  fpreal t,
143  bool checkgeochange = false,
144  bool probeonly = false);
145 
146  // Gets the GEO_PointTree for the current group setup.
147  GEO_PointTree *getPointTree();
148  /// NOTE: This is only valid if gdp hasn't been evicted/replaced,
149  /// though this was exactly as unsafe as before, when
150  /// GEO_PointTree held onto a pointer to the detail, and
151  /// MSS_EditState and MSS_BrushBaseState were accessing the
152  /// detail through there, since the GEO_PointTree didn't have
153  /// a read handle on the detail.
155  { return myGdpHandle.readLock(); }
156  void unlockPointTreeDetail(const GU_Detail *detail)
157  { myGdpHandle.unlock(detail); }
158 
159  // Gets or creates the cursor geometry:
160  GU_Detail *getCursorGdp();
161 
162  // This both orients the cursor and tracks what the current brush
163  // direction is.
164  // isuv is true if the intersection is from the UV viewport.
165  // hitu & hitv will be the parametric coordinates of the hit location
166  // on prim. prim will be null for 2d viewports (or in the 3d viewport
167  // if there was no hit)
168  void orientCursor(fpreal t, const UT_Vector3 &orig,
169  const UT_Vector3 &dir,
170  float scalehistory,
171  bool isuv, GA_Index prim,
172  float hitu, float hitv, float hitw);
173 
174  // Gets the interesction gdp.
175  virtual const GU_Detail *getIsectGdp(fpreal t);
176 
177  // The *Static methods can be hooked into buttons as callbacks to
178  // perform the listed function.
179 
180  // applyStencil will copy the current delta into the permament delta
181  // and clear the current.
182  static int applyStencilStatic(void *op, int idx, fpreal t,
183  const PRM_Template *);
184  void applyStencil(fpreal t, int recook = 1);
185 
186  // resetNormal recalculates the surface normals off the current deformed
187  // geometry.
188  static int resetNormalStatic(void *op, int idx, fpreal t,
189  const PRM_Template *);
190  void resetNormal(fpreal t);
191 
192  // flood applies the current operation (as found using OP()) to the
193  // entire selection.
194  static int floodStatic(void *op, int idx, fpreal t,
195  const PRM_Template *);
196  virtual void flood(fpreal t);
197 
198  // NOTE: There is a SOP_GDT::clearallStatic which can be used
199  // for reset all changes.
200  virtual void clearAllDeltas(fpreal t);
201 
202  static void customMergeModeStatic(GA_Offset ptoff,
203  GA_Offset vtxoff,
204  UT_Vector3 &result,
205  const UT_Vector3 &cd,
206  const UT_Vector3 &origcol,
207  void *data);
208  void customMergeMode(GA_Offset ptoff,
209  GA_Offset vtxoff,
210  UT_Vector3 &result,
211  const UT_Vector3 &cd,
212  const UT_Vector3 &origcol);
213 
214  static void brushOpCallbackStatic(
215  GA_Offset pt,
216  const UT_Array<GA_Offset> *ptneighbour,
217  GA_Offset vtx,
218  const UT_Array<GA_Offset> *vtxneighbor,
219  float alpha,
220  GEO_Delta *delta,
221  void *data);
222  virtual void brushOpCallback(
223  GA_Offset pt,
224  const UT_Array<GA_Offset> *ptneighbour,
225  GA_Offset vtx,
226  const UT_Array<GA_Offset> *vtxneighbour,
227  float alpha,
228  GEO_Delta *delta);
229 
230  // Returns 1 if there is anything in the brush's accumulation buffer
231  bool hasStencil() const;
232 
233  virtual void setCurrentColor(const UT_Vector3 &cd);
234 
235  // Use our brush & visualization mode to do the visualization:
236  void applyVisualizeStencil();
237  void applyVisualize();
238  void applyCaptureVisualize();
239 
240  int getIsectNodeId() const
241  {
242  return myIsectNodeId;
243  }
244  void setIsectNodeId(int node_id)
245  {
246  myIsectNodeId = node_id;
247  }
248 
249  virtual void unloadDataHack();
250  virtual bool unloadData();
251 
252 protected:
253  // cookMySop will apply the GDT and react to the Brush events,
254  // but you won't be able to patch in your own code.
255  virtual OP_ERROR cookMySop(OP_Context &context);
256 
257  // A wrapper function for duplicateChangedSource. At this level,
258  // it simply calls duplicateChnagedSource, but can be overridden
259  // in subclasses to define attributes on the duplicated gdp
260  // (for instance)
261  virtual void duplicateChangedSourceWrapper(
262  unsigned idx,
263  OP_Context &context,
264  int *changed,
265  bool force=false);
266 
267  // Call this method do all the GDT application and brush parsing.
268  // After calling this, any current brush strokes triggerd by the
269  // brush state will be processed, and your gdp will have the result
270  // of applying the GDT.
271  // This should be called after you have duplicateSource (and/or merely
272  // did a rollback), and have created any attributes you wish.
273  // Note that as a result of this, new attributes may be created,
274  // so attribute offsets should be refetched.
275  virtual OP_ERROR processBrushOp(OP_Context &context,
276  bool changed_input, bool changed_group);
277 
278  // This determines whether the given undoblock name matches one of our
279  // undoblocks. If it matches, then our undo is collapsed with this block.
280  // Remember to call the base class!
281  virtual bool matchesUndo(const char *undoname) const;
282 
283 protected:
284  // These apply the named operation through the brush's stencil,
285  // taking into account the various unusual parameters.
286  void doDeformation(fpreal t, const UT_Vector3 &cd);
287  void doPaint(fpreal t, const UT_Vector3 &cd,
288  int enablestamping = 1);
289  virtual void doErase() = 0;
290  virtual void addEraseAttributes(GU_Brush &brush) {}
291 
292  // Finds the seed point from a seed primitive. This is the closest
293  // point. Somewhat complicated with hulls to avoid n^2 search.
294  GA_Offset getSeedPoint(const GEO_Primitive *prim,
295  float u, float v, float w,
296  const UT_Vector3 &orig);
297 
298  virtual OP_Node *getRestGeoInput() { return 0; }
299 
300 public:
301  // If the action of the brush will change point positions, altersGeometry
302  // should return 1.
303  virtual int altersGeometry() const = 0;
304  // If the action of the brush will change point colours, altersColor
305  // should return 1.
306  virtual int altersColor() const = 0;
307 
308  // The RADIUS and OPACITY are defined locally as they take into
309  // account the current RAY_HITPRESSURE.
310  // The RADIUS function will also switch its output between RAWRADIUS
311  // and RAWUVRADIUS depending on the state of the brush cursor.
312  virtual fpreal RADIUS(fpreal t);
313  virtual fpreal RAWRADIUS(fpreal t) = 0;
314  virtual fpreal RAWUVRADIUS(fpreal t) = 0;
315  virtual fpreal RADIUSPRESSURE(fpreal t) = 0;
316  virtual fpreal OPACITY(fpreal t);
317  virtual fpreal RAWOPACITY(fpreal t) = 0;
318  virtual fpreal OPACITYPRESSURE(fpreal t) = 0;
319 
320  // DEPTH is how far into the surface the brush should stick,
321  // and HEIGHT is how far above.
322  virtual fpreal DEPTH(fpreal /* t */) { return 1.0; }
323  virtual fpreal HEIGHT(fpreal /* t */) { return 1.0; }
324 
325  virtual int USEDEPTH() { return 0; }
326  virtual int USECONNECTIVITY() { return 1; }
327 
328  virtual SOP_BrushOp OP(void) = 0;
329  virtual int ACCUMSTENCIL(void) = 0;
330  virtual int PROJECTIONTYPE(void) = 0;
331  virtual int REALTIME(void) = 0;
332  virtual int SHAPE(fpreal t) = 0;
333 protected:
334  virtual int MERGEMODE() = 0;
335  // Script does not yet do anything, and is reserved.
336  virtual void SCRIPT(UT_String &s, fpreal t) = 0;
337  virtual int AXIS() = 0;
338  virtual fpreal USERX(fpreal t) = 0;
339  virtual fpreal USERY(fpreal t) = 0;
340  virtual fpreal USERZ(fpreal t) = 0;
341 
342  virtual fpreal RAYORIENTX(fpreal t) = 0;
343  virtual fpreal RAYORIENTY(fpreal t) = 0;
344  virtual fpreal RAYORIENTZ(fpreal t) = 0;
345  virtual fpreal RAYHITX(fpreal t) = 0;
346  virtual fpreal RAYHITY(fpreal t) = 0;
347  virtual fpreal RAYHITZ(fpreal t) = 0;
348  virtual fpreal RAYHITU(fpreal t) = 0;
349  virtual fpreal RAYHITV(fpreal t) = 0;
350  virtual fpreal RAYHITW(fpreal t) = 0;
351  virtual fpreal RAYHITPRESSURE(fpreal t) = 0;
352  virtual int PRIMHIT(fpreal t) = 0;
353  virtual int PTHIT(fpreal /* t */) { return -1; }
354  virtual int EVENT() = 0;
355 
356  virtual bool USE_FOREGROUND() = 0;
357  virtual fpreal FGR(fpreal t) = 0;
358  virtual fpreal FGG(fpreal t) = 0;
359  virtual fpreal FGB(fpreal t) = 0;
360  virtual fpreal BGR(fpreal t) = 0;
361  virtual fpreal BGG(fpreal t) = 0;
362  virtual fpreal BGB(fpreal t) = 0;
363 
364  virtual fpreal SOFTEDGE(fpreal t) = 0;
365  virtual void KERNEL(UT_String &str, fpreal t) = 0;
366  virtual int UPTYPE(fpreal t) = 0;
367  virtual fpreal UPX(fpreal t) = 0;
368  virtual fpreal UPY(fpreal t) = 0;
369  virtual fpreal UPZ(fpreal t) = 0;
370 
371  virtual fpreal PAPERNOISE(fpreal t) = 0;
372  virtual fpreal SPLATTER(fpreal t) = 0;
373  virtual void BITMAP(UT_String &str, fpreal t) = 0;
374  virtual int BITMAPCHAN(fpreal t) = 0;
375  virtual fpreal ANGLE(fpreal t) = 0;
376  virtual fpreal SQUASH(fpreal t) = 0;
377  virtual int DOSTAMPING() = 0;
378  virtual int WRITEALPHA() = 0;
379  virtual int OVERRIDECD() = 0;
380  virtual void CDNAME(UT_String &str, fpreal t) = 0;
381  virtual int OVERRIDEALPHA() = 0;
382  virtual void ALPHANAME(UT_String &str, fpreal t) = 0;
383  virtual int PRESERVENML() { return 0; }
384  virtual int OVERRIDENML() = 0;
385  virtual void NMLNAME(UT_String &str, fpreal t) = 0;
386 
387  virtual fpreal SYMMETRYDIRX(fpreal t) = 0;
388  virtual fpreal SYMMETRYDIRY(fpreal t) = 0;
389  virtual fpreal SYMMETRYDIRZ(fpreal t) = 0;
390  virtual fpreal SYMMETRYORIGX(fpreal t) = 0;
391  virtual fpreal SYMMETRYORIGY(fpreal t) = 0;
392  virtual fpreal SYMMETRYORIGZ(fpreal t) = 0;
393  virtual int DOREFLECTION() = 0;
394  virtual int DOPOINTREFLECTION() { return 0; };
395  virtual int DOROTATION() = 0;
396  virtual int SYMMETRYROT(fpreal t) = 0;
397  virtual fpreal SYMMETRYDIST(fpreal t) = 0;
398 
399  virtual int DOUVREFLECTION() { return 0; }
400  virtual fpreal SYMMETRYUVORIGU(fpreal /*t*/) { return 0.5; }
401  virtual fpreal SYMMETRYUVORIGV(fpreal /*t*/) { return 0.5; }
402  virtual fpreal SYMMETRYUVANGLE(fpreal /*t*/) { return 0.0; }
403 
404  virtual int ADDATTRIB() = 0;
405  virtual void UVATTRIB(UT_String &uvattribname, fpreal t)
406  { uvattribname.clear(); }
407  virtual int VISUALIZE() { return 0; }
408  virtual int VISTYPE() { return 0; }
409  virtual fpreal VISLOW(fpreal /*t*/) { return 0.0; }
410  virtual fpreal VISHIGH(fpreal /*t*/) { return 1.0; }
411  virtual int VISMODE() { return 0; }
412  virtual fpreal ZEROWEIGHTCOLOR_R() { return 1.0; }
413  virtual fpreal ZEROWEIGHTCOLOR_G() { return 1.0; }
414  virtual fpreal ZEROWEIGHTCOLOR_B() { return 1.0; }
415 
416  virtual int NORMALIZEWEIGHT() { return 0; }
417 
418  virtual int USECAPTURE() { return 0; }
419  virtual int CAPTUREIDX(fpreal /*t*/) { return 0; }
422 
423  // Find out if the brush has moved or done anything to cause us to add its
424  // effect to the current gdp.
425  virtual bool hasStrokeChanged(fpreal t) = 0;
426  virtual bool hasStyleChanged (fpreal t) = 0;
427 
428  // Find if the nib file has changed:
429  virtual bool hasNibFileChanged(fpreal t) = 0;
430 
431  // Find if any of the nib description values have changed:
432  virtual bool hasNibLookChanged(fpreal t) = 0;
433  virtual bool hasAccumStencilChanged(fpreal t) = 0;
434 
435  virtual bool hasCaptureIdxChanged(fpreal /*t*/) { return 0; }
436 
437  virtual bool hasVisrangeChanged(fpreal /*t*/) { return 0; }
438 
439  // Do we want our cook selection to be updated and displayed?
440  virtual bool wantsCookSelection(void) const { return false; }
441 
442  virtual void rollbackCurrentDelta();
443  virtual void applyAndClearCurrentDelta();
444 
445  virtual const GA_PointGroup *getPointGroup() { return 0; }
446  virtual bool isGroupParmDirty(OP_Context &context)
447  {
448  return isParmDirty(SOP_GDT_GRP_IDX, context.getTime());
449  }
450 
451  void rebuildCaches(
452  const GU_Detail *isectgdp,
453  const GA_PrimitiveGroup *primgroup,
454  const GA_PointGroup *ptgroup,
455  bool invalidate_vtx,
456  bool invalidate_pt);
457 
460 
461  // This stores the last uv location chosen in the 3d viewport.
464 
465  // This is the last uv location chosen in the 3d viewport that
466  // was cooked with.
469 
470  // This is the last uv position that was cooked with.
473 
481 
482  // These two are intentionally ephemeral variable which is NOT saved.
483  // The state tweaks this to turn on/off visualization.
486 
487  /// These track our last geo and last isectgeo to see if it has changed.
488  /// @{
498  /// @}
499 
500  // This is so our callbacks know our cook time...
502 
503  bool myHitInUV;
505 
507 
509 
510  SOP_BrushOp myCachedBrushOp[SOP_BRUSH_NUM_PENS];
511 };
512 
513 #endif
virtual void applyAndClearCurrentDelta()
SOP_BrushOp getCachedOp(int pen) const
virtual bool unloadData() override
virtual int VISMODE()
virtual int VISUALIZE()
SOP_BrushUpType
Definition: SOP_BrushBase.h:68
virtual void rollbackCurrentDelta()
Applies the inverse of myCurrentDelta to the gdp.
virtual int VISTYPE()
virtual int USEDEPTH()
virtual fpreal ZEROWEIGHTCOLOR_R()
GU_Brush myBrush
GA_API const UT_StringHolder uv
fpreal getTime() const
Definition: OP_Context.h:34
const GLdouble * v
Definition: glcorearb.h:836
UT_Vector3 myUVBrushPos
void unlockPointTreeDetail(const GU_Detail *detail)
virtual bool matchesUndo(const char *undoname) const
GDT_Detail myMirroredDelta
GA_Index myLastUVPrimitive
virtual void unloadDataHack()
Do not use this function! Using it will likely cause crashes.
virtual int CAPTUREIDX(fpreal)
virtual void clearAllDeltas(fpreal t)
UT_ErrorSeverity
Definition: UT_Error.h:25
virtual int USECONNECTIVITY()
TIL_TextureMap * myNibFile
GU_RayIntersect * myRayIntersect
virtual void UVATTRIB(UT_String &uvattribname, fpreal t)
int64 myLastIsectGDPPrGrpId
virtual int PRESERVENML()
virtual GEO_Detail::CaptureType CAPTURETYPE()
UT_Vector3 myPendingLastUVPrimitiveUV
int64 myLastIsectGDPTopoId
virtual const GA_PrimitiveGroup * getPrimitiveSelection(void) const
virtual bool wantsCookSelection(void) const
void clear()
Reset the string to the default constructor.
Definition: UT_String.h:309
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
virtual int PTHIT(fpreal)
struct _cl_event * event
Definition: glcorearb.h:2960
int getIsectNodeId() const
GA_Size GA_Offset
Definition: GA_Types.h:617
virtual bool hasCaptureIdxChanged(fpreal)
long long int64
Definition: SYS_Types.h:106
int64 myLastIsectGDPVisId
GU_Detail * myBrushCursor
GDT_MirrorTransform myMirrorTransform
CaptureType
Methods for manipulating capture weights (GEO_CaptureWeight.C)
Definition: GEO_Detail.h:915
virtual void addEraseAttributes(GU_Brush &brush)
GA_Index myPendingLastUVPrimitive
#define SOP_BRUSH_NUM_PENS
Definition: SOP_BrushBase.h:78
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:102
virtual fpreal VISHIGH(fpreal)
static const UT_StringHolder theEmptyString
virtual fpreal ZEROWEIGHTCOLOR_B()
UT_Vector3 myLastUVPrimitiveUV
int64 myLastIsectGDPPrimId
const GA_Group * myGroup
Definition: SOP_GDT.h:117
virtual fpreal SYMMETRYUVORIGV(fpreal)
GLfloat GLfloat GLfloat alpha
Definition: glcorearb.h:111
SOP_BrushOp
Definition: SOP_BrushBase.h:38
virtual fpreal SYMMETRYUVANGLE(fpreal)
int64 myLastIsectGDPPtGrpId
virtual int NORMALIZEWEIGHT()
virtual void setHitPoint(int, fpreal)
Definition: SOP_BrushBase.h:95
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:611
virtual OP_ERROR cookInputGroups(OP_Context &context, int alone=0)
virtual void setHitInUV(bool inuv, const UT_StringHolder &uvattribname)
Definition: SOP_BrushBase.h:98
GA_API const UT_StringHolder orient
void setIsectNodeId(int node_id)
UT_Vector3 myLastUVPos
#define SOP_GDT_GRP_IDX
Definition: SOP_GDT.h:22
virtual fpreal DEPTH(fpreal)
virtual bool hasVisrangeChanged(fpreal)
virtual fpreal ZEROWEIGHTCOLOR_G()
double fpreal
Definition: SYS_Types.h:269
virtual OP_Node * getRestGeoInput()
UT_Matrix3 myCursorOrient
virtual int DOPOINTREFLECTION()
UT_Vector3 myLastPos
virtual fpreal SYMMETRYUVORIGU(fpreal)
UT_StringHolder myUVAttribName
virtual bool isGroupParmDirty(OP_Context &context)
virtual const GA_PointGroup * getPointGroup()
UT_Vector3 myUVBrushDir
virtual fpreal VISLOW(fpreal)
GA_Size myLastIsectGDPPtCount
#define SOP_API
Definition: SOP_API.h:10
int64 myLastIsectGDPPId
virtual fpreal HEIGHT(fpreal)
const GU_Detail * lockPointTreeDetail()
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
virtual int USECAPTURE()
SOP_BrushEvent
Definition: SOP_BrushBase.h:30
virtual int DOUVREFLECTION()
SOP_BrushVisType
Definition: SOP_BrushBase.h:73
virtual OP_ERROR cookMySop(OP_Context &context)=0
SOP_BrushShape
Definition: SOP_BrushBase.h:62
UT_Vector3 myBrushDir
SYS_FORCE_INLINE bool isstring() const
bool isParmDirty(int idx, fpreal t)