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 UsdPhysicsCustomTokens
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 /// \deprecated Use UsdPhysicsCustomTokens instead of CustomUsdPhysicsTokens,
62 /// this struct is kept for backward compatibility and will be removed in the
63 /// future.
64 using CustomUsdPhysicsTokens
65  [[deprecated("Use UsdPhysicsCustomTokens")]] = UsdPhysicsCustomTokens;
66 
67 /// Load USD physics from a given list of paths. This helper function traverses
68 /// the provided USD stage by constructing UsdPrimRanges from given include
69 /// paths (subhierarchies can be prunes through exclude paths) and returns
70 /// parsed physics objects through the report function.
71 /// \sa UsdPhysicsReportFn
72 ///
73 /// See the parsing utils documentation for more details.
74 ///
75 /// \param[in] stage Stage to be traversed and parsed.
76 /// \param[in] includePaths The vector of SdfPaths that are used to construct
77 /// UsdPrimRange for traversals. For each path a UsdPrim
78 /// is found on the stage and UsdRange traversal is
79 /// constructed from it. All the traversed UsdPrims are
80 /// parsed and physics descriptors are constructed and
81 /// reported through the report function.
82 /// \param[in] reportFn Report function that gets parsed USD physics data see
83 /// \sa UsdPhysicsReportFn
84 /// \param[in] userData User data passed to report function, this can be
85 /// arbitrary data structure, user data acts as a bridge
86 /// between reportFn and the data structures understood
87 /// by the Simulator. Implementer of reportFn can use the
88 /// parsed "objectDesc" to populate these
89 /// simulator-compatible data structures, which are
90 /// passed as userData here.
91 /// \param[in] excludePaths The vector of SdfPaths that are used to prune
92 /// UsdPrims from the parsing UsdPrimRange traversals
93 /// constructed from the include paths.
94 /// \param[in] customPhysicsTokens Custom tokens to be reported by the parsing
95 /// see \sa UsdPhysicsCustomTokens
96 /// \param[in] simulationOwners List of simulation owners that should be parsed,
97 /// adding SdfPath() indicates that objects without a
98 /// simulation owner should be parsed too.
99 /// \return True if load was successful
102  const UsdStageWeakPtr& stage,
103  const std::vector<SdfPath>& includePaths,
104  UsdPhysicsReportFn reportFn,
105  const VtValue& userData,
106  const std::vector<SdfPath>* excludePaths = nullptr,
107  const UsdPhysicsCustomTokens* customPhysicsTokens = nullptr,
108  const std::vector<SdfPath>* simulationOwners = nullptr);
109 
110 /// \deprecated Use UsdPhysicsLoadStageFromPrimRange instead of
111 /// LoadUsdPhysicsFromRange, this function is kept for backward compatibility
112 /// and will be removed in the future.
113 [[deprecated("Use UsdPhysicsLoadStageFromPrimRange")]]
115  const UsdStageWeakPtr& stage,
116  const std::vector<SdfPath>& includePaths,
117  UsdPhysicsReportFn reportFn,
118  const VtValue& userData,
119  const std::vector<SdfPath>* excludePaths = nullptr,
120  const UsdPhysicsCustomTokens* customPhysicsTokens = nullptr,
121  const std::vector<SdfPath>* simulationOwners = nullptr)
122 {
124  stage, includePaths, reportFn, userData, excludePaths,
125  customPhysicsTokens, simulationOwners);
126 }
127 
128 
130 
131 #endif
USDPHYSICS_API bool UsdPhysicsLoadStageFromPrimRange(const UsdStageWeakPtr &stage, const std::vector< SdfPath > &includePaths, UsdPhysicsReportFn reportFn, const VtValue &userData, const std::vector< SdfPath > *excludePaths=nullptr, const UsdPhysicsCustomTokens *customPhysicsTokens=nullptr, const std::vector< SdfPath > *simulationOwners=nullptr)
void
Definition: png.h:1083
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
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
bool LoadUsdPhysicsFromRange(const UsdStageWeakPtr &stage, const std::vector< SdfPath > &includePaths, UsdPhysicsReportFn reportFn, const VtValue &userData, const std::vector< SdfPath > *excludePaths=nullptr, const UsdPhysicsCustomTokens *customPhysicsTokens=nullptr, const std::vector< SdfPath > *simulationOwners=nullptr)
Definition: parseUtils.h:114
Definition: span.h:70
std::vector< TfToken > instancerTokens
Definition: parseUtils.h:58
std::vector< TfToken > jointTokens
Custom joints to be reported by parsing.
Definition: parseUtils.h:53
std::vector< TfToken > shapeTokens
Custom shapes to be reported by parsing.
Definition: parseUtils.h:55
UsdPhysicsCustomTokens UsdPhysicsCustomTokens
Definition: parseUtils.h:65
#define USDPHYSICS_API
Definition: api.h:23
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Definition: value.h:89