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(const GusdGT_PackedUSD& other);
76 
77  ~GusdGT_PackedUSD() override;
78 
79  // GT_Primitive interface --------------------------------------------------
80 public:
81  const char* className() const override;
82 
83  GT_PrimitiveHandle doSoftCopy() const override;
84 
85  GUSD_API
86  static int getStaticPrimitiveType();
87 
88  int getPrimitiveType() const override;
89 
90  void enlargeBounds(UT_BoundingBox boxes[], int nsegments) const override;
91 
92  int getMotionSegments() const override;
93 
94  int64 getMemoryUsage() const override;
95 
96  const GT_AttributeListHandle& getPointAttributes() const override;
97  const GT_AttributeListHandle& getVertexAttributes() const override;
98  const GT_AttributeListHandle& getUniformAttributes() const override;
99  const GT_AttributeListHandle& getDetailAttributes() const override;
100 
101  // -------------------------------------------------------------------------
102 
103  // Get the name of the referenced USD file
104  const UT_StringHolder& getFileName() const { return m_fileName; }
105 
106  // Get the name of the referenced USD file
107  const UT_StringHolder& getAuxFileName() const { return m_auxFileName; }
108 
109  // Get the node path in the referenced USD file
110  const SdfPath& getPrimPath() const { return m_primPath; }
111 
112  const SdfPath& getSrcPrimPath() const { return m_srcPrimPath; }
113 
114  const exint& getInstanceIndex() const { return m_instanceIndex; }
115 
116 private:
117  UT_StringHolder m_fileName;
118  UT_StringHolder m_auxFileName;
119  SdfPath m_primPath;
120  SdfPath m_srcPrimPath;
121  exint m_instanceIndex;
122  UsdTimeCode m_frame;
123  UT_BoundingBox m_box;
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
bool getUniqueID(int64 &id) const override
static GUSD_API int getStaticPrimitiveType()
GT_PrimitiveHandle endCollecting(const GT_GEODetailListHandle &geometry, GT_GEOPrimCollectData *data) const override
const SdfPath & getSrcPrimPath() const
Definition: GT_PackedUSD.h:112
int64 exint
Definition: SYS_Types.h:125
const UT_StringHolder & getFileName() const
Definition: GT_PackedUSD.h:104
int getMotionSegments() const override
Collection data container.
int getPrimitiveType() const override
void enlargeBounds(UT_BoundingBox boxes[], int nsegments) const override
void enlargeBounds(UT_BoundingBox boxes[], int nsegments) const override
bool refine(GT_Refine &refiner, const GT_RefineParms *parms=nullptr) const override
~GusdGT_PackedUSD() override
GusdGT_PackedUSD(const UT_StringHolder &fileName, const UT_StringHolder &auxFileName, const SdfPath &primPath, const SdfPath &srcPrimPath, exint index, UsdTimeCode frame, GusdPurposeSet purpose, GT_AttributeListHandle pointAttributes, GT_AttributeListHandle vertexAttributes, GT_AttributeListHandle uniformAttributes, GT_AttributeListHandle detailAttributes, const GU_PrimPacked *prim)
long long int64
Definition: SYS_Types.h:116
int getMotionSegments() const override
int64 getMemoryUsage() const override
const UT_StringHolder & getAuxFileName() const
Definition: GT_PackedUSD.h:107
const GT_AttributeListHandle & getUniformAttributes() const override
GT_PrimitiveHandle collect(const GT_GEODetailListHandle &geo, const GEO_Primitive *const *prim_list, int nsegments, GT_GEOPrimCollectData *data) const override
const GT_AttributeListHandle & getPointAttributes() const override
Definition: path.h:288
The base class for all GT primitive types.
Definition: GT_Primitive.h:43
GT_PrimitiveHandle doSoftCopy() const override
const exint & getInstanceIndex() const
Definition: GT_PackedUSD.h:114
const char * className() const override
Processes primitives generated by refinement process.
Definition: GT_Refine.h:20
GLboolean * data
Definition: glcorearb.h:130
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
const GT_AttributeListHandle & getVertexAttributes() const override
const SdfPath & getPrimPath() const
Definition: GT_PackedUSD.h:110
int64 getMemoryUsage() const override
~GusdGT_PackedUSDMesh() override
GT_PrimitiveHandle doSoftCopy() const override
GLuint index
Definition: glcorearb.h:785
const GT_AttributeListHandle & getDetailAttributes() const override
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
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
GusdPurposeSet
Definition: purpose.h:39
static int getStaticPrimitiveType()
GT_GEOPrimCollectData * beginCollecting(const GT_GEODetailListHandle &geometry, const GT_RefineParms *parms) const override
int getPrimitiveType() const override