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 };
79 
80 
81 /// Mapping from GA_Index to per-rig agent index
83  : public UT_IntrusiveRefCounter<GT_AgentIndexMap>
84 {
85 public:
86  void clear() { myIndexMap.entries(0); }
87  exint entries() const { return myIndexMap.entries(); }
88 
89  // returns the index within the rig given the agent prim's GA index.
90  int getAgentIndex(exint ga_index) const
91  { return myIndexMap(ga_index); }
92 
93  void setAgentIndex(int ga_index, int agent_index);
94 
95 private:
96  UT_IntArray myIndexMap;
97 };
98 
99 
100 /// Visibility and LOD class for agents.
102  : public UT_IntrusiveRefCounter<GT_AgentVisibility>
103 {
104 public:
105  void setEntries(exint entries) { myVisibility.entries(entries); }
106  exint entries() const { return myVisibility.entries(); }
107 
108  void setVisibility(exint idx, bool visible, fpreal lod = 1.0)
109  { myVisibility(idx) = visible ? lod : 0.0; }
110 
111  bool getVisibility(exint idx) const
112  { return myVisibility(idx) != 0.0f; }
113 
114  bool getLOD(exint idx, fpreal32 &lod) const
115  {
116  lod = myVisibility(idx);
117  return (lod < 0.0f);
118  }
119 
120  void allVisible() { myVisibility.constant(1.0); }
121 private:
122  UT_FloatArray myVisibility;
123 };
124 
125 /// Transform lists for rigs, one per agent
127  : public UT_IntrusiveRefCounter<GT_AgentRigTransforms>
128 {
129 public:
132 
133  void setEntries(exint entries)
134  {
135  myTransforms.entries(entries);
136  myChannelValues.entries(entries);
137  mySerial.entries(entries);
138  }
139 
141  { return myTransforms(agent_idx); }
142 
143  const UT_Array<UT_Matrix4F> &transforms(exint agent_idx) const
144  { return *myTransforms(agent_idx); }
145 
147  { return myChannelValues[agent_idx]; }
148 
149  const UT_Array<fpreal32> &channelValues(exint agent_idx) const
150  { return *myChannelValues(agent_idx); }
151 
152  int getSerial(exint agent_idx) { return mySerial(agent_idx); }
153  void setSerial(exint agent_idx, int serial)
154  { mySerial(agent_idx) = serial; }
155 private:
156  UT_Array<Matrix4ArrayConstPtr> myTransforms;
157  UT_Array<FloatArrayConstPtr> myChannelValues;
158  UT_IntArray mySerial;
159 };
160 
161 
162 /// Transforms for each entire agent
164  : public UT_IntrusiveRefCounter<GT_AgentTransforms>
165 {
166 public:
167  void setEntries(exint entries) { myTransforms.entries(entries); }
168 
170  { return myTransforms(agent_idx); }
171 
172  const UT_Matrix4F &agentTransform(exint agent_idx) const
173  { return myTransforms(agent_idx); }
174 private:
175  UT_Matrix4FArray myTransforms;
176 };
177 
178 /// Contains a bool array of selected agents.
180  : public UT_IntrusiveRefCounter<GT_AgentSelection>
181 {
182 public:
183  GT_AgentSelection() : mySelectState(0) {}
184 
185  void setEntries(exint entries) { mySelection.entries(entries); }
186 
187  void clear() { mySelection.zero(); mySelectState = 0; }
188  void allSelected() { mySelection.constant(1); mySelectState = 1; }
189  void partiallySelected() { mySelectState = -1; }
190 
191  void setSelected(exint idx, bool selected)
192  { mySelection(idx) = selected?1:0; }
193 
194  bool isSelected(exint idx) const
195  { return mySelection(idx)==1; }
196 
197  // Usage of these methods depends upon clear, allSelected, or
198  // partiallySelection() being called appropriately.
199  bool isFullySelected() const { return (mySelectState == 1); }
200  bool isNothingSelected() const { return (mySelectState == 0); }
201  bool isPartiallySelected() const { return (mySelectState == -1); }
202 
203 private:
204  UT_IntArray mySelection;
205  int mySelectState;
206 };
207 
208 /// Contains IDs for each agent
210  : public UT_IntrusiveRefCounter<GT_AgentID>
211 {
212 public:
213  void setEntries(exint entries) { myIDs.entries(entries); }
214  void setID(exint idx, int id) { myIDs(idx) = id; }
215  int getID(exint idx) const { return myIDs(idx); }
216 
217  const UT_IntArray &getIDs() const { return myIDs; }
218  void fetchIDs(int *id_array) const
219  { memcpy(id_array, myIDs.array(), myIDs.entries()*sizeof(int));}
220 private:
221  UT_IntArray myIDs;
222 };
223 
224 /// Rig-specific data for a shape, such as mapping from the capture attribute's
225 /// regions to the rig's transforms.
227  : public UT_IntrusiveRefCounter<GT_AgentShapeRigInfo>
228 {
229 public:
230  /// Map from region index to agent rig index.
232  /// Inverse rest transform for each region.
234  /// Cache of blendshape targets and the rig channel associated with each
235  /// primary target shape.
237 };
238 
239 /// Contains colors for each agent
241  : public UT_IntrusiveRefCounter<GT_AgentColors>
242 {
243 public:
244  void setColors(const GT_DataArrayHandle &colors, GT_Owner owner,
245  exint num_agents)
246  {
247  if (colors)
248  {
249  // Note the color is vec3 but padded to vec4 because TBOs
250  // only support 1,2 or 4 components with non-32b components.
251  // The fill below compensates for this.
252  myColors.setSizeNoInit(num_agents * 4);
253 
254  if (owner == GT_OWNER_DETAIL)
255  {
256  // For now, just fill an array with the constant color instead
257  // of adding extra optimizations for detail Cd.
258  colors->extendedFillArray(myColors.data(), 0, 1, 3, num_agents,
259  4);
260  }
261  else
262  colors->fillArray(myColors.data(), 0, num_agents, 3, 4);
263  }
264  else
265  myColors.clear();
266  }
267 
268  bool hasColor() const { return !myColors.isEmpty(); }
269 
270  /// Fetch the (4 uint8) color for an agent.
271  void fetchColor(exint agent_idx, uint8 *data) const
272  {
273  memcpy(data, myColors.data() + 4 * agent_idx, 4 * sizeof(uint8));
274  }
275 
276 private:
277  UT_Array<uint8> myColors;
278 };
279 
280 /// Flags for the supported viewport deformation types (blendshapes and/or
281 /// linear skinning).
282 namespace GT_AgentDeformFlags
283 {
284  static constexpr uint None = 0;
285  static constexpr uint BlendShapes = 1;
286  static constexpr uint Skinning = 2;
287 };
288 
289 /// Data common to all levels-of-detail for a series of GT_PrimAgentShapes
291  : public UT_IntrusiveRefCounter<GT_ShapeLODGroup>
292 {
293 public:
295  const GT_AgentRigTransformsHandle &rh,
296  const GT_AgentVisibilityHandle &vis,
297  const GT_AgentIndexMapHandle &map,
299  const GT_AgentIDHandle &ids,
300  const GT_AgentColorsHandle &colors,
301  int shape_id,
302  uint deform_flags);
303 
304  ~GT_ShapeLODGroup();
305 
306  void setRigInfo(const GT_AgentShapeRigInfoHandle &rig_info);
307 
308  bool isDeforming() const
309  {
310  return myDeformFlags != GT_AgentDeformFlags::None;
311  }
312  bool hasSkinning() const
313  {
314  return myDeformFlags & GT_AgentDeformFlags::Skinning;
315  }
316  bool hasBlendShapes() const
317  {
318  return myDeformFlags & GT_AgentDeformFlags::BlendShapes;
319  }
320 
321 public:
329 
334 
342 
347 
348  // this data is temporary, only valid during agent collection/refinement.
352 };
353 
354 
355 #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 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.
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
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
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 region index to agent rig index.
void setSerial(exint agent_idx, int serial)
GT_AgentTransformsHandle myAgentTransforms
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:80
exint entries() const
UT_UniquePtr< GT_VulkanAgentData > myVulkanData
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.