HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_AgentSupport.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: GT_AgentSupport.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  * Support classes for crowd agents:
10  *
11  * GT_AgentIndexMap - mapping of agent primitive GA index to per-rig index
12  * GT_AgentVisibility - list of LOD/visible per agent
13  * GT_AgentTransforms - agent packed primitive transform list
14  * GT_AgentRigTransforms - lists of rig transforms, one per agent
15  * GT_ShapeLODGroup - data common to LOD levels of a shape
16  */
17 #ifndef _GT_AgentSupport_h_
18 #define _GT_AgentSupport_h_
19 
20 #include "GT_API.h"
21 
22 #include "GT_DataArray.h"
23 
24 #include <UT/UT_EnumHelper.h>
25 #include <UT/UT_IntArray.h>
26 #include <UT/UT_IntrusivePtr.h>
27 #include <UT/UT_Matrix4.h>
28 #include <UT/UT_NonCopyable.h>
29 #include <UT/UT_SharedPtr.h>
30 #include <UT/UT_UniquePtr.h>
31 #include <UT/UT_VectorTypes.h>
32 
33 #include <SYS/SYS_AtomicInt.h>
34 #include <SYS/SYS_Types.h>
35 
38 
39 class RV_VKBuffer;
40 class RE_VertexArray;
41 class GU_PrimPacked;
42 
43 class GT_AgentIndexMap;
44 class GT_AgentVisibility;
46 class GT_AgentTransforms;
47 class GT_AgentSelection;
48 class GT_AgentID;
49 class GT_AgentColors;
52 
62 
63 /// Index of a shape binding in one of the agent's current layers.
65 {
66  GT_AgentShapeBindingID(int layer_idx, int shape_idx)
67  : myLayerIdx(layer_idx), myBindingIdx(shape_idx)
68  {
69  }
70 
73 };
75 
77 {
78 public:
79  GT_VulkanAgentData();
80  virtual ~GT_VulkanAgentData();
81 
82  UT_NON_COPYABLE(GT_VulkanAgentData);
83 };
84 
85 
86 /// Mapping from GA_Index to per-rig agent index
88  : public UT_IntrusiveRefCounter<GT_AgentIndexMap>
89 {
90 public:
91  void clear() { myIndexMap.clear(); }
92 
93  exint entries() const { return myIndexMap.entries(); }
95  {
96  myIndexMap.setSize(size);
97  }
98 
99  // returns the index within the rig given the agent prim's GA index.
100  int getAgentIndex(exint ga_index) const
101  { return myIndexMap(ga_index); }
102 
103  void setAgentIndex(int ga_index, int agent_index)
104  { myIndexMap[ga_index] = agent_index; }
105 
106 private:
107  UT_IntArray myIndexMap;
108 };
109 
110 
111 /// Visibility and LOD class for agents.
113  : public UT_IntrusiveRefCounter<GT_AgentVisibility>
114 {
115 public:
116  void setEntries(exint entries) { myVisibility.entries(entries); }
117  exint entries() const { return myVisibility.entries(); }
118 
119  void setVisibility(exint idx, bool visible, fpreal lod = 1.0)
120  { myVisibility(idx) = visible ? lod : 0.0; }
121 
122  bool getVisibility(exint idx) const
123  { return myVisibility(idx) != 0.0f; }
124 
125  bool getLOD(exint idx, fpreal32 &lod) const
126  {
127  lod = myVisibility(idx);
128  return (lod < 0.0f);
129  }
130 
131  void allVisible() { myVisibility.constant(1.0); }
132 private:
133  UT_FloatArray myVisibility;
134 };
135 
136 /// Transform lists for rigs, one per agent
138  : public UT_IntrusiveRefCounter<GT_AgentRigTransforms>
139 {
140 public:
141  GT_AgentRigTransforms(exint num_xforms, exint num_channels)
142  : myNumTransforms(num_xforms), myNumChannels(num_channels)
143  {
144  }
145 
148 
149  void setEntries(exint entries)
150  {
151  myTransforms.entries(entries);
152  myChannelValues.entries(entries);
153  mySerial.entries(entries);
154  }
155 
157  { return myTransforms(agent_idx); }
158 
159  const UT_Array<UT_Matrix4F> &transforms(exint agent_idx) const
160  { return *myTransforms(agent_idx); }
161 
163  { return myChannelValues[agent_idx]; }
164 
165  const UT_Array<fpreal32> &channelValues(exint agent_idx) const
166  { return *myChannelValues(agent_idx); }
167 
168  int getSerial(exint agent_idx) { return mySerial(agent_idx); }
169  void setSerial(exint agent_idx, int serial)
170  { mySerial(agent_idx) = serial; }
171 
172  /// The number of transforms in the agents' rig.
174  {
175  return myNumTransforms;
176  }
177 
178  /// The number of channel values in the agents' rig.
180  {
181  return myNumChannels;
182  }
183 
184 private:
185  UT_Array<Matrix4ArrayConstPtr> myTransforms;
186  UT_Array<FloatArrayConstPtr> myChannelValues;
187  UT_IntArray mySerial;
188  exint myNumTransforms = 0;
189  exint myNumChannels = 0;
190 };
191 
192 
193 /// Transforms for each entire agent
195  : public UT_IntrusiveRefCounter<GT_AgentTransforms>
196 {
197 public:
198  void setEntries(exint entries) { myTransforms.entries(entries); }
199 
201  { return myTransforms(agent_idx); }
202 
203  const UT_Matrix4F &agentTransform(exint agent_idx) const
204  { return myTransforms(agent_idx); }
205 private:
206  UT_Matrix4FArray myTransforms;
207 };
208 
209 /// Contains a bool array of selected agents.
211  : public UT_IntrusiveRefCounter<GT_AgentSelection>
212 {
213 public:
214  GT_AgentSelection() : mySelectState(0) {}
215 
216  void setEntries(exint entries) { mySelection.entries(entries); }
217 
218  void clear() { mySelection.zero(); mySelectState = 0; }
219  void allSelected() { mySelection.constant(1); mySelectState = 1; }
220  void partiallySelected() { mySelectState = -1; }
221 
222  void setSelected(exint idx, bool selected)
223  { mySelection(idx) = selected?1:0; }
224 
225  bool isSelected(exint idx) const
226  { return mySelection(idx)==1; }
227 
228  // Usage of these methods depends upon clear, allSelected, or
229  // partiallySelection() being called appropriately.
230  bool isFullySelected() const { return (mySelectState == 1); }
231  bool isNothingSelected() const { return (mySelectState == 0); }
232  bool isPartiallySelected() const { return (mySelectState == -1); }
233 
234 private:
235  UT_IntArray mySelection;
236  int mySelectState;
237 };
238 
239 /// Contains IDs for each agent
241  : public UT_IntrusiveRefCounter<GT_AgentID>
242 {
243 public:
244  void setEntries(exint entries) { myIDs.entries(entries); }
245  void setID(exint idx, int id) { myIDs(idx) = id; }
246  int getID(exint idx) const { return myIDs(idx); }
247 
248  const UT_IntArray &getIDs() const { return myIDs; }
249  void fetchIDs(int *id_array) const
250  { memcpy(id_array, myIDs.array(), myIDs.entries()*sizeof(int));}
251 private:
252  UT_IntArray myIDs;
253 };
254 
255 /// Rig-specific data for a shape, such as mapping from the capture attribute's
256 /// regions to the rig's transforms.
258  : public UT_IntrusiveRefCounter<GT_AgentShapeRigInfo>
259 {
260 public:
261  /// Map from the region index to agent rig index.
263  /// Inverse rest transform for each region.
265  /// Cache of blendshape targets and the rig channel associated with each
266  /// primary target shape.
268  /// Cached data for evaluating the ML deformer for the shape.
270  /// Any error messages from initializing the ML deformer.
272 };
273 
274 /// Contains colors for each agent
276  : public UT_IntrusiveRefCounter<GT_AgentColors>
277 {
278 public:
279  void setColors(const GT_DataArrayHandle &colors, GT_Owner owner,
280  exint num_agents)
281  {
282  if (colors)
283  {
284  // Note the color is vec3 but padded to vec4 because TBOs
285  // only support 1,2 or 4 components with non-32b components.
286  // The fill below compensates for this.
287  myColors.setSizeNoInit(num_agents * 4);
288 
289  if (owner == GT_OWNER_DETAIL)
290  {
291  // For now, just fill an array with the constant color instead
292  // of adding extra optimizations for detail Cd.
293  colors->extendedFillArray(myColors.data(), 0, 1, 3, num_agents,
294  4);
295  }
296  else
297  colors->fillArray(myColors.data(), 0, num_agents, 3, 4);
298  }
299  else
300  myColors.clear();
301  }
302 
303  bool hasColor() const { return !myColors.isEmpty(); }
304 
305  /// Fetch the (4 uint8) color for an agent.
306  void fetchColor(exint agent_idx, uint8 *data) const
307  {
308  memcpy(data, myColors.data() + 4 * agent_idx, 4 * sizeof(uint8));
309  }
310 
311 private:
312  UT_Array<uint8> myColors;
313 };
314 
315 /// Flags for the supported viewport deformation types (blendshapes and/or
316 /// linear skinning).
318 {
319  None = 0,
320  BlendShapes = 1,
321  LinearSkinning = 2,
322  // Note ML deform also expects blendshapes & skinning to be enabled.
323  MLSkinDeform = 4,
324 };
325 
327 
328 /// Data common to all levels-of-detail for a series of GT_PrimAgentShapes
331 {
332 public:
333  GT_ShapeLODGroup(const GT_AgentTransformsHandle &th,
334  const GT_AgentRigTransformsHandle &rh,
335  const GT_AgentVisibilityHandle &vis,
336  const GT_AgentIndexMapHandle &map,
338  const GT_AgentIDHandle &ids,
339  const GT_AgentColorsHandle &colors,
340  int shape_id,
341  GT_AgentDeformFlags deform_flags);
342 
343  ~GT_ShapeLODGroup();
344 
345  void setRigInfo(const GT_AgentShapeRigInfoHandle &rig_info);
346 
347  bool isDeforming() const
348  {
349  return myDeformFlags != GT_AgentDeformFlags::None;
350  }
351  bool hasSkinning() const
352  {
353  return (myDeformFlags & GT_AgentDeformFlags::LinearSkinning)
355  }
356  bool hasBlendShapes() const
357  {
358  return (myDeformFlags & GT_AgentDeformFlags::BlendShapes)
360  }
361  bool hasMLSkinDeform() const
362  {
363  return (myDeformFlags & GT_AgentDeformFlags::MLSkinDeform)
365  }
366 
367  GT_AgentDeformFlags deformFlags() const { return myDeformFlags; }
368 
376 
381 
387  GT_VulkanAgentData *myVulkanData = nullptr;
389 
394 
395  // this data is temporary, only valid during agent collection/refinement.
399 };
400 
401 
402 #endif
Mapping from GA_Index to per-rig agent index.
void setEntries(exint entries)
Visibility and LOD class for agents.
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
void setAgentIndex(int ga_index, int agent_index)
exint numTransforms() const
The number of transforms in the agents' rig.
void setEntries(exint entries)
Contains IDs for each agent.
bool isFullySelected() const
void setEntries(exint entries)
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:632
bool isSelected(exint idx) const
GT_AgentIDHandle myAgentPrimID
GT_AgentShapeBindingID(int layer_idx, int shape_idx)
Contains colors for each agent.
UT_Array< const GU_PrimPacked * > myAgents
UT_Array< RE_VertexArray * > * myRigTransformVA
bool hasSkinning() const
bool isDeforming() const
UT_Matrix4FArray myInvRestTransforms
Inverse rest transform for each region.
#define GT_API
Definition: GT_API.h:13
int64 exint
Definition: SYS_Types.h:125
GT_AgentDeformFlags
bool getLOD(exint idx, fpreal32 &lod) const
UT_StringHolder myMLDeformInitErrors
Any error messages from initializing the ML deformer.
exint entries() const
void setEntries(exint entries)
Data common to all levels-of-detail for a series of GT_PrimAgentShapes.
A reference counter base class for use with UT_IntrusivePtr.
float fpreal32
Definition: SYS_Types.h:200
UT_IntrusivePtr< GT_ShapeLODGroup > GT_ShapeLODGroupHandle
void setSelected(exint idx, bool selected)
UT_Array< RE_VertexArray * > * myPrimIDVA
UT_IntrusivePtr< GT_AgentColors > GT_AgentColorsHandle
GT_AgentRigTransforms(exint num_xforms, exint num_channels)
GU_AgentBlendShapeUtils::InputCache myBlendShapeInputs
void fetchColor(exint agent_idx, uint8 *data) const
Fetch the (4 uint8) color for an agent.
int getID(exint idx) const
void setEntries(exint entries)
GT_AgentColorsHandle myAgentColors
unsigned char uint8
Definition: SYS_Types.h:36
UT_Array< GT_AgentShapeBindingID > myBindings
const UT_Matrix4F & agentTransform(exint agent_idx) const
GLfloat f
Definition: glcorearb.h:1926
void fetchIDs(int *id_array) const
vint4 select(const vbool4 &mask, const vint4 &a, const vint4 &b)
Definition: simd.h:4983
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
Matrix4ArrayConstPtr & transformsPtr(exint agent_idx)
bool hasMLSkinDeform() const
GT_AgentSelectionHandle myAgentSelection
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
bool hasBlendShapes() const
#define SYS_DECLARE_IS_POD(T)
Declare a type as POD.
void setColors(const GT_DataArrayHandle &colors, GT_Owner owner, exint num_agents)
GT_AgentDeformFlags deformFlags() const
GLuint id
Definition: glcorearb.h:655
const UT_Array< fpreal32 > & channelValues(exint agent_idx) const
int getSerial(exint agent_idx)
GU_AgentMLSkinDeformerShapeCache myMLDeformCache
Cached data for evaluating the ML deformer for the shape.
bool hasColor() const
GT_AgentShapeRigInfoHandle myRigInfo
UT_SharedPtr< const UT_Array< UT_Matrix4F >> Matrix4ArrayConstPtr
GT_AgentRigTransformsHandle myAgentRigTransforms
UT_ENABLE_ENUM_BIT_FLAGS(NET_IODeviceOpenMode)
bool isNothingSelected() const
const UT_Array< UT_Matrix4F > & transforms(exint agent_idx) const
UT_IntrusivePtr< GT_AgentVisibility > GT_AgentVisibilityHandle
GT_Owner
Definition: GT_Types.h:90
UT_IntArray myDeformMap
Map from the region index to agent rig index.
void setSerial(exint agent_idx, int serial)
GLsizeiptr size
Definition: glcorearb.h:664
GT_AgentTransformsHandle myAgentTransforms
void setEntries(exint size)
UT_Matrix4F & agentTransform(exint agent_idx)
GT_AgentVisibilityHandle myVisibility
FloatArrayConstPtr & channelValuesPtr(exint agent_idx)
UT_IntArray myTransforms
GT_AgentIndexMapHandle myAgentIndexMap
UT_IntrusivePtr< GT_AgentID > GT_AgentIDHandle
fpreal64 fpreal
Definition: SYS_Types.h:283
UT_Array< RE_VertexArray * > * myTransformVA
int getAgentIndex(exint ga_index) const
const UT_IntArray & getIDs() const
Transform lists for rigs, one per agent.
UT_Array< RE_VertexArray * > * mySelectionVA
UT_IntrusivePtr< GT_AgentIndexMap > GT_AgentIndexMapHandle
UT_IntrusivePtr< GT_AgentSelection > GT_AgentSelectionHandle
UT_Array< RE_VertexArray * > * myColorVA
bool isPartiallySelected() const
void setID(exint idx, int id)
Contains a bool array of selected agents.
void setVisibility(exint idx, bool visible, fpreal lod=1.0)
UT_IntrusivePtr< GT_AgentRigTransforms > GT_AgentRigTransformsHandle
bool getVisibility(exint idx) const
A vulkan buffer object.
Definition: RV_VKBuffer.h:75
exint entries() const
Index of a shape binding in one of the agent's current layers.
UT_SharedPtr< const UT_Array< fpreal32 >> FloatArrayConstPtr
GT_AgentDeformFlags myDeformFlags
GLuint * ids
Definition: glcorearb.h:652
UT_IntrusivePtr< GT_AgentShapeRigInfo > GT_AgentShapeRigInfoHandle
GLint lod
Definition: glcorearb.h:2765
UT_IntrusivePtr< GT_AgentTransforms > GT_AgentTransformsHandle
Definition: format.h:1821
exint numChannels() const
The number of channel values in the agents' rig.
Transforms for each entire agent.