HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GABC_PackedGT.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) COPYRIGHTYEAR
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *----------------------------------------------------------------------------
26  */
27 
28 #ifndef __GABC_PackedGT__
29 #define __GABC_PackedGT__
30 
31 #include "GABC_API.h"
32 #include "GABC_Types.h"
34 #include <GT/GT_PrimInstance.h>
35 #include <GT/GT_GEOPrimPacked.h>
36 #include <GU/GU_DetailHandle.h>
37 
38 class GU_PrimPacked;
39 
40 namespace GABC_NAMESPACE
41 {
42 
43 /// Collector for packed primitives.
45 {
46 public:
48  virtual ~GABC_CollectPacked();
49 
50  /// @{
51  /// Interface defined for GT_GEOPrimCollect
52  virtual GT_GEOPrimCollectData *
54  const GT_RefineParms *parms) const;
55  virtual GT_PrimitiveHandle
57  const GEO_Primitive *const* prim_list,
58  int nsegments,
60  virtual GT_PrimitiveHandle
61  endCollecting(const GT_GEODetailListHandle &geometry,
63  /// @}
64 private:
65 };
66 
68 {
69 public:
71  {
72  myVisibilityAnimated = false;
73  myTransformAnimated = false;
74  }
75 
76  bool getVisibility(fpreal t, bool &visible) const;
77  bool getTransform(fpreal t, UT_Matrix4D &transform) const;
78 
79 
80  void setVisibilityAnimated(bool anim) { myVisibilityAnimated = anim;}
81  void setTransformAnimated(bool anim) { myTransformAnimated = anim; }
82 
83  void cacheVisibility(fpreal t, bool visible)
84  { myVisibility[ myVisibilityAnimated ? t : 0.0] = visible; }
86  { myTransform[ myTransformAnimated ? t : 0.0] = transform; }
87 
88 private:
89  UT_Map<fpreal, bool> myVisibility;
90  UT_Map<fpreal, UT_Matrix4D> myTransform;
91 
92  unsigned int myVisibilityAnimated : 1,
93  myTransformAnimated : 1;
94 
95 };
96 }; // GABC_NAMESPACE
97 
98 
99 /// Collection class for a single archive's worth of Alembic primitives.
100 /// This is generally only useful for the viewport.
102 {
103 public:
104  GABC_PackedArchive(const UT_StringHolder &archive_name,
105  const GT_GEODetailListHandle &source_list,
106  const GABC_NAMESPACE::GABC_IArchivePtr &archive);
107 
108  const UT_StringHolder &archiveName() const { return myName; }
109 
110  virtual int getPrimitiveType() const
111  { return GT_PRIM_ALEMBIC_ARCHIVE; }
112  virtual const char *className() const { return "GABC_PackedArchive"; }
113 
114  void appendAlembic(GA_Offset alembic_prim_offset)
115  { myAlembicOffsets.append(alembic_prim_offset); }
116 
117  bool bucketPrims(const GABC_PackedArchive *prev_archive,
118  const GT_RefineParms *ref_parms,
119  bool force_update);
120 
121  int getNumChildPrims() const
122  { return (myConstShapes.entries() +
123  myTransformShapes.entries() +
124  myDeformShapes.entries() +
125  myCombinedShapes.entries()); }
126 
128  { return myConstShapes; }
130  { return myTransformShapes; }
132  { return myDeformShapes; }
134  { return myCombinedShapes; }
135 
136  virtual void enlargeBounds(UT_BoundingBox boxes[],
137  int nsegments) const;
138  virtual int getMotionSegments() const { return 1; }
139  virtual int64 getMemoryUsage() const;
140  virtual GT_PrimitiveHandle doSoftCopy() const;
141 
142  void setRefinedSubset(bool reduced_consts,
143  UT_IntArray &const_prims,
144  bool reduced_transforms,
145  UT_IntArray &trans_prims);
146  bool hasConstantSubset() const { return myHasConstSubset; }
147  const UT_IntArray &getConstantSubset() const { return myConstSubset; }
148  bool hasTransformSubset() const { return myHasTransSubset; }
149  const UT_IntArray &getTransformSubset() const { return myTransSubset; }
150 
151  int64 getAlembicVersion() const { return myAlembicVersion; }
152 
153 private:
154  bool archiveMatch(const GABC_PackedArchive *archive) const;
155 
156  UT_StringHolder myName;
157  GT_GEODetailListHandle myDetailList;
158  UT_StringArray myAlembicObjects;
159  GA_OffsetArray myAlembicOffsets;
161 
162  UT_Array<GT_PrimitiveHandle> myConstShapes;
163  UT_Array<GT_PrimitiveHandle> myTransformShapes;
164  UT_Array<GT_PrimitiveHandle> myDeformShapes;
165  UT_Array<GT_PrimitiveHandle> myCombinedShapes;
166  UT_IntArray myConstSubset;
167  UT_IntArray myTransSubset;
168  bool myHasConstSubset;
169  bool myHasTransSubset;
170  int64 myAlembicVersion;
171 };
172 
173 
174 /// Single Alembic shape (non-instanced)
176 {
177 public:
179  const GU_PrimPacked *prim,
180  const GT_DataArrayHandle &vp_mat,
181  const GT_DataArrayHandle &vp_remap);
182 
184  virtual ~GABC_PackedAlembic();
185 
186  void initVisAnim();
187 
188  virtual int getPrimitiveType() const
189  { return GT_PRIM_ALEMBIC_SHAPE; }
190  virtual const char *className() const { return "GABC_PackedAlembic"; }
192  { return new GABC_PackedAlembic(*this); }
193 
195  bool &xform) const;
197  bool &xform) const;
198  virtual GT_PrimitiveHandle getBoxGeometry(const GT_RefineParms *p) const;
199  virtual GT_PrimitiveHandle getCentroidGeometry(const GT_RefineParms *p) const;
200 
201  virtual bool canInstance() const { return true; }
202  virtual bool getInstanceKey(UT_Options &options) const;
204  bool ignore_visibility=false) const;
206 
207  GT_TransformHandle fullCachedTransform();
208  bool isVisible();
209 
210  virtual bool refine(GT_Refine &refiner,
211  const GT_RefineParms *parms=NULL) const;
212  virtual bool getUniqueID(int64 &id) const
213  { id = myID; return true; }
214 
216  { myAnimType = t; }
217  GEO_AnimationType animationType() const { return myAnimType; }
218 
219  void setVisibilityAnimated(bool anim)
220  { myAnimVis = anim; }
221  bool visibilityAnimated() const { return myAnimVis; }
222 
223  bool getCachedGeometry(GT_PrimitiveHandle &ph) const;
224 
225  void cacheTransform(const GT_TransformHandle &ph);
226  bool getCachedTransform(GT_TransformHandle &ph) const;
227  void cacheVisibility(bool visible);
228  bool getCachedVisibility(bool &visible) const;
229 
230  GT_TransformHandle applyPrimTransform(const GT_TransformHandle &th)
231  const;
232  GT_TransformHandle getLocalTransform() const;
233 
234  int64 alembicVersion() const { return myAlembicVersion; }
235  void setAlembicVersion(int64 v) { myAlembicVersion = v; }
236 
237  virtual bool updateGeoPrim(const GU_ConstDetailHandle &dtl,
238  const GT_RefineParms &refine);
239 
241  { return myDetailAttribs; }
242 private:
243  int64 myID;
244  GEO_AnimationType myAnimType;
246  GT_AttributeListHandle myDetailAttribs;
247  UT_Matrix4D myTransform;
248  bool myAnimVis;
249  bool myVisibleConst; // only valid when myAnimVis is false.
250  int64 myAlembicVersion;
251  GA_Offset myOffset;
252  float myFrame;
253 };
254 
255 /// Alembic mesh which contains multiple alembic primitives merged together.
257 {
258 public:
259  GABC_PackedAlembicMesh(const GT_PrimitiveHandle &packed_geo, int64 id);
260  GABC_PackedAlembicMesh(const GT_PrimitiveHandle &packed_geo, int64 id,
261  UT_Array<GT_PrimitiveHandle> &individual_meshes);
263 
264  virtual int getPrimitiveType() const
265  { return GT_PRIM_ALEMBIC_SHAPE_MESH; }
266  virtual const char *className() const
267  { return "GABC_PackedAlembicMesh"; }
269  { return new GABC_PackedAlembicMesh(*this); }
270  virtual bool refine(GT_Refine &refiner,
271  const GT_RefineParms *parms=NULL) const;
272  virtual void enlargeBounds(UT_BoundingBox boxes[],
273  int nsegments) const;
274  virtual int getMotionSegments() const { return 1; }
275  virtual int64 getMemoryUsage() const;
276  virtual bool getUniqueID(int64 &id) const
277  { id = myID; return true; }
278 
279  void update(bool initial_update);
281  { return myTransformArray.get() != NULL; }
283  { return myTransformArray.get() != NULL; }
284 
285  int64 alembicVersion() const { return myAlembicVersion; }
286  void setAlembicVersion(int64 v) { myAlembicVersion = v; }
287 
288 private:
289  GT_PrimitiveHandle myMeshGeo;
290  GT_DataArrayHandle myTransformArray;
291  GT_DataArrayHandle myVisibilityArray;
293  int64 myID;
294  int64 myTransID;
295  int64 myVisID;
296  int64 myAlembicVersion;
297 };
298 
299 /// Packed instance with alembic extensions
301 {
302 public:
305  GABC_PackedInstance(const GT_PrimitiveHandle &geometry,
307  GEO_AnimationType animation,
308  const GT_GEOOffsetList &packed_prim_offsets=GT_GEOOffsetList(),
312  virtual ~GABC_PackedInstance();
313  virtual int getPrimitiveType() const
314  { return GT_PRIM_ALEMBIC_INSTANCE; }
315 
316  virtual const char *className() const { return "GABC_PackedInstance"; }
317 
318  GEO_AnimationType animationType() const { return myAnimType; }
319 
320  int64 alembicVersion() const { return myAlembicVersion; }
321  void setAlembicVersion(int64 v) { myAlembicVersion = v; }
322  bool updateGeoPrim(const GU_ConstDetailHandle &dtl,
323  const GT_RefineParms &refine);
324 
325 private:
326  GEO_AnimationType myAnimType;
328  int64 myAlembicVersion;
329 };
330 
331 
332 #endif
void setAlembicVersion(int64 v)
virtual bool updateGeoPrim(const GU_ConstDetailHandle &dtl, const GT_RefineParms &parms)
update any cached data for geometry and its attributes
virtual bool refine(GT_Refine &refiner, const GT_RefineParms *parms=NULL) const
void cacheTransform(fpreal t, const UT_Matrix4D &transform)
Definition: GABC_PackedGT.h:85
virtual GT_TransformHandle getInstanceTransform() const
virtual GT_PrimitiveHandle getInstanceGeometry(const GT_RefineParms *parms, bool ignore_visibility=false) const
png_infop int transforms
Definition: png.h:2591
bool visibilityAnimated() const
int64 getAlembicVersion() const
virtual GT_PrimitiveHandle doSoftCopy() const
virtual GT_PrimitiveHandle doSoftCopy() const
virtual bool updateGeoPrim(const GU_ConstDetailHandle &dtl, const GT_RefineParms &refine)
update any cached data for geometry and its attributes
virtual GT_PrimitiveHandle endCollecting(const GT_GEODetailListHandle &geometry, GT_GEOPrimCollectData *data) const
virtual const char * className() const
UT_IntrusivePtr< GT_AttributeList > GT_AttributeListHandle
Definition: GT_Handles.h:24
const GLdouble * v
Definition: glcorearb.h:836
virtual GT_PrimitiveHandle getPointCloud(const GT_RefineParms *parms, bool &requires_transform) const
virtual const GT_AttributeListHandle & getDetailAttributes() const
Collector for packed primitives.
Definition: GABC_PackedGT.h:44
virtual bool getInstanceKey(UT_Options &options) const
virtual GT_PrimitiveHandle collect(const GT_GEODetailListHandle &geo, const GEO_Primitive *const *prim_list, int nsegments, GT_GEOPrimCollectData *data) const
void setAlembicVersion(int64 v)
virtual int getPrimitiveType() const
bool hasConstantSubset() const
virtual GT_PrimitiveHandle getCentroidGeometry(const GT_RefineParms *parms) const
Packed instance with alembic extensions.
#define GABC_NAMESPACE
Definition: GABC_API.h:42
const UT_IntArray & getTransformSubset() const
Collection data container.
GA_Size GA_Offset
Definition: GA_Types.h:617
long long int64
Definition: SYS_Types.h:100
virtual GT_PrimitiveHandle doSoftCopy() const =0
virtual int getMotionSegments() const
const UT_Array< GT_PrimitiveHandle > & transformShapes() const
virtual GT_GEOPrimCollectData * beginCollecting(const GT_GEODetailListHandle &geometry, const GT_RefineParms *parms) const
virtual bool getUniqueID(int64 &id) const
int64 alembicVersion() const
GEO_AnimationType
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
virtual int getPrimitiveType() const
const UT_Array< GT_PrimitiveHandle > & constantShapes() const
bool hasAnimatedTransforms() const
virtual const char * className() const
Alembic mesh which contains multiple alembic primitives merged together.
GEO_AnimationType animationType() const
GLboolean * data
Definition: glcorearb.h:130
const UT_Array< GT_PrimitiveHandle > & combinedShapes() const
virtual int getPrimitiveType() const
GA_API const UT_StringHolder transform
The base class for all GT primitive types.
Definition: GT_Primitive.h:41
const UT_StringHolder & archiveName() const
void cacheVisibility(fpreal t, bool visible)
Definition: GABC_PackedGT.h:83
virtual const char * className() const
int64 alembicVersion() const
void setAnimationType(GEO_AnimationType t)
virtual int64 getMemoryUsage() const =0
virtual bool canInstance() const
const UT_IntArray & getConstantSubset() const
GEO_AnimationType animationType() const
Processes primitives generated by refinement process.
Definition: GT_Refine.h:20
virtual int getMotionSegments() const
Container for a GU packed primitive.
int getNumChildPrims() const
double fpreal
Definition: SYS_Types.h:263
A map of string to various well defined value types.
Definition: UT_Options.h:42
void appendAlembic(GA_Offset alembic_prim_offset)
const UT_Array< GT_PrimitiveHandle > & deformShapes() const
#define GABC_API
Definition: GABC_API.h:37
bool hasAnimatedVisibility() const
int64 alembicVersion() const
virtual const char * className() const
virtual bool getUniqueID(int64 &id) const
virtual GT_PrimitiveHandle getFullGeometry(const GT_RefineParms *parms, bool &requires_transform) const
bool hasTransformSubset() const
virtual GT_PrimitiveHandle getBoxGeometry(const GT_RefineParms *parms) const
UT_SharedPtr< GT_GEODetailList > GT_GEODetailListHandle
void setAlembicVersion(int64 v)
virtual void enlargeBounds(UT_BoundingBox boxes[], int nsegments) const =0
void setVisibilityAnimated(bool anim)
Single Alembic shape (non-instanced)
virtual int getPrimitiveType() const
virtual bool refine(GT_Refine &refiner, const GT_RefineParms *parms=NULL) const
GLenum src
Definition: glcorearb.h:1792