HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_AgentMLSkinDeformer.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 
8 #ifndef __GU_AgentMLSkinDeformer__
9 #define __GU_AgentMLSkinDeformer__
10 
11 #include "GU_API.h"
12 
14 #include "GU_AgentShapeDeformer.h"
15 #include "GU_AgentShapeLib.h"
16 
17 #include <SYS/SYS_Types.h>
18 #include <UT/UT_BoundingBox.h>
19 #include <UT/UT_NonCopyable.h>
20 #include <UT/UT_Span.h>
21 #include <UT/UT_UniquePtr.h>
22 
23 /// Agent shape deformer used for ML-driven skin deformation.
25 {
26 public:
28  ~GU_AgentMLSkinDeformer() override;
29 
31 
32  void
33  deform(GU_Detail &gdp, const GU_AgentShapeLib::Shape &src_shape,
34  exint xform_idx, const GU_Agent &src_agent) const override;
35 
36  void
38  exint xform_idx, const GU_Agent &src_agent) const override;
39 
40 private:
41  GU_AgentBlendShapeDeformer myBlendShapeDeformer;
42 };
43 
44 /// Caches data from the agent's rig, etc which is required for evaluating
45 /// the ML skin deformer for a specific agent shape, and provides methods for
46 /// evaluating the blend shape weights for a batch of agents.
48 {
49 public:
53 
54  /// Pre-compute the required info for running the ML skin deformer on the
55  /// given shape.
56  bool init(
57  const GU_AgentShapeLib::Shape &agent_shape,
58  const GU_AgentDefinition &agent_defn,
59  UT_StringHolder &error_msg);
60 
61  /// Run the model for a batch of agents given their world space transforms.
62  /// Outputs a flat list of the blend shape weights for each agent, in the
63  /// order of the blendshape inputs for this agent shape (e.g. length is
64  /// num_agent * numBlendShapes()).
65  bool evaluate(
67  &agent_world_poses,
68  UT_Array<GU_Agent::FloatType> &agent_blend_shape_weights,
69  UT_StringHolder &error_msg) const;
70 
71  /// Marshal the blendshape weights into the rig's channel order, for a
72  /// single agent.
73  void setRigChannelValues(
74  UT_Span<GU_Agent::FloatType> rig_channel_values,
76 
77  /// Returns the number of blendshape inputs for the shape.
78  exint numBlendShapes() const;
79 
80 private:
81  class Impl;
82 
83  UT_UniquePtr<Impl> myImpl;
84 };
85 
86 /// Utility for baking the ML deformer's blendshape weights back to channel
87 /// values for a set of agents (which may have mixed agent definitions and/or
88 /// have multiple shapes using ML deformers).
89 /// This can be useful for e.g. baking the blendshape weights for export to
90 /// other file formats.
92 {
93 public:
94  /// If the agent has one or more shapes using the ML deformer, returns a
95  /// unique ID for retrieving its evaluated channel values. Otherwise,
96  /// returns -1.
97  exint addAgent(const GU_Agent *agent);
98 
99  /// Evaluate the blendshape weights for all of the registered agents.
100  bool evaluate(UT_StringHolder &error_msg);
101 
102  /// Return the rig channel values for the specified agent. This must be
103  /// called after evaluate().
104  UT_Span<const GU_Agent::FloatType> getChannelValues(
105  const GU_Agent *agent,
106  exint id) const;
107 
108 private:
109  struct AgentList
110  {
111  /// List of agents which share the same agent definition and use an ML
112  /// deformer.
114  /// Concatenated list of rig channel values for the agent instances.
115  UT_Array<GU_Agent::FloatType> myRigChannelValues;
116  /// Map from an ML-deforming shape to a list of indices in myAgents
117  /// which use the shape.
119  };
120 
121  /// Map from agent definitions to lists of agents which have ML deformers.
123 };
124 
125 #endif
CE_API bool evaluate(const CE_OSDRefinement &topo, const CE_OSDEvaluator &eval, const cl::Buffer &coarse, const CE_OSDPatchCoords &patch_coords, const CE_FloatArray *refined_data, cl::Buffer &out, cl::Buffer *du, cl::Buffer *dv)
Unsorted map container.
Definition: UT_Map.h:114
SIM_API const UT_StringHolder agent
int64 exint
Definition: SYS_Types.h:125
Agent shape deformer used for ML-driven skin deformation.
GT_API const UT_StringHolder blend_shape_weights
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
virtual void computeBounds(UT_BoundingBox &box, const GU_AgentShapeLib::Shape &src_shape, exint xform_idx, const GU_Agent &src_agent) const
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
Shape(GA_Offset offset)
#define GU_API
Definition: GU_API.h:14
virtual void deform(GU_Detail &gdp, const GU_AgentShapeLib::Shape &src_shape, exint xform_idx, const GU_Agent &src_agent) const =0
UT_NON_COPYABLE(GU_AgentShapeDeformer)
Defines a deformer for an agent shape.