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 PRM_Parm;
28 class OP_Node;
29 
36 
37  // By default, we only require that a primitive be "defined", meaning it
38  // is a fully instantiated prim, not just an "over" with an incomplete set
39  // of attributes and metadata.
42 };
43 
44 // This enum specifies how a reference or sublayer or payload file reference
45 // is stored in the referring layer. The AUTO method stores paths specified
46 // as relative paths as relative paths, and paths specified as absolute paths
47 // as absolute paths. Paths specified as Search Paths (neither relative nor
48 // absolute) are always saved as-is.
50 {
54 };
55 
56 // This is the order of the viewport overrides layers. Note that they are
57 // ordered strongest to weakest, so the "solo" layers override the base layer,
58 // and the "custom" layer overrides the "solo" layers.
64 };
65 #define HUSD_OVERRIDES_NUM_LAYERS 4
66 
67 // 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 
114 /// Returns true if name is a valid identifier (ie, valid component of a path).
115 HUSD_API bool
117 
118 // Modifies the passed in string to make sure it conforms to USD primitive
119 // naming restrictions. Illegal characters are replaced by underscores.
120 HUSD_API bool
121 HUSDmakeValidUsdName(UT_String &name, bool addwarnings);
122 
123 // Returns the name of the node passed through the HUSDmakeValidUsdName method.
124 // This saves several lines of code every time we use this pattern.
127 
128 // Modifies the passed in string to make sure it conforms to USD primitive
129 // naming restrictions. Illegal characters are replaced by underscores. Each
130 // path component is validated separately. The returned path will always be
131 // an absolute path, prefixing "/" to any passed in relative path.
132 HUSD_API bool
133 HUSDmakeValidUsdPath(UT_String &path, bool addwarnings);
134 // As the above function, except it has the option of allowing the passed in
135 // and returned path to be a relative path.
136 HUSD_API bool
137 HUSDmakeValidUsdPath(UT_String &path, bool addwarnings, bool allow_relative);
138 // Like the above method, but accepts "defaultPrim" as well.
139 HUSD_API bool
141 
142 // Returns the path of the node passed through the HUSDmakeValidUsdPath method.
143 // This saves several lines of code every time we use this pattern.
146 
147 // Modifies the passed in string to make sure it conforms to USD property
148 // naming restrictions. This includes allowing multiple nested namespaces
149 // in the name. Illegal characters are replaced by underscores.
150 HUSD_API bool
151 HUSDmakeValidUsdPropertyName(UT_String &name, bool addwarnings);
152 
153 // Modifies the passed in string to make sure it conforms to USD variant
154 // naming restrictions. Note that these are different from normal primitive
155 // naming conventions, as defined in SdfSchemaBase::IsValidVariantIdentifier:
156 // One or more letter, number, '_', '|', or '-', with an optional leading '.'
157 // Illegal characters are replaced by underscores.
158 HUSD_API bool
159 HUSDmakeValidVariantName(UT_String &name, bool addwarnings);
160 
161 // Modifies the passed in string to make sure it conforms to USD primitive
162 // naming restrictions. Leading slashes are thrown away. Illegal characters
163 // are considered an error and cause this function to return false.
164 HUSD_API bool
165 HUSDmakeValidDefaultPrim(UT_String &default_prim, bool addwarnings);
166 
167 // Returns primitive name, given the primitive path.
169 HUSDgetUsdName(const UT_StringRef &primpath);
170 
171 // Returns primitive's parent path, given the primitive path.
173 HUSDgetUsdParentPath(const UT_StringRef &primpath);
174 
175 // Return the primary alias for the specified USD primitive type.
177 HUSDgetPrimTypeAlias(const UT_StringRef &primtype);
178 
179 // If layers are stripped during a flatten operation, this function handles
180 // the error creation based on the requested response. Returns true of the
181 // requested response is to generate an error, which usually means we should
182 // also stop processing.
183 HUSD_API bool
185 
186 /// Enum of USD transform operation types.
187 /// Note, they need to correspond to UsgGeomXformOp::Type enum.
188 enum class HUSD_XformType {
189  Invalid,
190  Translate,
191  Scale,
194  Orient,
195  Transform
196 };
197 
198 /// Enum of rotation axis.
199 enum class HUSD_XformAxis { X, Y, Z };
200 
201 /// Enum of rotation order.
202 enum class HUSD_XformAxisOrder { XYZ, XZY, YXZ, YZX, ZXY, ZYX };
203 
204 /// @{ Functions for obtaining transform name, suffix, and type.
206  UT_StringHolder &xform_namesuffix,
207  const UT_StringRef& xform_fullname);
211  const UT_StringRef &xform_namesuffix);
213  UT_StringHolder *xform_type = nullptr,
214  UT_StringHolder *xform_name = nullptr);
215 /// @}
216 
217 /// @{ Manipulate collection paths and components. The individual components
218 /// must be validated (see HUSDmakeValidName and HUSDmakeValidPath) before
219 /// calling these methods.
221  const UT_StringRef &collection_name);
223  UT_StringHolder &collection_name,
224  const UT_StringRef &collection_path);
226 /// @}
227 
228 /// @{ Create property paths from their components. The individual components
229 /// must be validated (see HUSDmakeValidName and HUSDmakeValidPath) before
230 /// calling these methods.
232  const UT_StringRef &property_name);
234  const UT_StringRef &attribute_name);
236  const UT_StringRef &relationship_name);
237 /// @}
238 
239 /// Returns the attribute name of the given primvar
241 
242 /// Returns the time code at which to author an attribute value.
244  const HUSD_TimeCode &timecode,
245  HUSD_TimeSampling time_sampling);
246 
247 /// Returns true if there are more than one time samples.
248 HUSD_API bool HUSDisTimeVarying(HUSD_TimeSampling time_sampling);
249 
250 /// Returns true if there is at least one time sample.
251 HUSD_API bool HUSDisTimeSampled(HUSD_TimeSampling time_sampling);
252 
253 /// Set a parameter value from the value of a USD property.
255  const UT_StringRef &primpath,
256  const UT_StringRef &attribname,
257  const HUSD_TimeCode &tc,
258  PRM_Parm &parm,
259  HUSD_TimeSampling &timesampling);
260 
261 #endif
262 
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 bool HUSDisValidUsdName(const UT_StringRef &name)
Returns true if name is a valid identifier (ie, valid component of a path).
HUSD_API bool HUSDsetParmFromProperty(HUSD_AutoAnyLock &lock, const UT_StringRef &primpath, const UT_StringRef &attribname, const HUSD_TimeCode &tc, PRM_Parm &parm, HUSD_TimeSampling &timesampling)
Set a parameter value from the value of a USD property.
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:30
HUSD_XformAxis
Enum of rotation axis.
Definition: HUSD_Utils.h:199
HUSD_OverridesLayerId
Definition: HUSD_Utils.h:59
HUSD_Variability
Definition: HUSD_Utils.h:68
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:188
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
HUSD_API bool HUSDmakeValidVariantName(UT_String &name, bool addwarnings)
HUSD_API UT_StringHolder HUSDmakeAttributePath(const UT_StringRef &prim_path, const UT_StringRef &attribute_name)
fpreal64 fpreal
Definition: SYS_Types.h:277
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:202
HUSD_PathSaveStyle
Definition: HUSD_Utils.h:49
HUSD_API UT_StringHolder HUSDgetPrimvarAttribName(const UT_StringRef &primvar)
Returns the attribute name of the given primvar.
HUSD_API bool HUSDapplyStripLayerResponse(HUSD_StripLayerResponse response)
const GLfloat * tc
Definition: glew.h:16304
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)