All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_PackedUSD.h
1 //
2 // Copyright 2017 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 
25 #ifndef __GUSD_GU_PACKEDIMPL_H__
26 #define __GUSD_GU_PACKEDIMPL_H__
27 
28 
29 #include <GU/GU_PackedImpl.h>
30 #include <GT/GT_Handles.h>
31 #include <SYS/SYS_Version.h>
32 #include <UT/UT_Error.h>
33 
34 #include "pxr/pxr.h"
35 #include "pxr/usd/usd/prim.h"
36 #include "pxr/usd/usdGeom/imageable.h"
37 #include "gusd/purpose.h"
38 #include "gusd/stageEdit.h"
39 #include "gusd/USD_Utils.h"
40 
41 class GusdPrimDef;
42 class GU_PrimPacked;
43 class GT_RefineParms;
44 
45 PXR_NAMESPACE_OPEN_SCOPE
46 
68 
69 class GusdGU_PackedUSD : public GU_PackedImpl
70 {
71 public:
72 
73  static GU_PrimPacked* Build(
74  GU_Detail& detail,
75  const UT_StringHolder& fileName,
76  const SdfPath& primPath,
77  UsdTimeCode frame,
78  const char* lod = nullptr,
79  GusdPurposeSet purposes = GUSD_PURPOSE_PROXY,
80  const UsdPrim& prim = UsdPrim(),
81  const UT_Matrix4D* xform = nullptr );
82 
83  static GU_PrimPacked* Build(
84  GU_Detail& detail,
85  const UT_StringHolder& fileName,
86  const SdfPath& primPath,
87  const SdfPath& srcPrimPath,
88  int index,
89  UsdTimeCode frame,
90  const char* lod = nullptr,
91  GusdPurposeSet purposes = GUSD_PURPOSE_PROXY,
92  const UsdPrim& prim = UsdPrim(),
93  const UT_Matrix4D* xform = nullptr );
94 
96  static GU_PrimPacked* Build(
97  GU_Detail& detail,
98  const UsdPrim& prim,
99  UsdTimeCode frame,
100  const char* lod = nullptr,
101  GusdPurposeSet purpose = GUSD_PURPOSE_PROXY,
102  const UT_Matrix4D* xform = nullptr );
103 
105  GusdGU_PackedUSD(const GusdGU_PackedUSD &src );
106  virtual ~GusdGU_PackedUSD();
107 
108  static void install(GA_PrimitiveFactory &factory);
109  GUSD_API
110  static GA_PrimitiveTypeId typeId();
111 
112  const UT_StringHolder& fileName() const { return m_fileName; }
113  UT_StringHolder intrinsicFileName() const { return m_fileName; }
114  void setFileName( const UT_StringHolder& fileName );
115 #if SYS_VERSION_FULL_INT >= 0x10050000
116  UT_StringHolder intrinsicFileName(const GU_PrimPacked *prim) const
117  { return intrinsicFileName(); }
118  void setFileName(GU_PrimPacked *prim, const UT_StringHolder& fileName)
119  { setFileName(fileName); }
120 #endif
121 
122  const UT_StringHolder& altFileName() const { return m_altFileName; }
123  UT_StringHolder intrinsicAltFileName() const { return m_altFileName; }
124  void setAltFileName( const UT_StringHolder& fileName );
125 #if SYS_VERSION_FULL_INT >= 0x10050000
126  UT_StringHolder intrinsicAltFileName(const GU_PrimPacked *prim) const
127  { return intrinsicAltFileName(); }
128  void setAltFileName(GU_PrimPacked *prim, const UT_StringHolder& fileName)
129  { setAltFileName(fileName); }
130 #endif
131 
132  const SdfPath& primPath() const { return m_primPath; }
133  UT_StringHolder intrinsicPrimPath() const { return m_primPath.GetText(); }
134  void setPrimPath( const UT_StringHolder& p );
135  void setPrimPath( const SdfPath& primPath );
136 #if SYS_VERSION_FULL_INT >= 0x10050000
137  UT_StringHolder intrinsicPrimPath(const GU_PrimPacked *prim) const
138  { return intrinsicPrimPath(); }
139  void setPrimPath(GU_PrimPacked *prim, const UT_StringHolder& p)
140  { setPrimPath(p); }
141 #endif
142 
143  // If this prim was unpacked from a point instancer, srcPrimPath is the path
144  // to the instancer.
145  const SdfPath& srcPrimPath() const { return m_srcPrimPath; }
146  UT_StringHolder intrinsicSrcPrimPath() const { return m_srcPrimPath.GetText(); }
147  void setSrcPrimPath( const UT_StringHolder& p );
148  void setSrcPrimPath( const SdfPath& primPath );
149 #if SYS_VERSION_FULL_INT >= 0x10050000
150  UT_StringHolder intrinsicSrcPrimPath(const GU_PrimPacked *prim) const
151  { return intrinsicSrcPrimPath(); }
152  void setSrcPrimPath(GU_PrimPacked *prim, const UT_StringHolder& p)
153  { setSrcPrimPath(p); }
154 #endif
155 
156  // If this prim was unpacked from a point instancer, index is the array
157  // index in the source point instancer.
158  exint index() const { return m_index; }
159  void setIndex( exint i );
160 #if SYS_VERSION_FULL_INT >= 0x10050000
161  exint index(const GU_PrimPacked *prim) const
162  { return index(); }
163  void setIndex(GU_PrimPacked *prim, exint i)
164  { setIndex(i); }
165 #endif
166 
167  // Return true if this is a prim that has been unpacked from a point instancer.
168  bool isPointInstance() const { return m_index >= 0; }
169 
170  // return the USD prim type
171  UT_StringHolder intrinsicType() const;
172 #if SYS_VERSION_FULL_INT >= 0x10050000
173  UT_StringHolder intrinsicType(const GU_PrimPacked *prim) const
174  { return intrinsicType(); }
175 #endif
176 
177  GA_Size usdLocalToWorldTransformSize() const { return 16; }
178  void usdLocalToWorldTransform(fpreal64* val, exint size) const;
179 #if SYS_VERSION_FULL_INT >= 0x10050000
180  GA_Size usdLocalToWorldTransformSize(const GU_PrimPacked *prim) const
181  { return 16; }
182  void usdLocalToWorldTransform(const GU_PrimPacked *prim,
183  fpreal64* val, exint size) const
184  { usdLocalToWorldTransform(val, size); }
185 #endif
186 
187  UsdTimeCode frame() const { return m_frame; }
188  fpreal intrinsicFrame() const { return GusdUSD_Utils::GetNumericTime(m_frame); }
189  void setFrame( UsdTimeCode frame );
190  void setFrame( fpreal frame );
191 #if SYS_VERSION_FULL_INT >= 0x10050000
192  fpreal intrinsicFrame(const GU_PrimPacked *prim) const
193  { return intrinsicFrame(); }
194  void setFrame(GU_PrimPacked *prim, fpreal frame)
195  { setFrame(frame); }
196 #endif
197 
198  GusdPurposeSet getPurposes() const { return m_purposes; }
199  void setPurposes( GusdPurposeSet purposes );
200 
201  exint getNumPurposes() const;
202  void getIntrinsicPurposes( UT_StringArray& purposes ) const;
203  void setIntrinsicPurposes( const UT_StringArray& purposes );
204 #if SYS_VERSION_FULL_INT >= 0x10050000
205  exint getNumPurposes(const GU_PrimPacked *prim) const
206  { return getNumPurposes(); }
207  void getIntrinsicPurposes(const GU_PrimPacked *prim,
208  UT_StringArray& purposes ) const
209  { getIntrinsicPurposes(purposes); }
210  void setIntrinsicPurposes(GU_PrimPacked *prim,
211  const UT_StringArray& purposes )
212  { setIntrinsicPurposes(purposes); }
213 #endif
214 
215  virtual GU_PackedFactory *getFactory() const override;
216  virtual GU_PackedImpl *copy() const override;
217  virtual void clearData() override;
218 
219  virtual bool isValid() const override;
220  virtual bool save(UT_Options &options, const GA_SaveMap &map) const override;
221 #if SYS_VERSION_FULL_INT < 0x10050000
222  virtual bool load(const UT_Options &options, const GA_LoadMap &map) override;
223  virtual void update(const UT_Options &options) override;
224 #else
225  bool load(const UT_Options &options, const GA_LoadMap &map);
226  void update(const UT_Options &options);
227  virtual bool load(GU_PrimPacked *prim,
228  const UT_Options &options,
229  const GA_LoadMap &map) override
230  { return load(options, map); }
231  virtual void update(GU_PrimPacked *prim,
232  const UT_Options &options) override
233  { update(options); }
234 #endif
235 
236  virtual bool getBounds(UT_BoundingBox &box) const override;
237  virtual bool getRenderingBounds(UT_BoundingBox &box) const override;
238  virtual void getVelocityRange(UT_Vector3 &min, UT_Vector3 &max) const override;
239  virtual void getWidthRange(fpreal &min, fpreal &max) const override;
240 
241  virtual bool getLocalTransform(UT_Matrix4D &m) const override;
242 
243 #if SYS_VERSION_FULL_INT < 0x11000000
244  virtual bool unpack(GU_Detail &destgdp) const override;
245  virtual bool unpackUsingPolygons(GU_Detail &destgdp) const override;
246 #else
247  virtual bool unpack(GU_Detail &destgdp,
248  const UT_Matrix4D *transform) const override;
249  virtual bool unpackUsingPolygons(GU_Detail &destgdp,
250  const GU_PrimPacked *prim) const override;
251 #endif
252 
253  bool visibleGT() const;
254  GT_PrimitiveHandle fullGT() const;
255 
256  // Return a structure that can be hashed to sort instances by prototype.
257  bool getInstanceKey(UT_Options& key) const;
258 
260  virtual int64 getMemoryUsage(bool inclusive) const override;
261 
264  virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const override;
265 
271  UsdPrim getUsdPrim(UT_ErrorSeverity sev=UT_ERROR_ABORT) const;
272 
273 #if SYS_VERSION_FULL_INT >= 0x11000000
274  bool unpackGeometry(
275  GU_Detail &destgdp,
276  const char* primvarPattern,
277  const UT_Matrix4D *transform,
278  const GT_RefineParms* parms=nullptr) const;
279 #else
280  bool unpackGeometry(
281  GU_Detail &destgdp,
282  const char* primvarPattern,
283  const GT_RefineParms* parms=nullptr) const;
284 #endif
285 
286  const UT_Matrix4D& getUsdTransform() const;
287 
288 private:
289 
290  bool unpackPrim(
291  GU_Detail& destgdp,
292  UsdGeomImageable prim,
293  const SdfPath& primPath,
294  const UT_Matrix4D& xform,
295  const GT_RefineParms& rparms ) const;
296 
297  void resetCaches();
298  void updateTransform();
299  void setTransform( const UT_Matrix4D& mx );
300 
301  // intrinsics
302  UT_StringHolder m_fileName;
303  UT_StringHolder m_altFileName;
304  SdfPath m_srcPrimPath;
305  int m_index;
306  SdfPath m_primPath;
307  UsdTimeCode m_frame;
308  GusdPurposeSet m_purposes;
309 
310 
311  // caches
312  mutable UsdPrim m_usdPrim;
313 #if SYS_VERSION_FULL_INT < 0x12000000
314  mutable UT_BoundingBox m_boundsCache;
315 #endif
316  mutable bool m_transformCacheValid;
317  mutable UT_Matrix4D m_transformCache;
318  mutable GT_PrimitiveHandle m_gtPrimCache;
319  mutable bool m_masterPathCacheValid;
320  mutable std::string m_masterPathCache;
321 };
322 
323 PXR_NAMESPACE_CLOSE_SCOPE
324 
325 #endif // __GUSD_GU_PACKEDIMPL_H__
A GU implementation of a packed USD prim.
Definition: GU_PackedUSD.h:69
virtual int64 getMemoryUsage(bool inclusive) const override
Report memory usage (includes all shared memory)
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:131
virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const override
Count memory usage using a UT_MemoryCounter in order to count shared memory correctly.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
UsdPrim getUsdPrim(UT_ErrorSeverity sev=UT_ERROR_ABORT) const
Get the underlying UsdPrim for this packed prim.
Base class for all prims that may require rendering or visualization of some sort.
Definition: imageable.h:74
SDF_API const char * GetText() const
Returns the string representation of this path as a c string.