HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rigidBodyAPI.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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_GENERATED_RIGIDBODYAPI_H
8 #define USDPHYSICS_GENERATED_RIGIDBODYAPI_H
9 
10 /// \file usdPhysics/rigidBodyAPI.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usdPhysics/api.h"
15 #include "pxr/usd/usd/prim.h"
16 #include "pxr/usd/usd/stage.h"
18 
19 #include "pxr/base/gf/matrix3f.h"
20 #include "pxr/base/gf/quatf.h"
21 
22 #include "pxr/base/vt/value.h"
23 
24 #include "pxr/base/gf/vec3d.h"
25 #include "pxr/base/gf/vec3f.h"
26 #include "pxr/base/gf/matrix4d.h"
27 
28 #include "pxr/base/tf/token.h"
29 #include "pxr/base/tf/type.h"
30 
32 
33 class SdfAssetPath;
34 
35 // -------------------------------------------------------------------------- //
36 // PHYSICSRIGIDBODYAPI //
37 // -------------------------------------------------------------------------- //
38 
39 /// \class UsdPhysicsRigidBodyAPI
40 ///
41 /// Applies physics body attributes to any UsdGeomXformable prim and
42 /// marks that prim to be driven by a simulation. If a simulation is running
43 /// it will update this prim's pose. All prims in the hierarchy below this
44 /// prim should move rigidly along with the body, except when the descendant
45 /// prim has its own UsdPhysicsRigidBodyAPI (marking a separate rigid body
46 /// subtree which moves independently of the parent rigid body).
47 ///
49 {
50 public:
51  /// Compile time constant representing what kind of schema this class is.
52  ///
53  /// \sa UsdSchemaKind
55 
56  /// Construct a UsdPhysicsRigidBodyAPI on UsdPrim \p prim .
57  /// Equivalent to UsdPhysicsRigidBodyAPI::Get(prim.GetStage(), prim.GetPath())
58  /// for a \em valid \p prim, but will not immediately throw an error for
59  /// an invalid \p prim
60  explicit UsdPhysicsRigidBodyAPI(const UsdPrim& prim=UsdPrim())
61  : UsdAPISchemaBase(prim)
62  {
63  }
64 
65  /// Construct a UsdPhysicsRigidBodyAPI on the prim held by \p schemaObj .
66  /// Should be preferred over UsdPhysicsRigidBodyAPI(schemaObj.GetPrim()),
67  /// as it preserves SchemaBase state.
68  explicit UsdPhysicsRigidBodyAPI(const UsdSchemaBase& schemaObj)
69  : UsdAPISchemaBase(schemaObj)
70  {
71  }
72 
73  /// Destructor.
75  virtual ~UsdPhysicsRigidBodyAPI();
76 
77  /// Return a vector of names of all pre-declared attributes for this schema
78  /// class and all its ancestor classes. Does not include attributes that
79  /// may be authored by custom/extended methods of the schemas involved.
81  static const TfTokenVector &
82  GetSchemaAttributeNames(bool includeInherited=true);
83 
84  /// Return a UsdPhysicsRigidBodyAPI holding the prim adhering to this
85  /// schema at \p path on \p stage. If no prim exists at \p path on
86  /// \p stage, or if the prim at that path does not adhere to this schema,
87  /// return an invalid schema object. This is shorthand for the following:
88  ///
89  /// \code
90  /// UsdPhysicsRigidBodyAPI(stage->GetPrimAtPath(path));
91  /// \endcode
92  ///
95  Get(const UsdStagePtr &stage, const SdfPath &path);
96 
97 
98  /// Returns true if this <b>single-apply</b> API schema can be applied to
99  /// the given \p prim. If this schema can not be a applied to the prim,
100  /// this returns false and, if provided, populates \p whyNot with the
101  /// reason it can not be applied.
102  ///
103  /// Note that if CanApply returns false, that does not necessarily imply
104  /// that calling Apply will fail. Callers are expected to call CanApply
105  /// before calling Apply if they want to ensure that it is valid to
106  /// apply a schema.
107  ///
108  /// \sa UsdPrim::GetAppliedSchemas()
109  /// \sa UsdPrim::HasAPI()
110  /// \sa UsdPrim::CanApplyAPI()
111  /// \sa UsdPrim::ApplyAPI()
112  /// \sa UsdPrim::RemoveAPI()
113  ///
115  static bool
116  CanApply(const UsdPrim &prim, std::string *whyNot=nullptr);
117 
118  /// Applies this <b>single-apply</b> API schema to the given \p prim.
119  /// This information is stored by adding "PhysicsRigidBodyAPI" to the
120  /// token-valued, listOp metadata \em apiSchemas on the prim.
121  ///
122  /// \return A valid UsdPhysicsRigidBodyAPI object is returned upon success.
123  /// An invalid (or empty) UsdPhysicsRigidBodyAPI object is returned upon
124  /// failure. See \ref UsdPrim::ApplyAPI() for conditions
125  /// resulting in failure.
126  ///
127  /// \sa UsdPrim::GetAppliedSchemas()
128  /// \sa UsdPrim::HasAPI()
129  /// \sa UsdPrim::CanApplyAPI()
130  /// \sa UsdPrim::ApplyAPI()
131  /// \sa UsdPrim::RemoveAPI()
132  ///
134  static UsdPhysicsRigidBodyAPI
135  Apply(const UsdPrim &prim);
136 
137 protected:
138  /// Returns the kind of schema this class belongs to.
139  ///
140  /// \sa UsdSchemaKind
142  UsdSchemaKind _GetSchemaKind() const override;
143 
144 private:
145  // needs to invoke _GetStaticTfType.
146  friend class UsdSchemaRegistry;
148  static const TfType &_GetStaticTfType();
149 
150  static bool _IsTypedSchema();
151 
152  // override SchemaBase virtuals.
154  const TfType &_GetTfType() const override;
155 
156 public:
157  // --------------------------------------------------------------------- //
158  // RIGIDBODYENABLED
159  // --------------------------------------------------------------------- //
160  /// Determines if this PhysicsRigidBodyAPI is enabled.
161  ///
162  /// | ||
163  /// | -- | -- |
164  /// | Declaration | `bool physics:rigidBodyEnabled = 1` |
165  /// | C++ Type | bool |
166  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Bool |
169 
170  /// See GetRigidBodyEnabledAttr(), and also
171  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
172  /// If specified, author \p defaultValue as the attribute's default,
173  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
174  /// the default for \p writeSparsely is \c false.
176  UsdAttribute CreateRigidBodyEnabledAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
177 
178 public:
179  // --------------------------------------------------------------------- //
180  // KINEMATICENABLED
181  // --------------------------------------------------------------------- //
182  /// Determines whether the body is kinematic or not. A kinematic
183  /// body is a body that is moved through animated poses or through
184  /// user defined poses. The simulation derives velocities for the
185  /// kinematic body based on the external motion. When a continuous motion
186  /// is not desired, this kinematic flag should be set to false.
187  ///
188  /// | ||
189  /// | -- | -- |
190  /// | Declaration | `bool physics:kinematicEnabled = 0` |
191  /// | C++ Type | bool |
192  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Bool |
195 
196  /// See GetKinematicEnabledAttr(), and also
197  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
198  /// If specified, author \p defaultValue as the attribute's default,
199  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
200  /// the default for \p writeSparsely is \c false.
202  UsdAttribute CreateKinematicEnabledAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
203 
204 public:
205  // --------------------------------------------------------------------- //
206  // STARTSASLEEP
207  // --------------------------------------------------------------------- //
208  /// Determines if the body is asleep when the simulation starts.
209  ///
210  /// | ||
211  /// | -- | -- |
212  /// | Declaration | `uniform bool physics:startsAsleep = 0` |
213  /// | C++ Type | bool |
214  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Bool |
215  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
218 
219  /// See GetStartsAsleepAttr(), and also
220  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
221  /// If specified, author \p defaultValue as the attribute's default,
222  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
223  /// the default for \p writeSparsely is \c false.
225  UsdAttribute CreateStartsAsleepAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
226 
227 public:
228  // --------------------------------------------------------------------- //
229  // VELOCITY
230  // --------------------------------------------------------------------- //
231  /// Linear velocity in the same space as the node's xform.
232  /// Units: distance/second.
233  ///
234  /// | ||
235  /// | -- | -- |
236  /// | Declaration | `vector3f physics:velocity = (0, 0, 0)` |
237  /// | C++ Type | GfVec3f |
238  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Vector3f |
241 
242  /// See GetVelocityAttr(), and also
243  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
244  /// If specified, author \p defaultValue as the attribute's default,
245  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
246  /// the default for \p writeSparsely is \c false.
248  UsdAttribute CreateVelocityAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
249 
250 public:
251  // --------------------------------------------------------------------- //
252  // ANGULARVELOCITY
253  // --------------------------------------------------------------------- //
254  /// Angular velocity in the same space as the node's xform.
255  /// Units: degrees/second.
256  ///
257  /// | ||
258  /// | -- | -- |
259  /// | Declaration | `vector3f physics:angularVelocity = (0, 0, 0)` |
260  /// | C++ Type | GfVec3f |
261  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Vector3f |
264 
265  /// See GetAngularVelocityAttr(), and also
266  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
267  /// If specified, author \p defaultValue as the attribute's default,
268  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
269  /// the default for \p writeSparsely is \c false.
271  UsdAttribute CreateAngularVelocityAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
272 
273 public:
274  // --------------------------------------------------------------------- //
275  // SIMULATIONOWNER
276  // --------------------------------------------------------------------- //
277  /// Single PhysicsScene that will simulate this body. By
278  /// default this is the first PhysicsScene found in the stage using
279  /// UsdStage::Traverse().
280  ///
283 
284  /// See GetSimulationOwnerRel(), and also
285  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create
288 
289 public:
290  // ===================================================================== //
291  // Feel free to add custom code below this line, it will be preserved by
292  // the code generator.
293  //
294  // Just remember to:
295  // - Close the class declaration with };
296  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
297  // - Close the include guard with #endif
298  // ===================================================================== //
299  // --(BEGIN CUSTOM CODE)--
300 
301  /// Mass information for a collision, used in ComputeMassProperties MassInformationFn callback
303  {
304  float volume; //< Collision volume
305  GfMatrix3f inertia; //< Collision inertia
306  GfVec3f centerOfMass; //< Collision center of mass
307  GfVec3f localPos; //< Collision local position with respect to the rigid body
308  GfQuatf localRot; //< Collision local rotation with respect to the rigid body
309  };
310 
311  /// Mass information function signature, for given UsdPrim gather MassInformation
313  typedef std::function<MassInformationFnSig> MassInformationFn;
314 
315  /// Compute mass properties of the rigid body
316  /// \p diagonalInertia Computed diagonal of the inertial tensor for the rigid body.
317  /// \p com Computed center of mass for the rigid body.
318  /// \p principalAxes Inertia tensor's principal axes orienttion for the rigid body.
319  /// \p massInfoFn Callback function to get collision mass information.
320  /// \return Computed mass of the rigid body
322  float ComputeMassProperties(GfVec3f* diagonalInertia, GfVec3f* com, GfQuatf* principalAxes,
323  const MassInformationFn& massInfoFn) const;
324 
325 };
326 
328 
329 #endif
USDPHYSICS_API UsdAttribute CreateVelocityAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
std::function< MassInformationFnSig > MassInformationFn
Definition: rigidBodyAPI.h:313
USDPHYSICS_API UsdAttribute GetVelocityAttr() const
static USDPHYSICS_API bool CanApply(const UsdPrim &prim, std::string *whyNot=nullptr)
USDPHYSICS_API UsdAttribute CreateAngularVelocityAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
Single Apply API schema.
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
USDPHYSICS_API UsdRelationship CreateSimulationOwnerRel() const
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USDPHYSICS_API UsdAttribute GetAngularVelocityAttr() const
Definition: vec3f.h:45
USDPHYSICS_API UsdAttribute CreateRigidBodyEnabledAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDPHYSICS_API UsdAttribute GetRigidBodyEnabledAttr() const
GA_API const UT_StringHolder com
static const UsdSchemaKind schemaKind
Definition: rigidBodyAPI.h:54
Definition: quatf.h:42
USDPHYSICS_API float ComputeMassProperties(GfVec3f *diagonalInertia, GfVec3f *com, GfQuatf *principalAxes, const MassInformationFn &massInfoFn) const
virtual USDPHYSICS_API ~UsdPhysicsRigidBodyAPI()
Destructor.
MassInformation MassInformationFnSig(const UsdPrim &)
Mass information function signature, for given UsdPrim gather MassInformation.
Definition: rigidBodyAPI.h:312
UsdPhysicsRigidBodyAPI(const UsdSchemaBase &schemaObj)
Definition: rigidBodyAPI.h:68
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
USDPHYSICS_API UsdRelationship GetSimulationOwnerRel() const
Definition: path.h:280
#define USDPHYSICS_API
Definition: api.h:23
UsdSchemaKind
Definition: common.h:112
Mass information for a collision, used in ComputeMassProperties MassInformationFn callback...
Definition: rigidBodyAPI.h:302
USDPHYSICS_API UsdAttribute CreateKinematicEnabledAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDPHYSICS_API UsdAttribute GetKinematicEnabledAttr() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USDPHYSICS_API UsdSchemaKind _GetSchemaKind() const override
static USDPHYSICS_API UsdPhysicsRigidBodyAPI Get(const UsdStagePtr &stage, const SdfPath &path)
UsdPhysicsRigidBodyAPI(const UsdPrim &prim=UsdPrim())
Definition: rigidBodyAPI.h:60
Definition: type.h:47
USDPHYSICS_API UsdAttribute GetStartsAsleepAttr() const
USDPHYSICS_API UsdAttribute CreateStartsAsleepAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
static USDPHYSICS_API UsdPhysicsRigidBodyAPI Apply(const UsdPrim &prim)
static USDPHYSICS_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
Definition: value.h:89