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