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 "HUSD_Path.h"
24 #include <UT/UT_StringHolder.h>
25 #include <UT/UT_IntArray.h>
26 #include <UT/UT_Map.h>
27 
28 class HUSD_PathSet;
29 class HUSD_TimeCode;
30 class UT_String;
32 class PRM_Parm;
33 class OP_Node;
34 
41 
42  // This value is only used to create the scene graph tree through
43  // HUSD_PrimHandle. It should never be used to find prims to edit.
45 
46  // This places no limitations on which prims to return, but will not
47  // return instance proxies or prototype prims.
49 
50  // By default, place no demands on the traversal. This will even return
51  // pure "over" primitives, which may have incomplete definitions.
53 };
54 
55 // This enum specifies how a reference or sublayer or payload file reference
56 // is stored in the referring layer. The AUTO method stores paths specified
57 // as relative paths as relative paths, and paths specified as absolute paths
58 // as absolute paths. Paths specified as Search Paths (neither relative nor
59 // absolute) are always saved as-is.
61 {
65 };
66 
67 // This is the order of the viewport overrides layers. Note that they are
68 // ordered strongest to weakest, so the "solo" layers override the base layer,
69 // and the "custom" layer overrides the "solo" layers.
75 };
76 #define HUSD_OVERRIDES_NUM_LAYERS 4
77 
78 // Enum values that correspond to the SdfVariability values in the USD library.
82 };
83 
84 // Enum describing possible behaviors when layers are stripped off because of
85 // a layer break operation.
90 };
91 
92 // Enum describing the possible time sampling levels.
93 enum class HUSD_TimeSampling {
94  NONE, // no time samples; just the default value (not time varying)
95  SINGLE, // single time sample exists (value is not really time varying)
96  MULTIPLE // more than one time sample exists (value may be time varying)
97 };
98 
99 // Callback function to be defined in the LOP library that returns a locked
100 // stage pointer for a LOP node given an "op:" prefixed path.
102 
103 // A list of path strings that contain instance id numbers (possibly nested).
104 // Expressed with a typedef in case we decide to make this a more efficient
105 // data structure in the future.
107 
108 // Configures the USD library for use within Houdini. The primary purpose is to
109 // set the prefered ArResolver to be the Houdini resolver. This should be
110 // called as soon as possible after loading the HUSD library.
111 HUSD_API void
113 
114 // Set the callback function that is used by the HUSD library to resolve a
115 // LOP node path into an HUSD_LockedStagePtr. This callback is used to help
116 // populate the GusdStageCache for a USD packed primitive with a "file" path
117 // that points to a LOP node using an "op:" style path.
118 HUSD_API void
120 
121 // Calls the GusdStageCache::SplitLopStageIdentifier method, without having to
122 // inclde the stageCache.h header, which is not allowed in the LOP library.
123 HUSD_API bool
124 HUSDsplitLopStageIdentifier(const UT_StringRef &identifier,
125  OP_Node *&lop,
126  bool &split_layers,
127  fpreal &t);
128 
129 
130 /// Returns true if name is a valid identifier (ie, valid component of a path).
131 HUSD_API bool
133 
134 // Modifies the passed in string to make sure it conforms to USD primitive
135 // naming restrictions. Illegal characters are replaced by underscores.
136 HUSD_API bool
137 HUSDmakeValidUsdName(UT_String &name, bool addwarnings);
138 
139 // Returns the name of the node passed through the HUSDmakeValidUsdName method.
140 // This saves several lines of code every time we use this pattern.
143 
144 // Modifies the passed in string to make sure it conforms to USD primitive
145 // naming restrictions. Illegal characters are replaced by underscores. Each
146 // path component is validated separately. The returned path will always be
147 // an absolute path, prefixing "/" to any passed in relative path.
148 HUSD_API bool
149 HUSDmakeValidUsdPath(UT_String &path, bool addwarnings);
150 
151 // As the above function, except it has the option of allowing the passed in
152 // and returned path to be a relative path.
153 HUSD_API bool
154 HUSDmakeValidUsdPath(UT_String &path, bool addwarnings, bool allow_relative);
155 
156 // Like the above method, but accepts "defaultPrim" as well.
157 HUSD_API bool
159 
160 // Ensures the given primitive path is unique and does not conflict
161 // with any existing primitives on the stage given by the lock.
162 // If suffix is given, if the given path is colliding, the new path
163 // will use it along with a digit to disambiguate it.
164 // Returns true if given path had to be changed; false otherwise.
165 HUSD_API bool
167  const UT_StringRef &suffix = UT_StringRef());
168 
169 // Returns the path of the node passed through the HUSDmakeValidUsdPath method.
170 // This saves several lines of code every time we use this pattern.
173 
174 // Modifies the passed in string to make sure it conforms to USD property
175 // naming restrictions. This includes allowing multiple nested namespaces
176 // in the name. Illegal characters are replaced by underscores.
177 HUSD_API bool
178 HUSDmakeValidUsdPropertyName(UT_String &name, bool addwarnings);
179 
180 // Modifies the passed in string to make sure it conforms to USD variant
181 // naming restrictions. Note that these are different from normal primitive
182 // naming conventions, as defined in SdfSchemaBase::IsValidVariantIdentifier:
183 // One or more letter, number, '_', '|', or '-', with an optional leading '.'
184 // Illegal characters are replaced by underscores.
185 HUSD_API bool
186 HUSDmakeValidVariantName(UT_String &name, bool addwarnings);
187 
188 // Modifies the passed in string to make sure it conforms to USD primitive
189 // naming restrictions. Leading slashes are thrown away. Illegal characters
190 // are considered an error and cause this function to return false.
191 HUSD_API bool
192 HUSDmakeValidDefaultPrim(UT_String &default_prim, bool addwarnings);
193 
194 // Returns primitive name, given the primitive path.
196 HUSDgetUsdName(const UT_StringRef &primpath);
197 
198 // Returns primitive's parent path, given the primitive path.
200 HUSDgetUsdParentPath(const UT_StringRef &primpath);
201 
202 // Modifies the provided path set so that if all the children of a prim are
203 // in the set, the children are removed, and the parent prim is put in the
204 // set instead. This procedure is applied recursively. This converts some
205 // parameters to USD types then calls the XUSD_Utils version of this method.
206 HUSD_API void
208  bool skip_point_instancers,
209  const HUSD_AutoAnyLock &lock,
211 
212 // Return the primary alias for the specified USD primitive type.
214 HUSDgetPrimTypeAlias(const UT_StringRef &primtype);
215 
216 // If layers are stripped during a flatten operation, this function handles
217 // the error creation based on the requested response. Returns true of the
218 // requested response is to generate an error, which usually means we should
219 // also stop processing.
220 HUSD_API bool
222 
223 /// Enum of USD transform operation types.
224 /// Note, they need to correspond to UsdGeomXformOp::Type enum.
225 enum class HUSD_XformType {
226  Invalid,
227  Translate,
228  Scale,
231  Orient,
232  Transform
233 };
234 
235 /// Enum of rotation axis.
236 enum class HUSD_XformAxis { X, Y, Z };
237 
238 /// Enum of rotation order.
239 enum class HUSD_XformAxisOrder { XYZ, XZY, YXZ, YZX, ZXY, ZYX };
240 
241 /// @{ Functions for obtaining transform name, suffix, and type.
243  UT_StringHolder &xform_namesuffix,
244  const UT_StringRef& xform_fullname);
248  const UT_StringRef &xform_namesuffix);
250  UT_StringHolder *xform_type = nullptr,
251  UT_StringHolder *xform_name = nullptr);
252 /// @}
253 
254 /// @{ Manipulate collection paths and components. The individual components
255 /// must be validated (see HUSDmakeValidName and HUSDmakeValidPath) before
256 /// calling these methods.
258  const UT_StringRef &collection_name);
260  UT_StringHolder &collection_name,
261  const UT_StringRef &collection_path);
263 /// @}
264 
265 /// @{ Create property paths from their components. The individual components
266 /// must be validated (see HUSDmakeValidName and HUSDmakeValidPath) before
267 /// calling these methods.
269  const UT_StringRef &property_name);
271  const UT_StringRef &attribute_name);
273  const UT_StringRef &relationship_name);
274 /// @}
275 
276 /// Returns the attribute name of the given primvar
278 
279 /// Returns the string name of the Usd Sdf type best suited for the parameter.
281 
282 /// Returns the time code at which to author an attribute value.
284  const HUSD_TimeCode &timecode,
285  HUSD_TimeSampling time_sampling);
286 
287 /// Returns true if there are more than one time samples.
288 HUSD_API bool HUSDisTimeVarying(HUSD_TimeSampling time_sampling);
289 
290 /// Returns true if there is at least one time sample.
291 HUSD_API bool HUSDisTimeSampled(HUSD_TimeSampling time_sampling);
292 
293 /// Set a parameter value from the value of a USD property.
295  const UT_StringRef &primpath,
296  const UT_StringRef &attribname,
297  const HUSD_TimeCode &tc,
298  PRM_Parm &parm,
299  HUSD_TimeSampling &timesampling);
300 
301 #endif
302 
HUSD_API void HUSDgetMinimalPathsForInheritableProperty(bool skip_point_instancers, const HUSD_AutoAnyLock &lock, HUSD_PathSet &paths)
HUSD_API bool HUSDmakeValidDefaultPrim(UT_String &default_prim, bool addwarnings)
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:101
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).
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
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)
GLuint const GLchar * name
Definition: glcorearb.h:785
HUSD_API UT_StringHolder HUSDgetUsdName(const UT_StringRef &primpath)
HUSD_PrimTraversalDemands
Definition: HUSD_Utils.h:35
GLdouble GLdouble t
Definition: glew.h:1403
HUSD_XformAxis
Enum of rotation axis.
Definition: HUSD_Utils.h:236
HUSD_OverridesLayerId
Definition: HUSD_Utils.h:70
HUSD_Variability
Definition: HUSD_Utils.h:79
UT_StringArray HUSD_InstanceSelection
Definition: HUSD_Utils.h:106
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:225
HUSD_API bool HUSDmakeValidUsdName(UT_String &name, bool addwarnings)
HUSD_TimeSampling
Definition: HUSD_Utils.h:93
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)
GLfloat GLfloat p
Definition: glew.h:16656
HUSD_StripLayerResponse
Definition: HUSD_Utils.h:86
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)
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
const GLfloat * tc
Definition: glew.h:16639
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:239
HUSD_PathSaveStyle
Definition: HUSD_Utils.h:60
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)
HUSD_API bool HUSDmakeUniqueUsdPath(UT_String &path, const HUSD_AutoAnyLock &lock, const UT_StringRef &suffix=UT_StringRef())
HUSD_API UT_StringHolder HUSDgetValidUsdName(OP_Node &node)
GLenum const void * paths
Definition: glew.h:13872
HUSD_API UT_StringHolder HUSDgetAttribTypeName(const PI_EditScriptedParm &p)
Returns the string name of the Usd Sdf type best suited for the parameter.