HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
parseUtils.h
Go to the documentation of this file.
1 //
2 // Copyright 2024 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef USDPHYSICS_PARSE_UTILS_H
8 #define USDPHYSICS_PARSE_UTILS_H
9 
10 /// \file usdPhysics/parseUtils.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usd/stage.h"
15 #include "pxr/usd/sdf/path.h"
16 
17 #include "pxr/usd/usdPhysics/api.h"
19 
20 
22 
23 
24 // -------------------------------------------------------------------------- //
25 // PHYSICSPARSEUTILS //
26 // -------------------------------------------------------------------------- //
27 
28 
29 /// UsdPhysicsReportFn - report function that reports parsed data in a batched
30 /// manner. This function is called after all the parsing is done and all the
31 /// physics descriptors are constructed.
32 ///
33 /// \param[in] type Type of the parsed physics objects
34 /// \param[in] primPaths Span of prim paths of the reported type
35 /// \param[in] objectDescs Corresponding span of object descriptors of the
36 /// reported type
37 /// \param[in] userData User data provided to the called parsing function
38 
39 using UsdPhysicsReportFn =
40 std::function<void(UsdPhysicsObjectType type,
41  TfSpan<const SdfPath> primPaths,
43  const VtValue& userData)>;
44 
45 /// \struct CustomUsdPhysicsTokens
46 ///
47 /// Token lists for custom physics objects that allow for custom physics
48 /// objects to be reported by parsing.
49 ///
51 {
52  /// Custom joints to be reported by parsing
53  std::vector<TfToken> jointTokens;
54  /// Custom shapes to be reported by parsing
55  std::vector<TfToken> shapeTokens;
56  /// Custom physics instancers, these make sure that the subhierarchy is
57  /// skipped and expected to be parsed individually
58  std::vector<TfToken> instancerTokens;
59 };
60 
61 /// Load USD physics from a given list of paths. This helper function traverses
62 /// the provided USD stage by constructing UsdPrimRanges from given include
63 /// paths (subhierarchies can be prunes through exclude paths) and returns
64 /// parsed physics objects through the report function.
65 /// \sa UsdPhysicsReportFn
66 ///
67 /// See the parsing utils documentation for more details.
68 ///
69 /// \param[in] stage Stage to be traversed and parsed.
70 /// \param[in] includePaths The vector of SdfPaths that are used to construct
71 /// UsdPrimRange for traversals. For each path a UsdPrim
72 /// is found on the stage and UsdRange traversal is
73 /// constructed from it. All the traversed UsdPrims are
74 /// parsed and physics descriptors are constructed and
75 /// reported through the report function.
76 /// \param[in] reportFn Report function that gets parsed USD physics data see
77 /// \sa UsdPhysicsReportFn
78 /// \param[in] userData User data passed to report function, this can be
79 /// arbitrary data structure, user data acts as a bridge
80 /// between reportFn and the data structures understood
81 /// by the Simulator. Implementer of reportFn can use the
82 /// parsed "objectDesc" to populate these
83 /// simulator-compatible data structures, which are
84 /// passed as userData here.
85 /// \param[in] excludePaths The vector of SdfPaths that are used to prune
86 /// UsdPrims from the parsing UsdPrimRange traversals
87 /// constructed from the include paths.
88 /// \param[in] customPhysicsTokens Custom tokens to be reported by the parsing
89 /// see \sa CustomUsdPhysicsTokens
90 /// \param[in] simulationOwners List of simulation owners that should be parsed,
91 /// adding SdfPath() indicates that objects without a
92 /// simulation owner should be parsed too.
93 /// \return True if load was successful
95  const std::vector<SdfPath>& includePaths,
96  UsdPhysicsReportFn reportFn,
97  const VtValue& userData,
98  const std::vector<SdfPath>* excludePaths = nullptr,
99  const CustomUsdPhysicsTokens* customPhysicsTokens = nullptr,
100  const std::vector<SdfPath>* simulationOwners = nullptr);
101 
102 
104 
105 #endif
std::vector< TfToken > shapeTokens
Custom shapes to be reported by parsing.
Definition: parseUtils.h:55
void
Definition: png.h:1083
std::vector< TfToken > instancerTokens
Definition: parseUtils.h:58
std::function< void(UsdPhysicsObjectType type, TfSpan< const SdfPath > primPaths, TfSpan< const UsdPhysicsObjectDesc > objectDescs, const VtValue &userData)> UsdPhysicsReportFn
Definition: parseUtils.h:43
UsdStagePtr UsdStageWeakPtr
Definition: common.h:38
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
Definition: span.h:70
#define USDPHYSICS_API
Definition: api.h:23
std::vector< TfToken > jointTokens
Custom joints to be reported by parsing.
Definition: parseUtils.h:53
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USDPHYSICS_API bool LoadUsdPhysicsFromRange(const UsdStageWeakPtr stage, const std::vector< SdfPath > &includePaths, UsdPhysicsReportFn reportFn, const VtValue &userData, const std::vector< SdfPath > *excludePaths=nullptr, const CustomUsdPhysicsTokens *customPhysicsTokens=nullptr, const std::vector< SdfPath > *simulationOwners=nullptr)
Definition: value.h:146