HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  ~SOP_BrushBase() override;
85 
86  OP_ERROR cookInputGroups(OP_Context &context, int alone = 0) override;
87 
88  // These set functions adjust the brushes current state.
89  // The MSS State will use them to inform the SOP how to recook.
90  virtual void setAccumulateStencil(bool yesno) = 0;
91  virtual void setRayOrigin(const UT_Vector3 &orig, fpreal t) = 0;
92  virtual void setRayOrientation(const UT_Vector3 &orient, fpreal t) = 0;
93  virtual void setHitPrimitive(int primidx, fpreal t) = 0;
94  virtual void setHitPoint(int /* ptidx */, fpreal /* t */) {}
95  virtual void setHitUVW(fpreal u, fpreal v, fpreal w, fpreal t) = 0;
96  virtual void setHitPressure(fpreal pressure, fpreal t) = 0;
97  virtual void setHitInUV(bool inuv, const UT_StringHolder &uvattribname)
98  {
99  myHitInUV = inuv;
100  if (myHitInUV)
101  {
102  UT_ASSERT(uvattribname.isstring());
103  if (uvattribname.isstring())
104  myUVAttribName = uvattribname;
105  else
106  myUVAttribName = GA_Names::uv;
107  }
108  else
109  {
110  myUVAttribName = UT_StringHolder::theEmptyString;
111  }
112  }
113  virtual void setBrushEvent(SOP_BrushEvent event) = 0;
114  virtual void setBrushOp(SOP_BrushOp op) = 0;
115  virtual void setBrushShape(SOP_BrushShape shape) = 0;
116  virtual void setProjectionType(int projtype) = 0;
117  virtual void useForegroundColor() = 0;
118  virtual void useBackgroundColor() = 0;
119  // These are used to update the current radius.
120  virtual void setRadius(fpreal radius, fpreal t) = 0;
121  virtual void setUVRadius(fpreal radius, fpreal t) = 0;
122 
123  void setCachedOp(int pen, SOP_BrushOp op);
124  SOP_BrushOp getCachedOp(int pen) const { UT_ASSERT(pen < SOP_BRUSH_NUM_PENS); return myCachedBrushOp[pen]; }
125 
127  {
128  return (const GA_PrimitiveGroup*) myGroup;
129  }
130 
131  // Gets the rayintersector for this current group setup and specified time.
132  // If the checkgeo is true, it will test to see if the intersect geo
133  // has changed. We normally do NOT want to do this as rebuilding the
134  // cache is expensive if it was our own change. However, when locating
135  // or mouse down we should enable this to catch other triggers.
136  // The probeonly, if set to true, will prevent the rebuilding of
137  // the GU_RayIntersect, so may return null. This provides a fast way
138  // to update the flags needed to check if geometry changes and
139  // a rebuild is necessary later.
140  virtual GU_RayIntersect *getRayIntersect(
141  fpreal t,
142  bool checkgeochange = false,
143  bool probeonly = false);
144 
145  // Gets the GEO_PointTree for the current group setup.
146  GEO_PointTree *getPointTree();
147  /// NOTE: This is only valid if gdp hasn't been evicted/replaced,
148  /// though this was exactly as unsafe as before, when
149  /// GEO_PointTree held onto a pointer to the detail, and
150  /// MSS_EditState and MSS_BrushBaseState were accessing the
151  /// detail through there, since the GEO_PointTree didn't have
152  /// a read handle on the detail.
154  { return myGdpHandle.readLock(); }
155  void unlockPointTreeDetail(const GU_Detail *detail)
156  { myGdpHandle.unlock(detail); }
157 
158  // Gets or creates the cursor geometry:
159  GU_Detail *getCursorGdp();
160 
161  // This both orients the cursor and tracks what the current brush
162  // direction is.
163  // isuv is true if the intersection is from the UV viewport.
164  // hitu & hitv will be the parametric coordinates of the hit location
165  // on prim. prim will be null for 2d viewports (or in the 3d viewport
166  // if there was no hit)
167  void orientCursor(fpreal t, const UT_Vector3 &orig,
168  const UT_Vector3 &dir,
169  float scalehistory,
170  bool isuv, GA_Index prim,
171  float hitu, float hitv, float hitw);
172 
173  // Gets the interesction gdp.
174  virtual const GU_Detail *getIsectGdp(fpreal t);
175 
176  // The *Static methods can be hooked into buttons as callbacks to
177  // perform the listed function.
178 
179  // applyStencil will copy the current delta into the permament delta
180  // and clear the current.
181  static int applyStencilStatic(void *op, int idx, fpreal t,
182  const PRM_Template *);
183  void applyStencil(fpreal t, int recook = 1);
184 
185  // resetNormal recalculates the surface normals off the current deformed
186  // geometry.
187  static int resetNormalStatic(void *op, int idx, fpreal t,
188  const PRM_Template *);
189  void resetNormal(fpreal t);
190 
191  // flood applies the current operation (as found using OP()) to the
192  // entire selection.
193  static int floodStatic(void *op, int idx, fpreal t,
194  const PRM_Template *);
195  virtual void flood(fpreal t);
196 
197  // NOTE: There is a SOP_GDT::clearallStatic which can be used
198  // for reset all changes.
199  void clearAllDeltas(fpreal t) override;
200 
201  static void customMergeModeStatic(GA_Offset ptoff,
202  GA_Offset vtxoff,
204  const UT_Vector3 &cd,
205  const UT_Vector3 &origcol,
206  void *data);
207  void customMergeMode(GA_Offset ptoff,
208  GA_Offset vtxoff,
210  const UT_Vector3 &cd,
211  const UT_Vector3 &origcol);
212 
213  static void brushOpCallbackStatic(
214  GA_Offset pt,
215  const UT_Array<GA_Offset> *ptneighbour,
216  GA_Offset vtx,
217  const UT_Array<GA_Offset> *vtxneighbor,
218  float alpha,
219  GEO_Delta *delta,
220  void *data);
221  virtual void brushOpCallback(
222  GA_Offset pt,
223  const UT_Array<GA_Offset> *ptneighbour,
224  GA_Offset vtx,
225  const UT_Array<GA_Offset> *vtxneighbour,
226  float alpha,
227  GEO_Delta *delta);
228 
229  // Returns 1 if there is anything in the brush's accumulation buffer
230  bool hasStencil() const;
231 
232  virtual void setCurrentColor(const UT_Vector3 &cd);
233 
234  // Use our brush & visualization mode to do the visualization:
235  void applyVisualizeStencil();
236  void applyVisualize();
237  void applyCaptureVisualize();
238 
239  int getIsectNodeId() const
240  {
241  return myIsectNodeId;
242  }
243  void setIsectNodeId(int node_id)
244  {
245  myIsectNodeId = node_id;
246  }
247 
248  void unloadDataHack() override;
249  bool unloadData() override;
250 
251 protected:
252  // cookMySop will apply the GDT and react to the Brush events,
253  // but you won't be able to patch in your own code.
254  OP_ERROR cookMySop(OP_Context &context) override;
255 
256  // A wrapper function for duplicateChangedSource. At this level,
257  // it simply calls duplicateChnagedSource, but can be overridden
258  // in subclasses to define attributes on the duplicated gdp
259  // (for instance)
260  virtual void duplicateChangedSourceWrapper(
261  unsigned idx,
262  OP_Context &context,
263  int *changed,
264  bool force=false);
265 
266  // Call this method do all the GDT application and brush parsing.
267  // After calling this, any current brush strokes triggerd by the
268  // brush state will be processed, and your gdp will have the result
269  // of applying the GDT.
270  // This should be called after you have duplicateSource (and/or merely
271  // did a rollback), and have created any attributes you wish.
272  // Note that as a result of this, new attributes may be created,
273  // so attribute offsets should be refetched.
274  virtual OP_ERROR processBrushOp(OP_Context &context,
275  bool changed_input, bool changed_group);
276 
277  // This determines whether the given undoblock name matches one of our
278  // undoblocks. If it matches, then our undo is collapsed with this block.
279  // Remember to call the base class!
280  bool matchesUndo(
281  const char *undoname) const override;
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  virtual int USENORMALS() { return 1; }
328 
329  virtual SOP_BrushOp OP() = 0;
330  virtual int ACCUMSTENCIL() = 0;
331  virtual int PROJECTIONTYPE() = 0;
332  virtual int REALTIME() = 0;
333  virtual int SHAPE(fpreal t) = 0;
334 protected:
335  virtual int MERGEMODE() = 0;
336  // Script does not yet do anything, and is reserved.
337  virtual void SCRIPT(UT_String &s, fpreal t) = 0;
338  virtual int AXIS() = 0;
339  virtual fpreal USERX(fpreal t) = 0;
340  virtual fpreal USERY(fpreal t) = 0;
341  virtual fpreal USERZ(fpreal t) = 0;
342 
343  virtual fpreal RAYORIENTX(fpreal t) = 0;
344  virtual fpreal RAYORIENTY(fpreal t) = 0;
345  virtual fpreal RAYORIENTZ(fpreal t) = 0;
346  virtual fpreal RAYHITX(fpreal t) = 0;
347  virtual fpreal RAYHITY(fpreal t) = 0;
348  virtual fpreal RAYHITZ(fpreal t) = 0;
349  virtual fpreal RAYHITU(fpreal t) = 0;
350  virtual fpreal RAYHITV(fpreal t) = 0;
351  virtual fpreal RAYHITW(fpreal t) = 0;
352  virtual fpreal RAYHITPRESSURE(fpreal t) = 0;
353  virtual int PRIMHIT(fpreal t) = 0;
354  virtual int PTHIT(fpreal /* t */) { return -1; }
355  virtual int EVENT() = 0;
356 
357  virtual bool USE_FOREGROUND() = 0;
358  virtual fpreal FGR(fpreal t) = 0;
359  virtual fpreal FGG(fpreal t) = 0;
360  virtual fpreal FGB(fpreal t) = 0;
361  virtual fpreal BGR(fpreal t) = 0;
362  virtual fpreal BGG(fpreal t) = 0;
363  virtual fpreal BGB(fpreal t) = 0;
364 
365  virtual fpreal SOFTEDGE(fpreal t) = 0;
366  virtual void KERNEL(UT_String &str, fpreal t) = 0;
367  virtual int UPTYPE(fpreal t) = 0;
368  virtual fpreal UPX(fpreal t) = 0;
369  virtual fpreal UPY(fpreal t) = 0;
370  virtual fpreal UPZ(fpreal t) = 0;
371 
372  virtual fpreal PAPERNOISE(fpreal t) = 0;
373  virtual fpreal SPLATTER(fpreal t) = 0;
374  virtual void BITMAP(UT_String &str, fpreal t) = 0;
375  virtual int BITMAPCHAN(fpreal t) = 0;
376  virtual fpreal ANGLE(fpreal t) = 0;
377  virtual fpreal SQUASH(fpreal t) = 0;
378  virtual int DOSTAMPING() = 0;
379  virtual int WRITEALPHA() = 0;
380  virtual int OVERRIDECD() = 0;
381  virtual void CDNAME(UT_String &str, fpreal t) = 0;
382  virtual int OVERRIDEALPHA() = 0;
383  virtual void ALPHANAME(UT_String &str, fpreal t) = 0;
384  virtual int PRESERVENML() { return 0; }
385  virtual int OVERRIDENML() = 0;
386  virtual void NMLNAME(UT_String &str, fpreal t) = 0;
387 
388  virtual fpreal SYMMETRYDIRX(fpreal t) = 0;
389  virtual fpreal SYMMETRYDIRY(fpreal t) = 0;
390  virtual fpreal SYMMETRYDIRZ(fpreal t) = 0;
391  virtual fpreal SYMMETRYORIGX(fpreal t) = 0;
392  virtual fpreal SYMMETRYORIGY(fpreal t) = 0;
393  virtual fpreal SYMMETRYORIGZ(fpreal t) = 0;
394  virtual int DOREFLECTION() = 0;
395  virtual int DOPOINTREFLECTION() { return 0; };
396  virtual int DOROTATION() = 0;
397  virtual int SYMMETRYROT(fpreal t) = 0;
398  virtual fpreal SYMMETRYDIST(fpreal t) = 0;
399 
400  virtual int DOUVREFLECTION() { return 0; }
401  virtual fpreal SYMMETRYUVORIGU(fpreal /*t*/) { return 0.5; }
402  virtual fpreal SYMMETRYUVORIGV(fpreal /*t*/) { return 0.5; }
403  virtual fpreal SYMMETRYUVANGLE(fpreal /*t*/) { return 0.0; }
404 
405  virtual int ADDATTRIB() = 0;
406  virtual void UVATTRIB(UT_String &uvattribname, fpreal t)
407  { uvattribname.clear(); }
408  virtual int VISUALIZE() { return 0; }
409  virtual int VISTYPE() { return 0; }
410  virtual fpreal VISLOW(fpreal /*t*/) { return 0.0; }
411  virtual fpreal VISHIGH(fpreal /*t*/) { return 1.0; }
412  virtual int VISMODE() { return 0; }
413  virtual fpreal ZEROWEIGHTCOLOR_R() { return 1.0; }
414  virtual fpreal ZEROWEIGHTCOLOR_G() { return 1.0; }
415  virtual fpreal ZEROWEIGHTCOLOR_B() { return 1.0; }
416 
417  virtual int NORMALIZEWEIGHT() { return 0; }
418 
419  virtual int USECAPTURE() { return 0; }
420  virtual int CAPTUREIDX(fpreal /*t*/) { return 0; }
423 
424  // Find out if the brush has moved or done anything to cause us to add its
425  // effect to the current gdp.
426  virtual bool hasStrokeChanged(fpreal t) = 0;
427  virtual bool hasStyleChanged (fpreal t) = 0;
428 
429  // Find if the nib file has changed:
430  virtual bool hasNibFileChanged(fpreal t) = 0;
431 
432  // Find if any of the nib description values have changed:
433  virtual bool hasNibLookChanged(fpreal t) = 0;
434  virtual bool hasAccumStencilChanged(fpreal t) = 0;
435 
436  virtual bool hasCaptureIdxChanged(fpreal /*t*/) { return 0; }
437 
438  virtual bool hasVisrangeChanged(fpreal /*t*/) { return 0; }
439 
440  // Do we want our cook selection to be updated and displayed?
441  virtual bool wantsCookSelection() const { return false; }
442 
443  void rollbackCurrentDelta() override;
445  override;
447  void applyAndClearCurrentDelta() override;
448  void applyPermanentDelta() override;
449 
450  virtual const GA_PointGroup *getPointGroup() { return 0; }
451  virtual bool isGroupParmDirty(OP_Context &context)
452  {
453  return isParmDirty(SOP_GDT_GRP_IDX, context.getTime());
454  }
455 
456  void rebuildCaches(
457  const GU_Detail *isectgdp,
458  const GA_PrimitiveGroup *primgroup,
459  const GA_PointGroup *ptgroup,
460  bool invalidate_vtx,
461  bool invalidate_pt);
462 
465 
466  // This stores the last uv location chosen in the 3d viewport.
469 
470  // This is the last uv location chosen in the 3d viewport that
471  // was cooked with.
474 
475  // This is the last uv position that was cooked with.
478 
486 
487  // These two are intentionally ephemeral variable which is NOT saved.
488  // The state tweaks this to turn on/off visualization.
491 
492  /// These track our last geo and last isectgeo to see if it has changed.
493  /// @{
503  /// @}
504 
505  // This is so our callbacks know our cook time...
507 
508  bool myHitInUV;
510 
512 
514 
515  SOP_BrushOp myCachedBrushOp[SOP_BRUSH_NUM_PENS];
516 };
517 
518 #endif
virtual void applyAndClearCurrentDelta()
SOP_BrushOp getCachedOp(int pen) const
GLdouble s
Definition: glew.h:1390
virtual int VISMODE()
virtual int VISUALIZE()
SOP_BrushUpType
Definition: SOP_BrushBase.h:68
GLuint const GLchar * name
Definition: glew.h:1814
virtual void rollbackCurrentDelta()
Applies the inverse of myCurrentDelta to the gdp.
virtual int VISTYPE()
GLclampf GLclampf GLclampf alpha
Definition: glew.h:1520
virtual void applyPermanentDelta()
Applies myPermanentDelta to the gdp.
virtual int USEDEPTH()
virtual fpreal ZEROWEIGHTCOLOR_R()
GU_Brush myBrush
GA_API const UT_StringHolder uv
fpreal getTime() const
Definition: OP_Context.h:60
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()
const GLdouble * v
Definition: glew.h:1391
UT_Vector3 myPendingLastUVPrimitiveUV
int64 myLastIsectGDPTopoId
virtual bool wantsCookSelection() 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:233
virtual int USENORMALS()
virtual int PTHIT(fpreal)
int getIsectNodeId() const
GA_Size GA_Offset
Definition: GA_Types.h:639
virtual bool hasCaptureIdxChanged(fpreal)
int64 myLastIsectGDPVisId
GU_Detail * myBrushCursor
GDT_MirrorTransform myMirrorTransform
virtual void rollbackCurrentDeltaElementsToInputValues()
CaptureType
Methods for manipulating capture weights (GEO_CaptureWeight.C)
Definition: GEO_Detail.h:982
virtual void addEraseAttributes(GU_Brush &brush)
GA_Index myPendingLastUVPrimitive
#define SOP_BRUSH_NUM_PENS
Definition: SOP_BrushBase.h:78
virtual fpreal VISHIGH(fpreal)
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
static const UT_StringHolder theEmptyString
virtual fpreal ZEROWEIGHTCOLOR_B()
UT_Vector3 myLastUVPrimitiveUV
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
int64 myLastIsectGDPPrimId
const GA_Group * myGroup
Definition: SOP_GDT.h:129
long long int64
Definition: SYS_Types.h:116
virtual fpreal SYMMETRYUVORIGV(fpreal)
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:94
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:633
virtual OP_ERROR cookInputGroups(OP_Context &context, int alone=0)
virtual void setHitInUV(bool inuv, const UT_StringHolder &uvattribname)
Definition: SOP_BrushBase.h:97
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()
cl_event event
Definition: glew.h:3695
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)
fpreal64 fpreal
Definition: SYS_Types.h:277
virtual const GA_PointGroup * getPointGroup()
UT_Vector3 myUVBrushDir
virtual const GA_PrimitiveGroup * getPrimitiveSelection() const
virtual fpreal VISLOW(fpreal)
GA_Size myLastIsectGDPPtCount
#define SOP_API
Definition: SOP_API.h:10
int64 myLastIsectGDPPId
virtual fpreal HEIGHT(fpreal)
GLuint64EXT * result
Definition: glew.h:14007
const GU_Detail * lockPointTreeDetail()
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:135
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
GLdouble GLdouble t
Definition: glew.h:1398
UT_Vector3 myBrushDir
SYS_FORCE_INLINE bool isstring() const
virtual void rollbackCurrentDeltaElementsToPermanentDeltaValues()
bool isParmDirty(int idx, fpreal t)
bool unloadData() override