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