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