HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GU_LinearSkinDeformer.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_LinearSkinDeformer.h (GU Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GU_LINEARSKINDEFORMER_H_INCLUDED__
12 #define __GU_LINEARSKINDEFORMER_H_INCLUDED__
13 
14 #include "GU_API.h"
16 #include <GA/GA_Range.h>
17 #include <UT/UT_Array.h>
18 #include <UT/UT_Matrix3.h>
19 #include <UT/UT_Matrix4.h>
20 #include <UT/UT_NonCopyable.h>
21 #include <UT/UT_Quaternion.h>
22 #include <UT/UT_UniquePtr.h>
23 #include <UT/UT_VectorTypes.h>
24 #include <SYS/SYS_TypeDecorate.h>
25 
26 #include <stddef.h>
27 
28 
29 class UT_TaskList;
30 class GA_Attribute;
31 class GA_ROAttributeRef;
33 class GU_Detail;
35 
36 
38 {
40  GU_CaptureElement(int i, float w) : myI(i), myW(w) { }
41 
42  bool operator>(const GU_CaptureElement& elem) const
43  {
44  return (myW > elem.myW);
45  }
46 
47  int myI;
48  float myW;
49 };
52 
53 
54 /// Class representing source data for GU_LinearSkinDeformer
56 {
57 public:
59 
60  int64 getMemoryUsage(bool inclusive) const;
61 
62  /// Reset all state
63  void reset();
64 
65  /// Setup the source geometry. Returns the number of transforms requireds
66  /// to deform using the capture weight attribute. If in error, then 0 is
67  /// returned.
68  /// If max_pt_weights > 0, then it will limit the number of weight entries
69  /// to use per point.
70  int init(
71  const GU_Detail& src,
72  const GA_Range& pt_range,
73  int max_pt_weights = 0);
74 
75  /// Append attribute to be deformed. How it is deformed depends on src's
76  /// GA_TypeInfo. initSrc() must have been called first.
77  void appendAttrib(
78  const GA_Attribute& src_attrib);
79 
80  const GU_Detail* srcGdp() const
81  { return myGdp; }
82  exint numPoints() const
83  { return myPointStarts.entries() > 0
84  ? myPointStarts.entries()-1 : 0; }
85 
86  /// Return the number of regions found by initSrc()
87  int numRegions() const
88  { return myRegionXforms.entries(); }
89 
90  /// Return the name given the region index. initSrc() must have been
91  /// called first.
92  const char* regionName(int i) const
93  { return myAttribCaptPath.getPath(i); }
94 
95  /// Static utility method to get capture parameters
96  static bool getCaptureParms(
97  const GU_Detail& src,
98  GA_ROAttributeRef& pcapt,
99  GEO_AttributeCapturePath& attr_cap_path,
100  UT_Array<UT_Matrix4F>& xforms,
101  int& max_pt_regions);
102 
103 private:
104  const GU_Detail* myGdp;
105  GEO_AttributeCapturePath myAttribCaptPath;
106  GA_OffsetArray myPointOffsets;
107  UT_ExintArray myPointStarts;
108  GU_CaptureElementArray myCaptureElements;
109 
110  UT_Array<UT_Matrix4F> myRegionXforms;
111 
112  UT_Array<const GA_Attribute*> myPosAttribs;
113  UT_Array<const GA_Attribute*> myVecAttribs;
114  UT_Array<const GA_Attribute*> myNmlAttribs;
115  UT_Array<const GA_Attribute*> myQuatAttribs;
116 
117  friend class GU_LinearSkinDeformer;
118 };
119 
120 
121 /// Performs linear blend skinning of geometry
123 {
124 public:
126 
127  /// Reset all state
128  void reset();
129 
130  /// Setup the destination geometry. Fails if the destination is missing
131  /// attributes that were appended to deform. A reference to the src is
132  /// maintained until reset() is called.
133  bool init(
134  GU_Detail& dst,
135  const GA_Range& pt_range,
137 
138  int numRegions() const
139  { return mySrc->myRegionXforms.entries(); }
140 
141  const char* regionName(int i) const
142  { return mySrc->regionName(i); }
143 
144  /// Set deforming transform for region_idx, which matches indices found in
145  /// the capture weight attribute. initSrc() must have been called first.
146  void setRegionTransform(
147  int region_idx,
148  const UT_Matrix4F& xform);
149 
150  /// Append UT_Tasks that will perform the deformation. The tasks will have
151  /// references to this object, so they must be executed before this object
152  /// is destroyed.
153  ///
154  /// The necessary steps in this specific order:
155  /// 1. N = GU_LinearSkinDeformerSource::init() for the point geometry you
156  /// want to deform
157  /// 2. GU_LinearSkinDeformerSource::appendAttrib() for each src attribute
158  /// you want to deform
159  /// 3. GU_LinearSkinDeformer::init() to set up where to put the results
160  /// 4. Call setRegionTransform() N times for each of the cregions
161  /// 5. Call appendDeformTasks()
162  /// 6. When done with the task list, spawn them: tasks.spawnRootAndWait();
163  ///
164  void appendDeformTasks(UT_TaskList& tasks);
165 
166  /// Do the deform.
167  ///
168  /// The necessary steps in this specific order:
169  /// 1. N = GU_LinearSkinDeformerSource::init() for the point geometry you
170  /// want to deform
171  /// 2. GU_LinearSkinDeformerSource::appendAttrib() for each src attribute
172  /// you want to deform
173  /// 3. GU_LinearSkinDeformer::init() to set up where to put the results
174  /// 4. Call setRegionTransform() N times for each of the cregions
175  /// 5. Call deform()
176  ///
177  void deform();
178 
180 
181 private:
182  void deformInParallel();
183 
184 private:
185  GU_Detail* myDstGdp;
186  GA_Range myDstRange;
187  UT_Array<GA_Attribute*> myDstPosAttribs;
188  UT_Array<GA_Attribute*> myDstVecAttribs;
189  UT_Array<GA_Attribute*> myDstNmlAttribs;
190  UT_Array<GA_Attribute*> myDstQuatAttribs;
191 
193  mySrc;
194 
195  AttribPtrArray mySrcPromotedAttribs;
196 
197  UT_Array<UT_Matrix4F> myPosXforms;
198  UT_Array<UT_Matrix3F> myNmlXforms;
199  UT_Array<UT_Quaternion> myQuatXforms;
200 
201  // This is only used when assertions are enabled
202  exint mySetupTransforms;
203 };
204 
205 #endif // __GU_LINEARSKINDEFORMER_H_INCLUDED__
Definition of a geometry attribute.
Definition: GA_Attribute.h:189
Performs linear blend skinning of geometry.
png_uint_32 i
Definition: png.h:2877
GU_CaptureElement(int i, float w)
A range of elements in an index-map.
Definition: GA_Range.h:42
long long int64
Definition: SYS_Types.h:100
const char * regionName(int i) const
Class representing source data for GU_LinearSkinDeformer.
This class provides a way to manage a reference to an attribute permitting Read-Only access...
int64 exint
Definition: SYS_Types.h:109
bool operator>(const GU_CaptureElement &elem) const
#define SYS_DECLARE_IS_POD(T)
Declare a type as POD.
#define GU_API
Definition: GU_API.h:11
const GU_Detail * srcGdp() const
GLenum GLenum dst
Definition: glcorearb.h:1792
int numRegions() const
Return the number of regions found by initSrc()
const char * regionName(int i) const
UT_Array< UT_UniquePtr< GA_Attribute > > AttribPtrArray
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
GLenum src
Definition: glcorearb.h:1792