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