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