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