HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HUSD_Info.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_Info_h__
19 #define __HUSD_Info_h__
20 
21 #include "HUSD_API.h"
22 #include "HUSD_DataHandle.h"
23 #include "HUSD_Utils.h"
24 #include <UT/UT_ArrayStringSet.h>
25 #include <UT/UT_StringMap.h>
26 #include <UT/UT_UniquePtr.h>
27 #include <UT/UT_VectorTypes.h>
28 
29 class husd_InfoPrivate;
30 class HUSD_TimeCode;
31 class HUSD_Path;
32 enum class HUSD_XformType;
33 enum class HUSD_TimeSampling;
34 template <typename T> class UT_BoundingBoxT;
36 class UT_InfoTree;
37 class UT_Options;
39 
41 {
42 public:
43  explicit HUSD_Info(HUSD_AutoAnyLock &lock);
44  ~HUSD_Info();
45 
46  static bool isArrayValueType(const UT_StringRef &valueType);
47  static bool isTokenArrayValueType(const UT_StringRef &valueType);
48  static int valueTypeScalarSize(const UT_StringRef &valueType);
49  static bool isPrimvarName(const UT_StringRef &name);
50  static void getPrimitiveKinds(UT_StringArray &kinds);
51  static void getUsdVersionInfo(UT_StringMap<UT_StringHolder> &info);
52 
53  // Get kind hierarchy information.
54  static bool isModelKind(const UT_StringRef &kind);
55  static bool isGroupKind(const UT_StringRef &kind);
56  static bool isComponentKind(const UT_StringRef &kind);
57 
58  // Test for paths that represent instance prototypes.
59  static bool isPathInPrototype(const HUSD_Path &primpath);
60 
61  // Get the global variant selection fallback settings from the USD library.
62  static void getGlobalVariantSelectionFallbacks(
64  variantselections);
65 
66  // Test if a string is a stage variable expression, optionally setting
67  // an error if the expression isn't valid.
68  static bool isStageVariableExpression(const UT_StringRef &expr,
69  bool check_for_errors = true);
70 
71  // Get basic information from the auto lock used to construct this
72  // info object.
73  bool isStageValid() const;
74  bool getStageRootLayer(UT_StringHolder &identifier) const;
75  static bool isLopLayer(const UT_StringRef &identifier);
76  static bool getLayerSavePath(const UT_StringHolder &identifier,
77  const UT_StringMap<UT_StringHolder> &refargs,
78  UT_StringHolder &savepath);
79 
80  // Reload a layer. Does the USD reload and clears Houdini-specific caches
81  // associated with loaded layers. Optionally finds all referenced layers
82  // and also reloads them (recursively).
83  static bool reload(const UT_StringRef &filepath,
84  bool recursive,
85  bool force_load = false);
86  // Reloads as above, but uses the asset resolver context from the auto lock
87  // used to construct this info object.
88  bool reloadWithContext(const UT_StringRef &filepath,
89  bool recursive,
90  bool force_load = false) const;
91  // Clear the current stage from the GusdUSD_XformCache.
92  void clearGusdXformCache() const;
93 
94  // Returns the identifiers and a human readable name for all sublayers of
95  // the stage root layer in strongest to weakest order.
96  bool getSourceLayers(UT_StringArray &names,
97  UT_StringArray &identifiers,
98  UT_IntArray &fromlops,
99  UT_IntArray &fromsops) const;
100  bool getLayerHierarchy(UT_InfoTree &hierarchy) const;
101  bool getLayerSavePath(UT_StringHolder &savepath) const;
102  bool getLayersAboveLayerBreak(
103  UT_StringArray &identifiers) const;
104 
105  // Check if the layer specified by the file path can be found. Uses the
106  // stage's resolver context if this object was created with a lock.
107  bool getLayerExists(const UT_StringRef &filepath) const;
108 
109  // Layer information
110  bool getStartTimeCode(fpreal64 &starttimecode) const;
111  bool getEndTimeCode(fpreal64 &endtimecode) const;
112  bool getFramesPerSecond(fpreal64 &fps) const;
113  bool getTimeCodesPerSecond(fpreal64 &tcs) const;
114  bool getMetrics(UT_StringHolder &upaxis,
115  fpreal64 &metersperunit) const;
116 
117  // Return the "current render settings" metadata from the stage. If it's
118  // not set, return an empty string.
119  UT_StringHolder getCurrentRenderSettings() const;
120  // Return the paths to all render settings prims on the stage.
121  bool getAllRenderSettings(UT_StringArray &paths) const;
122  // Return a render settings path using the following priorities:
123  // 1. The provided explicit_path, if a prim exists there.
124  // 2. The current settings prim according to the stage metadata.
125  // 3. If there is exactly one settings prim on the stage, return it.
126  // If pick_first_of_many is true and there is more than one render
127  // settings prim, pick the first one.
128  // 4. Return an empty path.
129  HUSD_Path getBestRenderSettings(
130  const UT_StringRef &explicit_path =
132  bool pick_first_of_many = false) const;
133  // Return a camera path using the following priorities:
134  // 1. The provided explicit_path, if a camera exists there.
135  // 2. The camera according to the supplied render_settings prim
136  // (note that no smart fallback is used here if the prim is empty
137  // or doesn't point to a render settings prim - use the result of
138  // getBestRenderSettings if this is the intent).
139  // 3. If there is exactly one camera prim on the stage, return it.
140  // If pick_first_of_many is true and there is more than one camera
141  // prim, pick the first one.
142  // 4. Return an empty path.
143  HUSD_Path getBestCamera(
144  const UT_StringRef &explicit_path =
146  const UT_StringHolder &render_settings =
148  bool pick_first_of_many = false) const;
149 
150  // General primitive information (parent, children, kinds)
151  bool isPrimAtPath(const UT_StringRef &primpath) const;
152  bool isActive(const UT_StringRef &primpath) const;
153  bool isVisible(const UT_StringRef &primpath,
154  const HUSD_TimeCode &time_code,
155  HUSD_TimeSampling *time_sampling=nullptr) const;
156  bool isInstance(const UT_StringRef &primpath) const;
157  UT_StringHolder getKind(const UT_StringRef &primpath) const;
158  bool isKind(const UT_StringRef &primpath,
159  const UT_StringRef &kind) const;
160  UT_StringHolder getSpecifier(const UT_StringRef &primpath) const;
161  bool isAbstract(const UT_StringRef &primpath) const;
162  bool isModel(const UT_StringRef &primpath) const;
163  UT_StringHolder getPrimType(const UT_StringRef &primpath) const;
164  bool isPrimType(const UT_StringRef &primpath,
165  const UT_StringRef &type) const;
166  bool hasPrimAPI(const UT_StringRef &primpath,
167  const UT_StringRef &api) const;
168  bool hasPayload(const UT_StringRef &primpath) const;
169  UT_StringHolder getIcon(const UT_StringRef &primpath) const;
170  UT_StringHolder getPurpose(const UT_StringRef &primpath) const;
171  UT_StringHolder getDrawMode(const UT_StringRef &primpath) const;
172 
173  // Tests the value of the "editable" attribute from the HoudiniEditableAPI
174  // schema, used to indicate if a prim should be modified by LOPs.
175  bool isEditable(const UT_StringRef &primpath) const;
176  // Tests the value of the "selectable" attribute from the
177  // HoudiniSelectableAPI schema, used to indicate if a prim is selectable.
178  bool isSelectable(const UT_StringRef &primpath,
179  UT_Map<HUSD_Path, bool> *cache = nullptr) const;
180  // Tests the value of the IsHidden metadata, used to indicate if a prim
181  // should be shown in the scene graph tree.
182  bool isHiddenInUi(const UT_StringRef &primpath) const;
183 
184  // Determines the primitive kind that should be used for the specified
185  // primitive to maintain a valid model kind hierarchy.
186  UT_StringHolder getAutoParentPrimKind(
187  const UT_StringRef &primpath) const;
188 
189  // Get information about child primitives.
190  bool hasChildren(const UT_StringRef &primpath) const;
191  void getChildren(const UT_StringRef &primpath,
192  UT_StringArray &childnames) const;
193 
194  // Return a simple count of the number of descendant prims.
195  exint getDescendantCount(const UT_StringRef &primpath,
196  HUSD_PrimTraversalDemands demands) const;
197 
198  // Gather general statistics about the descendants of a primitive.
200  STATS_SIMPLE_COUNTS = 0x0000,
201  STATS_PURPOSE_COUNTS = 0x0001,
202  STATS_GEOMETRY_COUNTS = 0x0002
203  };
204  void getDescendantStats(const UT_StringRef &primpath,
205  UT_Options &stats,
206  DescendantStatsFlags
207  flags = STATS_SIMPLE_COUNTS) const;
208 
209  // Searches up the scene graph tree starting from "primpath" looking for
210  // the first prim with the specified kindhint. If none of that kind are
211  // found, it will look for the least nested prim of the base kind. So
212  // if kindhint is assembly, and there is no assembly, it will return
213  // the least nested group. Then fall back to the least nested model.
214  // Then finall fall back to returning the original primpath. This
215  // method will never return an empty string. If kindhint is an empty
216  // string, the original primpath is always returned.
217  UT_StringHolder getSelectionAncestor(const UT_StringRef &primpath,
218  const UT_StringRef &kindhint,
219  bool allow_kind_mismatch,
220  bool allow_instance_proxies,
221  bool allow_hidden_prims) const;
222 
223  // Populates "stats" with counts of various features of the stage.
224  // Wrapper around API method UsdUtilsComputeUsdStageStats
225  bool computeStageStats(UT_Options &stats) const;
226 
227  static bool computeStageStats(const UT_StringRef &path,
228  UT_Options &stats);
229 
230  // Wrapper for UsdUtilsComputeAllDependencies
231  static bool computeAllDependencies(const UT_StringRef &path,
232  UT_StringArray &layers,
233  UT_StringArray &resolved,
234  UT_StringArray &unresolved);
235 
236  // Wrapper for UsdUtilsExtractExternalReferences
237  static bool extractExternalReferences(const UT_StringRef &path,
238  UT_StringArray &sub_layers,
239  UT_StringArray &references,
240  UT_StringArray &payloads);
241 
242  // Evaluates a primitive pattern on a stage created by loading the
243  // specified USD file.
244  static bool getExpandedPathSet(const UT_StringRef &filepath,
245  const UT_StringRef &primpattern,
246  HUSD_PathSet &paths);
247 
248  // Return the root prims in the layer identified by the path and file
249  // format arguments provided. The root prims are added to the output
250  // string set as paths.
251  static bool getLayerRootPrims(const UT_StringRef &filepath,
252  const UT_StringMap<UT_StringHolder> &fileargs,
253  HUSD_PathSet &rootprims);
254 
255  // Return true if the layer identified by the path and file format
256  // arguments provided has any prims outside the specified path.
257  static bool hasAnyPrimsOutside(const UT_StringRef &filepath,
258  const UT_StringMap<UT_StringHolder> &fileargs,
259  const UT_StringRef &primpath);
260 
261  // Attributes
262  enum class QueryAspect
263  {
264  ANY, // Any attribute
265  ARRAY // Attribute of some array type.
266  };
267  // Checks existence or property of a prim's attribute.
268  bool isAttribAtPath(const UT_StringRef &attribpath,
269  QueryAspect query = QueryAspect::ANY) const;
270  bool isAttribAtPath(const UT_StringRef &primpath,
271  const UT_StringRef &attribname,
272  QueryAspect query = QueryAspect::ANY) const;
273 
274  // Length of array attributes (1 for non-arrays).
275  exint getAttribLength(const UT_StringRef &attribpath,
276  const HUSD_TimeCode &time_code,
277  HUSD_TimeSampling *time_sampling=nullptr) const;
278  exint getAttribLength(const UT_StringRef &primpath,
279  const UT_StringRef &attribname,
280  const HUSD_TimeCode &time_code,
281  HUSD_TimeSampling *time_sampling=nullptr) const;
282 
283  // Tuple size of attributes (eg, 2,3,4 for vectors, 1 for scalars)
284  // For array attributes, returns the tuple size of contained element type.
285  exint getAttribSize(const UT_StringRef &attribpath) const;
286  exint getAttribSize(const UT_StringRef &primpath,
287  const UT_StringRef &attribname) const;
288 
289  // Returns the name of the attribute type (eg, "float", "double3[]").
290  // Note, this is different than attribute value type name (eg, "GfVec3d")
291  UT_StringHolder getAttribTypeName(const UT_StringRef &attrpath) const;
292  UT_StringHolder getAttribTypeName(const UT_StringRef &primpath,
293  const UT_StringRef &attribname) const;
294 
295  // Time samples array (may be empty)
296  bool getAttribTimeSamples(const UT_StringRef &attribpath,
297  UT_FprealArray &time_samples) const;
298  bool getAttribTimeSamples(const UT_StringRef &primpath,
299  const UT_StringRef &attribname,
300  UT_FprealArray &time_samples) const;
301 
302  // Transforms
303  UT_Matrix4D getLocalXform(const UT_StringRef &primpath,
304  const HUSD_TimeCode &time_code,
305  HUSD_TimeSampling *time_sampling=nullptr) const;
306  UT_Matrix4D getWorldXform(const UT_StringRef &primpath,
307  const HUSD_TimeCode &time_code,
308  HUSD_TimeSampling *time_sampling=nullptr) const;
309  UT_Matrix4D getParentXform(const UT_StringRef &primpath,
310  const HUSD_TimeCode &time_code,
311  HUSD_TimeSampling *time_sampling=nullptr) const;
312  UT_Matrix4D getXformFromOpOrder(const UT_StringRef &primpath,
313  const HUSD_TimeCode &time_code,
314  const UT_StringArray &xformOpOrder,
315  HUSD_TimeSampling *time_sampling=nullptr) const;
316  bool getXformOrder(const UT_StringRef &primpath,
317  UT_StringArray &xform_order) const;
318  bool isXformReset(const UT_StringRef &primpath) const;
319  bool getXformTimeSamples(const UT_StringRef &primpath,
320  const UT_Vector2F &interval,
321  UT_Array<HUSD_TimeCode> &timecodes) const;
322 
323  UT_StringHolder findXformName(const UT_StringRef &primpath,
324  const UT_StringRef &xform_name_suffix) const;
325  UT_StringHolder getUniqueXformName(const UT_StringRef &primpath,
326  HUSD_XformType type,
327  const UT_StringRef &xform_name_suffix) const;
328 
329  static const UT_StringHolder &getTransformAttribName();
330  static const UT_StringHolder &getTimeVaryingAttribName();
331  void getAttributeNames(const UT_StringRef &primpath,
332  UT_ArrayStringSet &attrib_names) const;
333  void extractAttributes(const UT_StringRef &primpath,
334  const UT_ArrayStringSet &which_attribs,
335  const HUSD_TimeCode &tc,
337  HUSD_TimeSampling *time_sampling=nullptr) const;
338 
339  // Bounds
340  UT_BoundingBoxD getBounds(const UT_StringRef &primpath,
341  const UT_StringArray &purposes,
342  const HUSD_TimeCode &time_code) const;
343 
344  // Point Instancers
345  bool getPointInstancerXforms( const UT_StringRef &primpath,
346  UT_Array<UT_Matrix4D> &xforms,
347  const HUSD_TimeCode &time_code);
348  UT_BoundingBoxD getPointInstancerBounds(const UT_StringRef &primpath,
349  exint instance_index,
350  const UT_StringArray &purposes,
351  const HUSD_TimeCode &time_code) const;
352  int getPointInstancerInstanceCount(
353  const UT_StringRef &primpath,
354  const HUSD_TimeCode &time_code) const;
355 
356  // Lights
357  bool hasAnyVisibleLights(
358  const HUSD_TimeCode &time_code) const;
359 
360  // Variants
361  bool getVariantSets(const UT_StringRef &primpath,
362  UT_StringArray &vset_names) const;
363  bool getVariants(const UT_StringRef &primpath,
364  const UT_StringRef &variantset,
365  UT_StringArray &vset_names) const;
366  UT_StringHolder getVariantSelection(const UT_StringRef &primpath,
367  const UT_StringRef &variantset) const;
368 
369  // Collections
370  bool isCollectionAtPath(
371  const UT_StringRef &collectionpath) const;
372  UT_StringHolder getCollectionExpansionRule(
373  const UT_StringRef &collectionpath) const;
374  bool getCollectionIncludePaths(
375  const UT_StringRef &collectionpath,
376  UT_StringArray &primpaths) const;
377  bool getCollectionExcludePaths(
378  const UT_StringRef &collectionpath,
379  UT_StringArray &primpaths) const;
380  bool getCollectionComputedPaths(
381  const UT_StringRef &collectionpath,
382  UT_StringArray &primpaths) const;
383  bool collectionContains(
384  const UT_StringRef &collectionpath,
385  const UT_StringRef &primpath) const;
386  bool getCollections(const UT_StringRef &primpath,
388  &collection_info_map) const;
389 
390  // Materials
391  UT_StringHolder getBoundMaterial(const UT_StringRef &primpath) const;
392 
393  // Primvars
394  bool isPrimvarAtPath(const UT_StringRef &primpath,
395  const UT_StringRef &primvarname,
396  QueryAspect query = QueryAspect::ANY,
397  bool allow_inheritance = false) const;
398  void getPrimvarNames(const UT_StringRef &primpath,
399  UT_ArrayStringSet &primvar_names,
400  bool allow_inheritance = false) const;
401  exint getPrimvarLength(const UT_StringRef &primpath,
402  const UT_StringRef &primvarname,
403  const HUSD_TimeCode &time_code,
404  HUSD_TimeSampling *time_sampling=nullptr,
405  bool allow_inheritance = false) const;
406  exint getPrimvarSize(const UT_StringRef &primpath,
407  const UT_StringRef &primvarname,
408  bool allow_inheritance = false) const;
409  UT_StringHolder getPrimvarTypeName(const UT_StringRef &primpath,
410  const UT_StringRef &primvarname,
411  bool allow_inheritance = false) const;
412  bool getPrimvarTimeSamples(const UT_StringRef &primpath,
413  const UT_StringRef &primvarname,
414  UT_FprealArray &time_samples,
415  bool allow_inheritance = false) const;
416 
417  // Relationships
418  void getRelationshipNames(const UT_StringRef &primpath,
419  UT_ArrayStringSet &rel_names) const;
420 
421  bool isRelationshipAtPath(
422  const UT_StringRef &relpath) const;
423  bool isRelationshipAtPath(const UT_StringRef &primpath,
424  const UT_StringRef &relationahipname) const;
425 
426  bool getRelationshipTargets (
427  const UT_StringRef &relpath,
428  UT_StringArray &target_paths) const;
429  bool getRelationshipTargets (
430  const UT_StringRef &primpath,
431  const UT_StringRef &relationshipname,
432  UT_StringArray &target_paths) const;
433 
434  bool getRelationshipForwardedTargets (
435  const UT_StringRef &relpath,
436  UT_StringArray &target_paths) const;
437  bool getRelationshipForwardedTargets (
438  const UT_StringRef &primpath,
439  const UT_StringRef &relationshipname,
440  UT_StringArray &target_paths) const;
441 
442  // Metadata
443  void getMetadataNames(const UT_StringRef &object_path,
444  UT_ArrayStringSet &metadata_names) const;
445  bool isMetadataAtPath(const UT_StringRef &object_path,
446  const UT_StringRef &metadata_name,
447  QueryAspect query = QueryAspect::ANY) const;
448  exint getMetadataLength(const UT_StringRef &object_path,
449  const UT_StringRef &metadata_name) const;
450 
451  // Access information from the active layer, rather than the stage.
452  bool isActiveLayerPrimAtPath(const UT_StringRef &primpath,
453  const UT_StringRef &prim_type =
455  // Returns the identifiers and a human readable name for all sublayers of
456  // the active layer in strongest to weakest order.
457  bool getActiveLayerSubLayers(UT_StringArray &names,
458  UT_StringArray &identifiers,
459  UT_IntArray &fromlops,
460  UT_IntArray &fromsops) const;
461 
462  // Shader parameters.
463  void getShaderInputAttributeNames(
464  const UT_StringRef &primpath,
465  UT_ArrayStringSet &attrib_names) const;
466 
467  // Obtains a value for a metadata on a given object.
468  // The object path can point to a primitive, attribute, or a relationship.
469  // The metadata name can be a simple name (eg, "active") or a name path
470  // into metadata dictionaries (eg "assetInfo:foo" or "customData:bar:baz").
471  template<typename UtValueType>
472  bool getMetadata(const UT_StringRef &object_path,
473  const UT_StringRef &name,
474  UtValueType &value) const;
475 
476  // Obtains a value for custom data on a given object.
477  template<typename UtValueType>
478  bool getCustomData(const UT_StringRef &primpath,
479  const UT_StringRef &name,
480  UtValueType &value) const;
481 
482  // Obtains a value for asset info on a given object.
483  template<typename UtValueType>
484  bool getAssetInfo(const UT_StringRef &primpath,
485  const UT_StringRef &name,
486  UtValueType &value) const;
487 
488 private:
490  HUSD_AutoAnyLock &myAnyLock;
491 };
492 
493 #endif
494 
GLenum query
Definition: glad.h:2772
GLbitfield flags
Definition: glcorearb.h:1596
PXL_API void reload()
Reload the configuration.
Unsorted map container.
Definition: UT_Map.h:107
Axis-aligned bounding box (AABB).
Definition: GEO_Detail.h:41
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
int64 exint
Definition: SYS_Types.h:125
#define HUSD_API
Definition: HUSD_API.h:32
HUSD_PrimTraversalDemands
Definition: HUSD_Utils.h:39
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
double fpreal64
Definition: SYS_Types.h:201
DescendantStatsFlags
Definition: HUSD_Info.h:199
GU_API GA_OffsetArray getChildren(const GU_Detail *gdp, const GA_Offset &node, bool recurse=false)
static const UT_StringHolder theEmptyString
HUSD_XformType
Definition: HUSD_Utils.h:287
HUSD_TimeSampling
Definition: HUSD_Utils.h:99
GLuint const GLchar * name
Definition: glcorearb.h:786
A map of string to various well defined value types.
Definition: UT_Options.h:84
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
Definition: core.h:1131
type
Definition: core.h:1059
GEO_API int getPrimType(const TypeMask &mask)
UT_StringMap< UT_StringHolder > HUSD_CollectionInfoMap
Definition: HUSD_Info.h:37