HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_AgentBlendShapeUtils.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 
7 #ifndef __GU_AgentBlendShapeUtils__
8 #define __GU_AgentBlendShapeUtils__
9 
10 #include "GU_API.h"
11 
12 #include "GU_DetailHandle.h"
13 #include <UT/UT_StringArray.h>
14 #include <UT/UT_StringHolder.h>
15 
16 class GU_AgentRig;
17 class GU_AgentShapeLib;
18 
19 namespace GU_AgentBlendShapeUtils
20 {
21 /// Adds in-between shapes to a blendshape input (the primary shape).
22 /// This sets up the required detail attributes ("blendshape_shapenames" and
23 /// "blendshape_inbetweenweights") on the primary shape's geometry.
24 /// The shapes should be separately added to the shape library.
25 void GU_API addInBetweenShapes(GU_Detail &primary_shape_gdp,
26  const UT_StringArray &inbetween_shape_names,
27  const UT_Array<fpreal> &inbetween_weights);
28 
29 /// Adds blendshape inputs to a shape.
30 /// This sets up the required detail attributes ("blendshape_shapenames" and
31 /// "blendshape_channels") on the base shape's geometry.
32 /// The shapes should be separately added to the shape library.
33 void GU_API addInputsToBaseShape(GU_Detail &base_shape,
34  const UT_StringArray &shape_names,
35  const UT_StringArray &channel_names);
36 
37 /// Adds detail attributes to the base shape ("blendshape_ptidattr",
38 /// "blendshape_primidattr") for the blendshape deformer's optional parameters.
39 void GU_API setDeformerParameters(GU_Detail &base_shape,
40  const UT_StringHolder &attribs,
41  const UT_StringHolder &ptidattr,
42  const UT_StringHolder &primidattr);
43 
44 /// Reads the detail attributes for the blendshape deformer's optional
45 /// parameters.
46 /// If not specified, attribs is set to "P", ptidattr is set to "id", and
47 /// primidattr is set to "".
48 void GU_API getDeformerParameters(const GU_Detail &base_shape,
49  UT_StringHolder &attribs,
50  UT_StringHolder &ptidattr,
51  UT_StringHolder &primidattr);
52 
53 /// Removes the detail attributes added by addInputsToBaseShape() and
54 /// setDeformerParameters().
55 void GU_API clearInputShapes(GU_Detail &base_shape);
56 
57 /// Removes the detail attributes added by addInBetweenShapes().
58 void GU_API clearInBetweenShapes(GU_Detail &base_shape);
59 
62 
64 {
65 public:
66  /// Populates the cache. If the optional rig is not provided,
67  /// inputChannelIndex() will be invalid.
68  bool reset(
69  const GU_Detail &base_shape,
70  const GU_AgentShapeLib &shapelib,
71  const GU_AgentRig *rig);
72 
73  /// Returns the number of blendshape inputs (primary shapes).
74  exint numInputs() const { return myChannelIndices.entries(); }
75 
76  /// Returns the GU_AgentRig channel index for the specified input.
78  {
79  return myChannelIndices[i];
80  }
81 
82  /// Returns the name of the primary target shape for the specified input.
83  const UT_StringHolder &primaryShapeName(exint i) const;
84 
85  /// Returns the names and weights of the in-between target shapes for the
86  /// specified input (i.e. shapes with weight 0 or 1 are skipped).
87  void getInBetweenShapes(exint i, UT_StringArray &shape_names,
88  FloatArray &shape_weights) const;
89 
90  /// Appends to the provided list of shapes and weights, given an input
91  /// index and weight value. When there are in-between shapes this selects
92  /// the appropriate pair of shapes to blend between based on the provided
93  /// weight.
94  void getShapes(exint i, FloatType w, UT_Array<const GU_Detail *> &shapes,
95  FloatArray &weights) const;
96 
97  /// The total number of primary and in-between shapes.
98  exint numTargetShapes() const { return myNumTargets; }
99 
100  /// Returns a list of the geometry for the target shapes.
101  UT_Array<GU_ConstDetailHandle> targetShapes() const;
102 
103  /// Fill a buffer (of max length numTargetShapes()) with the index and
104  /// weight for each active target shape based on the provided rig channel
105  /// values. Returns the number of active target shapes.
106  int fillTargetShapeWeights(
107  const FloatType *channel_values,
108  std::pair<int32, fpreal32> *target_weights) const;
109 
110 private:
111  /// Returns the number of shapes for the specified input. If there are
112  /// in-between shapes this is >= 3, since there are implicit shapes with
113  /// weights 0 and 1, and otherwise 1 is returned.
114  inline exint numShapes(exint i) const
115  {
116  return myInputStarts[i + 1] - myInputStarts[i];
117  }
118 
119  void
120  addInput(exint channel_idx, const UT_Array<GU_ConstDetailHandle> &shapes,
121  const UT_StringArray &shape_names,
122  const FloatArray &shape_weights);
123 
124  /// Channel indices for GU_AgentRig.
125  UT_Array<exint> myChannelIndices;
126 
127  /// Index into myShapes, myShapeWeights, and myShapeNames for where the
128  /// shapes for each channel start.
129  /// The shapes for each input are ordered by weight.
130  UT_Array<exint> myInputStarts;
131 
133  FloatArray myShapeWeights;
134  UT_StringArray myShapeNames;
135 
136  /// Index between [0, myNumTargets) for the primary / in-between shapes.
137  /// The implicit null shapes have a value of -1.
138  UT_Array<exint> myTargetIds;
139  exint myNumTargets = 0;
140 };
141 
142 } // namespace GU_AgentBlendShapeUtils
143 
144 #endif
int64 exint
Definition: SYS_Types.h:125
float fpreal32
Definition: SYS_Types.h:200
void GU_API getDeformerParameters(const GU_Detail &base_shape, UT_StringHolder &attribs, UT_StringHolder &ptidattr, UT_StringHolder &primidattr)
exint inputChannelIndex(exint i) const
Returns the GU_AgentRig channel index for the specified input.
A rig for the agent primitive.
Definition: GU_AgentRig.h:38
GLboolean reset
Definition: glad.h:5138
void GU_API setDeformerParameters(GU_Detail &base_shape, const UT_StringHolder &attribs, const UT_StringHolder &ptidattr, const UT_StringHolder &primidattr)
void GU_API addInBetweenShapes(GU_Detail &primary_shape_gdp, const UT_StringArray &inbetween_shape_names, const UT_Array< fpreal > &inbetween_weights)
#define GU_API
Definition: GU_API.h:14
void GU_API clearInBetweenShapes(GU_Detail &base_shape)
Removes the detail attributes added by addInBetweenShapes().
UT_Array< FloatType > FloatArray
exint numInputs() const
Returns the number of blendshape inputs (primary shapes).
exint numTargetShapes() const
The total number of primary and in-between shapes.
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
void GU_API clearInputShapes(GU_Detail &base_shape)
void GU_API addInputsToBaseShape(GU_Detail &base_shape, const UT_StringArray &shape_names, const UT_StringArray &channel_names)