HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SOP_DetailAttrib.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  * DetailAttrib SOP
27  */
28 
29 #include "SOP_DetailAttrib.h"
30 
31 #include <GU/GU_Detail.h>
32 #include <GA/GA_Handle.h>
33 #include <OP/OP_AutoLockInputs.h>
34 #include <OP/OP_Operator.h>
35 #include <OP/OP_OperatorTable.h>
36 #include <PRM/PRM_Include.h>
37 #include <UT/UT_DSOVersion.h>
38 
39 using namespace HDK_Sample;
40 void
42 {
43  table->addOperator(new OP_Operator(
44  "hdk_detailattrib",
45  "DetailAttrib",
48  1,
49  1));
50 }
51 
52 
53 static PRM_Name sop_names[] = {
54  PRM_Name("attribname", "Attribute"),
55  PRM_Name("value", "Value"),
56 };
57 
58 static PRM_Default sop_valueDefault(0.1);
59 static PRM_Range sop_valueRange(PRM_RANGE_RESTRICTED,0,PRM_RANGE_UI,1);
60 
63 {
64  PRM_Template(PRM_STRING, 1, &sop_names[0], 0),
65  PRM_Template(PRM_FLT_J, 1, &sop_names[1], &sop_valueDefault, 0,
66  &sop_valueRange),
67  PRM_Template()
68 };
69 
70 
71 OP_Node *
73 {
74  return new SOP_DetailAttrib(net, name, entry);
75 }
76 
77 
79  : SOP_Node(net, name, entry)
80 {
81  // This indicates that this SOP manually manages its data IDs,
82  // so that Houdini can identify what attributes may have changed,
83  // e.g. to reduce work for the viewport, or other SOPs that
84  // check whether data IDs have changed.
85  // By default, (i.e. if this line weren't here), all data IDs
86  // would be bumped after the SOP cook, to indicate that
87  // everything might have changed.
88  // If some data IDs don't get bumped properly, the viewport
89  // may not update, or SOPs that check data IDs
90  // may not cook correctly, so be *very* careful!
92 }
93 
95 {
96 }
97 
98 
101 {
102  fpreal t = context.getTime();
103 
104  // We must lock our inputs before we try to access their geometry.
105  // OP_AutoLockInputs will automatically unlock our inputs when we return.
106  // NOTE: Don't call unlockInputs yourself when using this!
107  OP_AutoLockInputs inputs(this);
108  if (inputs.lock(context) >= UT_ERROR_ABORT)
109  return error();
110 
111  duplicateSource(0, context);
112 
113  UT_String aname;
114  ATTRIBNAME(aname, t);
115 
116  // Try with a float
118 
119  // Not present, so create the detail attribute:
120  if (!attrib.isValid())
121  attrib = GA_RWHandleF(gdp->addFloatTuple(GA_ATTRIB_DETAIL, aname, 1));
122 
123  if (attrib.isValid())
124  {
125  // Store the value in the detail attribute
126  // NOTE: The detail is *always* at GA_Offset(0)
127  attrib.set(GA_Offset(0), VALUE(t));
128  attrib.bumpDataId();
129  }
130 
131  return error();
132 }
133 
void newSopOperator(OP_OperatorTable *table)
virtual OP_ERROR error()
PRM_API const PRM_Type PRM_STRING
OP_ERROR lock(OP_Context &context)
Locks all inputs.
GA_Attribute * addFloatTuple(GA_AttributeOwner owner, GA_AttributeScope scope, const UT_StringHolder &name, int tuple_size, const GA_Defaults &defaults=GA_Defaults(0.0), const UT_Options *creation_args=0, const GA_AttributeOptions *attribute_options=0, GA_Storage storage=GA_STORE_REAL32, const GA_ReuseStrategy &reuse=GA_ReuseStrategy())
fpreal getTime() const
Definition: OP_Context.h:62
static PRM_Template myTemplateList[]
UT_ErrorSeverity
Definition: UT_Error.h:25
bool addOperator(OP_Operator *op, std::ostream *err=nullptr)
GA_Size GA_Offset
Definition: GA_Types.h:641
static OP_Node * myConstructor(OP_Network *net, const char *name, OP_Operator *entry)
OP_ERROR cookMySop(OP_Context &context) override
SOP_NodeFlags mySopFlags
Definition: SOP_Node.h:1625
void ATTRIBNAME(UT_String &str, fpreal t)
GLuint const GLchar * name
Definition: glcorearb.h:786
PRM_API const PRM_Type PRM_FLT_J
GLenum GLenum GLsizei void * table
Definition: glad.h:5129
void setManagesDataIDs(bool onOff)
Definition: SOP_NodeFlags.h:36
GLdouble t
Definition: glad.h:2397
GU_Detail * gdp
Definition: SOP_Node.h:1622
const GA_Attribute * findFloatTuple(GA_AttributeOwner owner, GA_AttributeScope scope, const UT_StringRef &name, int min_size=1, int max_size=-1) const
SYS_FORCE_INLINE void set(GA_Offset off, const T &val) const
Definition: GA_Handle.h:354
SOP_DetailAttrib(OP_Network *net, const char *, OP_Operator *entry)
fpreal64 fpreal
Definition: SYS_Types.h:277
GA_RWHandleT< fpreal32 > GA_RWHandleF
Definition: GA_Handle.h:1355
OP_ERROR duplicateSource(unsigned index, OP_Context &context, GU_Detail *gdp, bool clean=true)