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 accordingly.
45 ///
47 {
48 public:
49  /// Compile time constant representing what kind of schema this class is.
50  ///
51  /// \sa UsdSchemaKind
53 
54  /// Construct a UsdPhysicsRigidBodyAPI on UsdPrim \p prim .
55  /// Equivalent to UsdPhysicsRigidBodyAPI::Get(prim.GetStage(), prim.GetPath())
56  /// for a \em valid \p prim, but will not immediately throw an error for
57  /// an invalid \p prim
58  explicit UsdPhysicsRigidBodyAPI(const UsdPrim& prim=UsdPrim())
59  : UsdAPISchemaBase(prim)
60  {
61  }
62 
63  /// Construct a UsdPhysicsRigidBodyAPI on the prim held by \p schemaObj .
64  /// Should be preferred over UsdPhysicsRigidBodyAPI(schemaObj.GetPrim()),
65  /// as it preserves SchemaBase state.
66  explicit UsdPhysicsRigidBodyAPI(const UsdSchemaBase& schemaObj)
67  : UsdAPISchemaBase(schemaObj)
68  {
69  }
70 
71  /// Destructor.
73  virtual ~UsdPhysicsRigidBodyAPI();
74 
75  /// Return a vector of names of all pre-declared attributes for this schema
76  /// class and all its ancestor classes. Does not include attributes that
77  /// may be authored by custom/extended methods of the schemas involved.
79  static const TfTokenVector &
80  GetSchemaAttributeNames(bool includeInherited=true);
81 
82  /// Return a UsdPhysicsRigidBodyAPI holding the prim adhering to this
83  /// schema at \p path on \p stage. If no prim exists at \p path on
84  /// \p stage, or if the prim at that path does not adhere to this schema,
85  /// return an invalid schema object. This is shorthand for the following:
86  ///
87  /// \code
88  /// UsdPhysicsRigidBodyAPI(stage->GetPrimAtPath(path));
89  /// \endcode
90  ///
93  Get(const UsdStagePtr &stage, const SdfPath &path);
94 
95 
96  /// Returns true if this <b>single-apply</b> API schema can be applied to
97  /// the given \p prim. If this schema can not be a applied to the prim,
98  /// this returns false and, if provided, populates \p whyNot with the
99  /// reason it can not be applied.
100  ///
101  /// Note that if CanApply returns false, that does not necessarily imply
102  /// that calling Apply will fail. Callers are expected to call CanApply
103  /// before calling Apply if they want to ensure that it is valid to
104  /// apply a schema.
105  ///
106  /// \sa UsdPrim::GetAppliedSchemas()
107  /// \sa UsdPrim::HasAPI()
108  /// \sa UsdPrim::CanApplyAPI()
109  /// \sa UsdPrim::ApplyAPI()
110  /// \sa UsdPrim::RemoveAPI()
111  ///
113  static bool
114  CanApply(const UsdPrim &prim, std::string *whyNot=nullptr);
115 
116  /// Applies this <b>single-apply</b> API schema to the given \p prim.
117  /// This information is stored by adding "PhysicsRigidBodyAPI" to the
118  /// token-valued, listOp metadata \em apiSchemas on the prim.
119  ///
120  /// \return A valid UsdPhysicsRigidBodyAPI object is returned upon success.
121  /// An invalid (or empty) UsdPhysicsRigidBodyAPI object is returned upon
122  /// failure. See \ref UsdPrim::ApplyAPI() for conditions
123  /// resulting in failure.
124  ///
125  /// \sa UsdPrim::GetAppliedSchemas()
126  /// \sa UsdPrim::HasAPI()
127  /// \sa UsdPrim::CanApplyAPI()
128  /// \sa UsdPrim::ApplyAPI()
129  /// \sa UsdPrim::RemoveAPI()
130  ///
132  static UsdPhysicsRigidBodyAPI
133  Apply(const UsdPrim &prim);
134 
135 protected:
136  /// Returns the kind of schema this class belongs to.
137  ///
138  /// \sa UsdSchemaKind
140  UsdSchemaKind _GetSchemaKind() const override;
141 
142 private:
143  // needs to invoke _GetStaticTfType.
144  friend class UsdSchemaRegistry;
146  static const TfType &_GetStaticTfType();
147 
148  static bool _IsTypedSchema();
149 
150  // override SchemaBase virtuals.
152  const TfType &_GetTfType() const override;
153 
154 public:
155  // --------------------------------------------------------------------- //
156  // RIGIDBODYENABLED
157  // --------------------------------------------------------------------- //
158  /// Determines if this PhysicsRigidBodyAPI is enabled.
159  ///
160  /// | ||
161  /// | -- | -- |
162  /// | Declaration | `bool physics:rigidBodyEnabled = 1` |
163  /// | C++ Type | bool |
164  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Bool |
167 
168  /// See GetRigidBodyEnabledAttr(), and also
169  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
170  /// If specified, author \p defaultValue as the attribute's default,
171  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
172  /// the default for \p writeSparsely is \c false.
174  UsdAttribute CreateRigidBodyEnabledAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
175 
176 public:
177  // --------------------------------------------------------------------- //
178  // KINEMATICENABLED
179  // --------------------------------------------------------------------- //
180  /// Determines whether the body is kinematic or not. A kinematic
181  /// body is a body that is moved through animated poses or through
182  /// user defined poses. The simulation derives velocities for the
183  /// kinematic body based on the external motion. When a continuous motion
184  /// is not desired, this kinematic flag should be set to false.
185  ///
186  /// | ||
187  /// | -- | -- |
188  /// | Declaration | `bool physics:kinematicEnabled = 0` |
189  /// | C++ Type | bool |
190  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Bool |
193 
194  /// See GetKinematicEnabledAttr(), and also
195  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
196  /// If specified, author \p defaultValue as the attribute's default,
197  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
198  /// the default for \p writeSparsely is \c false.
200  UsdAttribute CreateKinematicEnabledAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
201 
202 public:
203  // --------------------------------------------------------------------- //
204  // STARTSASLEEP
205  // --------------------------------------------------------------------- //
206  /// Determines if the body is asleep when the simulation starts.
207  ///
208  /// | ||
209  /// | -- | -- |
210  /// | Declaration | `uniform bool physics:startsAsleep = 0` |
211  /// | C++ Type | bool |
212  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Bool |
213  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
216 
217  /// See GetStartsAsleepAttr(), and also
218  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
219  /// If specified, author \p defaultValue as the attribute's default,
220  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
221  /// the default for \p writeSparsely is \c false.
223  UsdAttribute CreateStartsAsleepAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
224 
225 public:
226  // --------------------------------------------------------------------- //
227  // VELOCITY
228  // --------------------------------------------------------------------- //
229  /// Linear velocity in the same space as the node's xform.
230  /// Units: distance/second.
231  ///
232  /// | ||
233  /// | -- | -- |
234  /// | Declaration | `vector3f physics:velocity = (0, 0, 0)` |
235  /// | C++ Type | GfVec3f |
236  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Vector3f |
239 
240  /// See GetVelocityAttr(), and also
241  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
242  /// If specified, author \p defaultValue as the attribute's default,
243  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
244  /// the default for \p writeSparsely is \c false.
246  UsdAttribute CreateVelocityAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
247 
248 public:
249  // --------------------------------------------------------------------- //
250  // ANGULARVELOCITY
251  // --------------------------------------------------------------------- //
252  /// Angular velocity in the same space as the node's xform.
253  /// Units: degrees/second.
254  ///
255  /// | ||
256  /// | -- | -- |
257  /// | Declaration | `vector3f physics:angularVelocity = (0, 0, 0)` |
258  /// | C++ Type | GfVec3f |
259  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Vector3f |
262 
263  /// See GetAngularVelocityAttr(), and also
264  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
265  /// If specified, author \p defaultValue as the attribute's default,
266  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
267  /// the default for \p writeSparsely is \c false.
269  UsdAttribute CreateAngularVelocityAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
270 
271 public:
272  // --------------------------------------------------------------------- //
273  // SIMULATIONOWNER
274  // --------------------------------------------------------------------- //
275  /// Single PhysicsScene that will simulate this body. By
276  /// default this is the first PhysicsScene found in the stage using
277  /// UsdStage::Traverse().
278  ///
281 
282  /// See GetSimulationOwnerRel(), and also
283  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create
286 
287 public:
288  // ===================================================================== //
289  // Feel free to add custom code below this line, it will be preserved by
290  // the code generator.
291  //
292  // Just remember to:
293  // - Close the class declaration with };
294  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
295  // - Close the include guard with #endif
296  // ===================================================================== //
297  // --(BEGIN CUSTOM CODE)--
298 
299  /// Mass information for a collision, used in ComputeMassProperties MassInformationFn callback
301  {
302  float volume; //< Collision volume
303  GfMatrix3f inertia; //< Collision inertia
304  GfVec3f centerOfMass; //< Collision center of mass
305  GfVec3f localPos; //< Collision local position with respect to the rigid body
306  GfQuatf localRot; //< Collision local rotation with respect to the rigid body
307  };
308 
309  /// Mass information function signature, for given UsdPrim gather MassInformation
311  typedef std::function<MassInformationFnSig> MassInformationFn;
312 
313  /// Compute mass properties of the rigid body
314  /// \p diagonalInertia Computed diagonal of the inertial tensor for the rigid body.
315  /// \p com Computed center of mass for the rigid body.
316  /// \p principalAxes Inertia tensor's principal axes orienttion for the rigid body.
317  /// \p massInfoFn Callback function to get collision mass information.
318  /// \return Computed mass of the rigid body
320  float ComputeMassProperties(GfVec3f* diagonalInertia, GfVec3f* com, GfQuatf* principalAxes,
321  const MassInformationFn& massInfoFn) const;
322 
323 };
324 
326 
327 #endif
USDPHYSICS_API UsdAttribute CreateVelocityAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
std::function< MassInformationFnSig > MassInformationFn
Definition: rigidBodyAPI.h:311
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.
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:52
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:310
UsdPhysicsRigidBodyAPI(const UsdSchemaBase &schemaObj)
Definition: rigidBodyAPI.h:66
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
USDPHYSICS_API UsdRelationship GetSimulationOwnerRel() const
Definition: path.h:273
#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:300
USDPHYSICS_API UsdAttribute CreateKinematicEnabledAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
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:58
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:146