HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VOP_CustomContext.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 #ifndef __VOP_CustomContext_h__
27 #define __VOP_CustomContext_h__
28 
29 #include <SOP/SOP_Node.h>
30 #include <VOP/VOP_Node.h>
31 #include <OP/OP_OperatorTable.h>
32 #include <SYS/SYS_Types.h>
33 
34 /// @file
35 /// This example contains code which shows how to create a custom VOP SOP in
36 /// the HDK. The custom VOP nodes within can dynamically change their inputs
37 /// and outputs. For simplicity, the Custom VOP SOP does not generate any
38 /// geometry.
39 namespace HDK_Sample {
40 
42 {
43 public:
44  bool allowOperatorAsChild(OP_Operator *op) override;
45 };
46 
47 /// C++ SOP node to provide the custom VOP context
48 class SOP_CustomVop : public SOP_Node
49 {
50 public:
51  /// Creates an instance of this node with the given name in the given
52  /// network.
53  static OP_Node * myConstructor(
54  OP_Network *net,
55  const char *name,
56  OP_Operator *entry);
57 
58  /// Our parameter templates.
60 
61  /// We override these to specify that our child network type is VOPs.
62  // @{
63  const char * getChildType() const override;
64  OP_OpTypeId getChildTypeID() const override;
65  // @}
66 
67  /// Override this to provide custom behaviour for what is allowed in the
68  /// tab menu.
70  { return &myOperatorFilter; }
71 
72  /// Override this to do VOP network evaluation
73  OP_ERROR cookMySop(OP_Context &context) override;
74 
75  static const char *theChildTableName;
76 
77 protected:
79  OP_Network *net,
80  const char *name,
81  OP_Operator *entry);
82  ~SOP_CustomVop() override;
83 
84 private:
85  OP_OperatorTable * createAndGetOperatorTable();
86 
87 private:
88  SOP_CustomVopOperatorFilter myOperatorFilter;
89 };
90 
91 /// C++ VOP node to select one of its inputs and feed it into the output.
92 class VOP_CustomVop : public VOP_Node
93 {
94 public:
95  /// Creates an instance of this node with the given name in the given
96  /// network.
97  static OP_Node * myConstructor(
98  OP_Network *net,
99  const char *name,
100  OP_Operator *entry);
101 
102  /// Our parameter templates.
104 
105  /// This function is called to run the creation script (if there is one).
106  /// The return value is false if the node was deleted while running the
107  /// script. In this case obviously the node pointer becomes invalid and
108  /// should not be used any more. It returns true if the node still exists.
109  ///
110  /// We override this in order to perform initial creation we are created
111  /// created for the first time in a .hip file. This function is NOT called
112  /// when being loaded from .hip files.
113  bool runCreateScript() override;
114 
115  /// Provides the labels to appear on input and output buttons.
116  // @{
117  const char * inputLabel(unsigned idx) const override;
118  const char * outputLabel(unsigned idx) const override;
119  // @}
120 
121  /// Controls the number of input/output buttons visible on the node tile.
122  // @{
123  unsigned getNumVisibleInputs() const override;
124  unsigned getNumVisibleOutputs() const override;
125  // @}
126 
127  /// Returns the index of the first "unordered" input, meaning that inputs
128  /// before this one should not be collapsed when they are disconnected.
129  /// In this example, we don't need to implement this.
130  //virtual unsigned orderedInputs() const;
131 
132 protected:
134  OP_Network *net,
135  const char *name,
136  OP_Operator *entry);
137  ~VOP_CustomVop() override;
138 
139  /// Returns the internal name of the supplied input. This input name is
140  /// used when the code generator substitutes variables return by getCode.
142  UT_String &name,
143  int idx) const override;
144  /// Reverse mapping of internal input names to an input index.
146  const UT_String &name) const override;
147  /// Fills in the info about the vop type connected to the idx-th input.
149  VOP_TypeInfo &type_info, int idx) override;
150 
151  /// Returns the internal name of the supplied output. This name is used
152  /// when the code generator substitutes variables return by getCode.
154  UT_String &out,
155  int idx) const override;
156  /// Fills out the info about data type of each output connector.
158  VOP_TypeInfo &type_info, int idx) override;
159 
160  /// This methods should be overriden in most VOP nodes. It should fill in
161  /// voptypes vector with vop types that are allowed to be connected to this
162  /// node at the input at index idx. Note that
163  /// this method should return valid vop types even
164  /// when nothing is connected to the corresponding input.
166  unsigned idx,
167  VOP_VopTypeInfoArray &type_infos) override;
168 
169 private:
170  static void nodeEventHandler(
171  OP_Node *caller,
172  void *callee,
174  void *data);
175 
176  void handleParmChanged(int parm_index);
177 
178 private:
179 
180 };
181 
182 } // End of HDK_Sample namespace
183 
184 #endif // __VOP_CustomContext_h__
static const char * theChildTableName
UT_ErrorSeverity
Definition: UT_Error.h:25
void getInputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx) override
Fills in the info about the vop type connected to the idx-th input.
bool allowOperatorAsChild(OP_Operator *op) override
C++ VOP node to select one of its inputs and feed it into the output.
OP_OperatorFilter * getOperatorFilter() override
static OP_Node * myConstructor(OP_Network *net, const char *name, OP_Operator *entry)
void getAllowedInputTypeInfosSubclass(unsigned idx, VOP_VopTypeInfoArray &type_infos) override
static OP_Node * myConstructor(OP_Network *net, const char *name, OP_Operator *entry)
const char * inputLabel(unsigned idx) const override
Provides the labels to appear on input and output buttons.
static PRM_Template myTemplateList[]
Our parameter templates.
VOP_CustomVop(OP_Network *net, const char *name, OP_Operator *entry)
const char * getChildType() const override
We override these to specify that our child network type is VOPs.
OP_OpTypeId getChildTypeID() const override
We override these to specify that our child network type is VOPs.
OP_OpTypeId
Definition: OP_OpTypeId.h:18
GLuint const GLchar * name
Definition: glcorearb.h:786
const char * outputLabel(unsigned idx) const override
Provides the labels to appear on input and output buttons.
unsigned getNumVisibleInputs() const override
Controls the number of input/output buttons visible on the node tile.
void getOutputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx) override
Fills out the info about data type of each output connector.
static PRM_Template myTemplateList[]
Our parameter templates.
SOP_CustomVop(OP_Network *net, const char *name, OP_Operator *entry)
OP_EventType
Definition: OP_Value.h:22
C++ SOP node to provide the custom VOP context.
void getInputNameSubclass(UT_String &name, int idx) const override
int getInputFromNameSubclass(const UT_String &name) const override
Reverse mapping of internal input names to an input index.
type
Definition: core.h:1059
void getOutputNameSubclass(UT_String &out, int idx) const override
Definition: format.h:895
unsigned getNumVisibleOutputs() const override
OP_ERROR cookMySop(OP_Context &context) override
Override this to do VOP network evaluation.