HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SOP_CPPWave.C
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 /// This is the pure C++ implementation of the wave SOP.
29 /// @see @ref HOM/SOP_HOMWave.py, @ref HOM/SOP_HOMWaveNumpy.py, @ref HOM/SOP_HOMWaveInlinecpp.py, @ref HOM/SOP_HOMWave.C, @ref SOP/SOP_VEXWave.vfl
30 
31 #include "SOP_CPPWave.h"
32 
33 #include <GU/GU_Detail.h>
34 #include <GA/GA_Handle.h>
35 #include <OP/OP_AutoLockInputs.h>
36 #include <OP/OP_Director.h>
37 #include <OP/OP_Operator.h>
38 #include <OP/OP_OperatorTable.h>
39 #include <PRM/PRM_Include.h>
40 #include <UT/UT_DSOVersion.h>
41 #include <SYS/SYS_Math.h>
42 
43 using namespace HDK_Sample;
44 
45 void
47 {
48  table->addOperator(new OP_Operator(
49  "cpp_wave",
50  "CPP Wave ",
53  1,
54  1,
55  0));
56 }
57 
60  PRM_Template(),
61 };
62 
63 
64 OP_Node *
66 {
67  return new SOP_CPPWave(net, name, op);
68 }
69 
71  : SOP_Node(net, name, op)
72 {
73  // This indicates that this SOP manually manages its data IDs,
74  // so that Houdini can identify what attributes may have changed,
75  // e.g. to reduce work for the viewport, or other SOPs that
76  // check whether data IDs have changed.
77  // By default, (i.e. if this line weren't here), all data IDs
78  // would be bumped after the SOP cook, to indicate that
79  // everything might have changed.
80  // If some data IDs don't get bumped properly, the viewport
81  // may not update, or SOPs that check data IDs
82  // may not cook correctly, so be *very* careful!
84 }
85 
87 {
88 }
89 
92 {
93  // We must lock our inputs before we try to access their geometry.
94  // OP_AutoLockInputs will automatically unlock our inputs when we return.
95  // NOTE: Don't call unlockInputs yourself when using this!
96  OP_AutoLockInputs inputs(this);
97  if (inputs.lock(context) >= UT_ERROR_ABORT)
98  return error();
99 
100  // Duplicate input geometry
101  duplicateSource(0, context);
102 
103  // Flag the SOP as being time dependent (i.e. cook on time changes)
104  flags().setTimeDep(true);
105 
106  fpreal frame = OPgetDirector()->getChannelManager()->getSample(context.getTime());
107  frame *= 0.03;
108 
109  // NOTE: If you are only interested in the P attribute, use gdp->getP(),
110  // or don't bother making a new GA_RWHandleV3, and just use
111  // gdp->getPos3(ptoff) and gdp->setPos3(ptoff, Pvalue).
112  // This just gives an example supplying an attribute name.
114  GA_Offset ptoff;
115  GA_FOR_ALL_PTOFF(gdp, ptoff)
116  {
117  UT_Vector3 Pvalue = Phandle.get(ptoff);
118  Pvalue.y() = sin(Pvalue.x()*.2 + Pvalue.z()*.3 + frame);
119  Phandle.set(ptoff, Pvalue);
120  }
121  // If we've modified an attribute, and we're managing our own data IDs,
122  // we must bump the data ID for that attribute.
123  Phandle.bumpDataId();
124 
125  return error();
126 }
virtual OP_ERROR error()
const OP_NodeFlags & flags() const
Definition: OP_Node.h:1400
OP_ERROR lock(OP_Context &context)
Locks all inputs.
fpreal getTime() const
Definition: OP_Context.h:62
constexpr SYS_FORCE_INLINE T & z() noexcept
Definition: UT_Vector3.h:667
UT_ErrorSeverity
Definition: UT_Error.h:25
bool addOperator(OP_Operator *op, std::ostream *err=nullptr)
void newSopOperator(OP_OperatorTable *table)
Definition: SOP_CPPWave.C:46
CH_Manager * getChannelManager()
Definition: OP_Director.h:113
GA_Size GA_Offset
Definition: GA_Types.h:646
fpreal getSample(fpreal t) const
Definition: CH_Manager.h:1239
SOP_CPPWave(OP_Network *net, const char *name, OP_Operator *op)
Definition: SOP_CPPWave.C:70
SOP_NodeFlags mySopFlags
Definition: SOP_Node.h:1628
static PRM_Template myTemplateList[]
Definition: SOP_CPPWave.h:45
GLuint const GLchar * name
Definition: glcorearb.h:786
SYS_FORCE_INLINE const GA_Attribute * findAttribute(GA_AttributeScope scope, const UT_StringRef &name, const GA_AttributeOwner search_order[], int search_size) const
Definition: GA_Detail.h:1010
#define GA_FOR_ALL_PTOFF(gdp, ptoff)
Definition: GA_GBMacros.h:88
GLenum GLenum GLsizei void * table
Definition: glad.h:5129
void setManagesDataIDs(bool onOff)
Definition: SOP_NodeFlags.h:36
GU_Detail * gdp
Definition: SOP_Node.h:1625
OP_ERROR cookMySop(OP_Context &context) override
Definition: SOP_CPPWave.C:91
void setTimeDep(bool on_off)
Definition: OP_NodeFlags.h:111
fpreal64 fpreal
Definition: SYS_Types.h:277
OP_API OP_Director * OPgetDirector()
static OP_Node * myConstructor(OP_Network *, const char *, OP_Operator *)
Definition: SOP_CPPWave.C:65
constexpr SYS_FORCE_INLINE T & y() noexcept
Definition: UT_Vector3.h:665
SYS_API double sin(double x)
Definition: SYS_FPUMath.h:71
constexpr SYS_FORCE_INLINE T & x() noexcept
Definition: UT_Vector3.h:663
OP_ERROR duplicateSource(unsigned index, OP_Context &context, GU_Detail *gdp, bool clean=true)