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 
37 
38 class RV_VKBuffer;
39 class RE_VertexArray;
40 class GU_PrimPacked;
41 
42 class GT_AgentIndexMap;
43 class GT_AgentVisibility;
45 class GT_AgentTransforms;
46 class GT_AgentSelection;
47 class GT_AgentID;
48 class GT_AgentColors;
51 
61 
62 /// Index of a shape binding in one of the agent's current layers.
64 {
65  GT_AgentShapeBindingID(int layer_idx, int shape_idx)
66  : myLayerIdx(layer_idx), myBindingIdx(shape_idx)
67  {
68  }
69 
72 };
74 
76 {
77 public:
78  GT_VulkanAgentData();
79  virtual ~GT_VulkanAgentData();
80 
81  UT_NON_COPYABLE(GT_VulkanAgentData);
82 };
83 
84 
85 /// Mapping from GA_Index to per-rig agent index
87  : public UT_IntrusiveRefCounter<GT_AgentIndexMap>
88 {
89 public:
90  void clear() { myIndexMap.clear(); }
91 
92  exint entries() const { return myIndexMap.entries(); }
94  {
95  myIndexMap.setSize(size);
96  }
97 
98  // returns the index within the rig given the agent prim's GA index.
99  int getAgentIndex(exint ga_index) const
100  { return myIndexMap(ga_index); }
101 
102  void setAgentIndex(int ga_index, int agent_index)
103  { myIndexMap[ga_index] = agent_index; }
104 
105 private:
106  UT_IntArray myIndexMap;
107 };
108 
109 
110 /// Visibility and LOD class for agents.
112  : public UT_IntrusiveRefCounter<GT_AgentVisibility>
113 {
114 public:
115  void setEntries(exint entries) { myVisibility.entries(entries); }
116  exint entries() const { return myVisibility.entries(); }
117 
118  void setVisibility(exint idx, bool visible, fpreal lod = 1.0)
119  { myVisibility(idx) = visible ? lod : 0.0; }
120 
121  bool getVisibility(exint idx) const
122  { return myVisibility(idx) != 0.0f; }
123 
124  bool getLOD(exint idx, fpreal32 &lod) const
125  {
126  lod = myVisibility(idx);
127  return (lod < 0.0f);
128  }
129 
130  void allVisible() { myVisibility.constant(1.0); }
131 private:
132  UT_FloatArray myVisibility;
133 };
134 
135 /// Transform lists for rigs, one per agent
137  : public UT_IntrusiveRefCounter<GT_AgentRigTransforms>
138 {
139 public:
142 
143  void setEntries(exint entries)
144  {
145  myTransforms.entries(entries);
146  myChannelValues.entries(entries);
147  mySerial.entries(entries);
148  }
149 
151  { return myTransforms(agent_idx); }
152 
153  const UT_Array<UT_Matrix4F> &transforms(exint agent_idx) const
154  { return *myTransforms(agent_idx); }
155 
157  { return myChannelValues[agent_idx]; }
158 
159  const UT_Array<fpreal32> &channelValues(exint agent_idx) const
160  { return *myChannelValues(agent_idx); }
161 
162  int getSerial(exint agent_idx) { return mySerial(agent_idx); }
163  void setSerial(exint agent_idx, int serial)
164  { mySerial(agent_idx) = serial; }
165 private:
166  UT_Array<Matrix4ArrayConstPtr> myTransforms;
167  UT_Array<FloatArrayConstPtr> myChannelValues;
168  UT_IntArray mySerial;
169 };
170 
171 
172 /// Transforms for each entire agent
174  : public UT_IntrusiveRefCounter<GT_AgentTransforms>
175 {
176 public:
177  void setEntries(exint entries) { myTransforms.entries(entries); }
178 
180  { return myTransforms(agent_idx); }
181 
182  const UT_Matrix4F &agentTransform(exint agent_idx) const
183  { return myTransforms(agent_idx); }
184 private:
185  UT_Matrix4FArray myTransforms;
186 };
187 
188 /// Contains a bool array of selected agents.
190  : public UT_IntrusiveRefCounter<GT_AgentSelection>
191 {
192 public:
193  GT_AgentSelection() : mySelectState(0) {}
194 
195  void setEntries(exint entries) { mySelection.entries(entries); }
196 
197  void clear() { mySelection.zero(); mySelectState = 0; }
198  void allSelected() { mySelection.constant(1); mySelectState = 1; }
199  void partiallySelected() { mySelectState = -1; }
200 
201  void setSelected(exint idx, bool selected)
202  { mySelection(idx) = selected?1:0; }
203 
204  bool isSelected(exint idx) const
205  { return mySelection(idx)==1; }
206 
207  // Usage of these methods depends upon clear, allSelected, or
208  // partiallySelection() being called appropriately.
209  bool isFullySelected() const { return (mySelectState == 1); }
210  bool isNothingSelected() const { return (mySelectState == 0); }
211  bool isPartiallySelected() const { return (mySelectState == -1); }
212 
213 private:
214  UT_IntArray mySelection;
215  int mySelectState;
216 };
217 
218 /// Contains IDs for each agent
220  : public UT_IntrusiveRefCounter<GT_AgentID>
221 {
222 public:
223  void setEntries(exint entries) { myIDs.entries(entries); }
224  void setID(exint idx, int id) { myIDs(idx) = id; }
225  int getID(exint idx) const { return myIDs(idx); }
226 
227  const UT_IntArray &getIDs() const { return myIDs; }
228  void fetchIDs(int *id_array) const
229  { memcpy(id_array, myIDs.array(), myIDs.entries()*sizeof(int));}
230 private:
231  UT_IntArray myIDs;
232 };
233 
234 /// Rig-specific data for a shape, such as mapping from the capture attribute's
235 /// regions to the rig's transforms.
237  : public UT_IntrusiveRefCounter<GT_AgentShapeRigInfo>
238 {
239 public:
240  /// Map from the region index to agent rig index.
242  /// Inverse rest transform for each region.
244  /// Cache of blendshape targets and the rig channel associated with each
245  /// primary target shape.
247 };
248 
249 /// Contains colors for each agent
251  : public UT_IntrusiveRefCounter<GT_AgentColors>
252 {
253 public:
254  void setColors(const GT_DataArrayHandle &colors, GT_Owner owner,
255  exint num_agents)
256  {
257  if (colors)
258  {
259  // Note the color is vec3 but padded to vec4 because TBOs
260  // only support 1,2 or 4 components with non-32b components.
261  // The fill below compensates for this.
262  myColors.setSizeNoInit(num_agents * 4);
263 
264  if (owner == GT_OWNER_DETAIL)
265  {
266  // For now, just fill an array with the constant color instead
267  // of adding extra optimizations for detail Cd.
268  colors->extendedFillArray(myColors.data(), 0, 1, 3, num_agents,
269  4);
270  }
271  else
272  colors->fillArray(myColors.data(), 0, num_agents, 3, 4);
273  }
274  else
275  myColors.clear();
276  }
277 
278  bool hasColor() const { return !myColors.isEmpty(); }
279 
280  /// Fetch the (4 uint8) color for an agent.
281  void fetchColor(exint agent_idx, uint8 *data) const
282  {
283  memcpy(data, myColors.data() + 4 * agent_idx, 4 * sizeof(uint8));
284  }
285 
286 private:
287  UT_Array<uint8> myColors;
288 };
289 
290 /// Flags for the supported viewport deformation types (blendshapes and/or
291 /// linear skinning).
293 {
294  None = 0,
295  BlendShapes = 1,
296  Skinning = 2,
297 };
298 
300 
301 /// Data common to all levels-of-detail for a series of GT_PrimAgentShapes
304 {
305 public:
306  GT_ShapeLODGroup(const GT_AgentTransformsHandle &th,
307  const GT_AgentRigTransformsHandle &rh,
308  const GT_AgentVisibilityHandle &vis,
309  const GT_AgentIndexMapHandle &map,
311  const GT_AgentIDHandle &ids,
312  const GT_AgentColorsHandle &colors,
313  int shape_id,
314  GT_AgentDeformFlags deform_flags);
315 
316  ~GT_ShapeLODGroup();
317 
318  void setRigInfo(const GT_AgentShapeRigInfoHandle &rig_info);
319 
320  bool isDeforming() const
321  {
322  return myDeformFlags != GT_AgentDeformFlags::None;
323  }
324  bool hasSkinning() const
325  {
326  return (myDeformFlags & GT_AgentDeformFlags::Skinning)
328  }
329  bool hasBlendShapes() const
330  {
331  return (myDeformFlags & GT_AgentDeformFlags::BlendShapes)
333  }
334 
335  GT_AgentDeformFlags deformFlags() const { return myDeformFlags; }
336 
337 public:
345 
350 
356  GT_VulkanAgentData *myVulkanData = nullptr;
358 
363 
364  // this data is temporary, only valid during agent collection/refinement.
368 };
369 
370 
371 #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)
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
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
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)
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)
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:278
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:81
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
Transforms for each entire agent.