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 
69  /// Import computed transforms into 'xforms'. If packed_xform_only is true,
70  /// only the agent transforms are returned. If false, the rig * agent
71  /// transforms are returned.
72  void getMatGroupTransforms(exint grp_idx, UT_Matrix4FArray &xforms,
73  bool packed_xform_only) const;
74 
75  /// Copy transforms into a fp32 mat buffer. Must be num_instances in size.
76  void fetchMatGroupTransforms(int idx,
78  bool packed_xform_only) const;
79 
80  /// Copy rig transforms into a fp32 4x3 matrix buffer.
81  /// Must be num_instances * getNumTransformsPerInstance() in size.
82  void fetchMatGroupRigTransforms(int idx, fpreal32 *buf) const;
83 
84  /// Copy weights for the active target shapes into a buffer.
85  /// Must be num_instances * getNumBlendWeightsPerInstance() in size.
86  void fetchMatGroupBlendWeights(
87  int idx,
88  std::pair<int32, fpreal32> *active_targets) const;
89 
90  /// Copy colors into a 4 x uint8 buffer.
91  void fetchMatGroupColors(int idx, uint8 *buf) const;
92 
93  /// Return a list of visible instances in this material group, based on the
94  /// visibility info computed by the GT_GEOPackedAgent. returns -1 if
95  /// only some are visible, 0 if none are visible, and 1 if all are visible.
96  /// The 'lod_bias' is a factor that will favour lower LOD levels if > 1,
97  /// and higher LOD levels if < 1. A bias of zero will disable LOD.
98  int getVisibleInstances(int grp_idx,
99  UT_IntArray &inst_idx,
100  int lod_base = 0.0,
101  fpreal lod_bias = 1.0) const;
102 
103 
104  // non-const methods for GT_GEOPackedAgent to modify the shapes
105 
106  /// Add a instance
107  void addShapeInstance(int xform_index,
108  int material_id,
109  GA_Index agent_prim_idx,
110  GA_Index agent_pnt_idx,
111  const GT_AgentShapeBindingID &binding);
112 
113 
114  // GT_Primitive pure virtual overrides
115  const char *className() const override
116  { return "GT_PrimAgentShape"; }
117  int getPrimitiveType() const override
118  { return GT_PRIM_AGENT_SHAPE; }
120  int nsegments) const override
121  { doEnlargeBounds(boxes, nsegments, false); }
123  int nsegments) const override
124  { doEnlargeBounds(boxes, nsegments, true); }
125  int getMotionSegments() const override { return 1; }
126  int64 getMemoryUsage() const override;
128  { return new GT_PrimAgentShape(*this); }
129  GT_PrimitiveHandle doHarden() const override { return doSoftCopy(); }
130 
131  bool refine(GT_Refine &refiner,
132  const GT_RefineParms *parms = NULL
133  ) const override;
134 
135  bool getTopologyVersion(int64 &version) const override;
136 
138  {
139  public:
145  };
146 
147  // Stylesheet agent shape support. Unstyled groups are those with just
148  // primitive agent material assignments, whereas styled groups have the
149  // shape assignments as well.
150  int getNumUnstyledGroups() const;
151  ShapeInstance &getShapeInstancesForUnstyledGroup(int mat_group);
152  void resetStyledMatGroups();
153  ShapeInstance *addStyledMatGroup(int mat_id);
154 
155 private:
156  void doEnlargeBounds(UT_BoundingBox boxes[], int nsegments,
157  bool render) const;
158 
159  UT_SortedMap<int,int> myMatGroupMap;
160 
161 private:
162 
163  UT_Array<ShapeInstance> myMatGroup;
164  UT_Array<ShapeInstance *> myStyledMatGroup;
165  bool myUseStyledMatGroups;
166 
167  GT_ShapeLODGroupHandle myLODGroup;
168  GT_PrimitiveHandle myGeometry;
169  GU_ConstDetailHandle myDetail;
170  mutable UT_Vector2iArray myVisibleInstances;
171  int myLODLevel;
172  GT_DataArrayHandle myMatRemap;
173 };
174 
176 
177 inline const GT_PrimitiveHandle &
179 { return myGeometry; }
180 
181 inline exint
183 {
184  return myUseStyledMatGroups ? myStyledMatGroup.entries()
185  : myMatGroup.entries();
186 }
187 
188 inline exint
190 {
191  const ShapeInstance &inst = myUseStyledMatGroups ? *myStyledMatGroup(i)
192  : myMatGroup(i);
193  return inst.myPrimIDs.entries();
194 }
195 
196 inline int
198 {
199  const ShapeInstance &inst = myUseStyledMatGroups ? *myStyledMatGroup(i)
200  : myMatGroup(i);
201  return inst.myMaterialID;
202 }
203 
204 inline const UT_IntArray &
206 {
207  const ShapeInstance &inst = myUseStyledMatGroups ? *myStyledMatGroup(i)
208  : myMatGroup(i);
209  return inst.myPrimIDs;
210 }
211 
212 inline const UT_IntArray &
214 {
215  const ShapeInstance &inst = myUseStyledMatGroups ? *myStyledMatGroup(i)
216  : myMatGroup(i);
217  return inst.myPointIDs;
218 }
219 
220 inline int
222 {
223  return myMatGroup.entries();
224 }
225 
228 {
229  return myMatGroup(mat_group);
230 }
231 
232 inline void
234 {
235  for(auto grp : myStyledMatGroup)
236  delete grp;
237  myStyledMatGroup.entries(0);
238  myUseStyledMatGroups = false;
239 }
240 
243 {
244  myUseStyledMatGroups = true;
245  myStyledMatGroup.append(new ShapeInstance);
246  myStyledMatGroup.last()->myMaterialID = mat_id;
247  return myStyledMatGroup.last();
248 }
249 
250 inline GU_ConstDetailHandle &
252 { return const_cast<GT_PrimAgentShape *>(this)->myDetail; }
253 
254 inline int
256 { return myLODLevel; }
257 
258 inline const GT_ShapeLODGroupHandle &
260 { return myLODGroup; }
261 
262 #endif
263 
264 
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:11
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:634
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
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
Processes primitives generated by refinement process.
Definition: GT_Refine.h:20
exint entries() const
Alias of size(). size() is preferred.
Definition: UT_Array.h:611
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