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