HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
attribListsBuilder.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5 */
6 
7 #ifndef GUSD_ATTRIBLISTSBUILDER_H
8 #define GUSD_ATTRIBLISTSBUILDER_H
9 
10 #include "api.h"
11 
12 #include <GT/GT_Handles.h>
13 #include <GT/GT_Types.h>
14 #include <UT/UT_SmallArray.h>
15 #include <UT/UT_StringArray.h>
16 #include <UT/UT_StringHolder.h>
17 
18 #include <pxr/pxr.h>
19 
21 
22 struct GusdPrimvarInfo;
23 
24 /// Utility for efficiently building the GT_AttributeList for each owner type.
26 {
27 public:
28  /// Enable collecting point attributes and configure the required number of
29  /// entries for the arrays.
30  void enablePointAttribs(exint num_points);
31 
32  /// Enable collecting vertex attributes and configure the required number of
33  /// entries for the arrays.
34  void enableVertexAttribs(exint num_vertices);
35 
36  /// Enable collecting uniform attributes and configure the required number
37  /// of entries for the arrays.
38  void enableUniformAttribs(exint num_uniform);
39 
40  /// Enable collecting constant / detail attributes.
41  void enableDetailAttribs();
42 
43  /// Configure whether constant attributes should be promoted to another
44  /// owner. GT_OWNER_DETAIL disables promotion.
45  /// (Note that GU_MergeUtils may layer promote mismatched detail attribs)
47  {
48  myPromoteConstantAttribs = owner;
49  }
50 
51  /// Add an attribute to the appropriate owner's list. Constant attributes
52  /// may be promoted to the owner configured by setPromoteConstantAttribs().
53  /// This may fail if, for example, the data array doesn't match the
54  /// required number of entries, or if the owner type is not enabled.
55  bool add(const GusdPrimvarInfo &info, const GT_DataArrayHandle &data);
56 
57  /// Build the GT_AttributeList for point attributes. This may return nullptr
58  /// if there aren't any attributes.
59  GT_AttributeListHandle buildPointAttribs() const;
60 
61  /// Build the GT_AttributeList for vertex attributes. This may return
62  /// nullptr if there aren't any attributes.
63  GT_AttributeListHandle buildVertexAttribs() const;
64 
65  /// Build the GT_AttributeList for uniform attributes. This may return
66  /// nullptr if there aren't any attributes.
67  GT_AttributeListHandle buildUniformAttribs() const;
68 
69  /// Build the GT_AttributeList for detail attributes. This may return
70  /// nullptr if there aren't any attributes.
71  GT_AttributeListHandle buildDetailAttribs();
72 
73 private:
74  /// Record the attribute in the appropriate usdconfig* attribute(s).
75  void recordUsdConfigAttribs(const GusdPrimvarInfo &info);
76 
77  /// Builder implementation for a single GT_AttributeList.
78  class GUSD_API ListBuilder
79  {
80  public:
81  void enable(exint min_entries);
82 
83  bool isEnabled() const { return myEnabled; }
84  exint getMinEntries() const { return myMinEntries; }
85 
86  bool add(const GusdPrimvarInfo &info, const GT_DataArrayHandle &data);
87 
88  GT_AttributeListHandle makeList() const;
89 
90  private:
91  bool myEnabled = false;
92  exint myMinEntries = 0;
95  };
96 
97  ListBuilder myPointAttribs;
98  ListBuilder myVertexAttribs;
99  ListBuilder myUniformAttribs;
100  ListBuilder myDetailAttribs;
101  GT_Owner myPromoteConstantAttribs = GT_OWNER_DETAIL;
102 
103  /// @{
104  /// To correctly round-trip certain attribute types back to USD, we add
105  /// configuration attributes such as `usdconfigboolattribs` to the geometry
106  /// to indicate how they should be handled by the SOP Import LOP.
107  UT_StringArray myConstantAttribs;
108  UT_StringArray myScalarConstantAttribs;
109  UT_StringArray myBoolAttribs;
110  UT_StringArray myUIntAttribs;
111  UT_StringArray myUInt64Attribs;
112  UT_StringArray myAssetPathAttribs;
113  UT_StringArray myIndexedAttribs;
114  /// @}
115 };
116 
118 
119 #endif
void setPromoteConstantAttribs(GT_Owner owner)
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
Utility for efficiently building the GT_AttributeList for each owner type.
int64 exint
Definition: SYS_Types.h:125
GT_Owner
Definition: GT_Types.h:90
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
#define GUSD_API
Definition: api.h:42
ImageBuf OIIO_API add(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
Definition: format.h:1821