| 1 | // | 
| 2 | // Redistribution and use in source and binary forms, with or without | 
| 3 | // modification, are permitted provided that the following conditions | 
| 4 | // are met: | 
| 5 | //  * Redistributions of source code must retain the above copyright | 
| 6 | //    notice, this list of conditions and the following disclaimer. | 
| 7 | //  * Redistributions in binary form must reproduce the above copyright | 
| 8 | //    notice, this list of conditions and the following disclaimer in the | 
| 9 | //    documentation and/or other materials provided with the distribution. | 
| 10 | //  * Neither the name of NVIDIA CORPORATION nor the names of its | 
| 11 | //    contributors may be used to endorse or promote products derived | 
| 12 | //    from this software without specific prior written permission. | 
| 13 | // | 
| 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY | 
| 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
| 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 
| 17 | // PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR | 
| 18 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 
| 19 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 
| 20 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 
| 21 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 
| 22 | // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
| 23 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
| 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| 25 | // | 
| 26 | // Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved. | 
| 27 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. | 
| 28 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.   | 
| 29 |  | 
| 30 |  | 
| 31 | #ifndef PX_PHYSICS_EXTENSIONS_RIGIDACTOR_H | 
| 32 | #define PX_PHYSICS_EXTENSIONS_RIGIDACTOR_H | 
| 33 | /** \addtogroup extensions | 
| 34 |   @{ | 
| 35 | */ | 
| 36 |  | 
| 37 | #include "PxPhysXConfig.h" | 
| 38 | #include "PxPhysics.h" | 
| 39 | #include "PxRigidActor.h" | 
| 40 |  | 
| 41 | #if !PX_DOXYGEN | 
| 42 | namespace physx | 
| 43 | { | 
| 44 | #endif | 
| 45 |  | 
| 46 | /** | 
| 47 | \brief utility functions for use with PxRigidActor and subclasses | 
| 48 |  | 
| 49 | @see PxRigidActor PxRigidStatic PxRigidBody PxRigidDynamic PxArticulationLink | 
| 50 | */ | 
| 51 |  | 
| 52 | class PxRigidActorExt | 
| 53 | { | 
| 54 | public: | 
| 55 |  | 
| 56 | 	/** | 
| 57 | 	\brief Creates a new shape with default properties and a list of materials and adds it to the list of shapes of this actor. | 
| 58 | 	 | 
| 59 | 	This is equivalent to the following | 
| 60 |  | 
| 61 | 	PxShape* shape(...) = PxGetPhysics().createShape(...);	// reference count is 1 | 
| 62 | 	actor->attachShape(shape);								// increments reference count | 
| 63 | 	shape->release();										// releases user reference, leaving reference count at 1 | 
| 64 |  | 
| 65 | 	As a consequence, detachShape() will result in the release of the last reference, and the shape will be deleted. | 
| 66 |  | 
| 67 | 	\note The default shape flags to be set are: eVISUALIZATION, eSIMULATION_SHAPE, eSCENE_QUERY_SHAPE (see #PxShapeFlag). | 
| 68 | 	Triangle mesh, heightfield or plane geometry shapes configured as eSIMULATION_SHAPE are not supported for  | 
| 69 | 	non-kinematic PxRigidDynamic instances. | 
| 70 |  | 
| 71 | 	\note Creating compounds with a very large number of shapes may adversely affect performance and stability. | 
| 72 |  | 
| 73 | 	<b>Sleeping:</b> Does <b>NOT</b> wake the actor up automatically. | 
| 74 |  | 
| 75 | 	\param[in] actor the actor to which to attach the shape | 
| 76 | 	\param[in] geometry	the geometry of the shape | 
| 77 | 	\param[in] materials a pointer to an array of material pointers | 
| 78 | 	\param[in] materialCount the count of materials | 
| 79 | 	\param[in] shapeFlags optional PxShapeFlags | 
| 80 |  | 
| 81 | 	\return The newly created shape. | 
| 82 |  | 
| 83 | 	@see PxShape PxShape::release(), PxPhysics::createShape(), PxRigidActor::attachShape() | 
| 84 | 	*/ | 
| 85 |  | 
| 86 | 	static PxShape* createExclusiveShape(PxRigidActor& actor, const PxGeometry& geometry, PxMaterial*const* materials, PxU16 materialCount,  | 
| 87 | 								         PxShapeFlags shapeFlags = PxShapeFlag::eVISUALIZATION | PxShapeFlag::eSCENE_QUERY_SHAPE | PxShapeFlag::eSIMULATION_SHAPE) | 
| 88 | 	{ | 
| 89 | 		PxShape* shape = PxGetPhysics().createShape(geometry, materials, materialCount, isExclusive: true, shapeFlags); | 
| 90 | 		if(shape) | 
| 91 | 		{ | 
| 92 | 			bool status = actor.attachShape(shape&: *shape);	// attach can fail, if e.g. we try and attach a trimesh simulation shape to a dynamic actor | 
| 93 | 			shape->release();		// if attach fails, we hold the only counted reference, and so this cleans up properly | 
| 94 | 			if(!status) | 
| 95 | 				shape = NULL; | 
| 96 | 		} | 
| 97 | 		return shape; | 
| 98 | 	} | 
| 99 | 	 | 
| 100 | 	/** | 
| 101 | 	\brief Creates a new shape with default properties and a single material adds it to the list of shapes of this actor. | 
| 102 |  | 
| 103 | 	This is equivalent to the following | 
| 104 |  | 
| 105 | 	PxShape* shape(...) = PxGetPhysics().createShape(...);	// reference count is 1 | 
| 106 | 	actor->attachShape(shape);								// increments reference count | 
| 107 | 	shape->release();										// releases user reference, leaving reference count at 1 | 
| 108 |  | 
| 109 | 	As a consequence, detachShape() will result in the release of the last reference, and the shape will be deleted. | 
| 110 |  | 
| 111 | 	\note The default shape flags to be set are: eVISUALIZATION, eSIMULATION_SHAPE, eSCENE_QUERY_SHAPE (see #PxShapeFlag). | 
| 112 | 	Triangle mesh, heightfield or plane geometry shapes configured as eSIMULATION_SHAPE are not supported for  | 
| 113 | 	non-kinematic PxRigidDynamic instances. | 
| 114 |  | 
| 115 | 	\note Creating compounds with a very large number of shapes may adversely affect performance and stability. | 
| 116 |  | 
| 117 | 	<b>Sleeping:</b> Does <b>NOT</b> wake the actor up automatically. | 
| 118 |  | 
| 119 | 	\param[in] actor the actor to which to attach the shape | 
| 120 | 	\param[in] geometry	the geometry of the shape | 
| 121 | 	\param[in] material	the material for the shape | 
| 122 | 	\param[in] shapeFlags optional PxShapeFlags | 
| 123 |  | 
| 124 | 	\return The newly created shape. | 
| 125 |  | 
| 126 | 	@see PxShape PxShape::release(), PxPhysics::createShape(), PxRigidActor::attachShape() | 
| 127 | 	*/ | 
| 128 |  | 
| 129 | 	static PX_FORCE_INLINE	PxShape*	createExclusiveShape(PxRigidActor& actor, const PxGeometry& geometry, const PxMaterial& material,  | 
| 130 | 													         PxShapeFlags shapeFlags = PxShapeFlag::eVISUALIZATION | PxShapeFlag::eSCENE_QUERY_SHAPE | PxShapeFlag::eSIMULATION_SHAPE) | 
| 131 | 	{ | 
| 132 | 		PxMaterial* materialPtr = const_cast<PxMaterial*>(&material); | 
| 133 | 		return createExclusiveShape(actor, geometry, materials: &materialPtr, materialCount: 1, shapeFlags); | 
| 134 | 	} | 
| 135 |  | 
| 136 |  | 
| 137 | 	/** | 
| 138 | 	\brief Gets a list of bounds based on shapes in rigid actor. This list can be used to cook/create | 
| 139 | 	bounding volume hierarchy though PxCooking API. | 
| 140 |  | 
| 141 | 	\param[in] actor The actor from which the bounds list is retrieved. | 
| 142 | 	\param[out] numBounds Number of bounds in returned list. | 
| 143 |  | 
| 144 | 	@see PxShape PxBVHStructure PxCooking::createBVHStructure PxCooking::cookBVHStructure | 
| 145 | 	*/ | 
| 146 | 	static PxBounds3*					getRigidActorShapeLocalBoundsList(const PxRigidActor& actor, PxU32& numBounds); | 
| 147 |  | 
| 148 | }; | 
| 149 |  | 
| 150 | #if !PX_DOXYGEN | 
| 151 | } // namespace physx | 
| 152 | #endif | 
| 153 |  | 
| 154 | /** @} */ | 
| 155 | #endif | 
| 156 |  |