HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_PrimAgentShape.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_PrimAgentShape.h (GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 #ifndef GT_PrimAgentShape_h
11 #define GT_PrimAgentShape_h
12 
13 #include "GT_API.h"
14 #include "GT_GEOPackedAgent.h"
15 #include "GT_AgentSupport.h"
16 
17 #include <GU/GU_DetailHandle.h>
18 
19 #include <UT/UT_IntArray.h>
20 #include <UT/UT_Map.h>
21 #include <UT/UT_Matrix4.h>
22 #include <UT/UT_VectorTypes.h>
23 #include <UT/UT_IntrusivePtr.h>
24 #include <UT/UT_NonCopyable.h>
25 
26 #include <SYS/SYS_AtomicInt.h>
27 #include <SYS/SYS_Types.h>
28 
29 class RE_VertexArray;
30 
31 /// A shape belonging to agents, instanced with material assignments.
33 {
34 public:
37  GT_PrimAgentShape(const GT_PrimitiveHandle &geometry,
38  const GU_ConstDetailHandle &dh,
39  const GT_ShapeLODGroupHandle &agent_group,
40  int lod_level,
41  GT_DataArray *mat_remap);
42  ~GT_PrimAgentShape() override;
43 
44  /// shape geometry.
45  const GT_PrimitiveHandle &geometry() const;
46  GU_ConstDetailHandle &detail() const;
47 
48  /// Access to the shared data between LOD levels of the same agent shape
49  const GT_ShapeLODGroupHandle &shapeGroup() const;
50 
51  /// Which LOD level this shape represents: 0=primary, 1+ lower resolutions
52  int lodLevel() const;
53 
54  /// one set of transforms per material.
55  exint getNumMatGroups() const;
56  exint getMatGroupNumInstances(exint grp_idx) const;
57  int getMatGroupMaterialID(exint grp_idx) const;
58  const UT_IntArray &getMatGroupAgentPrimIDs(exint grp_idx) const;
59  const UT_IntArray &getMatGroupAgentPointIDs(exint grp_idx) const;
60 
61  GT_DataArrayHandle getMatRemapAttrib() const { return myMatRemap; }
62 
63  int getNumTransformsPerInstance() const;
64  int getNumBlendWeightsPerInstance() const;
65  /// Number of points in the shape. If there are blendshapes, each target
66  /// shape in the BlendShapeOffsets buffer also has this number of points.
67  int getNumPoints() const;
68  /// Returns whether there are any blendshapes with normal offsets (i.e. the
69  /// BlendShapeNormalOffsets buffer should be used).
70  bool hasBlendShapeNormalOffsets() const;
71 
72  /// Import computed transforms into 'xforms'. If packed_xform_only is true,
73  /// only the agent transforms are returned. If false, the rig * agent
74  /// transforms are returned.
75  void getMatGroupTransforms(exint grp_idx, UT_Matrix4FArray &xforms,
76  bool packed_xform_only) const;
77 
78  /// Copy transforms into a fp32 mat buffer. Must be num_instances in size.
79  void fetchMatGroupTransforms(int idx,
81  bool packed_xform_only) const;
82 
83  /// Copy rig transforms into a fp32 4x3 matrix buffer.
84  /// Must be num_instances * getNumTransformsPerInstance() in size.
85  void fetchMatGroupRigTransforms(int idx, fpreal32 *buf) const;
86 
87  /// Copy weights for the active target shapes into a buffer.
88  /// Must be num_instances * getNumBlendWeightsPerInstance() in size.
89  /// The weights are only filled for the visible instances whose LOD level is
90  /// <= max_blend_shape_lod_level.
91  bool fetchMatGroupBlendWeights(
92  int idx,
93  int max_blend_shape_lod_level,
94  int lod_base,
95  fpreal lod_bias,
96  std::pair<int32, fpreal32> *active_targets,
97  UT_StringHolder &error_msg) const;
98 
99  /// Copy colors into a 4 x uint8 buffer.
100  void fetchMatGroupColors(int idx, uint8 *buf) const;
101 
102  /// Return a list of visible instances in this material group, based on the
103  /// visibility info computed by the GT_GEOPackedAgent. returns -1 if
104  /// only some are visible, 0 if none are visible, and 1 if all are visible.
105  /// The 'lod_bias' is a factor that will favour lower LOD levels if > 1,
106  /// and higher LOD levels if < 1. A bias of zero will disable LOD.
107  int getVisibleInstances(int grp_idx,
108  UT_IntArray &inst_idx,
109  int lod_base = 0.0,
110  fpreal lod_bias = 1.0) const;
111 
112 
113  // non-const methods for GT_GEOPackedAgent to modify the shapes
114 
115  /// Add a instance
116  void addShapeInstance(int xform_index,
117  int material_id,
118  GA_Index agent_prim_idx,
119  GA_Index agent_pnt_idx,
120  const GT_AgentShapeBindingID &binding);
121 
122 
123  // GT_Primitive pure virtual overrides
124  const char *className() const override
125  { return "GT_PrimAgentShape"; }
126  int getPrimitiveType() const override
127  { return GT_PRIM_AGENT_SHAPE; }
129  int nsegments) const override
130  { doEnlargeBounds(boxes, nsegments, false); }
132  int nsegments) const override
133  { doEnlargeBounds(boxes, nsegments, true); }
134  int getMotionSegments() const override { return 1; }
135  int64 getMemoryUsage() const override;
137  { return new GT_PrimAgentShape(*this); }
138  GT_PrimitiveHandle doHarden() const override { return doSoftCopy(); }
139 
140  bool refine(GT_Refine &refiner,
141  const GT_RefineParms *parms = NULL
142  ) const override;
143 
144  bool getTopologyVersion(int64 &version) const override;
145 
147  {
148  public:
154  };
155 
156  // Stylesheet agent shape support. Unstyled groups are those with just
157  // primitive agent material assignments, whereas styled groups have the
158  // shape assignments as well.
159  int getNumUnstyledGroups() const;
160  ShapeInstance &getShapeInstancesForUnstyledGroup(int mat_group);
161  void resetStyledMatGroups();
162  ShapeInstance *addStyledMatGroup(int mat_id);
163 
164 private:
165  void doEnlargeBounds(UT_BoundingBox boxes[], int nsegments,
166  bool render) const;
167 
168  UT_SortedMap<int,int> myMatGroupMap;
169 
170 private:
171 
172  UT_Array<ShapeInstance> myMatGroup;
173  UT_Array<ShapeInstance *> myStyledMatGroup;
174  bool myUseStyledMatGroups;
175 
176  GT_ShapeLODGroupHandle myLODGroup;
177  GT_PrimitiveHandle myGeometry;
178  GU_ConstDetailHandle myDetail;
179  mutable UT_Array<int> myVisibleInstances;
180  int myLODLevel;
181  GT_DataArrayHandle myMatRemap;
182 
183  mutable UT_Array<fpreal32> myMLShapeWeights;
184  mutable UT_Array<UT_Span<const UT_Matrix4F>> myMLPoseInputs;
185 };
186 
188 
189 inline const GT_PrimitiveHandle &
191 { return myGeometry; }
192 
193 inline exint
195 {
196  return myUseStyledMatGroups ? myStyledMatGroup.entries()
197  : myMatGroup.entries();
198 }
199 
200 inline exint
202 {
203  const ShapeInstance &inst = myUseStyledMatGroups ? *myStyledMatGroup(i)
204  : myMatGroup(i);
205  return inst.myPrimIDs.entries();
206 }
207 
208 inline int
210 {
211  const ShapeInstance &inst = myUseStyledMatGroups ? *myStyledMatGroup(i)
212  : myMatGroup(i);
213  return inst.myMaterialID;
214 }
215 
216 inline const UT_IntArray &
218 {
219  const ShapeInstance &inst = myUseStyledMatGroups ? *myStyledMatGroup(i)
220  : myMatGroup(i);
221  return inst.myPrimIDs;
222 }
223 
224 inline const UT_IntArray &
226 {
227  const ShapeInstance &inst = myUseStyledMatGroups ? *myStyledMatGroup(i)
228  : myMatGroup(i);
229  return inst.myPointIDs;
230 }
231 
232 inline int
234 {
235  return myMatGroup.entries();
236 }
237 
240 {
241  return myMatGroup(mat_group);
242 }
243 
244 inline void
246 {
247  for(auto grp : myStyledMatGroup)
248  delete grp;
249  myStyledMatGroup.entries(0);
250  myUseStyledMatGroups = false;
251 }
252 
255 {
256  myUseStyledMatGroups = true;
257  myStyledMatGroup.append(new ShapeInstance);
258  myStyledMatGroup.last()->myMaterialID = mat_id;
259  return myStyledMatGroup.last();
260 }
261 
262 inline GU_ConstDetailHandle &
264 { return const_cast<GT_PrimAgentShape *>(this)->myDetail; }
265 
266 inline int
268 { return myLODLevel; }
269 
270 inline const GT_ShapeLODGroupHandle &
272 { return myLODGroup; }
273 
274 #endif
275 
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
virtual bool refine(GT_Refine &refiner, const GT_RefineParms *parms=NULL) const
GT_DataArrayHandle getMatRemapAttrib() const
virtual bool getTopologyVersion(int64 &version) const
Returns the topology version for the primitive.
ShapeInstance & getShapeInstancesForUnstyledGroup(int mat_group)
int getNumUnstyledGroups() const
#define GT_API
Definition: GT_API.h:13
int64 exint
Definition: SYS_Types.h:125
GT_PrimitiveHandle doSoftCopy() const override
ShapeInstance * addStyledMatGroup(int mat_id)
int getMatGroupMaterialID(exint grp_idx) const
UT_Array< GT_AgentShapeBindingID > myBindings
float fpreal32
Definition: SYS_Types.h:200
IFDmantra you can see code vm_image_mplay_direction endcode When SOHO starts a render
Definition: HDK_Image.dox:266
const UT_IntArray & getMatGroupAgentPointIDs(exint grp_idx) const
int getMotionSegments() const override
unsigned char uint8
Definition: SYS_Types.h:36
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:41
virtual GT_PrimitiveHandle doSoftCopy() const =0
const char * className() const override
long long int64
Definition: SYS_Types.h:116
void enlargeBounds(UT_BoundingBox boxes[], int nsegments) const override
int lodLevel() const
Which LOD level this shape represents: 0=primary, 1+ lower resolutions.
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:647
The base class for all GT primitive types.
Definition: GT_Primitive.h:43
GU_ConstDetailHandle & detail() const
virtual int64 getMemoryUsage() const =0
exint getNumMatGroups() const
one set of transforms per material.
GT_API const UT_StringHolder version
Processes primitives generated by refinement process.
Definition: GT_Refine.h:20
exint entries() const
Alias of size(). size() is preferred.
Definition: UT_Array.h:669
void enlargeRenderBounds(UT_BoundingBox boxes[], int nsegments) const override
GA_API const UT_StringHolder parms
const GT_ShapeLODGroupHandle & shapeGroup() const
Access to the shared data between LOD levels of the same agent shape.
const GT_PrimitiveHandle & geometry() const
shape geometry.
fpreal64 fpreal
Definition: SYS_Types.h:283
A shape belonging to agents, instanced with material assignments.
const UT_IntArray & getMatGroupAgentPrimIDs(exint grp_idx) const
int getPrimitiveType() const override
Index of a shape binding in one of the agent's current layers.
GT_PrimitiveHandle doHarden() const override
exint getMatGroupNumInstances(exint grp_idx) const