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