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  UT_StringHolder *warnings = nullptr);
73 
74  /// Returns the number of blendshape inputs (primary shapes).
75  exint numInputs() const { return myChannelIndices.entries(); }
76 
77  /// Returns the GU_AgentRig channel index for the specified input.
79  {
80  return myChannelIndices[i];
81  }
82 
83  /// Returns the name of the primary target shape for the specified input.
84  const UT_StringHolder &primaryShapeName(exint i) const;
85 
86  /// Returns the names and weights of the in-between target shapes for the
87  /// specified input (i.e. shapes with weight 0 or 1 are skipped).
88  void getInBetweenShapes(exint i, UT_StringArray &shape_names,
89  FloatArray &shape_weights) const;
90 
91  /// Appends to the provided list of shapes and weights, given an input
92  /// index and weight value. When there are in-between shapes this selects
93  /// the appropriate pair of shapes to blend between based on the provided
94  /// weight.
95  void getShapes(exint i, FloatType w, UT_Array<const GU_Detail *> &shapes,
96  FloatArray &weights) const;
97 
98  /// The total number of primary and in-between shapes.
99  exint numTargetShapes() const { return myNumTargets; }
100 
101  /// Returns a list of the geometry for the target shapes.
102  UT_Array<GU_ConstDetailHandle> targetShapes() const;
103 
104  /// Fill a buffer (of max length numTargetShapes()) with the index and
105  /// weight for each active target shape based on the provided rig channel
106  /// values. Returns the number of active target shapes.
107  int fillTargetShapeWeights(
108  const FloatType *channel_values,
109  std::pair<int32, fpreal32> *target_weights) const;
110 
111 private:
112  /// Returns the number of shapes for the specified input. If there are
113  /// in-between shapes this is >= 3, since there are implicit shapes with
114  /// weights 0 and 1, and otherwise 1 is returned.
115  inline exint numShapes(exint i) const
116  {
117  return myInputStarts[i + 1] - myInputStarts[i];
118  }
119 
120  void
121  addInput(exint channel_idx, const UT_Array<GU_ConstDetailHandle> &shapes,
122  const UT_StringArray &shape_names,
123  const FloatArray &shape_weights);
124 
125  /// Channel indices for GU_AgentRig.
126  UT_Array<exint> myChannelIndices;
127 
128  /// Index into myShapes, myShapeWeights, and myShapeNames for where the
129  /// shapes for each channel start.
130  /// The shapes for each input are ordered by weight.
131  UT_Array<exint> myInputStarts;
132 
134  FloatArray myShapeWeights;
135  UT_StringArray myShapeNames;
136 
137  /// Index between [0, myNumTargets) for the primary / in-between shapes.
138  /// The implicit null shapes have a value of -1.
139  UT_Array<exint> myTargetIds;
140  exint myNumTargets = 0;
141 };
142 
143 } // namespace GU_AgentBlendShapeUtils
144 
145 #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)