HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_PackedUSD.h
Go to the documentation of this file.
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 #ifndef __GUSD_GT_PACKEDUSD_H__
25 #define __GUSD_GT_PACKEDUSD_H__
26 
27 #include "gusd/api.h"
28 #include "gusd/purpose.h"
29 
30 #include "pxr/pxr.h"
31 #include "pxr/usd/sdf/path.h"
32 #include "pxr/usd/usd/timeCode.h"
33 
34 #include <GT/GT_GEOPrimCollect.h>
35 #include <GT/GT_Primitive.h>
36 
37 class GU_PrimPacked;
38 
40 
41 /// A GT implementation of a packed USD prim.
42 ///
43 /// This is a file backed prim that holds a reference to a prim in a usd file
44 /// at a particular frame. The prim can be a group of prims.
45 ///
46 /// When we write USD packed prim to a USD file, we write a reference to the
47 /// original file. USD has a limitation that it can only make references to root
48 /// nodes.
49 ///
50 /// When we write a reference into a USD file, we might want to use a different
51 /// file path than we use in the Houdini session. For example, we might want to
52 /// use a relative path vs. an absolute one. We might want to use a coalesced
53 /// file vs per frame files. We don't want to enshrine this logic in the core so
54 /// we provide a second "auxilary" file name that can be used for this. If
55 /// this fileName is left empty, we just us the primary file name.
56 ///
57 
59 {
60 public:
62  const UT_StringHolder& fileName,
63  const UT_StringHolder& auxFileName,
64  const SdfPath& primPath,
65  const SdfPath& srcPrimPath,
66  exint index,
67  UsdTimeCode frame,
68  GusdPurposeSet purpose, // Unused
69  GT_AttributeListHandle pointAttributes,
70  GT_AttributeListHandle vertexAttributes,
71  GT_AttributeListHandle uniformAttributes,
72  GT_AttributeListHandle detailAttributes,
73  const GU_PrimPacked* prim );
74 
75  ~GusdGT_PackedUSD() override;
76 
77  // GT_Primitive interface --------------------------------------------------
78 public:
79  const char* className() const override;
80 
81  GT_PrimitiveHandle doSoftCopy() const override;
82 
83  static int getStaticPrimitiveType();
84 
85  int getPrimitiveType() const override;
86 
87  void enlargeBounds(UT_BoundingBox boxes[], int nsegments) const override;
88 
89  int getMotionSegments() const override;
90 
91  int64 getMemoryUsage() const override;
92 
93  const GT_AttributeListHandle& getPointAttributes() const override;
94  const GT_AttributeListHandle& getVertexAttributes() const override;
95  const GT_AttributeListHandle& getUniformAttributes() const override;
96  const GT_AttributeListHandle& getDetailAttributes() const override;
97 
98  // -------------------------------------------------------------------------
99 
100  // Get the name of the referenced USD file
101  const UT_StringHolder& getFileName() const { return m_fileName; }
102 
103  // Get the name of the referenced USD file
104  const UT_StringHolder& getAuxFileName() const { return m_auxFileName; }
105 
106  // Get the node path in the referenced USD file
107  const SdfPath& getPrimPath() const { return m_primPath; }
108 
109  const SdfPath& getSrcPrimPath() const { return m_srcPrimPath; }
110 
111  const exint& getInstanceIndex() const { return m_instanceIndex; }
112 
113  const TfToken &getTypeName() const { return m_typeName; }
114 
115 private:
116  UT_StringHolder m_fileName;
117  UT_StringHolder m_auxFileName;
118  SdfPath m_primPath;
119  SdfPath m_srcPrimPath;
120  exint m_instanceIndex;
121  UsdTimeCode m_frame;
122  UT_BoundingBox m_box;
123  TfToken m_typeName;
124 
125  GT_AttributeListHandle m_pointAttributes;
126  GT_AttributeListHandle m_vertexAttributes;
127  GT_AttributeListHandle m_uniformAttributes;
128  GT_AttributeListHandle m_detailAttributes;
129 };
130 
131 
132 //------------------------------------------------------------------------------
133 // class GusdGT_PackedUSDMesh
134 //------------------------------------------------------------------------------
135 
136 /*
137  * A utility class which supports meshes which have been coalesced together
138  * for viewport efficiency. Based on GT_PackedAlembicMesh in the HDK.
139  */
140 
142 {
143 public:
145  const GT_PrimitiveHandle& mesh,
146  int64 id,
147  UT_Array<GT_PrimitiveHandle>& sourceMeshes);
148 
149  ~GusdGT_PackedUSDMesh() override;
150 
151  const char* className() const override;
152 
153  static int getStaticPrimitiveType();
154 
155  int getPrimitiveType() const override;
156 
157  GT_PrimitiveHandle doSoftCopy() const override;
158 
159  bool refine(
160  GT_Refine& refiner,
161  const GT_RefineParms* parms=nullptr) const override;
162 
163  void enlargeBounds(
164  UT_BoundingBox boxes[],
165  int nsegments) const override;
166 
167  int getMotionSegments() const override;
168 
169  int64 getMemoryUsage() const override;
170 
171  bool getUniqueID(int64& id) const override;
172 
173 private:
174  GT_PrimitiveHandle m_mesh;
175  int64 m_id;
176  // Handles to uncoalesced meshes must be kept alive for viewport picking
177  // to work correctly.
178  UT_Array<GT_PrimitiveHandle> m_sourceMeshes;
179 };
180 
181 
182 //------------------------------------------------------------------------------
183 // class GusdGT_PrimCollect
184 //------------------------------------------------------------------------------
185 
186 /*
187  * A collector for Packed USD primitives which creates corresponding
188  * GusdGT_PackedUSD prims
189  */
190 
191 // XXX This could be named something more explicit like GusdGT_PackedUSDCollect
192 
194 {
195 public:
197  ~GusdGT_PrimCollect() override;
198 
201  const GT_GEODetailListHandle &geometry,
202  const GT_RefineParms *parms) const override;
203 
205  collect(
206  const GT_GEODetailListHandle &geo,
207  const GEO_Primitive *const* prim_list,
208  int nsegments,
209  GT_GEOPrimCollectData *data) const override;
210 
213  const GT_GEODetailListHandle &geometry,
214  GT_GEOPrimCollectData *data) const override;
215 };
216 
218 
219 
220 #endif // __GUSD_GU_PRIMCOLLECT_H__
~GusdGT_PrimCollect() override
virtual int getMotionSegments() const =0
bool getUniqueID(int64 &id) const override
virtual int getPrimitiveType() const
GT_PrimitiveHandle endCollecting(const GT_GEODetailListHandle &geometry, GT_GEOPrimCollectData *data) const override
const SdfPath & getSrcPrimPath() const
Definition: GT_PackedUSD.h:109
int64 exint
Definition: SYS_Types.h:125
const UT_StringHolder & getFileName() const
Definition: GT_PackedUSD.h:101
const TfToken & getTypeName() const
Definition: GT_PackedUSD.h:113
int getMotionSegments() const override
Collection data container.
virtual const GT_AttributeListHandle & getUniformAttributes() const
Definition: token.h:87
virtual GT_PrimitiveHandle doSoftCopy() const =0
void enlargeBounds(UT_BoundingBox boxes[], int nsegments) const override
bool refine(GT_Refine &refiner, const GT_RefineParms *parms=nullptr) const override
virtual const GT_AttributeListHandle & getDetailAttributes() const
long long int64
Definition: SYS_Types.h:116
const UT_StringHolder & getAuxFileName() const
Definition: GT_PackedUSD.h:104
GT_PrimitiveHandle collect(const GT_GEODetailListHandle &geo, const GEO_Primitive *const *prim_list, int nsegments, GT_GEOPrimCollectData *data) const override
Definition: path.h:290
The base class for all GT primitive types.
Definition: GT_Primitive.h:43
const exint & getInstanceIndex() const
Definition: GT_PackedUSD.h:111
virtual int64 getMemoryUsage() const =0
Processes primitives generated by refinement process.
Definition: GT_Refine.h:20
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
const SdfPath & getPrimPath() const
Definition: GT_PackedUSD.h:107
int64 getMemoryUsage() const override
~GusdGT_PackedUSDMesh() override
virtual const GT_AttributeListHandle & getVertexAttributes() const
GT_PrimitiveHandle doSoftCopy() const override
GLuint index
Definition: glcorearb.h:786
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
virtual const GT_AttributeListHandle & getPointAttributes() const
const char * className() const override
#define GUSD_API
Definition: api.h:40
GusdGT_PackedUSDMesh(const GT_PrimitiveHandle &mesh, int64 id, UT_Array< GT_PrimitiveHandle > &sourceMeshes)
UT_SharedPtr< GT_GEODetailList > GT_GEODetailListHandle
virtual void enlargeBounds(UT_BoundingBox boxes[], int nsegments) const =0
GusdPurposeSet
Definition: purpose.h:39
virtual const char * className() const =0
static int getStaticPrimitiveType()
Definition: format.h:895
GT_GEOPrimCollectData * beginCollecting(const GT_GEODetailListHandle &geometry, const GT_RefineParms *parms) const override
int getPrimitiveType() const override