HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HUSD_Utils.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Side Effects Software Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #ifndef __HUSD_Utils_h__
19 #define __HUSD_Utils_h__
20 
21 #include "HUSD_API.h"
22 #include "HUSD_DataHandle.h"
23 #include <UT/UT_StringHolder.h>
24 
25 class HUSD_TimeCode;
26 class UT_String;
27 class OP_Node;
28 
35 
36  // By default, we only require that a primitive be "defined", meaning it
37  // is a fully instantiated prim, not just an "over" with an incomplete set
38  // of attributes and metadata.
41 };
42 
43 // This enum specifies how a reference or sublayer or payload file reference
44 // is stored in the referring layer. The AUTO method stores paths specified
45 // as relative paths as relative paths, and paths specified as absolute paths
46 // as absolute paths. Paths specified as Search Paths (neither relative nor
47 // absolute) are always saved as-is.
49 {
53 };
54 
55 // This is the order of the viewport overrides layers. Note that they are
56 // ordered strongest to weakest, so the "solo" layers override the base layer,
57 // and the "custom" layer overrides the "solo" layers.
63 };
64 #define HUSD_OVERRIDES_NUM_LAYERS 4
65 
66 // Enum valus that correspond to the SdfVariability values in the USD library.
71 };
72 
73 // Enum describing possible behaviors when layers are stripped off because of
74 // a layer break operation.
79 };
80 
81 // Enum describing the possible time sampling levels.
82 enum class HUSD_TimeSampling {
83  NONE, // no time samples; just the default value (not time varying)
84  SINGLE, // single time sample exists (value is not really time varying)
85  MULTIPLE // more than one time sample exists (value may be time varying)
86 };
87 
88 // Callback function to be defined in the LOP library that returns a locked
89 // stage pointer for a LOP node given an "op:" prefixed path.
91 
92 // Configures the USD library for use within Houdini. The primary purpose is to
93 // set the prefered ArResolver to be the Houdini resolver. This should be
94 // called as soon as possible after loading the HUSD library.
95 HUSD_API void
97 
98 // Set the callback function that is used by the HUSD library to resolve a
99 // LOP node path into an HUSD_LockedStagePtr. This callback is used to help
100 // populate the GusdStageCache for a USD packed primitive with a "file" path
101 // that points to a LOP node using an "op:" style path.
102 HUSD_API void
104 
105 // Calls the GusdStageCache::SplitLopStageIdentifier method, without having to
106 // inclde the stageCache.h header, which is not allowed in the LOP library.
107 HUSD_API bool
108 HUSDsplitLopStageIdentifier(const UT_StringRef &identifier,
109  OP_Node *&lop,
110  bool &split_layers,
111  fpreal &t);
112 
113 // Modifies the passed in string to make sure it conforms to USD primitive
114 // naming restrictions. Illegal characters are replaced by underscores.
115 HUSD_API bool
116 HUSDmakeValidUsdName(UT_String &name, bool addwarnings);
117 
118 // Returns the name of the node passed through the HUSDmakeValidUsdName method.
119 // This saves several lines of code every time we use this pattern.
122 
123 // Modifies the passed in string to make sure it conforms to USD primitive
124 // naming restrictions. Illegal characters are replaced by underscores. Each
125 // path component is validated separately.
126 HUSD_API bool
127 HUSDmakeValidUsdPath(UT_String &path, bool addwarnings);
128 // Like the above method, but accepts "defaultPrim" as well.
129 HUSD_API bool
131 
132 // Returns the path of the node passed through the HUSDmakeValidUsdPath method.
133 // This saves several lines of code every time we use this pattern.
136 
137 // Modifies the passed in string to make sure it conforms to USD property
138 // naming restrictions. This includes allowing multiple nested namespaces
139 // in the name. Illegal characters are replaced by underscores.
140 HUSD_API bool
141 HUSDmakeValidUsdPropertyName(UT_String &name, bool addwarnings);
142 
143 // Modifies the passed in string to make sure it conforms to USD variant
144 // naming restrictions. Note that these are different from normal primitive
145 // naming conventions, as defined in SdfSchemaBase::IsValidVariantIdentifier:
146 // One or more letter, number, '_', '|', or '-', with an optional leading '.'
147 // Illegal characters are replaced by underscores.
148 HUSD_API bool
149 HUSDmakeValidVariantName(UT_String &name, bool addwarnings);
150 
151 // Modifies the passed in string to make sure it conforms to USD primitive
152 // naming restrictions. Leading slashes are thrown away. Illegal characters
153 // are considered an error and cause this function to return false.
154 HUSD_API bool
155 HUSDmakeValidDefaultPrim(UT_String &default_prim, bool addwarnings);
156 
157 // Returns primitive name, given the primitive path.
159 HUSDgetUsdName(const UT_StringRef &primpath);
160 
161 // Returns primitive's parent path, given the primitive path.
163 HUSDgetUsdParentPath(const UT_StringRef &primpath);
164 
165 // Return the primary alias for the specified USD primitive type.
167 HUSDgetPrimTypeAlias(const UT_StringRef &primtype);
168 
169 // If layers are stripped during a flatten operation, this function handles
170 // the error creation based on the requested response. Returns true of the
171 // requested response is to generate an error, which usually means we should
172 // also stop processing.
173 HUSD_API bool
175 
176 /// Enum of USD transform operation types.
177 /// Note, they need to correspond to UsgGeomXformOp::Type enum.
178 enum class HUSD_XformType {
179  Invalid,
180  Translate,
181  Scale,
184  Orient,
185  Transform
186 };
187 
188 /// Enum of rotation axis.
189 enum class HUSD_XformAxis { X, Y, Z };
190 
191 /// Enum of rotation order.
192 enum class HUSD_XformAxisOrder { XYZ, XZY, YXZ, YZX, ZXY, ZYX };
193 
194 /// @{ Functions for obtaining transform name, suffix, and type.
196  UT_StringHolder &xform_namesuffix,
197  const UT_StringRef& xform_fullname);
201  const UT_StringRef &xform_namesuffix);
203  UT_StringHolder *xform_type = nullptr,
204  UT_StringHolder *xform_name = nullptr);
205 /// @}
206 
207 /// @{ Manipulate collection paths and components. The individual components
208 /// must be validated (see HUSDmakeValidName and HUSDmakeValidPath) before
209 /// calling these methods.
211  const UT_StringRef &collection_name);
213  UT_StringHolder &collection_name,
214  const UT_StringRef &collection_path);
216 /// @}
217 
218 /// @{ Create property paths from their components. The individual components
219 /// must be validated (see HUSDmakeValidName and HUSDmakeValidPath) before
220 /// calling these methods.
222  const UT_StringRef &property_name);
224  const UT_StringRef &attribute_name);
226  const UT_StringRef &relationship_name);
227 /// @}
228 
229 /// Returns the attribute name of the given primvar
231 
232 /// Returns the time code at which to author an attribute value.
234  const HUSD_TimeCode &timecode,
235  HUSD_TimeSampling time_sampling);
236 
237 /// Returns true if there are more than one time samples.
238 HUSD_API bool HUSDisTimeVarying(HUSD_TimeSampling time_sampling);
239 
240 /// Returns true if there is at least one time sample.
241 HUSD_API bool HUSDisTimeSampled(HUSD_TimeSampling time_sampling);
242 
243 #endif
244 
HUSD_API bool HUSDmakeValidDefaultPrim(UT_String &default_prim, bool addwarnings)
GLuint const GLchar * name
Definition: glew.h:1814
HUSD_API UT_StringHolder HUSDmakePropertyPath(const UT_StringRef &prim_path, const UT_StringRef &property_name)
HUSD_LockedStagePtr(* HUSD_LopStageResolver)(const UT_StringRef &path)
Definition: HUSD_Utils.h:90
HUSD_API void HUSDinitialize()
HUSD_API UT_StringHolder HUSDgetValidUsdPath(OP_Node &node)
HUSD_API void HUSDsetLopStageResolver(HUSD_LopStageResolver resolver)
#define HUSD_API
Definition: HUSD_API.h:32
HUSD_API bool HUSDmakeValidUsdPropertyName(UT_String &name, bool addwarnings)
HUSD_API bool HUSDsplitLopStageIdentifier(const UT_StringRef &identifier, OP_Node *&lop, bool &split_layers, fpreal &t)
HUSD_API bool HUSDmakeValidUsdPath(UT_String &path, bool addwarnings)
HUSD_API UT_StringHolder HUSDgetUsdName(const UT_StringRef &primpath)
HUSD_PrimTraversalDemands
Definition: HUSD_Utils.h:29
HUSD_XformAxis
Enum of rotation axis.
Definition: HUSD_Utils.h:189
HUSD_OverridesLayerId
Definition: HUSD_Utils.h:58
HUSD_Variability
Definition: HUSD_Utils.h:67
HUSD_API UT_StringHolder HUSDmakeCollectionPath(const UT_StringRef &prim_path, const UT_StringRef &collection_name)
HUSD_API UT_StringHolder HUSDgetUsdParentPath(const UT_StringRef &primpath)
HUSD_XformType
Definition: HUSD_Utils.h:178
HUSD_API bool HUSDmakeValidUsdName(UT_String &name, bool addwarnings)
HUSD_TimeSampling
Definition: HUSD_Utils.h:82
HUSD_API bool HUSDisValidCollectionPath(const UT_StringRef &path)
HUSD_API bool HUSDisXformAttribute(const UT_StringRef &attr, UT_StringHolder *xform_type=nullptr, UT_StringHolder *xform_name=nullptr)
Functions for obtaining transform name, suffix, and type.
HUSD_API UT_StringHolder HUSDmakeRelationshipPath(const UT_StringRef &prim_path, const UT_StringRef &relationship_name)
HUSD_API UT_StringHolder HUSDgetXformSuffix(const UT_StringRef &xform_fullname)
Functions for obtaining transform name, suffix, and type.
HUSD_API bool HUSDgetXformTypeAndSuffix(HUSD_XformType &xform_type, UT_StringHolder &xform_namesuffix, const UT_StringRef &xform_fullname)
Functions for obtaining transform name, suffix, and type.
HUSD_API bool HUSDsplitCollectionPath(UT_StringHolder &prim_path, UT_StringHolder &collection_name, const UT_StringRef &collection_path)
HUSD_StripLayerResponse
Definition: HUSD_Utils.h:75
HUSD_API HUSD_TimeCode HUSDgetEffectiveTimeCode(const HUSD_TimeCode &timecode, HUSD_TimeSampling time_sampling)
Returns the time code at which to author an attribute value.
HUSD_API bool HUSDisTimeVarying(HUSD_TimeSampling time_sampling)
Returns true if there are more than one time samples.
HUSD_API bool HUSDmakeValidUsdPathOrDefaultPrim(UT_String &path, bool addwarnings)
GLsizei const GLchar *const * path
Definition: glew.h:6461
double fpreal
Definition: SYS_Types.h:276
HUSD_API bool HUSDmakeValidVariantName(UT_String &name, bool addwarnings)
HUSD_API UT_StringHolder HUSDmakeAttributePath(const UT_StringRef &prim_path, const UT_StringRef &attribute_name)
UT_SharedPtr< HUSD_LockedStage > HUSD_LockedStagePtr
HUSD_API UT_StringHolder HUSDgetXformName(HUSD_XformType xform_type, const UT_StringRef &xform_namesuffix)
Functions for obtaining transform name, suffix, and type.
HUSD_XformAxisOrder
Enum of rotation order.
Definition: HUSD_Utils.h:192
HUSD_PathSaveStyle
Definition: HUSD_Utils.h:48
HUSD_API UT_StringHolder HUSDgetPrimvarAttribName(const UT_StringRef &primvar)
Returns the attribute name of the given primvar.
HUSD_API bool HUSDapplyStripLayerResponse(HUSD_StripLayerResponse response)
HUSD_API HUSD_XformType HUSDgetXformType(const UT_StringRef &xform_fullname)
Functions for obtaining transform name, suffix, and type.
HUSD_API bool HUSDisTimeSampled(HUSD_TimeSampling time_sampling)
Returns true if there is at least one time sample.
HUSD_API UT_StringHolder HUSDgetPrimTypeAlias(const UT_StringRef &primtype)
GLdouble GLdouble t
Definition: glew.h:1398
HUSD_API UT_StringHolder HUSDgetValidUsdName(OP_Node &node)