HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SOP_CustomBrush.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *----------------------------------------------------------------------------
26  */
27 
28 #ifndef __SOP_CustomBrush_h__
29 #define __SOP_CustomBrush_h__
30 
31 #include <SOP/SOP_Node.h>
32 #include <UT/UT_Array.h>
33 
34 namespace HDK_Sample {
35 enum
36 {
37  // Group parameters
47 };
48 
49 // structure to describe the paint applied to a particular point
50 // the colors are assumed to be pre-multiplied by the alpha
52 {
55 
61 };
62 
63 class SOP_CustomBrush : public SOP_Node
64 {
65 public:
66  // our constructor
67  SOP_CustomBrush(OP_Network *net, const char *name, OP_Operator *op);
68  // our destructor
69  virtual ~SOP_CustomBrush();
70 
72  static OP_Node *myConstructor(OP_Network*, const char *, OP_Operator *);
73 
74  virtual OP_ERROR cookInputGroups(OP_Context &context, int alone = 0);
75 
76  // used by undo/redo to update the paint
78 
79 protected:
80  // Method to cook geometry for the SOP
81  virtual OP_ERROR cookMySop(OP_Context &context);
82 
83  // save the SOP's data (including the applied paint)
84  virtual OP_ERROR save(std::ostream &os, const OP_SaveFlags &flags,
85  const char *path_prefix,
86  const UT_String &name_override = UT_String());
87  // load the SOP's data (including the applied paint)
88  virtual bool load(UT_IStream &is, const char *extension,
89  const char *path);
90 
91  // callback used by the "Clear All" parameter
92  static int clearAllStatic(void *op, int, fpreal time, const PRM_Template *);
93  void clearAll();
94 
95 private:
96  UT_Vector3 evalVector3(int idx, fpreal t)
97  {
98  return UT_Vector3(evalFloat(idx, 0, t),
99  evalFloat(idx, 1, t),
100  evalFloat(idx, 2, t));
101  }
102 
103  UT_Vector3 getOrigin(fpreal t)
104  { return evalVector3(SOP_CUSTOMBRUSH_ORIGIN_IDX, t); }
105 
106  UT_Vector3 getDirection(fpreal t)
107  { return evalVector3(SOP_CUSTOMBRUSH_DIRECTION_IDX, t); }
108 
109  fpreal getRadius(fpreal t)
110  { return evalFloat(SOP_CUSTOMBRUSH_RADIUS_IDX, 0, t); }
111 
112  UT_Vector3 getBrushColor(fpreal t)
113  { return evalVector3(SOP_CUSTOMBRUSH_COLOR_IDX, t); }
114 
115  fpreal getBrushAlpha(fpreal t)
116  { return evalFloat(SOP_CUSTOMBRUSH_ALPHA_IDX, 0, t); }
117 
118  int getOperation(fpreal t)
119  { return evalInt(SOP_CUSTOMBRUSH_OPERATION_IDX, 0, t); }
120 
121  int getEvent(fpreal t)
122  { return evalInt(SOP_CUSTOMBRUSH_EVENT_IDX, 0, t); }
123 
124  const GA_PointGroup *myGroup;
125 
126  // expected number of points in the input
127  GA_Size myNumPts;
128 
129  // contains previous expected number of points in the input for undos
130  GA_Size myOldNumPts;
131 
132  // stores applied paint values
134 
135  // contains previous paint values for undos
137 };
138 } // End HDK_Sample namespace
139 
140 #endif
virtual bool load(UT_IStream &is, const char *extension, const char *path)
static int clearAllStatic(void *op, int, fpreal time, const PRM_Template *)
UT_Vector3T< float > UT_Vector3
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
GLboolean GLboolean g
Definition: glcorearb.h:1221
fpreal evalFloat(int pi, int vi, fpreal t) const
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
UT_ErrorSeverity
Definition: UT_Error.h:25
GLbitfield flags
Definition: glcorearb.h:1595
SOP_CustomBrush(OP_Network *net, const char *name, OP_Operator *op)
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
virtual OP_ERROR cookMySop(OP_Context &context)
virtual OP_ERROR save(std::ostream &os, const OP_SaveFlags &flags, const char *path_prefix, const UT_String &name_override=UT_String())
void updateData(exint numpts, UT_Array< SOP_CustomBrushData > &data)
int64 exint
Definition: SYS_Types.h:109
SOP_CustomBrushData(GA_Index ptnum, fpreal r, fpreal g, fpreal b, fpreal a)
virtual OP_ERROR cookInputGroups(OP_Context &context, int alone=0)
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:611
static OP_Node * myConstructor(OP_Network *, const char *, OP_Operator *)
double fpreal
Definition: SYS_Types.h:263
exint evalInt(int pi, int vi, fpreal t) const
GLboolean r
Definition: glcorearb.h:1221
static PRM_Template myTemplateList[]