All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_USD.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 #ifndef _GUSD_GU_USD_H_
25 #define _GUSD_GU_USD_H_
26 
27 #include <GA/GA_Attribute.h>
28 #include <GA/GA_Handle.h>
29 #include <GA/GA_Range.h>
30 #include <UT/UT_ErrorManager.h>
31 
32 #include "pxr/pxr.h"
33 
34 #include "api.h"
35 #include "defaultArray.h"
36 #include "stageCache.h"
37 #include "USD_Traverse.h"
38 #include "USD_Utils.h"
39 
40 class GA_AttributeFilter;
41 class GT_RefineParms;
42 class GU_Detail;
43 class GU_PrimPacked;
44 
45 PXR_NAMESPACE_OPEN_SCOPE
46 
49 #define GUSD_PATH_ATTR "usdpath"
50 #define GUSD_PRIMPATH_ATTR "usdprimpath"
51 #define GUSD_FRAME_ATTR "frame"
52 #define GUSD_VARIANTS_ATTR "usdvariants"
53 #define GUSD_CONSTRAINT_ATTR "usdconstraint"
54 #define GUSD_PURPOSE_ATTR "usdpurpose"
55 #define GUSD_ACTIVE_ATTR "usdactive"
56 #define GUSD_VISIBLE_ATTR "usdvisible"
57 
58 #define GUSD_OVERTRANSFORMS_ATTR "usdovertransforms"
59 #define GUSD_OVERPOINTS_ATTR "usdoverpoints"
60 #define GUSD_OVERPRIMVARS_ATTR "usdoverprimvars"
61 #define GUSD_OVERALL_ATTR "usdoverall"
62 
63 #define GUSD_WRITESTATICTOPOLOGY_ATTR "usdwritestatictopology"
64 #define GUSD_WRITESTATICPRIMVARS_ATTR "usdwritestaticprimvars"
65 #define GUSD_WRITESTATICGEO_ATTR "usdwritestaticgeo"
66 
70 class GUSD_API GusdGU_USD
71 {
72 public:
74  static bool OffsetArrayFromRange(const GA_Range& r,
75  GA_OffsetArray& offsets);
76 
78  static bool ComputeRangeIndexMap(const GA_Range& r,
79  GA_OffsetArray& indexMap);
80 
81  static bool
82  BindPrims(GusdStageCacheReader& cache,
83  UT_Array<UsdPrim>& prims,
84  const GA_Detail& gd,
85  const GA_Range& rng,
86  UT_Array<SdfPath>* variants=nullptr,
87  GusdDefaultArray<GusdPurposeSet>* purposes=nullptr,
88  GusdDefaultArray<UsdTimeCode>* times=nullptr,
89  UT_ErrorSeverity sev=UT_ERROR_ABORT);
90 
96  static bool
97  BindPrimsFromAttrs(GusdStageCacheReader& cache,
98  UT_Array<UsdPrim>& prims,
99  const GA_Range& rng,
100  const GA_Attribute& pathAttr,
101  const GA_Attribute& primPathAttr,
102  const GA_Attribute* variantsAttr,
103  UT_Array<SdfPath>* variants=nullptr,
104  UT_ErrorSeverity sev=UT_ERROR_ABORT);
105 
106  static bool
107  BindPrimsFromPackedPrims(UT_Array<UsdPrim>& prims,
108  const GA_Range& rng,
109  UT_Array<SdfPath>* variants=nullptr,
110  UT_Array<GusdPurposeSet>* purposes=nullptr,
111  UT_ErrorSeverity sev=UT_ERROR_ABORT);
112 
113  static bool GetTimeCodesFromAttr(const GA_Range& rng,
114  const GA_Attribute& attr,
115  UT_Array<UsdTimeCode>& times);
116 
117  static bool GetTimeCodesFromPackedPrims(const GA_Range& rng,
118  UT_Array<UsdTimeCode>& times);
119 
123  static bool GetPrimPathsFromStringAttr(const GA_Attribute& attr,
124  UT_Array<SdfPath>& paths,
125  UT_ErrorSeverity sev=UT_ERROR_ABORT);
126 
127  static bool GetPrimPathsFromStringAttr(const GA_Attribute& attr,
128  const GA_Range& rng,
129  UT_Array<SdfPath>& paths,
130  UT_ErrorSeverity sev=UT_ERROR_ABORT);
136  static bool GetTokensFromStringAttr(const GA_Attribute& attr,
137  UT_Array<TfToken>& tokens,
138  const char* nameSpace=nullptr);
139 
140  static bool GetTokensFromStringAttr(const GA_Attribute& attr,
141  const GA_Range& rng,
142  UT_Array<TfToken>& tokens,
143  const char* nameSpace=nullptr);
151  static GA_Offset AppendRefPoints(
152  GU_Detail& gd,
153  const UT_Array<UsdPrim>& prims,
154  const char* pathAttrName=GUSD_PATH_ATTR,
155  const char* primPathAttrName=GUSD_PRIMPATH_ATTR);
156 
157  typedef GU_PrimPacked* (*PackedPrimBuildFunc)(
158  GU_Detail& detail,
159  const UT_StringHolder& fileName,
160  const SdfPath& primPath,
161  const UsdTimeCode& frame,
162  const char* lod,
163  const GusdPurposeSet purposes );
164 
167  static void RegisterPackedPrimBuildFunc( const TfToken& typeName,
168  PackedPrimBuildFunc func );
169 
172  static bool AppendPackedPrims(
173  GU_Detail& gd,
174  const UT_Array<UsdPrim>& prims,
175  const UT_Array<SdfPath>& variants,
176  const GusdDefaultArray<UsdTimeCode>& times,
178  const GusdDefaultArray<GusdPurposeSet>& purposes);
179 
180  typedef GusdUSD_Traverse::PrimIndexPair PrimIndexPair;
181 
188  static GA_Offset AppendExpandedRefPoints(
189  GU_Detail& gd,
190  const GA_Detail& srcGd,
191  const GA_Range& srcRng,
192  const UT_Array<PrimIndexPair>& prims,
193  const GA_AttributeFilter& filter,
194  const char* pathAttrName=GUSD_PATH_ATTR,
195  const char* primPathAttrName=GUSD_PRIMPATH_ATTR);
196 
197  static bool AppendExpandedPackedPrims(
198  GU_Detail& gd,
199  const GA_Detail& srcGd,
200  const GA_Range& srcRng,
201  const UT_Array<PrimIndexPair>& primIndexPairs,
202  const UT_Array<SdfPath>& variants,
203  const GusdDefaultArray<UsdTimeCode>& times,
204  const GA_AttributeFilter& filter,
205  bool unpackToPolygons,
206  const UT_String& primvarPattern);
207 
214  static bool WriteVariantSelectionsToAttr(
215  GU_Detail& gd,
216  const GA_Range& rng,
217  const UT_Array<UsdPrim>& prims,
218  const GusdUSD_Utils::VariantSelArray& selections,
219  const char* variantsAttr=GUSD_VARIANTS_ATTR,
220  const UT_Array<SdfPath>* prevVariants=nullptr);
221 
222  static bool WriteVariantSelectionsToPackedPrims(
223  GU_Detail& gd,
224  const GA_Range& rng,
225  const UT_Array<UsdPrim>& prims,
226  const GusdUSD_Utils::VariantSelArray& selections,
227  const UT_Array<SdfPath>* prevVariants=nullptr);
228 
233  static GA_Offset AppendRefPointsForExpandedVariants(
234  GU_Detail& gd,
235  const GA_Detail& srcGd,
236  const GA_Range& srcRng,
237  const UT_Array<UT_StringHolder>& orderedVariants,
238  const GusdUSD_Utils::IndexPairArray& variantIndices,
239  const GA_AttributeFilter& filter,
240  const char* variantsAttr=GUSD_VARIANTS_ATTR);
241 
242  static GA_Offset AppendPackedPrimsForExpandedVariants(
243  GU_Detail& gd,
244  const GA_Detail& srcGd,
245  const GA_Range& srcRng,
246  const UT_Array<UT_StringHolder>& orderedVariants,
247  const GusdUSD_Utils::IndexPairArray& variantIndices,
248  const GA_AttributeFilter& filter);
249 
251  static bool CopyAttributes(
252  const GA_Range& srcRng,
253  const GA_Range& dstRng,
254  const GA_IndexMap& dstMap,
255  const UT_Array<const GA_Attribute*>& attrs);
256 
257  static bool GetPackedPrimViewportLODAndPurposes(
258  const GA_Detail& gd,
259  const GA_OffsetArray& offsets,
260  UT_StringArray& viewportLOD,
261  UT_Array<GusdPurposeSet>& purposes);
262 
269  static bool ComputeTransformsFromAttrs(const GA_Detail& gd,
270  GA_AttributeOwner owner,
271  const GA_OffsetArray& offsets,
272  UT_Matrix4D* xforms);
273 
274  static bool ComputeTransformsFromPackedPrims(const GA_Detail& gd,
275  const GA_OffsetArray& offsets,
276  UT_Matrix4D* xforms);
277 
280  {
281  ORIENTATTR_ORIENT,
283  ORIENTATTR_IGNORE
284  };
285 
287  {
288  SCALEATTR_SCALE,
290  SCALEATTR_IGNORE
291  };
292 
296  static bool SetTransformAttrs(GU_Detail& gd,
297  const GA_Range& r,
298  const GA_OffsetArray& indexMap,
299  OrientAttrRepresentation orientRep,
300  ScaleAttrRepresentation scaleRep,
301  const UT_Matrix4D* xforms);
302 
303  static bool SetPackedPrimTransforms(GU_Detail& gd,
304  const GA_Range& r,
305  const UT_Matrix4D* xforms);
306 
307  static bool MultTransformableAttrs(GU_Detail& gd,
308  const GA_Range& r,
309  const GA_OffsetArray& indexMap,
310  const UT_Matrix4D* xforms,
311  bool keepLengths=false,
312  const GA_AttributeFilter* filter=nullptr);
313 
315  static bool ImportPrimUnpacked(GU_Detail& gd,
316  const UsdPrim& prim,
317  UsdTimeCode time,
318  const char* lod = nullptr,
319  GusdPurposeSet purpose = GusdPurposeSet(
320  GUSD_PURPOSE_DEFAULT|GUSD_PURPOSE_PROXY),
321  const char* primvarPattern = "*",
322  const UT_Matrix4D* xform = nullptr,
323  const GT_RefineParms* refineParms = nullptr);
324 };
325 
326 PXR_NAMESPACE_CLOSE_SCOPE
327 
328 #endif /*_GUSD_GU_USD_H_*/
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
Set of helpers for working with ranges of prims/points, etc.
Definition: GU_USD.h:70
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
Methods for USD scene traversal.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:131
quaternion orient.
Definition: GU_USD.h:282
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
ScaleAttrRepresentation
Definition: GU_USD.h:286
OrientAttrRepresentation
Support representations of attributes when authoring new transforms.
Definition: GU_USD.h:279
Helper for reading from a GusdStageCache.
Definition: stageCache.h:141