HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SOP_CustomBrush.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024
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  ~SOP_CustomBrush() override;
70 
72  static OP_Node *myConstructor(OP_Network*, const char *, OP_Operator *);
73 
75  int alone = 0) override;
76 
77  // used by undo/redo to update the paint
79 
80 protected:
81  // Method to cook geometry for the SOP
82  OP_ERROR cookMySop(OP_Context &context) override;
83 
84  // save the SOP's data (including the applied paint)
85  OP_ERROR save(std::ostream &os,
86  const OP_SaveFlags &flags,
87  const char *path_prefix,
88  const UT_String &name_override = UT_String()
89  ) override;
90  // load the SOP's data (including the applied paint)
91  bool load(UT_IStream &is,
92  const char *extension,
93  const char *path) override;
94 
95  // callback used by the "Clear All" parameter
96  static int clearAllStatic(void *op, int, fpreal time, const PRM_Template *);
97  void clearAll();
98 
99 private:
100  UT_Vector3 evalVector3(int idx, fpreal t)
101  {
102  return UT_Vector3(evalFloat(idx, 0, t),
103  evalFloat(idx, 1, t),
104  evalFloat(idx, 2, t));
105  }
106 
107  UT_Vector3 getOrigin(fpreal t)
108  { return evalVector3(SOP_CUSTOMBRUSH_ORIGIN_IDX, t); }
109 
110  UT_Vector3 getDirection(fpreal t)
111  { return evalVector3(SOP_CUSTOMBRUSH_DIRECTION_IDX, t); }
112 
113  fpreal getRadius(fpreal t)
114  { return evalFloat(SOP_CUSTOMBRUSH_RADIUS_IDX, 0, t); }
115 
116  UT_Vector3 getBrushColor(fpreal t)
117  { return evalVector3(SOP_CUSTOMBRUSH_COLOR_IDX, t); }
118 
119  fpreal getBrushAlpha(fpreal t)
120  { return evalFloat(SOP_CUSTOMBRUSH_ALPHA_IDX, 0, t); }
121 
122  int getOperation(fpreal t)
123  { return evalInt(SOP_CUSTOMBRUSH_OPERATION_IDX, 0, t); }
124 
125  int getEvent(fpreal t)
126  { return evalInt(SOP_CUSTOMBRUSH_EVENT_IDX, 0, t); }
127 
128  const GA_PointGroup *myGroup;
129 
130  // expected number of points in the input
131  GA_Size myNumPts;
132 
133  // contains previous expected number of points in the input for undos
134  GA_Size myOldNumPts;
135 
136  // stores applied paint values
138 
139  // contains previous paint values for undos
141 };
142 } // End HDK_Sample namespace
143 
144 #endif
GLbitfield flags
Definition: glcorearb.h:1596
static int clearAllStatic(void *op, int, fpreal time, const PRM_Template *)
GT_API const UT_StringHolder time
UT_Vector3T< float > UT_Vector3
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
GLboolean GLboolean g
Definition: glcorearb.h:1222
int64 exint
Definition: SYS_Types.h:125
fpreal evalFloat(int pi, int vi, fpreal t) const
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
UT_ErrorSeverity
Definition: UT_Error.h:25
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:235
bool load(UT_IStream &is, const char *extension, const char *path) override
OP_ERROR save(std::ostream &os, const OP_SaveFlags &flags, const char *path_prefix, const UT_String &name_override=UT_String()) override
void updateData(exint numpts, UT_Array< SOP_CustomBrushData > &data)
OP_ERROR cookMySop(OP_Context &context) override
SOP_CustomBrushData(GA_Index ptnum, fpreal r, fpreal g, fpreal b, fpreal a)
OP_ERROR cookInputGroups(OP_Context &context, int alone=0) override
GLuint const GLchar * name
Definition: glcorearb.h:786
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:635
static OP_Node * myConstructor(OP_Network *, const char *, OP_Operator *)
GLdouble t
Definition: glad.h:2397
fpreal64 fpreal
Definition: SYS_Types.h:277
exint evalInt(int pi, int vi, fpreal t) const
GLboolean r
Definition: glcorearb.h:1222
static PRM_Template myTemplateList[]
OIIO_UTIL_API std::string extension(string_view filepath, bool include_dot=true) noexcept
Definition: format.h:895