HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_PolyFrame.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: GU_PolyFrame.h (Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GU_PolyFrame__
12 #define __GU_PolyFrame__
13 
14 #include "GU_API.h"
15 
16 #include <GA/GA_Handle.h>
17 #include <GEO/GEO_PrimPolySoup.h>
18 #include <UT/UT_SharedPtr.h>
19 #include <UT/UT_Vector3.h>
20 #include <string.h>
21 
22 // GU_PolyFrame::theMinVertices[] depends on the ordering of this enumeration.
24 {
31 };
32 
34 {
38 };
39 
41 {
47 };
48 
50 {
51 public:
54  , which(GU_POLYFRAME_NORMAL)
55  , orthogonal(false)
56  , left_handed(false)
57  , uv_name(0)
58  {
59  ::memset(names, 0, sizeof(const char *) * 3);
60  }
61 
62  GU_PolyFrameStyle style; // Specifies how the frame vectors are
63  // to be calculated.
64 
65  int which; // A bit mask that specifies which basis
66  // vectors are to be evaluated. Bits
67  // can be set using members of the
68  // GU_PolyFrameVector enumeration.
69 
70  bool orthogonal; // Indicates that the frame vectors
71  // must be made orthogonal.
72 
73  bool left_handed; // When false (default), it produces a
74  // right-handed frame, else left-handed.
75  // This only applies when orthogonal is
76  // true.
77 
78  const char *names[3]; // Specifies the names of the frame
79  // vector attributes that are being
80  // computed. names[0] points to the
81  // name of the tangent vector. names[1]
82  // points to the name of the bitangent
83  // vector. names[2] points to the name
84  // of the normal. names[0] and/or
85  // names[1] will be ignored if the
86  // corresponding bit in 'which' is not
87  // set.
88 
89  const char *uv_name; // Optionally overrides the texture
90  // attribute name used when style is
91  // GU_POLYFRAME_TEXTURE_COORDS
92 };
93 
94 class GA_PointGroup;
95 class GA_PrimitiveGroup;
96 class GEO_Hull;
97 class GEO_Face;
98 class GU_Detail;
99 class UT_BitArray;
100 class UT_String;
101 
103 {
104 public:
105  GU_PolyFrame(GU_Detail *gdp);
106  virtual ~GU_PolyFrame();
107 
108  GU_Detail *getDetail() const { return myGdp; }
109  void setDetail(GU_Detail *gdp) { myGdp = gdp; }
110 
111  // Computes the frame attributes specified in parms on the gdp supplied to
112  // the constructor or set via setDetail()
113  //
114  // If a point_group is given, this will still set default values for any
115  // newly created attributes (i.e. ones that didn't pre-exist on myGdp),
116  // on points that are not in point_group.
117  GU_PolyFrameError computeFrames(
118  const GU_PolyFrameParms &parms,
119  const GA_PointGroup *point_group = nullptr,
120  const GA_PrimitiveGroup *prim_group = nullptr);
121 
122  static GU_PolyFrameError computeFrames(
123  GA_AttributeUPtr &tangent,
124  GA_AttributeUPtr &bitangent,
125  GA_AttributeUPtr &normal,
126  const GU_Detail &gdp,
127  const GA_ROHandleV3 &Pattrib,
128  const GU_PolyFrameParms &parms,
129  const GA_PointGroup *point_group = nullptr,
130  const GA_PrimitiveGroup *prim_group = nullptr,
131  const GA_Attribute *existing_normal = nullptr);
132 
133  void setSaveAttribFlag(bool val) { storeAttribs = val; }
135  {
136  if (storeAttribs)
137  handle = myAttribs->normal();
138  }
140  {
141  if (storeAttribs)
142  handle = myAttribs->tangent();
143  }
145  {
146  if (storeAttribs)
147  handle = myAttribs->bitangent();
148  }
149 
150 private:
151  struct Frame
152  {
153  UT_Vector3 tangent;
154  UT_Vector3 bitangent;
155  UT_Vector3 normal;
156 
157  const UT_Vector3 &getVector(int i) const
158  {
159  UT_ASSERT(i >= 0 && i <= 2);
160 
161  if (i == 0)
162  return tangent;
163  else if (i == 1)
164  return bitangent;
165  else
166  return normal;
167  }
168  };
169 
170  enum class NormalMethod
171  {
172  COMPATIBLE,
173  GEOCOMPUTENORMAL
174  };
175 
176  // Utility class for creating and passing around attributes.
177  //
178  // Holds ownership of any created detached attributes.
179  class FrameAttribHandles
180  {
181  public:
182  FrameAttribHandles() = default;
183 
184  const GA_RWHandleV3 &handle(int index) const
185  {
186  UT_ASSERT(index >= 0 && index < 3);
187  return myHandles[index];
188  }
189 
190  void findOrAddAttrib(
191  int index,
192  GU_Detail &gdp,
193  const UT_StringRef &name,
194  GA_AttributeOwner owner,
195  GA_TypeInfo type);
196 
197  bool createDetachedOutputAttrib(
198  const GU_Detail &gdp,
199  int index,
200  GA_AttributeOwner owner,
201  GA_AttributeUPtr &attrib);
202 
203  // Creates any temporary attributes required for computing the output
204  // attribs explicitly requested by the caller of computeFrames(). We
205  // take ownership of these attributes.
206  void createTempAttrib(
207  const GU_Detail &gdp,
208  int index,
209  GA_AttributeOwner owner);
210 
211  bool createdOnGdp(int index) const { return myCreatedOnDetail[index]; }
212 
213  const GA_RWHandleV3 &tangent() const { return myHandles[0]; }
214 
215  const GA_RWHandleV3 &bitangent() const { return myHandles[1]; }
216 
217  const GA_RWHandleV3 &normal() const { return myHandles[2]; }
218 
219  private:
220  GA_AttributeUPtr myTempAttribs[3];
221  GA_RWHandleV3 myHandles[3];
222  bool myCreatedOnDetail[3];
223  };
224 
225  static GU_PolyFrameError computeFrames(
226  const GU_Detail &gdp,
227  const GA_ROHandleV3 &Pattrib,
228  const GU_PolyFrameParms &parms,
229  const GA_PointGroup *point_group,
230  const GA_PrimitiveGroup *prim_group,
231  const GA_Attribute *existing_normal,
232  FrameAttribHandles &attribs,
233  NormalMethod normalmethod,
234  UT_BitArray *uncomputed);
235 
236  static void computeFrames(
237  const GU_Detail &gdp,
238  const GA_ROHandleV3 &pattrib,
239  const GU_PolyFrameParms &parms,
240  const GA_PointGroup *point_group,
241  const GA_PrimitiveGroup *prim_group,
242  const GEO_Face &prim,
243  UT_BitArray *uncomputed,
244  GA_Size &nleft,
245  bool pervertex,
246  const GA_ROHandleV2 &uv,
247  const FrameAttribHandles &attribs);
248 
249  // depending on parms, this creates output attributes on myGdp.
250  static bool createOutputAttribsOnDetail(
251  GU_Detail &gdp,
252  const GU_PolyFrameParms &parms,
253  FrameAttribHandles &attribs);
254 
255  static bool createDetachedOutputAttribs(
256  const GU_Detail &gdp,
257  const GU_PolyFrameParms &parms,
258  FrameAttribHandles &attribs,
259  GA_AttributeUPtr &tangent,
260  GA_AttributeUPtr &bitangent,
261  GA_AttributeUPtr &normal);
262 
263  // creates any temporary attributes which are not requested by
264  // parms but required for computing the specified parms.style of frame.
265  static bool createTempAttribs(
266  const GU_Detail &gdp,
267  const GU_PolyFrameParms &parms,
268  FrameAttribHandles &attribs);
269 
270  static const GA_ROHandleV2 getUVHandle(
271  const GU_Detail &gdp,
272  const UT_StringRef &uvname);
273 
274  static void setFrame(
275  const GU_Detail &gdp,
276  const GU_PolyFrameParms &parms,
277  const GA_PointGroup *point_group,
278  const FrameAttribHandles &attribs,
279  const GEO_Face *face,
280  GA_Index pointIndex,
281  GA_Size vertexIndex,
282  bool pervertex,
283  const Frame &frame);
284 
285  // Frame computation methods for each style in GU_PolyFrameStyle.
286  static Frame computeFirstEdgeFrame(
287  const GU_Detail &gdp,
288  const GA_ROHandleV3 &Pattrib,
289  const GEO_Face &prim,
290  GA_Index pointIndex,
291  GA_Size vtx,
292  const GA_ROHandleV3 &normal);
293  static Frame computeTwoEdgesFrame(
294  const GU_Detail &gdp,
295  const GA_ROHandleV3 &Pattrib,
296  const GEO_Face &prim,
297  GA_Index pt,
298  GA_Size vtx,
299  const GA_ROHandleV3 &normal);
300  static Frame computeCentroidFrame(
301  const GU_Detail &gdp,
302  const GA_ROHandleV3 &Pattrib,
303  const GEO_Face &prim,
304  GA_Index pt,
305  GA_Size vtx,
306  const UT_Vector3 &centroid,
307  const GA_ROHandleV3 &normal);
308  static Frame computeTexCoordsFrame(
309  const GU_Detail &gdp,
310  const GA_ROHandleV3 &Pattrib,
311  const GEO_Face &prim,
312  GA_Index pt,
313  GA_Size vtx,
314  const GA_ROHandleV2 &uv,
315  const GA_ROHandleV3 &normal);
316  static void computeTexFramePrim(
317  const GU_Detail &gdp,
318  const GA_ROHandleV3 &Pattrib,
319  GA_Offset primoff,
320  const GA_ROHandleV2 &uv,
321  const FrameAttribHandles &attribs);
322  static void computeTexFrameSoup(
323  const GU_Detail &gdp,
324  const GA_ROHandleV3 &Pattrib,
325  GA_Offset primoff,
327  const GA_ROHandleV2 &uv,
328  const FrameAttribHandles &attribs);
329  static Frame computeTexFrame(
330  const GU_Detail &gdp,
331  const GA_ROHandleV3 &Pattrib,
332  GA_Index pt,
333  const FrameAttribHandles &attribs);
334  static GU_PolyFrame::Frame computeDefaultFrame(
335  const GEO_Face *prim = nullptr);
336  static GU_PolyFrame::Frame computeDefaultFrame(
337  const GEO_PrimPolySoup::PolygonIterator *it = nullptr);
338 
339  // Utility methods.
340  static void computeMeshCentroid(
341  const GEO_Hull *hull,
342  const GA_ROHandleV3 &Pattrib,
343  GA_Size vertex_no,
344  UT_Vector3 &centroid);
345  static void createPointNormals(
346  const GU_Detail &gdp,
347  const GA_ROHandleV3 &Pattrib,
348  const GA_RWHandleV3 &offset,
349  const GA_Attribute *normalattrbefore,
350  const NormalMethod normalmethod);
351  static const char *getLayeredAttribName(
352  const GU_Detail *gdp,
353  const char *name);
354  static bool isStylePerVertex(GU_PolyFrameStyle style);
355  static void makeOrthogonal(Frame &frame, bool left_handed);
356 
357  static int theMinVertices[];
358 
359  GU_Detail *myGdp;
360 
361  // // Introduced to compare values for unit tests
362  bool storeAttribs;
364 };
365 
366 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
void getAttribNormals(GA_RWHandleV3 &handle)
Definition: GU_PolyFrame.h:134
GA_API const UT_StringHolder uv
void getAttribTangents(GA_RWHandleV3 &handle)
Definition: GU_PolyFrame.h:139
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:236
GA_Size GA_Offset
Definition: GA_Types.h:646
GLintptr offset
Definition: glcorearb.h:665
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
GU_PolyFrameStyle
Definition: GU_PolyFrame.h:23
void getAttribBitangents(GA_RWHandleV3 &handle)
Definition: GU_PolyFrame.h:144
const char * uv_name
Definition: GU_PolyFrame.h:89
#define GU_API
Definition: GU_API.h:14
GLuint const GLchar * name
Definition: glcorearb.h:786
GU_PolyFrameVector
Definition: GU_PolyFrame.h:33
void setSaveAttribFlag(bool val)
Definition: GU_PolyFrame.h:133
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:640
GU_Detail * getDetail() const
Definition: GU_PolyFrame.h:108
GA_TypeInfo
Definition: GA_Types.h:101
UT_UniquePtr< GA_Attribute > GA_AttributeUPtr
Definition: GA_Attribute.h:930
GU_PolyFrameError
Definition: GU_PolyFrame.h:40
GA_AttributeOwner
Definition: GA_Types.h:35
GLuint index
Definition: glcorearb.h:786
GU_PolyFrameStyle style
Definition: GU_PolyFrame.h:62
GLuint GLfloat * val
Definition: glcorearb.h:1608
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
type
Definition: core.h:1059
void setDetail(GU_Detail *gdp)
Definition: GU_PolyFrame.h:109