HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
collisionAPI.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_COLLISIONAPI_H
8 #define USDPHYSICS_GENERATED_COLLISIONAPI_H
9 
10 /// \file usdPhysics/collisionAPI.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/vt/value.h"
20 
21 #include "pxr/base/gf/vec3d.h"
22 #include "pxr/base/gf/vec3f.h"
23 #include "pxr/base/gf/matrix4d.h"
24 
25 #include "pxr/base/tf/token.h"
26 #include "pxr/base/tf/type.h"
27 
29 
30 class SdfAssetPath;
31 
32 // -------------------------------------------------------------------------- //
33 // PHYSICSCOLLISIONAPI //
34 // -------------------------------------------------------------------------- //
35 
36 /// \class UsdPhysicsCollisionAPI
37 ///
38 /// Applies collision attributes to a UsdGeomXformable prim. If a
39 /// simulation is running, this geometry will collide with other geometries that
40 /// have PhysicsCollisionAPI applied. If a prim in the parent hierarchy has the
41 /// RigidBodyAPI applied, this collider is a part of that body. If there is
42 /// no body in the parent hierarchy, this collider is considered to be static.
43 ///
45 {
46 public:
47  /// Compile time constant representing what kind of schema this class is.
48  ///
49  /// \sa UsdSchemaKind
51 
52  /// Construct a UsdPhysicsCollisionAPI on UsdPrim \p prim .
53  /// Equivalent to UsdPhysicsCollisionAPI::Get(prim.GetStage(), prim.GetPath())
54  /// for a \em valid \p prim, but will not immediately throw an error for
55  /// an invalid \p prim
56  explicit UsdPhysicsCollisionAPI(const UsdPrim& prim=UsdPrim())
57  : UsdAPISchemaBase(prim)
58  {
59  }
60 
61  /// Construct a UsdPhysicsCollisionAPI on the prim held by \p schemaObj .
62  /// Should be preferred over UsdPhysicsCollisionAPI(schemaObj.GetPrim()),
63  /// as it preserves SchemaBase state.
64  explicit UsdPhysicsCollisionAPI(const UsdSchemaBase& schemaObj)
65  : UsdAPISchemaBase(schemaObj)
66  {
67  }
68 
69  /// Destructor.
71  virtual ~UsdPhysicsCollisionAPI();
72 
73  /// Return a vector of names of all pre-declared attributes for this schema
74  /// class and all its ancestor classes. Does not include attributes that
75  /// may be authored by custom/extended methods of the schemas involved.
77  static const TfTokenVector &
78  GetSchemaAttributeNames(bool includeInherited=true);
79 
80  /// Return a UsdPhysicsCollisionAPI holding the prim adhering to this
81  /// schema at \p path on \p stage. If no prim exists at \p path on
82  /// \p stage, or if the prim at that path does not adhere to this schema,
83  /// return an invalid schema object. This is shorthand for the following:
84  ///
85  /// \code
86  /// UsdPhysicsCollisionAPI(stage->GetPrimAtPath(path));
87  /// \endcode
88  ///
91  Get(const UsdStagePtr &stage, const SdfPath &path);
92 
93 
94  /// Returns true if this <b>single-apply</b> API schema can be applied to
95  /// the given \p prim. If this schema can not be a applied to the prim,
96  /// this returns false and, if provided, populates \p whyNot with the
97  /// reason it can not be applied.
98  ///
99  /// Note that if CanApply returns false, that does not necessarily imply
100  /// that calling Apply will fail. Callers are expected to call CanApply
101  /// before calling Apply if they want to ensure that it is valid to
102  /// apply a schema.
103  ///
104  /// \sa UsdPrim::GetAppliedSchemas()
105  /// \sa UsdPrim::HasAPI()
106  /// \sa UsdPrim::CanApplyAPI()
107  /// \sa UsdPrim::ApplyAPI()
108  /// \sa UsdPrim::RemoveAPI()
109  ///
111  static bool
112  CanApply(const UsdPrim &prim, std::string *whyNot=nullptr);
113 
114  /// Applies this <b>single-apply</b> API schema to the given \p prim.
115  /// This information is stored by adding "PhysicsCollisionAPI" to the
116  /// token-valued, listOp metadata \em apiSchemas on the prim.
117  ///
118  /// \return A valid UsdPhysicsCollisionAPI object is returned upon success.
119  /// An invalid (or empty) UsdPhysicsCollisionAPI object is returned upon
120  /// failure. See \ref UsdPrim::ApplyAPI() for conditions
121  /// resulting in failure.
122  ///
123  /// \sa UsdPrim::GetAppliedSchemas()
124  /// \sa UsdPrim::HasAPI()
125  /// \sa UsdPrim::CanApplyAPI()
126  /// \sa UsdPrim::ApplyAPI()
127  /// \sa UsdPrim::RemoveAPI()
128  ///
130  static UsdPhysicsCollisionAPI
131  Apply(const UsdPrim &prim);
132 
133 protected:
134  /// Returns the kind of schema this class belongs to.
135  ///
136  /// \sa UsdSchemaKind
138  UsdSchemaKind _GetSchemaKind() const override;
139 
140 private:
141  // needs to invoke _GetStaticTfType.
142  friend class UsdSchemaRegistry;
144  static const TfType &_GetStaticTfType();
145 
146  static bool _IsTypedSchema();
147 
148  // override SchemaBase virtuals.
150  const TfType &_GetTfType() const override;
151 
152 public:
153  // --------------------------------------------------------------------- //
154  // COLLISIONENABLED
155  // --------------------------------------------------------------------- //
156  /// Determines if the PhysicsCollisionAPI is enabled.
157  ///
158  /// | ||
159  /// | -- | -- |
160  /// | Declaration | `bool physics:collisionEnabled = 1` |
161  /// | C++ Type | bool |
162  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Bool |
165 
166  /// See GetCollisionEnabledAttr(), and also
167  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
168  /// If specified, author \p defaultValue as the attribute's default,
169  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
170  /// the default for \p writeSparsely is \c false.
172  UsdAttribute CreateCollisionEnabledAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
173 
174 public:
175  // --------------------------------------------------------------------- //
176  // SIMULATIONOWNER
177  // --------------------------------------------------------------------- //
178  /// Single PhysicsScene that will simulate this collider.
179  /// By default this object belongs to the first PhysicsScene.
180  /// Note that if a RigidBodyAPI in the hierarchy above has a different
181  /// simulationOwner then it has a precedence over this relationship.
182  ///
185 
186  /// See GetSimulationOwnerRel(), and also
187  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create
190 
191 public:
192  // ===================================================================== //
193  // Feel free to add custom code below this line, it will be preserved by
194  // the code generator.
195  //
196  // Just remember to:
197  // - Close the class declaration with };
198  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
199  // - Close the include guard with #endif
200  // ===================================================================== //
201  // --(BEGIN CUSTOM CODE)--
202 };
203 
205 
206 #endif
USDPHYSICS_API UsdAttribute CreateCollisionEnabledAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
Single Apply API schema.
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USDPHYSICS_API UsdRelationship GetSimulationOwnerRel() const
static USDPHYSICS_API bool CanApply(const UsdPrim &prim, std::string *whyNot=nullptr)
UsdPhysicsCollisionAPI(const UsdPrim &prim=UsdPrim())
Definition: collisionAPI.h:56
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
Definition: path.h:273
#define USDPHYSICS_API
Definition: api.h:23
USDPHYSICS_API UsdSchemaKind _GetSchemaKind() const override
UsdSchemaKind
Definition: common.h:112
static USDPHYSICS_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
UsdPhysicsCollisionAPI(const UsdSchemaBase &schemaObj)
Definition: collisionAPI.h:64
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
virtual USDPHYSICS_API ~UsdPhysicsCollisionAPI()
Destructor.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USDPHYSICS_API UsdRelationship CreateSimulationOwnerRel() const
Definition: type.h:47
USDPHYSICS_API UsdAttribute GetCollisionEnabledAttr() const
static USDPHYSICS_API UsdPhysicsCollisionAPI Apply(const UsdPrim &prim)
static USDPHYSICS_API UsdPhysicsCollisionAPI Get(const UsdStagePtr &stage, const SdfPath &path)
static const UsdSchemaKind schemaKind
Definition: collisionAPI.h:50
Definition: value.h:146