HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_Muscle.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_Muscle.h
7  *
8  * COMMENTS: Meta-ball based muscle deformer, used by SOP_Muscle
9  */
10 
11 #ifndef __GU_Muscle_h__
12 #define __GU_Muscle_h__
13 
14 #include "GU_API.h"
15 #include "GU_Detail.h"
16 #include <GA/GA_Handle.h>
17 
18 class GEO_PrimPoly;
19 class GU_PrimMetaball;
20 class GU_PrimSphere;
21 
22 // Default values for group names
23 #define DEFAULT_CENTER_GROUP "center"
24 
25 typedef fpreal gu_Cubic[4];
26 
28 {
31 };
32 
33 //-----------------------------------------------------------------------------
34 
36 {
37 public:
38 
40 
42 
43  // Parameters directly corresponding to those appearing in the UI:
44 
45  // Muscle Name
47 
48  // Muscle scale
49  fpreal fullscalex, fullscaley, fullscalez;
50 
51  // Control positions
52  fpreal pos2, pos3, pos4;
53 
54  // Control scales
55  fpreal sx1, sx2, sx3, sx4, sx5;
56  fpreal sy1, sy2, sy3, sy4, sy5;
57  fpreal sz1, sz2, sz3, sz4, sz5;
58 
59  // Primitives per segment
61 
62  // Muscle Type - Metaball Capture, Spheres Only
64 
65  // Center Line parameters
66  int basis;
68  int firstcv;
69  int lastcv;
70  float cvtension;
71 };
72 
73 //-----------------------------------------------------------------------------
74 
76 {
77 public:
78 
79  GU_Muscle();
81 
82  bool build(GU_MuscleParms &parms,
84  &inputXforms);
85 
86  GA_PointGroup *getCenterPoints() { return myCenterPoints; }
87  GA_PrimitiveGroup *getPrimitiveGroup() { return myPrimitives; }
88  int getNumPrimitives() { return myNumPrimitives; }
89 
90  bool getTranslates(
91  UT_Array<UT_Matrix4> &translates);
92 
93  bool getRotates(UT_Array<UT_Matrix4> &rotates);
94 
95  const GEO_PrimPoly *getCenterCurve();
96 
97 private:
98 
99  // Computes the a set of cubics for the left hand side of the
100  // profile curve.
101  static void calcLeftCurve(gu_Cubic &curve1,
102  gu_Cubic &curve2,
103  fpreal y1, fpreal y2, fpreal y3,
104  fpreal x2, fpreal x3);
105 
106  // Computes the set of cubics for the right hand side of the
107  // profile curve.
108  static void calcRightCurve(gu_Cubic &curve1,
109  gu_Cubic &curve2,
110  fpreal y3, fpreal y4, fpreal y5,
111  fpreal x3, fpreal x4);
112 
113  // Evaluates a profile curve using the given cubics and division information.
114  static inline fpreal evalProfile(fpreal t,
115  const gu_Cubic &curve1,
116  const gu_Cubic &curve2,
117  const gu_Cubic &curve3,
118  const gu_Cubic &curve4,
119  fpreal x2, fpreal x3, fpreal x4);
120 
121  // This function takes the existing centre line and uses it to
122  // construct a new centre line with points at the given positions
123  // along the curve. It is needed to make point distribution uniform.
124  GEO_PrimPoly *resampleCenterLine(const UT_FloatArray
125  &positions);
126 
127  // Adds primitives depending on the muscle type
128  void addPrimitives(int numPrimitives);
129 
130  // Sets up scale transforms using an array of scale values
131  void setupScaleXforms(const UT_Vector3Array
132  &scales);
133 
134  // Returns a list of muscle primitive positions (ie. u values 0 <= u <= 1)
135  // along the center line as well as three dimensional scale values for
136  // each muscle primitive.
137  bool getPrimitiveInfo( UT_FloatArray &positions,
138  UT_Vector3Array &scales,
139  bool controlPointsOnly=false);
140 
141 
142  // Transforms each muscle primitive to place it along the
143  // center line and orient it appropriately
144  void transformPrimitives(GEO_PrimPoly *guide);
145 
146  // Builds the center line for this muscle.
147  bool buildCenterLine(const UT_Array<UT_Matrix4>
148  &inputXforms);
149 
150  void CENTERGROUP(UT_String &str)
151  {
152  str = DEFAULT_CENTER_GROUP;
153  }
154 
155  // A function to be called by subdivide point groups, used to create
156  // polygons interpolating between our anchor points.
157  void addPoly(GA_PointGroup *group);
158 
159  // Adds metaball primitives (and a group to store them) if necessary.
160  void addMetaPrimitives(int numMeta);
161 
162  //Adds sphere primitives (and a group to store them) if necessary.
163  void addSpherePrimitives(int numSpheres);
164 
165  void getPrimitiveTranslates(GEO_PrimPoly *guide,
166  int numPrimitives,
167  UT_Array<UT_Matrix4> &translates);
168 
169 private:
170 
171  GU_MuscleParms *myParms;
172 
173  // Stores the centre curve for this muscle
174  GEO_PrimPoly *myCenterCurve;
175 
176  // Stores the centre curve points for this
177  // muscle
178  GA_PointGroup *myCenterPoints;
179 
180  // Stores the primitives (spheres or metaballs)
181  // currently used by this muscle
182  GA_PrimitiveGroup *myPrimitives;
183 
184  // Stores the number of primitives we are currently
185  // storing
186  int myNumPrimitives;
187 
188  // Since we never duplicate any input sources,
189  // we should be able to just store the normal
190  // offset
191  GA_RWHandleV3 myNormalAttrib;
192 
193  // Array used to cache the scale transforms for our metaballs
194  // so that we don't have to evaluate them unless the profile
195  // channels have actually changed
196  UT_Array<UT_Matrix4> myCachedScaleXforms;
197 
198  // Transforms that can be used by muscle handles
199  // to position/scale/orient themselves
200  UT_Array<UT_Matrix4> mySavedRotates;
201  UT_Array<UT_Matrix4> mySavedTranslates;
202 };
203 
204 
205 
206 #endif
int getNumPrimitives()
Definition: GU_Muscle.h:88
GA_PrimitiveGroup * getPrimitiveGroup()
Definition: GU_Muscle.h:87
GU_Detail * gdp
Definition: GU_Muscle.h:39
int primsPerSegment
Definition: GU_Muscle.h:60
fpreal fullscalez
Definition: GU_Muscle.h:49
GU_Detail * myExtraGdp
Definition: GU_Muscle.h:41
GLdouble GLdouble x2
Definition: glad.h:2349
fpreal sy5
Definition: GU_Muscle.h:56
fpreal sz5
Definition: GU_Muscle.h:57
fpreal gu_Cubic[4]
Definition: GU_Muscle.h:25
GU_MuscleType
Definition: GU_Muscle.h:27
fpreal pos4
Definition: GU_Muscle.h:52
GLdouble y1
Definition: glad.h:2349
#define GU_API
Definition: GU_API.h:14
float cvtension
Definition: GU_Muscle.h:70
GU_MuscleType type
Definition: GU_Muscle.h:63
GLdouble t
Definition: glad.h:2397
GA_PointGroup * getCenterPoints()
Definition: GU_Muscle.h:86
#define DEFAULT_CENTER_GROUP
Definition: GU_Muscle.h:23
fpreal64 fpreal
Definition: SYS_Types.h:277
~GU_Muscle()
Definition: GU_Muscle.h:80
GLdouble GLdouble GLdouble y2
Definition: glad.h:2349
fpreal sx5
Definition: GU_Muscle.h:55
UT_String name
Definition: GU_Muscle.h:46