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  void fetchMatGroupBlendWeights(
90  int idx,
91  std::pair<int32, fpreal32> *active_targets) const;
92 
93  /// Copy colors into a 4 x uint8 buffer.
94  void fetchMatGroupColors(int idx, uint8 *buf) const;
95 
96  /// Return a list of visible instances in this material group, based on the
97  /// visibility info computed by the GT_GEOPackedAgent. returns -1 if
98  /// only some are visible, 0 if none are visible, and 1 if all are visible.
99  /// The 'lod_bias' is a factor that will favour lower LOD levels if > 1,
100  /// and higher LOD levels if < 1. A bias of zero will disable LOD.
101  int getVisibleInstances(int grp_idx,
102  UT_IntArray &inst_idx,
103  int lod_base = 0.0,
104  fpreal lod_bias = 1.0) const;
105 
106 
107  // non-const methods for GT_GEOPackedAgent to modify the shapes
108 
109  /// Add a instance
110  void addShapeInstance(int xform_index,
111  int material_id,
112  GA_Index agent_prim_idx,
113  GA_Index agent_pnt_idx,
114  const GT_AgentShapeBindingID &binding);
115 
116 
117  // GT_Primitive pure virtual overrides
118  const char *className() const override
119  { return "GT_PrimAgentShape"; }
120  int getPrimitiveType() const override
121  { return GT_PRIM_AGENT_SHAPE; }
123  int nsegments) const override
124  { doEnlargeBounds(boxes, nsegments, false); }
126  int nsegments) const override
127  { doEnlargeBounds(boxes, nsegments, true); }
128  int getMotionSegments() const override { return 1; }
129  int64 getMemoryUsage() const override;
131  { return new GT_PrimAgentShape(*this); }
132  GT_PrimitiveHandle doHarden() const override { return doSoftCopy(); }
133 
134  bool refine(GT_Refine &refiner,
135  const GT_RefineParms *parms = NULL
136  ) const override;
137 
138  bool getTopologyVersion(int64 &version) const override;
139 
141  {
142  public:
148  };
149 
150  // Stylesheet agent shape support. Unstyled groups are those with just
151  // primitive agent material assignments, whereas styled groups have the
152  // shape assignments as well.
153  int getNumUnstyledGroups() const;
154  ShapeInstance &getShapeInstancesForUnstyledGroup(int mat_group);
155  void resetStyledMatGroups();
156  ShapeInstance *addStyledMatGroup(int mat_id);
157 
158 private:
159  void doEnlargeBounds(UT_BoundingBox boxes[], int nsegments,
160  bool render) const;
161 
162  UT_SortedMap<int,int> myMatGroupMap;
163 
164 private:
165 
166  UT_Array<ShapeInstance> myMatGroup;
167  UT_Array<ShapeInstance *> myStyledMatGroup;
168  bool myUseStyledMatGroups;
169 
170  GT_ShapeLODGroupHandle myLODGroup;
171  GT_PrimitiveHandle myGeometry;
172  GU_ConstDetailHandle myDetail;
173  mutable UT_Vector2iArray myVisibleInstances;
174  int myLODLevel;
175  GT_DataArrayHandle myMatRemap;
176 };
177 
179 
180 inline const GT_PrimitiveHandle &
182 { return myGeometry; }
183 
184 inline exint
186 {
187  return myUseStyledMatGroups ? myStyledMatGroup.entries()
188  : myMatGroup.entries();
189 }
190 
191 inline exint
193 {
194  const ShapeInstance &inst = myUseStyledMatGroups ? *myStyledMatGroup(i)
195  : myMatGroup(i);
196  return inst.myPrimIDs.entries();
197 }
198 
199 inline int
201 {
202  const ShapeInstance &inst = myUseStyledMatGroups ? *myStyledMatGroup(i)
203  : myMatGroup(i);
204  return inst.myMaterialID;
205 }
206 
207 inline const UT_IntArray &
209 {
210  const ShapeInstance &inst = myUseStyledMatGroups ? *myStyledMatGroup(i)
211  : myMatGroup(i);
212  return inst.myPrimIDs;
213 }
214 
215 inline const UT_IntArray &
217 {
218  const ShapeInstance &inst = myUseStyledMatGroups ? *myStyledMatGroup(i)
219  : myMatGroup(i);
220  return inst.myPointIDs;
221 }
222 
223 inline int
225 {
226  return myMatGroup.entries();
227 }
228 
231 {
232  return myMatGroup(mat_group);
233 }
234 
235 inline void
237 {
238  for(auto grp : myStyledMatGroup)
239  delete grp;
240  myStyledMatGroup.entries(0);
241  myUseStyledMatGroups = false;
242 }
243 
246 {
247  myUseStyledMatGroups = true;
248  myStyledMatGroup.append(new ShapeInstance);
249  myStyledMatGroup.last()->myMaterialID = mat_id;
250  return myStyledMatGroup.last();
251 }
252 
253 inline GU_ConstDetailHandle &
255 { return const_cast<GT_PrimAgentShape *>(this)->myDetail; }
256 
257 inline int
259 { return myLODLevel; }
260 
261 inline const GT_ShapeLODGroupHandle &
263 { return myLODGroup; }
264 
265 #endif
266 
267 
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:40
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:640
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:648
void enlargeRenderBounds(UT_BoundingBox boxes[], int nsegments) const override
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:277
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