HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SOP_ParmOverride.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: SOP Library (C++)
7  *
8  * COMMENTS:
9  * Helper class for evaluating parms with override dropdown menus.
10  */
11 
12 #ifndef __SOP_ParmOverride_h__
13 #define __SOP_ParmOverride_h__
14 
15 #include "SOP_API.h"
16 #include "SOP_NodeVerb.h"
17 #include "FS/FS_Info.h"
18 #include "TIL/TIL_TextureMap.h"
19 
21 {
22 public:
23  enum class OverrideType
24  {
25  NONE = 0,
28  SKINATTRIB,
29  TEXTURE
30  };
31 
32  class CacheData
33  {
34  public:
48  };
49 
51  const SOP_NodeVerb::CookParms &_cookparms,
52  const SOP_NodeParms &_parms,
53  const UT_StringHolder &_baseparmname,
54  const GU_Detail *_gdp,
55  const GU_Detail *_clumpgdp,
56  const GU_Detail *_skingdp,
57  const GA_ROHandleV3 &_uvattrib,
58  const UT_ValArray<OverrideType> &_overridetypes);
59 
61  {
62  return overridetype;
63  }
64 
65  fpreal baseValue() const
66  {
67  return baseparmvalue;
68  }
69 
70  // eval curve, clump, skin and texture
71  void eval(
72  UT_FloatArray &out,
74  const GA_Offset skinprimoff,
75  const GA_OffsetArray &skinvertoffsets,
76  const UT_FloatArray &skinvertweights,
77  const UT_Vector3 &uv,
78  const GA_Offset curveprimoff,
79  const GA_OffsetListRef &curvevertoffsets,
80  const GA_Offset clumpprimoff,
81  const UT_ValArray<GA_OffsetArray> &clumpvertoffsets,
82  const UT_ValArray<UT_FloatArray> &clumpvertweights)
83  {
84  eval(
85  out,
86  target,
87  skinprimoff,
88  &skinvertoffsets,
89  &skinvertweights,
90  uv,
91  curveprimoff,
92  &curvevertoffsets,
93  clumpprimoff,
94  &clumpvertoffsets,
95  &clumpvertweights);
96  }
97 
98  // eval curve, skin and texture
99  void eval(
100  UT_FloatArray &out,
102  const GA_Offset skinprimoff,
103  const GA_OffsetArray &skinvertoffsets,
104  const UT_FloatArray &skinvertweights,
105  const UT_Vector3 &uv,
106  const GA_Offset curveprimoff,
107  const GA_OffsetListRef &curvevertoffsets)
108  {
109  eval(
110  out,
111  target,
112  skinprimoff,
113  &skinvertoffsets,
114  &skinvertweights,
115  uv,
116  curveprimoff,
117  &curvevertoffsets,
118  GA_INVALID_OFFSET, // no clump offset
119  nullptr, // no clump vert arrays
120  nullptr);
121  }
122 
124  const GA_Offset skinprimoff,
125  const GA_OffsetArray &skinvertoffsets,
126  const UT_FloatArray &skinvertweights,
127  const UT_Vector3 &uv);
128 
130  const GA_Offset skinptoff);
131 
133  GA_AttributeOwner target) const;
134 
135  bool needSkin() const;
136 
137  bool needUV() const;
138 
139  const GA_Attribute* getRequiredAttrib() const;
140 
141  bool hasChanged(const CacheData *cache) const;
142 
143  bool
146  {
147  if (!cachedata ||
148  hasChanged(cachedata.get()))
149  {
150  cachedata.reset(getCacheData());
151  return true;
152  }
153  return false;
154  }
155 
156 private:
157  typedef UT_Tuple<int, int> UdimCoord;
158  struct MyHashCompare {
159  static size_t hash( const UdimCoord& x ) {
160  int xhash = SYSwang_inthash(std::get<0>(x));
161  return SYSwang_inthash(xhash + std::get<1>(x));
162  }
163  //! True if strings are equal
164  static bool equal( const UdimCoord& x, const UdimCoord& y ) {
165  return x==y;
166  }
167  };
168  typedef UT_ConcurrentHashMap<UdimCoord, UT_UniquePtr<TIL_TextureMap>, MyHashCompare> TexPathMap;
169 
170  // This eval() accepts pointers to the various offset arrays,
171  // so the public functions, which accept references, can pass nullptrs
172  // for unused arrays.
173  void eval(
174  UT_FloatArray &out,
176  const GA_Offset skinprimoff,
177  const GA_OffsetArray *skinvertoffsets,
178  const UT_FloatArray *skinvertweights,
179  const UT_Vector3 &uv,
180  const GA_Offset curveprimoff,
181  const GA_OffsetListRef *curvevertoffsets,
182  const GA_Offset clumpprimoff,
183  const UT_ValArray<GA_OffsetArray> *clumpvertoffsets,
184  const UT_ValArray<UT_FloatArray> *clumpvertweights);
185 
186  float lookupTexture(UT_Vector3 uv);
187 
188  static exint
189  findParmIndex(
190  const SOP_NodeParms &parms,
191  const UT_StringHolder &parmname);
192 
193  CacheData *getCacheData() const;
194 
195  void check();
196 
197  const SOP_NodeVerb::CookParms &cookparms;
198  const SOP_NodeParms &parms;
199  const UT_StringHolder &baseparmname;
200  const GU_Detail *curvegdp;
201  const GU_Detail *clumpgdp;
202  const GU_Detail *skingdp;
203  const GA_ROHandleV3 &uvattrib;
204  exint baseparmindex;
205  SOP_NodeParms::ParmType baseparmtype;
206  exint overrideparmindex;
207  exint curveattribparmindex;
208  exint clumpattribparmindex;
209  exint skinattribparmindex;
210  exint textureparmindex;
211 
212  fpreal baseparmvalue;
213  OverrideType overridetype;
214  UT_StringHolder curveattribname;
215  UT_StringHolder clumpattribname;
216  UT_StringHolder skinattribname;
217  UT_StringHolder texturepath;
218  bool texturevalid;
219  GA_ROHandleF curveattrib;
220  GA_ROHandleF clumpattrib;
221  GA_ROHandleF skinattrib;
222  UT_UniquePtr<TIL_TextureMap> texturemap;
223  TexPathMap udimmaps;
224  //UT_ValArray<UT_UniquePtr<TIL_TextureMap>> udimmaps;
225  UT_Lock udimlock;
226  bool useudim;
227 
228 public:
229  template<typename T>
230  static T
232  const GU_Detail *gdp,
234  const GA_ROHandleT<T> &attrib,
235  const GA_Offset &primoff,
236  const GA_Offset &vertoff)
237  {
238  if (!attrib.isValid())
239  return 1.0;
240 
241  GA_AttributeOwner owner = attrib.getAttribute()->getOwner();
242  if (owner == GA_ATTRIB_VERTEX)
243  {
244  return attrib.get(vertoff);
245  }
246  else if (owner == GA_ATTRIB_POINT)
247  {
248  GA_Offset pointoff = gdp->vertexPoint(vertoff);
249  return attrib.get(pointoff);
250  }
251  else if (owner == GA_ATTRIB_PRIMITIVE)
252  {
253  return attrib.get(primoff);
254  }
255  else // (owner == GA_ATTRIB_DETAIL)
256  {
257  return attrib.get(GA_Offset(0));
258  }
259  }
260 
261  template<typename T>
262  static T
264  const GU_Detail *gdp,
265  const GA_ROHandleT<T> &attrib,
266  const GA_Offset &primoff,
267  const GA_OffsetArray &vertoffsets,
268  const UT_FloatArray &vertweights,
269  const T defaultvalue=T(0.0f))
270  {
271  if (!attrib.isValid())
272  {
273  return defaultvalue;
274  }
275 
276  T value;
277  GA_AttributeOwner owner = attrib.getAttribute()->getOwner();
278  if (owner == GA_ATTRIB_VERTEX)
279  {
280  value = 0;
281  for (exint i = 0; i < vertoffsets.entries(); ++i)
282  {
283  T vertexvalue = attrib.get(vertoffsets(i));
284  value += vertweights(i) * vertexvalue;
285  }
286  }
287  else if (owner == GA_ATTRIB_POINT)
288  {
289  value = 0;
290  for (exint i = 0; i < vertoffsets.entries(); ++i)
291  {
292  T pointvalue = attrib.get(
293  gdp->vertexPoint(vertoffsets(i)));
294  value += vertweights(i) * pointvalue;
295  }
296  }
297  else if (owner == GA_ATTRIB_PRIMITIVE)
298  {
299  if (GAisValid(primoff))
300  value = attrib.get(primoff);
301  else
302  value = defaultvalue;
303  }
304  else // (owner == GA_ATTRIB_DETAIL)
305  {
306  value = attrib.get(GA_Offset(0));
307  }
308 
309  return value;
310  }
311 
312 };
313 
314 #endif
315 
Definition of a geometry attribute.
Definition: GA_Attribute.h:196
GA_API const UT_StringHolder uv
GLenum target
Definition: glew.h:2865
int64 GA_DataId
Definition: GA_Types.h:685
bool GAisValid(GA_Size v)
Definition: GA_Types.h:647
bool needUV() const
int64 exint
Definition: SYS_Types.h:125
bool needSkin() const
fpreal evalSkinPoint(const GA_Offset skinptoff)
std::tuple< Types...> UT_Tuple
Definition: UT_Tuple.h:53
#define GA_INVALID_OFFSET
Definition: GA_Types.h:676
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:33
const GA_ATINumeric * getAttribute() const
Definition: GA_Handle.h:163
GA_Size GA_Offset
Definition: GA_Types.h:639
GLclampf f
Definition: glew.h:3499
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1252
bool updateOverrideCache(UT_UniquePtr< SOP_ParmOverride::CacheData > &cachedata) const
SYS_FORCE_INLINE T get(GA_Offset off, int comp=0) const
Definition: GA_Handle.h:193
SYS_FORCE_INLINE GA_Offset vertexPoint(GA_Offset vertex) const
Given a vertex, return the point it references.
Definition: GA_Detail.h:480
const GA_Attribute * getRequiredAttrib() const
SYS_FORCE_INLINE bool isValid() const
Definition: GA_Handle.h:184
exint entries() const
Alias of size(). size() is preferred.
Definition: UT_Array.h:460
GA_AttributeOwner getOwner() const
fpreal baseValue() const
GA_AttributeOwner
Definition: GA_Types.h:33
bool hasChanged(const CacheData *cache) const
fpreal64 fpreal
Definition: SYS_Types.h:277
static T interpAttrib(const GU_Detail *gdp, const GA_ROHandleT< T > &attrib, const GA_Offset &primoff, const GA_OffsetArray &vertoffsets, const UT_FloatArray &vertweights, const T defaultvalue=T(0.0f))
bool equal(T1 a, T2 b, T3 t)
Definition: ImathFun.h:143
OverrideType overrideType() const
fpreal evalSkin(const GA_Offset skinprimoff, const GA_OffsetArray &skinvertoffsets, const UT_FloatArray &skinvertweights, const UT_Vector3 &uv)
bool evaluatesToSingleValue(GA_AttributeOwner target) const
static T evalAttrib(const GU_Detail *gdp, const GA_AttributeOwner target, const GA_ROHandleT< T > &attrib, const GA_Offset &primoff, const GA_Offset &vertoff)
void eval(UT_FloatArray &out, const GA_AttributeOwner target, const GA_Offset skinprimoff, const GA_OffsetArray &skinvertoffsets, const UT_FloatArray &skinvertweights, const UT_Vector3 &uv, const GA_Offset curveprimoff, const GA_OffsetListRef &curvevertoffsets)
GLsizei const GLfloat * value
Definition: glew.h:1849
void eval(UT_FloatArray &out, const GA_AttributeOwner target, const GA_Offset skinprimoff, const GA_OffsetArray &skinvertoffsets, const UT_FloatArray &skinvertweights, const UT_Vector3 &uv, const GA_Offset curveprimoff, const GA_OffsetListRef &curvevertoffsets, const GA_Offset clumpprimoff, const UT_ValArray< GA_OffsetArray > &clumpvertoffsets, const UT_ValArray< UT_FloatArray > &clumpvertweights)
SOP_ParmOverride(const SOP_NodeVerb::CookParms &_cookparms, const SOP_NodeParms &_parms, const UT_StringHolder &_baseparmname, const GU_Detail *_gdp, const GU_Detail *_clumpgdp, const GU_Detail *_skingdp, const GA_ROHandleV3 &_uvattrib, const UT_ValArray< OverrideType > &_overridetypes)