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_StringMap.h>
25 #include <UT/UT_ArrayStringSet.h>
26 
27 class HUSD_TimeCode;
28 class HUSD_Path;
29 enum class HUSD_XformType;
30 enum class HUSD_TimeSampling;
31 template <typename T> class UT_BoundingBoxT;
33 class UT_InfoTree;
34 class UT_Options;
36 
38 {
39 public:
40  explicit HUSD_Info(HUSD_AutoAnyLock &lock);
41  ~HUSD_Info();
42 
43  static bool isArrayValueType(const UT_StringRef &valueType);
44  static bool isTokenArrayValueType(const UT_StringRef &valueType);
45  static bool isPrimvarName(const UT_StringRef &name);
46  static void getPrimitiveKinds(UT_StringArray &kinds);
47  static void getUsdVersionInfo(UT_StringMap<UT_StringHolder> &info);
48 
49  // Get kind hierarchy information.
50  static bool isModelKind(const UT_StringRef &kind);
51  static bool isGroupKind(const UT_StringRef &kind);
52  static bool isComponentKind(const UT_StringRef &kind);
53 
54  // Test for paths that represent instance prototypes.
55  static bool isPathInPrototype(const HUSD_Path &primpath);
56 
57  // Get basic information from the auto lock used to construct this
58  // info object.
59  bool isStageValid() const;
60  bool getStageRootLayer(UT_StringHolder &identifier) const;
61  static bool isLopLayer(const UT_StringRef &identifier);
62  static bool getLayerSavePath(const UT_StringHolder &identifier,
63  const UT_StringMap<UT_StringHolder> &refargs,
64  UT_StringHolder &savepath);
65 
66  // Reload a layer. Does the USD reload and clears Houdini-specific caches
67  // associated with loaded layers. Optionally finds all referenced layers
68  // and also reloads them (recursively).
69  static bool reload(const UT_StringRef &filepath,
70  bool recursive);
71  // Reloads as above, but uses the asset resolver context from the auto lock
72  // used to construct this info object.
73  bool reloadWithContext(const UT_StringRef &filepath,
74  bool recursive) const;
75 
76  // Returns the identifiers and a human readable name for all sublayers of
77  // the stage root layer in strongest to weakest order.
78  bool getSourceLayers(UT_StringArray &names,
79  UT_StringArray &identifiers,
80  UT_IntArray &fromlops,
81  UT_IntArray &fromsops) const;
82  bool getLayerHierarchy(UT_InfoTree &hierarchy) const;
83  bool getLayerSavePath(UT_StringHolder &savepath) const;
84  bool getLayersAboveLayerBreak(
85  UT_StringArray &identifiers) const;
86 
87  // Check if the layer specified by the file path can be found. Uses the
88  // stage's resolver context if this object was created with a lock.
89  bool getLayerExists(const UT_StringRef &filepath) const;
90 
91  // Layer information
92  bool getStartTimeCode(fpreal64 &starttimecode) const;
93  bool getEndTimeCode(fpreal64 &endtimecode) const;
94  bool getFramesPerSecond(fpreal64 &fps) const;
95  bool getTimeCodesPerSecond(fpreal64 &tcs) const;
96  bool getMetrics(UT_StringHolder &upaxis,
97  fpreal64 &metersperunit) const;
98 
99  // Return the "current render settings" metadata from the stage. If it's
100  // not set, return an empty string.
101  UT_StringHolder getCurrentRenderSettings() const;
102  // Return the paths to all render settings prims on the stage.
103  bool getAllRenderSettings(UT_StringArray &paths) const;
104  // Return a render settings path using the following priorities:
105  // 1. The provided explicit_path, if a prim exists there.
106  // 2. The current settings prim according to the stage metadata.
107  // 3. If there is exactly one settings prim on the stage, return it.
108  // 4. Return an empty path.
109  HUSD_Path getBestRenderSettings(
110  const UT_StringRef &explicit_path =
112 
113  // General primitive information (parent, children, kinds)
114  bool isPrimAtPath(const UT_StringRef &primpath) const;
115  bool isActive(const UT_StringRef &primpath) const;
116  bool isVisible(const UT_StringRef &primpath,
117  const HUSD_TimeCode &time_code,
118  HUSD_TimeSampling *time_sampling=nullptr) const;
119  bool isInstance(const UT_StringRef &primpath) const;
120  UT_StringHolder getKind(const UT_StringRef &primpath) const;
121  bool isKind(const UT_StringRef &primpath,
122  const UT_StringRef &kind) const;
123  UT_StringHolder getSpecifier(const UT_StringRef &primpath) const;
124  bool isAbstract(const UT_StringRef &primpath) const;
125  bool isModel(const UT_StringRef &primpath) const;
126  UT_StringHolder getPrimType(const UT_StringRef &primpath) const;
127  bool isPrimType(const UT_StringRef &primpath,
128  const UT_StringRef &type) const;
129  bool hasPrimAPI(const UT_StringRef &primpath,
130  const UT_StringRef &api) const;
131  bool hasPayload(const UT_StringRef &primpath) const;
132  UT_StringHolder getIcon(const UT_StringRef &primpath) const;
133  UT_StringHolder getPurpose(const UT_StringRef &primpath) const;
134  UT_StringHolder getDrawMode(const UT_StringRef &primpath) const;
135 
136  // Tests the value of the "editable" attribute from the HoudiniEditableAPI
137  // schema, used to indicate if a prim should be modified by LOPs.
138  bool isEditable(const UT_StringRef &primpath) const;
139  // Tests the value of the "selectable" attribute from the
140  // HoudiniSelectableAPI schema, used to indicate if a prim is selectable.
141  bool isSelectable(const UT_StringRef &primpath,
142  UT_Map<HUSD_Path, bool> *cache = nullptr) const;
143  // Tests the value of the IsHidden metadata, used to indicate if a prim
144  // should be shown in the scene graph tree.
145  bool isHiddenInUi(const UT_StringRef &primpath) const;
146 
147  // Determines the primitive kind that should be used for the specified
148  // primitive to maintain a valid model kind hierarchy.
149  UT_StringHolder getAutoParentPrimKind(
150  const UT_StringRef &primpath) const;
151 
152  // Get information about child primitives.
153  bool hasChildren(const UT_StringRef &primpath) const;
154  void getChildren(const UT_StringRef &primpath,
155  UT_StringArray &childnames) const;
156 
157  // Return a simple count of the number of descendant prims.
158  exint getDescendantCount(const UT_StringRef &primpath,
159  HUSD_PrimTraversalDemands demands) const;
160 
161  // Gather general statistics about the descendants of a primitive.
163  STATS_SIMPLE_COUNTS = 0x0000,
164  STATS_PURPOSE_COUNTS = 0x0001,
165  STATS_GEOMETRY_COUNTS = 0x0002
166  };
167  void getDescendantStats(const UT_StringRef &primpath,
168  UT_Options &stats,
169  DescendantStatsFlags
170  flags = STATS_SIMPLE_COUNTS) const;
171 
172  // Searches up the scene graph tree starting from "primpath" looking for
173  // the first prim with the specified kindhint. If none of that kind are
174  // found, it will look for the least nested prim of the base kind. So
175  // if kindhint is assembly, and there is no assembly, it will return
176  // the least nested group. Then fall back to the least nested model.
177  // Then finall fall back to returning the original primpath. This
178  // method will never return an empty string. If kindhint is an empty
179  // string, the original primpath is always returned.
180  UT_StringHolder getSelectionAncestor(const UT_StringRef &primpath,
181  const UT_StringRef &kindhint,
182  bool allow_kind_mismatch,
183  bool allow_instance_proxies,
184  bool allow_hidden_prims) const;
185 
186  // Attributes
187  enum class QueryAspect
188  {
189  ANY, // Any attribute
190  ARRAY // Attribute of some array type.
191  };
192  // Checks existence or property of a prim's attribute.
193  bool isAttribAtPath(const UT_StringRef &attribpath,
194  QueryAspect query = QueryAspect::ANY) const;
195  bool isAttribAtPath(const UT_StringRef &primpath,
196  const UT_StringRef &attribname,
197  QueryAspect query = QueryAspect::ANY) const;
198 
199  // Length of array attributes (1 for non-arrays).
200  exint getAttribLength(const UT_StringRef &attribpath,
201  const HUSD_TimeCode &time_code,
202  HUSD_TimeSampling *time_sampling=nullptr) const;
203  exint getAttribLength(const UT_StringRef &primpath,
204  const UT_StringRef &attribname,
205  const HUSD_TimeCode &time_code,
206  HUSD_TimeSampling *time_sampling=nullptr) const;
207 
208  // Tuple size of attributes (eg, 2,3,4 for vectors, 1 for scalars)
209  // For array attributes, returns the tuple size of contained element type.
210  exint getAttribSize(const UT_StringRef &attribpath) const;
211  exint getAttribSize(const UT_StringRef &primpath,
212  const UT_StringRef &attribname) const;
213 
214  // Returns the name of the attribute type (eg, "float", "double3[]").
215  // Note, this is different than attribute value type name (eg, "GfVec3d")
216  UT_StringHolder getAttribTypeName(const UT_StringRef &attrpath) const;
217  UT_StringHolder getAttribTypeName(const UT_StringRef &primpath,
218  const UT_StringRef &attribname) const;
219 
220  // Time samples array (may be empty)
221  bool getAttribTimeSamples(const UT_StringRef &attribpath,
222  UT_FprealArray &time_samples) const;
223  bool getAttribTimeSamples(const UT_StringRef &primpath,
224  const UT_StringRef &attribname,
225  UT_FprealArray &time_samples) const;
226 
227  // Transforms
228  UT_Matrix4D getLocalXform(const UT_StringRef &primpath,
229  const HUSD_TimeCode &time_code,
230  HUSD_TimeSampling *time_sampling=nullptr) const;
231  UT_Matrix4D getWorldXform(const UT_StringRef &primpath,
232  const HUSD_TimeCode &time_code,
233  HUSD_TimeSampling *time_sampling=nullptr) const;
234  UT_Matrix4D getParentXform(const UT_StringRef &primpath,
235  const HUSD_TimeCode &time_code,
236  HUSD_TimeSampling *time_sampling=nullptr) const;
237  bool getXformOrder(const UT_StringRef &primpath,
238  UT_StringArray &xform_order) const;
239  bool isXformReset(const UT_StringRef &primpath ) const;
240 
241  UT_StringHolder findXformName(const UT_StringRef &primpath,
242  const UT_StringRef &xform_name_suffix) const;
243  UT_StringHolder getUniqueXformName(const UT_StringRef &primpath,
244  HUSD_XformType type,
245  const UT_StringRef &xform_name_suffix) const;
246 
247  static const UT_StringHolder &getTransformAttribName();
248  static const UT_StringHolder &getTimeVaryingAttribName();
249  void getAttributeNames(const UT_StringRef &primpath,
250  UT_ArrayStringSet &attrib_names) const;
251  void extractAttributes(const UT_StringRef &primpath,
252  const UT_ArrayStringSet &which_attribs,
253  const HUSD_TimeCode &tc,
255  HUSD_TimeSampling *time_sampling=nullptr) const;
256 
257  // Bounds
258  UT_BoundingBoxD getBounds(const UT_StringRef &primpath,
259  const UT_StringArray &purposes,
260  const HUSD_TimeCode &time_code) const;
261 
262  // Point Instancers
263  bool getPointInstancerXforms( const UT_StringRef &primpath,
264  UT_Array<UT_Matrix4D> &xforms,
265  const HUSD_TimeCode &time_code);
266  UT_BoundingBoxD getPointInstancerBounds(const UT_StringRef &primpath,
267  exint instance_index,
268  const UT_StringArray &purposes,
269  const HUSD_TimeCode &time_code) const;
270 
271  // Variants
272  bool getVariantSets(const UT_StringRef &primpath,
273  UT_StringArray &vset_names) const;
274  bool getVariants(const UT_StringRef &primpath,
275  const UT_StringRef &variantset,
276  UT_StringArray &vset_names) const;
277  UT_StringHolder getVariantSelection(const UT_StringRef &primpath,
278  const UT_StringRef &variantset) const;
279 
280  // Collections
281  bool isCollectionAtPath(
282  const UT_StringRef &collectionpath) const;
283  UT_StringHolder getCollectionExpansionRule(
284  const UT_StringRef &collectionpath) const;
285  bool getCollectionIncludePaths(
286  const UT_StringRef &collectionpath,
287  UT_StringArray &primpaths) const;
288  bool getCollectionExcludePaths(
289  const UT_StringRef &collectionpath,
290  UT_StringArray &primpaths) const;
291  bool getCollectionComputedPaths(
292  const UT_StringRef &collectionpath,
293  UT_StringArray &primpaths) const;
294  bool collectionContains(
295  const UT_StringRef &collectionpath,
296  const UT_StringRef &primpath) const;
297  bool getCollections(const UT_StringRef &primpath,
299  &collection_info_map) const;
300 
301  // Materials
302  UT_StringHolder getBoundMaterial(const UT_StringRef &primpath) const;
303 
304  // Primvars
305  bool isPrimvarAtPath(const UT_StringRef &primpath,
306  const UT_StringRef &primvarname,
307  QueryAspect query = QueryAspect::ANY,
308  bool allow_inheritance = false) const;
309  void getPrimvarNames(const UT_StringRef &primpath,
310  UT_ArrayStringSet &primvar_names,
311  bool allow_inheritance = false) const;
312  exint getPrimvarLength(const UT_StringRef &primpath,
313  const UT_StringRef &primvarname,
314  const HUSD_TimeCode &time_code,
315  HUSD_TimeSampling *time_sampling=nullptr,
316  bool allow_inheritance = false) const;
317  exint getPrimvarSize(const UT_StringRef &primpath,
318  const UT_StringRef &primvarname,
319  bool allow_inheritance = false) const;
320  UT_StringHolder getPrimvarTypeName(const UT_StringRef &primpath,
321  const UT_StringRef &primvarname,
322  bool allow_inheritance = false) const;
323  bool getPrimvarTimeSamples(const UT_StringRef &primpath,
324  const UT_StringRef &primvarname,
325  UT_FprealArray &time_samples,
326  bool allow_inheritance = false) const;
327 
328  // Relationships
329  void getRelationshipNames(const UT_StringRef &primpath,
330  UT_ArrayStringSet &rel_names) const;
331 
332  bool isRelationshipAtPath(
333  const UT_StringRef &relpath) const;
334  bool isRelationshipAtPath(const UT_StringRef &primpath,
335  const UT_StringRef &relationahipname) const;
336 
337  bool getRelationshipTargets (
338  const UT_StringRef &relpath,
339  UT_StringArray &target_paths) const;
340  bool getRelationshipTargets (
341  const UT_StringRef &primpath,
342  const UT_StringRef &relationshipname,
343  UT_StringArray &target_paths) const;
344 
345  bool getRelationshipForwardedTargets (
346  const UT_StringRef &relpath,
347  UT_StringArray &target_paths) const;
348  bool getRelationshipForwardedTargets (
349  const UT_StringRef &primpath,
350  const UT_StringRef &relationshipname,
351  UT_StringArray &target_paths) const;
352 
353  // Metadata
354  void getMetadataNames(const UT_StringRef &object_path,
355  UT_ArrayStringSet &metadata_names) const;
356  bool isMetadataAtPath(const UT_StringRef &object_path,
357  const UT_StringRef &metadata_name,
358  QueryAspect query = QueryAspect::ANY) const;
359  exint getMetadataLength(const UT_StringRef &object_path,
360  const UT_StringRef &metadata_name) const;
361 
362  // Access information from the active layer, rather than the stage.
363  bool isActiveLayerPrimAtPath(const UT_StringRef &primpath,
364  const UT_StringRef &prim_type =
366  // Returns the identifiers and a human readable name for all sublayers of
367  // the active layer in strongest to weakest order.
368  bool getActiveLayerSubLayers(UT_StringArray &names,
369  UT_StringArray &identifiers,
370  UT_IntArray &fromlops,
371  UT_IntArray &fromsops) const;
372 
373  // Shader parameters.
374  void getShaderInputAttributeNames(
375  const UT_StringRef &primpath,
376  UT_ArrayStringSet &attrib_names) const;
377 
378  // Obtains a value for a metadata on a given object.
379  // The object path can point to a primitive, attribute, or a relationship.
380  // The metadata name can be a simple name (eg, "active") or a name path
381  // into metadata dictionaries (eg "assetInfo:foo" or "customData:bar:baz").
382  template<typename UtValueType>
383  bool getMetadata(const UT_StringRef &object_path,
384  const UT_StringRef &name,
385  UtValueType &value) const;
386 
387  // Obtains a value for custom data on a given object.
388  template<typename UtValueType>
389  bool getCustomData(const UT_StringRef &primpath,
390  const UT_StringRef &name,
391  UtValueType &value) const;
392 
393  // Obtains a value for asset info on a given object.
394  template<typename UtValueType>
395  bool getAssetInfo(const UT_StringRef &primpath,
396  const UT_StringRef &name,
397  UtValueType &value) const;
398 
399 private:
400  HUSD_AutoAnyLock &myAnyLock;
401 };
402 
403 #endif
404 
Unsorted map container.
Definition: UT_Map.h:107
Axis-aligned bounding box (AABB).
Definition: GEO_Detail.h:43
int64 exint
Definition: SYS_Types.h:125
#define HUSD_API
Definition: HUSD_API.h:32
GLuint const GLchar * name
Definition: glcorearb.h:786
HUSD_PrimTraversalDemands
Definition: HUSD_Utils.h:37
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
double fpreal64
Definition: SYS_Types.h:201
DescendantStatsFlags
Definition: HUSD_Info.h:162
static const UT_StringHolder theEmptyString
HUSD_XformType
Definition: HUSD_Utils.h:228
HUSD_TimeSampling
Definition: HUSD_Utils.h:96
GLuint const GLuint * names
Definition: glew.h:2695
GLbitfield flags
Definition: glcorearb.h:1596
A map of string to various well defined value types.
Definition: UT_Options.h:84
const GLfloat * tc
Definition: glew.h:16639
Definition: core.h:1131
type
Definition: core.h:1059
GEO_API int getPrimType(const TypeMask &mask)
GLenum query
Definition: glew.h:5734
GU_API GA_OffsetArray getChildren(GU_Detail *gdp, const GA_Offset &node, bool recurse=false)
UT_StringMap< UT_StringHolder > HUSD_CollectionInfoMap
Definition: HUSD_Info.h:34
GLenum const void * paths
Definition: glew.h:13872