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