This commit is contained in:
2025-11-28 23:13:44 +05:30
commit a3a8e79709
7360 changed files with 1156074 additions and 0 deletions

View File

@ -0,0 +1,138 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_BVH_STRUCTURE
#define PX_PHYSICS_BVH_STRUCTURE
/** \addtogroup geomutils
@{
*/
#include "common/PxBase.h"
#include "foundation/PxTransform.h"
#include "foundation/PxBounds3.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Class representing the bounding volume hierarchy structure.
PxBVHStructure can be provided to PxScene::addActor. In this case the scene query
pruning structure inside PhysX SDK will store/update one bound per actor.
The scene queries against such an actor will query actor bounds and then
make a local space query against the provided BVH structure, which is in
actor's local space.
@see PxScene::addActor
*/
class PxBVHStructure: public PxBase
{
public:
/**
\brief Raycast test against a BVH structure.
\param[in] origin The origin of the ray.
\param[in] unitDir Normalized direction of the ray.
\param[in] maxDist Maximum ray length, has to be in the [0, inf) range
\param[in] maxHits Max number of returned hits = size of 'rayHits' buffer
\param[out] rayHits Raycast hits information, bounds indices
\return Number of hits
*/
virtual PxU32 raycast(const PxVec3& origin,
const PxVec3& unitDir,
PxReal maxDist,
PxU32 maxHits,
PxU32* PX_RESTRICT rayHits) const = 0;
/**
\brief Sweep test against a BVH structure.
\param[in] aabb The axis aligned bounding box to sweep
\param[in] unitDir Normalized direction of the sweep.
\param[in] maxDist Maximum sweep length, has to be in the [0, inf) range
\param[in] maxHits Max number of returned hits = size of 'sweepHits' buffer
\param[out] sweepHits Sweep hits information, bounds indices
\return Number of hits
*/
virtual PxU32 sweep(const PxBounds3& aabb,
const PxVec3& unitDir,
PxReal maxDist,
PxU32 maxHits,
PxU32* PX_RESTRICT sweepHits) const = 0;
/**
\brief AABB overlap test against a BVH structure.
\param[in] aabb The axis aligned bounding box
\param[in] maxHits Max number of returned hits = size of 'overlapHits' buffer
\param[out] overlapHits Overlap hits information, bounds indices
\return Number of hits
*/
virtual PxU32 overlap(const PxBounds3& aabb,
PxU32 maxHits,
PxU32* PX_RESTRICT overlapHits) const = 0;
/**
\brief Retrieve the bounds in the BVH.
@see PxBounds3
*/
virtual const PxBounds3* getBounds() const = 0;
/**
\brief Returns the number of bounds in the BVH.
You can use #getBounds() to retrieve the bounds.
\return Number of bounds in the BVH.
*/
virtual PxU32 getNbBounds() const = 0;
virtual const char* getConcreteTypeName() const { return "PxBVHStructure"; }
protected:
PX_INLINE PxBVHStructure(PxType concreteType, PxBaseFlags baseFlags) : PxBase(concreteType, baseFlags) {}
PX_INLINE PxBVHStructure(PxBaseFlags baseFlags) : PxBase(baseFlags) {}
virtual ~PxBVHStructure() {}
virtual bool isKindOf(const char* name) const { return !::strcmp("PxBVHStructure", name) || PxBase::isKindOf(name); }
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@ -0,0 +1,109 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_NX_BOX_GEOMETRY
#define PX_PHYSICS_NX_BOX_GEOMETRY
/** \addtogroup geomutils
@{
*/
#include "geometry/PxGeometry.h"
#include "foundation/PxVec3.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Class representing the geometry of a box.
The geometry of a box can be fully specified by its half extents. This is the half of its width, height, and depth.
\note The scaling of the box is expected to be baked into these values, there is no additional scaling parameter.
*/
class PxBoxGeometry : public PxGeometry
{
public:
/**
\brief Default constructor, initializes to a box with zero dimensions.
*/
PX_INLINE PxBoxGeometry() : PxGeometry(PxGeometryType::eBOX), halfExtents(0,0,0) {}
/**
\brief Constructor to initialize half extents from scalar parameters.
\param hx Initial half extents' x component.
\param hy Initial half extents' y component.
\param hz Initial half extents' z component.
*/
PX_INLINE PxBoxGeometry(PxReal hx, PxReal hy, PxReal hz) : PxGeometry(PxGeometryType::eBOX), halfExtents(hx, hy, hz) {}
/**
\brief Constructor to initialize half extents from vector parameter.
\param halfExtents_ Initial half extents.
*/
PX_INLINE PxBoxGeometry(PxVec3 halfExtents_) : PxGeometry(PxGeometryType::eBOX), halfExtents(halfExtents_) {}
/**
\brief Returns true if the geometry is valid.
\return True if the current settings are valid
\note A valid box has a positive extent in each direction (halfExtents.x > 0, halfExtents.y > 0, halfExtents.z > 0).
It is illegal to call PxRigidActor::createShape and PxPhysics::createShape with a box that has zero extent in any direction.
@see PxRigidActor::createShape, PxPhysics::createShape
*/
PX_INLINE bool isValid() const;
public:
/**
\brief Half of the width, height, and depth of the box.
*/
PxVec3 halfExtents;
};
PX_INLINE bool PxBoxGeometry::isValid() const
{
if (mType != PxGeometryType::eBOX)
return false;
if (!halfExtents.isFinite())
return false;
if (halfExtents.x <= 0.0f || halfExtents.y <= 0.0f || halfExtents.z <= 0.0f)
return false;
return true;
}
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@ -0,0 +1,109 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_NX_CAPSULE_GEOMETRY
#define PX_PHYSICS_NX_CAPSULE_GEOMETRY
/** \addtogroup geomutils
@{
*/
#include "geometry/PxGeometry.h"
#include "foundation/PxFoundationConfig.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Class representing the geometry of a capsule.
Capsules are shaped as the union of a cylinder of length 2 * halfHeight and with the
given radius centered at the origin and extending along the x axis, and two hemispherical ends.
\note The scaling of the capsule is expected to be baked into these values, there is no additional scaling parameter.
The function PxTransformFromSegment is a helper for generating an appropriate transform for the capsule from the capsule's interior line segment.
@see PxTransformFromSegment
*/
class PxCapsuleGeometry : public PxGeometry
{
public:
/**
\brief Default constructor, initializes to a capsule with zero height and radius.
*/
PX_INLINE PxCapsuleGeometry() : PxGeometry(PxGeometryType::eCAPSULE), radius(0), halfHeight(0) {}
/**
\brief Constructor, initializes to a capsule with passed radius and half height.
*/
PX_INLINE PxCapsuleGeometry(PxReal radius_, PxReal halfHeight_) : PxGeometry(PxGeometryType::eCAPSULE), radius(radius_), halfHeight(halfHeight_) {}
/**
\brief Returns true if the geometry is valid.
\return True if the current settings are valid.
\note A valid capsule has radius > 0, halfHeight > 0.
It is illegal to call PxRigidActor::createShape and PxPhysics::createShape with a capsule that has zero radius or height.
@see PxRigidActor::createShape, PxPhysics::createShape
*/
PX_INLINE bool isValid() const;
public:
/**
\brief The radius of the capsule.
*/
PxReal radius;
/**
\brief half of the capsule's height, measured between the centers of the hemispherical ends.
*/
PxReal halfHeight;
};
PX_INLINE bool PxCapsuleGeometry::isValid() const
{
if (mType != PxGeometryType::eCAPSULE)
return false;
if (!PxIsFinite(radius) || !PxIsFinite(halfHeight))
return false;
if (radius <= 0.0f || halfHeight <= 0.0f)
return false;
return true;
}
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@ -0,0 +1,197 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_GEOMUTILS_NX_CONVEXMESH
#define PX_PHYSICS_GEOMUTILS_NX_CONVEXMESH
/** \addtogroup geomutils
@{
*/
#include "foundation/Px.h"
#include "common/PxBase.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Polygon data
Plane format: (mPlane[0],mPlane[1],mPlane[2]).dot(x) + mPlane[3] = 0
With the normal outward-facing from the hull.
*/
struct PxHullPolygon
{
PxReal mPlane[4]; //!< Plane equation for this polygon
PxU16 mNbVerts; //!< Number of vertices/edges in the polygon
PxU16 mIndexBase; //!< Offset in index buffer
};
/**
\brief A convex mesh.
Internally represented as a list of convex polygons. The number
of polygons is limited to 256.
To avoid duplicating data when you have several instances of a particular
mesh positioned differently, you do not use this class to represent a
convex object directly. Instead, you create an instance of this mesh via
the PxConvexMeshGeometry and PxShape classes.
<h3>Creation</h3>
To create an instance of this class call PxPhysics::createConvexMesh(),
and PxConvexMesh::release() to delete it. This is only possible
once you have released all of its #PxShape instances.
<h3>Visualizations:</h3>
\li #PxVisualizationParameter::eCOLLISION_AABBS
\li #PxVisualizationParameter::eCOLLISION_SHAPES
\li #PxVisualizationParameter::eCOLLISION_AXES
\li #PxVisualizationParameter::eCOLLISION_FNORMALS
\li #PxVisualizationParameter::eCOLLISION_EDGES
@see PxConvexMeshDesc PxPhysics.createConvexMesh()
*/
class PxConvexMesh : public PxBase
{
public:
/**
\brief Returns the number of vertices.
\return Number of vertices.
@see getVertices()
*/
PX_PHYSX_COMMON_API virtual PxU32 getNbVertices() const = 0;
/**
\brief Returns the vertices.
\return Array of vertices.
@see getNbVertices()
*/
PX_PHYSX_COMMON_API virtual const PxVec3* getVertices() const = 0;
/**
\brief Returns the index buffer.
\return Index buffer.
@see getNbPolygons() getPolygonData()
*/
PX_PHYSX_COMMON_API virtual const PxU8* getIndexBuffer() const = 0;
/**
\brief Returns the number of polygons.
\return Number of polygons.
@see getIndexBuffer() getPolygonData()
*/
PX_PHYSX_COMMON_API virtual PxU32 getNbPolygons() const = 0;
/**
\brief Returns the polygon data.
\param[in] index Polygon index in [0 ; getNbPolygons()[.
\param[out] data Polygon data.
\return True if success.
@see getIndexBuffer() getNbPolygons()
*/
PX_PHYSX_COMMON_API virtual bool getPolygonData(PxU32 index, PxHullPolygon& data) const = 0;
/**
\brief Decrements the reference count of a convex mesh and releases it if the new reference count is zero.
@see PxPhysics.createConvexMesh() PxConvexMeshGeometry PxShape
*/
PX_PHYSX_COMMON_API virtual void release() = 0;
/**
\brief Returns the reference count of a convex mesh.
At creation, the reference count of the convex mesh is 1. Every shape referencing this convex mesh increments the
count by 1. When the reference count reaches 0, and only then, the convex mesh gets destroyed automatically.
\return the current reference count.
*/
PX_PHYSX_COMMON_API virtual PxU32 getReferenceCount() const = 0;
/**
\brief Acquires a counted reference to a convex mesh.
This method increases the reference count of the convex mesh by 1. Decrement the reference count by calling release()
*/
PX_PHYSX_COMMON_API virtual void acquireReference() = 0;
/**
\brief Returns the mass properties of the mesh assuming unit density.
The following relationship holds between mass and volume:
mass = volume * density
The mass of a unit density mesh is equal to its volume, so this function returns the volume of the mesh.
Similarly, to obtain the localInertia of an identically shaped object with a uniform density of d, simply multiply the
localInertia of the unit density mesh by d.
\param[out] mass The mass of the mesh assuming unit density.
\param[out] localInertia The inertia tensor in mesh local space assuming unit density.
\param[out] localCenterOfMass Position of center of mass (or centroid) in mesh local space.
*/
PX_PHYSX_COMMON_API virtual void getMassInformation(PxReal& mass, PxMat33& localInertia, PxVec3& localCenterOfMass) const = 0;
/**
\brief Returns the local-space (vertex space) AABB from the convex mesh.
\return local-space bounds
*/
PX_PHYSX_COMMON_API virtual PxBounds3 getLocalBounds() const = 0;
PX_PHYSX_COMMON_API virtual const char* getConcreteTypeName() const { return "PxConvexMesh"; }
/**
\brief This method decides whether a convex mesh is gpu compatible. If the total number of vertices are more than 64 or any number of vertices in a polygon is more than 32, or
convex hull data was not cooked with GPU data enabled during cooking or was loaded from a serialized collection, the convex hull is incompatible with GPU collision detection. Otherwise
it is compatible.
\return True if the convex hull is gpu compatible
*/
PX_PHYSX_COMMON_API virtual bool isGpuCompatible() const = 0;
protected:
PX_INLINE PxConvexMesh(PxType concreteType, PxBaseFlags baseFlags) : PxBase(concreteType, baseFlags) {}
PX_INLINE PxConvexMesh(PxBaseFlags baseFlags) : PxBase(baseFlags) {}
PX_PHYSX_COMMON_API virtual ~PxConvexMesh() {}
PX_PHYSX_COMMON_API virtual bool isKindOf(const char* name) const { return !::strcmp("PxConvexMesh", name) || PxBase::isKindOf(name); }
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@ -0,0 +1,151 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_NX_CONVEXMESH_GEOMETRY
#define PX_PHYSICS_NX_CONVEXMESH_GEOMETRY
/** \addtogroup geomutils
@{
*/
#include "geometry/PxGeometry.h"
#include "geometry/PxMeshScale.h"
#include "common/PxCoreUtilityTypes.h"
#include "geometry/PxConvexMesh.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxConvexMesh;
/**
\brief Flags controlling the simulated behavior of the convex mesh geometry.
Used in ::PxConvexMeshGeometryFlags.
*/
struct PxConvexMeshGeometryFlag
{
enum Enum
{
eTIGHT_BOUNDS = (1<<0) //!< Use tighter (but more expensive to compute) bounds around the convex geometry.
};
};
/**
\brief collection of set bits defined in PxConvexMeshGeometryFlag.
@see PxConvexMeshGeometryFlag
*/
typedef PxFlags<PxConvexMeshGeometryFlag::Enum,PxU8> PxConvexMeshGeometryFlags;
PX_FLAGS_OPERATORS(PxConvexMeshGeometryFlag::Enum,PxU8)
/**
\brief Convex mesh geometry class.
This class unifies a convex mesh object with a scaling transform, and
lets the combined object be used anywhere a PxGeometry is needed.
The scaling is a transform along arbitrary axes contained in the scale object.
The vertices of the mesh in geometry (or shape) space is the
PxMeshScale::toMat33() transform, multiplied by the vertex space vertices
in the PxConvexMesh object.
*/
class PxConvexMeshGeometry : public PxGeometry
{
public:
/**
\brief Default constructor.
Creates an empty object with a NULL mesh and identity scale.
*/
PX_INLINE PxConvexMeshGeometry() :
PxGeometry (PxGeometryType::eCONVEXMESH),
scale (PxMeshScale(1.0f)),
convexMesh (NULL),
meshFlags (PxConvexMeshGeometryFlag::eTIGHT_BOUNDS)
{}
/**
\brief Constructor.
\param[in] mesh Mesh pointer. May be NULL, though this will not make the object valid for shape construction.
\param[in] scaling Scale factor.
\param[in] flags Mesh flags.
\
*/
PX_INLINE PxConvexMeshGeometry( PxConvexMesh* mesh,
const PxMeshScale& scaling = PxMeshScale(),
PxConvexMeshGeometryFlags flags = PxConvexMeshGeometryFlag::eTIGHT_BOUNDS) :
PxGeometry (PxGeometryType::eCONVEXMESH),
scale (scaling),
convexMesh (mesh),
meshFlags (flags)
{
}
/**
\brief Returns true if the geometry is valid.
\return True if the current settings are valid for shape creation.
\note A valid convex mesh has a positive scale value in each direction (scale.x > 0, scale.y > 0, scale.z > 0).
It is illegal to call PxRigidActor::createShape and PxPhysics::createShape with a convex that has zero extent in any direction.
@see PxRigidActor::createShape, PxPhysics::createShape
*/
PX_INLINE bool isValid() const;
public:
PxMeshScale scale; //!< The scaling transformation (from vertex space to shape space).
PxConvexMesh* convexMesh; //!< A reference to the convex mesh object.
PxConvexMeshGeometryFlags meshFlags; //!< Mesh flags.
PxPadding<3> paddingFromFlags; //!< padding for mesh flags
};
PX_INLINE bool PxConvexMeshGeometry::isValid() const
{
if(mType != PxGeometryType::eCONVEXMESH)
return false;
if(!scale.scale.isFinite() || !scale.rotation.isUnit())
return false;
if(!scale.isValidForConvexMesh())
return false;
if(!convexMesh)
return false;
return true;
}
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@ -0,0 +1,94 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_NX_GEOMETRY
#define PX_PHYSICS_NX_GEOMETRY
/** \addtogroup geomutils
@{
*/
#include "common/PxPhysXCommonConfig.h"
#include "foundation/PxFlags.h"
#include "foundation/PxMath.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief A geometry type.
Used to distinguish the type of a ::PxGeometry object.
*/
struct PxGeometryType
{
enum Enum
{
eSPHERE,
ePLANE,
eCAPSULE,
eBOX,
eCONVEXMESH,
eTRIANGLEMESH,
eHEIGHTFIELD,
eGEOMETRY_COUNT, //!< internal use only!
eINVALID = -1 //!< internal use only!
};
};
/**
\brief A geometry object.
A geometry object defines the characteristics of a spatial object, but without any information
about its placement in the world.
\note This is an abstract class. You cannot create instances directly. Create an instance of one of the derived classes instead.
*/
class PxGeometry
{
public:
/**
\brief Returns the type of the geometry.
\return The type of the object.
*/
PX_CUDA_CALLABLE PX_FORCE_INLINE PxGeometryType::Enum getType() const { return mType; }
protected:
PX_CUDA_CALLABLE PX_FORCE_INLINE PxGeometry(PxGeometryType::Enum type) : mType(type) {}
PxGeometryType::Enum mType;
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@ -0,0 +1,214 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_GEOMETRYHELPERS
#define PX_PHYSICS_GEOMETRYHELPERS
/** \addtogroup geomutils
@{
*/
#include "foundation/PxPlane.h"
#include "foundation/PxTransform.h"
#include "foundation/PxUnionCast.h"
#include "common/PxPhysXCommonConfig.h"
#include "geometry/PxGeometry.h"
#include "geometry/PxBoxGeometry.h"
#include "geometry/PxSphereGeometry.h"
#include "geometry/PxCapsuleGeometry.h"
#include "geometry/PxPlaneGeometry.h"
#include "geometry/PxConvexMeshGeometry.h"
#include "geometry/PxHeightFieldGeometry.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Geometry holder class
This class contains enough space to hold a value of any PxGeometry subtype.
Its principal use is as a convenience class to allow geometries to be returned polymorphically
from functions. See PxShape::getGeometry();
*/
PX_ALIGN_PREFIX(4)
class PxGeometryHolder
{
public:
PX_FORCE_INLINE PxGeometryType::Enum getType() const
{
return any().getType();
}
PX_FORCE_INLINE PxGeometry& any()
{
return *PxUnionCast<PxGeometry*>(&bytes.geometry);
}
PX_FORCE_INLINE const PxGeometry& any() const
{
return *PxUnionCast<const PxGeometry*>(&bytes.geometry);
}
PX_FORCE_INLINE PxSphereGeometry& sphere()
{
return get<PxSphereGeometry, PxGeometryType::eSPHERE>();
}
PX_FORCE_INLINE const PxSphereGeometry& sphere() const
{
return get<const PxSphereGeometry, PxGeometryType::eSPHERE>();
}
PX_FORCE_INLINE PxPlaneGeometry& plane()
{
return get<PxPlaneGeometry, PxGeometryType::ePLANE>();
}
PX_FORCE_INLINE const PxPlaneGeometry& plane() const
{
return get<const PxPlaneGeometry, PxGeometryType::ePLANE>();
}
PX_FORCE_INLINE PxCapsuleGeometry& capsule()
{
return get<PxCapsuleGeometry, PxGeometryType::eCAPSULE>();
}
PX_FORCE_INLINE const PxCapsuleGeometry& capsule() const
{
return get<const PxCapsuleGeometry, PxGeometryType::eCAPSULE>();
}
PX_FORCE_INLINE PxBoxGeometry& box()
{
return get<PxBoxGeometry, PxGeometryType::eBOX>();
}
PX_FORCE_INLINE const PxBoxGeometry& box() const
{
return get<const PxBoxGeometry, PxGeometryType::eBOX>();
}
PX_FORCE_INLINE PxConvexMeshGeometry& convexMesh()
{
return get<PxConvexMeshGeometry, PxGeometryType::eCONVEXMESH>();
}
PX_FORCE_INLINE const PxConvexMeshGeometry& convexMesh() const
{
return get<const PxConvexMeshGeometry, PxGeometryType::eCONVEXMESH>();
}
PX_FORCE_INLINE PxTriangleMeshGeometry& triangleMesh()
{
return get<PxTriangleMeshGeometry, PxGeometryType::eTRIANGLEMESH>();
}
PX_FORCE_INLINE const PxTriangleMeshGeometry& triangleMesh() const
{
return get<const PxTriangleMeshGeometry, PxGeometryType::eTRIANGLEMESH>();
}
PX_FORCE_INLINE PxHeightFieldGeometry& heightField()
{
return get<PxHeightFieldGeometry, PxGeometryType::eHEIGHTFIELD>();
}
PX_FORCE_INLINE const PxHeightFieldGeometry& heightField() const
{
return get<const PxHeightFieldGeometry, PxGeometryType::eHEIGHTFIELD>();
}
PX_FORCE_INLINE void storeAny(const PxGeometry& geometry)
{
PX_ASSERT_WITH_MESSAGE( (geometry.getType() >= PxGeometryType::eSPHERE) &&
(geometry.getType() < PxGeometryType::eGEOMETRY_COUNT),
"Unexpected GeometryType in PxGeometryHolder::storeAny");
switch(geometry.getType())
{
case PxGeometryType::eSPHERE: put<PxSphereGeometry>(geometry); break;
case PxGeometryType::ePLANE: put<PxPlaneGeometry>(geometry); break;
case PxGeometryType::eCAPSULE: put<PxCapsuleGeometry>(geometry); break;
case PxGeometryType::eBOX: put<PxBoxGeometry>(geometry); break;
case PxGeometryType::eCONVEXMESH: put<PxConvexMeshGeometry>(geometry); break;
case PxGeometryType::eTRIANGLEMESH: put<PxTriangleMeshGeometry>(geometry); break;
case PxGeometryType::eHEIGHTFIELD: put<PxHeightFieldGeometry>(geometry); break;
case PxGeometryType::eGEOMETRY_COUNT:
case PxGeometryType::eINVALID: break;
}
}
PX_FORCE_INLINE PxGeometryHolder() {}
PX_FORCE_INLINE PxGeometryHolder(const PxGeometry& geometry){ storeAny(geometry); }
private:
template<typename T> void put(const PxGeometry& geometry)
{
static_cast<T&>(any()) = static_cast<const T&>(geometry);
}
template<typename T, PxGeometryType::Enum type> T& get()
{
PX_ASSERT(getType() == type);
return static_cast<T&>(any());
}
template<typename T, PxGeometryType::Enum type> T& get() const
{
PX_ASSERT(getType() == type);
return static_cast<T&>(any());
}
union {
PxU8 geometry[sizeof(PxGeometry)];
PxU8 box[sizeof(PxBoxGeometry)];
PxU8 sphere[sizeof(PxSphereGeometry)];
PxU8 capsule[sizeof(PxCapsuleGeometry)];
PxU8 plane[sizeof(PxPlaneGeometry)];
PxU8 convex[sizeof(PxConvexMeshGeometry)];
PxU8 mesh[sizeof(PxTriangleMeshGeometry)];
PxU8 heightfield[sizeof(PxHeightFieldGeometry)];
} bytes;
}
PX_ALIGN_SUFFIX(4);
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@ -0,0 +1,225 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_GEOMUTILS_PX_GEOMETRY_QUERY
#define PX_PHYSICS_GEOMUTILS_PX_GEOMETRY_QUERY
/**
\brief Maximum sweep distance for scene sweeps. The distance parameter for sweep functions will be clamped to this value.
The reason for this is GJK support cannot be evaluated near infinity. A viable alternative can be a sweep followed by an infinite raycast.
@see PxScene
*/
#define PX_MAX_SWEEP_DISTANCE 1e8f
/** \addtogroup geomutils
@{
*/
#include "common/PxPhysXCommonConfig.h"
#include "PxQueryReport.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxGeometry;
struct PxSweepHit;
struct PxRaycastHit;
class PxTriangle;
/**
\brief Collection of geometry object queries (sweeps, raycasts, overlaps, ...).
*/
class PxGeometryQuery
{
public:
/**
\brief Sweep a specified geometry object in space and test for collision with a given object.
The following combinations are supported.
\li PxSphereGeometry vs. {PxSphereGeometry, PxPlaneGeometry, PxCapsuleGeometry, PxBoxGeometry, PxConvexMeshGeometry, PxTriangleMeshGeometry, PxHeightFieldGeometry}
\li PxCapsuleGeometry vs. {PxSphereGeometry, PxPlaneGeometry, PxCapsuleGeometry, PxBoxGeometry, PxConvexMeshGeometry, PxTriangleMeshGeometry, PxHeightFieldGeometry}
\li PxBoxGeometry vs. {PxSphereGeometry, PxPlaneGeometry, PxCapsuleGeometry, PxBoxGeometry, PxConvexMeshGeometry, PxTriangleMeshGeometry, PxHeightFieldGeometry}
\li PxConvexMeshGeometry vs. {PxSphereGeometry, PxPlaneGeometry, PxCapsuleGeometry, PxBoxGeometry, PxConvexMeshGeometry, PxTriangleMeshGeometry, PxHeightFieldGeometry}
\param[in] unitDir Normalized direction along which object geom0 should be swept
\param[in] maxDist Maximum sweep distance, has to be in the [0, inf) range
\param[in] geom0 The geometry object to sweep. Supported geometries are #PxSphereGeometry, #PxCapsuleGeometry, #PxBoxGeometry and #PxConvexMeshGeometry
\param[in] pose0 Pose of the geometry object to sweep
\param[in] geom1 The geometry object to test the sweep against
\param[in] pose1 Pose of the geometry object to sweep against
\param[out] sweepHit The sweep hit information. Only valid if this method returns true.
\param[in] hitFlags Specify which properties per hit should be computed and written to result hit array. Combination of #PxHitFlag flags
\param[in] inflation Surface of the swept shape is additively extruded in the normal direction, rounding corners and edges.
\return True if the swept geometry object geom0 hits the object geom1
@see PxSweepHit PxGeometry PxTransform
*/
PX_PHYSX_COMMON_API static bool sweep(const PxVec3& unitDir,
const PxReal maxDist,
const PxGeometry& geom0,
const PxTransform& pose0,
const PxGeometry& geom1,
const PxTransform& pose1,
PxSweepHit& sweepHit,
PxHitFlags hitFlags = PxHitFlag::eDEFAULT,
const PxReal inflation = 0.f);
/**
\brief Overlap test for two geometry objects.
All combinations are supported except:
\li PxPlaneGeometry vs. {PxPlaneGeometry, PxTriangleMeshGeometry, PxHeightFieldGeometry}
\li PxTriangleMeshGeometry vs. {PxTriangleMeshGeometry, PxHeightFieldGeometry}
\li PxHeightFieldGeometry vs. {PxHeightFieldGeometry}
\param[in] geom0 The first geometry object
\param[in] pose0 Pose of the first geometry object
\param[in] geom1 The second geometry object
\param[in] pose1 Pose of the second geometry object
\return True if the two geometry objects overlap
@see PxGeometry PxTransform
*/
PX_PHYSX_COMMON_API static bool overlap(const PxGeometry& geom0, const PxTransform& pose0,
const PxGeometry& geom1, const PxTransform& pose1);
/**
\brief Raycast test against a geometry object.
\param[in] origin The origin of the ray to test the geometry object against
\param[in] unitDir Normalized direction of the ray to test the geometry object against
\param[in] geom The geometry object to test the ray against
\param[in] pose Pose of the geometry object
\param[in] maxDist Maximum ray length, has to be in the [0, inf) range
\param[in] hitFlags Specification of the kind of information to retrieve on hit. Combination of #PxHitFlag flags
\param[in] maxHits max number of returned hits = size of 'rayHits' buffer
\param[out] rayHits Raycast hits information
\return Number of hits between the ray and the geometry object
@see PxRaycastHit PxGeometry PxTransform
*/
PX_PHYSX_COMMON_API static PxU32 raycast(const PxVec3& origin,
const PxVec3& unitDir,
const PxGeometry& geom,
const PxTransform& pose,
PxReal maxDist,
PxHitFlags hitFlags,
PxU32 maxHits,
PxRaycastHit* PX_RESTRICT rayHits);
/**
\brief Compute minimum translational distance (MTD) between two geometry objects.
All combinations of geom objects are supported except:
- plane/plane
- plane/mesh
- plane/heightfield
- mesh/mesh
- mesh/heightfield
- heightfield/heightfield
The function returns a unit vector ('direction') and a penetration depth ('depth').
The depenetration vector D = direction * depth should be applied to the first object, to
get out of the second object.
Returned depth should always be positive or null.
If objects do not overlap, the function can not compute the MTD and returns false.
\param[out] direction Computed MTD unit direction
\param[out] depth Penetration depth. Always positive or null.
\param[in] geom0 The first geometry object
\param[in] pose0 Pose of the first geometry object
\param[in] geom1 The second geometry object
\param[in] pose1 Pose of the second geometry object
\return True if the MTD has successfully been computed, i.e. if objects do overlap.
@see PxGeometry PxTransform
*/
PX_PHYSX_COMMON_API static bool computePenetration(PxVec3& direction, PxF32& depth,
const PxGeometry& geom0, const PxTransform& pose0,
const PxGeometry& geom1, const PxTransform& pose1);
/**
\brief Computes distance between a point and a geometry object.
Currently supported geometry objects: box, sphere, capsule, convex.
\param[in] point The point P
\param[in] geom The geometry object
\param[in] pose Pose of the geometry object
\param[out] closestPoint Optionally returned closest point to P on the geom object. Only valid when returned distance is strictly positive.
\return Square distance between the point and the geom object, or 0.0 if the point is inside the object, or -1.0 if the geometry type is not supported.
@see PxGeometry PxTransform
*/
PX_PHYSX_COMMON_API static PxReal pointDistance(const PxVec3& point, const PxGeometry& geom, const PxTransform& pose, PxVec3* closestPoint=NULL);
/**
\brief get the bounds for a geometry object
\param[in] geom The geometry object
\param[in] pose Pose of the geometry object
\param[in] inflation Scale factor for computed world bounds. Box extents are multiplied by this value.
\return The bounds of the object
@see PxGeometry PxTransform
*/
PX_PHYSX_COMMON_API static PxBounds3 getWorldBounds(const PxGeometry& geom, const PxTransform& pose, float inflation=1.01f);
/**
\brief Checks if provided geometry is valid.
\param[in] geom The geometry object.
\return True if geometry is valid.
@see PxGeometry PxSphereGeometry, PxCapsuleGeometry, PxBoxGeometry, PxConvexGeometry
*/
PX_PHYSX_COMMON_API static bool isValid(const PxGeometry& geom);
};
#if !PX_DOXYGEN
}
#endif
/** @} */
#endif

View File

@ -0,0 +1,262 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_GEOMUTILS_NX_HEIGHTFIELD
#define PX_PHYSICS_GEOMUTILS_NX_HEIGHTFIELD
/** \addtogroup geomutils
@{
*/
#include "geometry/PxHeightFieldFlag.h"
#include "geometry/PxHeightFieldSample.h"
#include "common/PxBase.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxHeightFieldDesc;
/**
\brief A height field class.
Height fields work in a similar way as triangle meshes specified to act as
height fields, with some important differences:
Triangle meshes can be made of nonuniform geometry, while height fields are
regular, rectangular grids. This means that with PxHeightField, you sacrifice
flexibility in return for improved performance and decreased memory consumption.
In local space rows extend in X direction, columns in Z direction and height in Y direction.
Like Convexes and TriangleMeshes, HeightFields are referenced by shape instances
(see #PxHeightFieldGeometry, #PxShape).
To avoid duplicating data when you have several instances of a particular
height field differently, you do not use this class to represent a
height field object directly. Instead, you create an instance of this height field
via the PxHeightFieldGeometry and PxShape classes.
<h3>Creation</h3>
To create an instance of this class call PxPhysics::createHeightField() or
PxCooking::createHeightField(const PxHeightFieldDesc&, PxPhysicsInsertionCallback&).
To delete it call release(). This is only possible
once you have released all of its PxHeightFiedShape instances.
<h3>Visualizations:</h3>
\li #PxVisualizationParameter::eCOLLISION_AABBS
\li #PxVisualizationParameter::eCOLLISION_SHAPES
\li #PxVisualizationParameter::eCOLLISION_AXES
\li #PxVisualizationParameter::eCOLLISION_FNORMALS
\li #PxVisualizationParameter::eCOLLISION_EDGES
@see PxHeightFieldDesc PxHeightFieldGeometry PxShape PxPhysics.createHeightField() PxCooking.createHeightField()
*/
class PxHeightField : public PxBase
{
public:
/**
\brief Decrements the reference count of a height field and releases it if the new reference count is zero.
@see PxPhysics.createHeightField() PxHeightFieldDesc PxHeightFieldGeometry PxShape
*/
PX_PHYSX_COMMON_API virtual void release() = 0;
/**
\brief Writes out the sample data array.
The user provides destBufferSize bytes storage at destBuffer.
The data is formatted and arranged as PxHeightFieldDesc.samples.
\param[out] destBuffer The destination buffer for the sample data.
\param[in] destBufferSize The size of the destination buffer.
\return The number of bytes written.
@see PxHeightFieldDesc.samples
*/
PX_PHYSX_COMMON_API virtual PxU32 saveCells(void* destBuffer, PxU32 destBufferSize) const = 0;
/**
\brief Replaces a rectangular subfield in the sample data array.
The user provides the description of a rectangular subfield in subfieldDesc.
The data is formatted and arranged as PxHeightFieldDesc.samples.
\param[in] startCol First cell in the destination heightfield to be modified. Can be negative.
\param[in] startRow First row in the destination heightfield to be modified. Can be negative.
\param[in] subfieldDesc Description of the source subfield to read the samples from.
\param[in] shrinkBounds If left as false, the bounds will never shrink but only grow. If set to true the bounds will be recomputed from all HF samples at O(nbColums*nbRows) perf cost.
\return True on success, false on failure. Failure can occur due to format mismatch.
\note Modified samples are constrained to the same height quantization range as the original heightfield.
Source samples that are out of range of target heightfield will be clipped with no error.
PhysX does not keep a mapping from the heightfield to heightfield shapes that reference it.
Call PxShape::setGeometry on each shape which references the height field, to ensure that internal data structures are updated to reflect the new geometry.
Please note that PxShape::setGeometry does not guarantee correct/continuous behavior when objects are resting on top of old or new geometry.
@see PxHeightFieldDesc.samples PxShape.setGeometry
*/
PX_PHYSX_COMMON_API virtual bool modifySamples(PxI32 startCol, PxI32 startRow, const PxHeightFieldDesc& subfieldDesc, bool shrinkBounds = false) = 0;
/**
\brief Retrieves the number of sample rows in the samples array.
\return The number of sample rows in the samples array.
@see PxHeightFieldDesc.nbRows
*/
PX_PHYSX_COMMON_API virtual PxU32 getNbRows() const = 0;
/**
\brief Retrieves the number of sample columns in the samples array.
\return The number of sample columns in the samples array.
@see PxHeightFieldDesc.nbColumns
*/
PX_PHYSX_COMMON_API virtual PxU32 getNbColumns() const = 0;
/**
\brief Retrieves the format of the sample data.
\return The format of the sample data.
@see PxHeightFieldDesc.format PxHeightFieldFormat
*/
PX_PHYSX_COMMON_API virtual PxHeightFieldFormat::Enum getFormat() const = 0;
/**
\brief Retrieves the offset in bytes between consecutive samples in the array.
\return The offset in bytes between consecutive samples in the array.
@see PxHeightFieldDesc.sampleStride
*/
PX_PHYSX_COMMON_API virtual PxU32 getSampleStride() const = 0;
/**
\brief Retrieves the convex edge threshold.
\return The convex edge threshold.
@see PxHeightFieldDesc.convexEdgeThreshold
*/
PX_PHYSX_COMMON_API virtual PxReal getConvexEdgeThreshold() const = 0;
/**
\brief Retrieves the flags bits, combined from values of the enum ::PxHeightFieldFlag.
\return The flags bits, combined from values of the enum ::PxHeightFieldFlag.
@see PxHeightFieldDesc.flags PxHeightFieldFlag
*/
PX_PHYSX_COMMON_API virtual PxHeightFieldFlags getFlags() const = 0;
/**
\brief Retrieves the height at the given coordinates in grid space.
\return The height at the given coordinates or 0 if the coordinates are out of range.
*/
PX_PHYSX_COMMON_API virtual PxReal getHeight(PxReal x, PxReal z) const = 0;
/**
\brief Returns the reference count for shared heightfields.
At creation, the reference count of the heightfield is 1. Every shape referencing this heightfield increments the
count by 1. When the reference count reaches 0, and only then, the heightfield gets destroyed automatically.
\return the current reference count.
*/
PX_PHYSX_COMMON_API virtual PxU32 getReferenceCount() const = 0;
/**
\brief Acquires a counted reference to a heightfield.
This method increases the reference count of the heightfield by 1. Decrement the reference count by calling release()
*/
PX_PHYSX_COMMON_API virtual void acquireReference() = 0;
/**
\brief Returns material table index of given triangle
\note This function takes a post cooking triangle index.
\param[in] triangleIndex (internal) index of desired triangle
\return Material table index, or 0xffff if no per-triangle materials are used
*/
PX_PHYSX_COMMON_API virtual PxMaterialTableIndex getTriangleMaterialIndex(PxTriangleID triangleIndex) const = 0;
/**
\brief Returns a triangle face normal for a given triangle index
\note This function takes a post cooking triangle index.
\param[in] triangleIndex (internal) index of desired triangle
\return Triangle normal for a given triangle index
*/
PX_PHYSX_COMMON_API virtual PxVec3 getTriangleNormal(PxTriangleID triangleIndex) const = 0;
/**
\brief Returns heightfield sample of given row and column
\param[in] row Given heightfield row
\param[in] column Given heightfield column
\return Heightfield sample
*/
PX_PHYSX_COMMON_API virtual const PxHeightFieldSample& getSample(PxU32 row, PxU32 column) const = 0;
/**
\brief Returns the number of times the heightfield data has been modified
This method returns the number of times modifySamples has been called on this heightfield, so that code that has
retained state that depends on the heightfield can efficiently determine whether it has been modified.
\return the number of times the heightfield sample data has been modified.
*/
PX_PHYSX_COMMON_API virtual PxU32 getTimestamp() const = 0;
PX_PHYSX_COMMON_API virtual const char* getConcreteTypeName() const { return "PxHeightField"; }
protected:
PX_INLINE PxHeightField(PxType concreteType, PxBaseFlags baseFlags) : PxBase(concreteType, baseFlags) {}
PX_INLINE PxHeightField(PxBaseFlags baseFlags) : PxBase(baseFlags) {}
PX_PHYSX_COMMON_API virtual ~PxHeightField() {}
PX_PHYSX_COMMON_API virtual bool isKindOf(const char* name) const { return !::strcmp("PxHeightField", name) || PxBase::isKindOf(name); }
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@ -0,0 +1,187 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_COLLISION_NXHEIGHTFIELDDESC
#define PX_COLLISION_NXHEIGHTFIELDDESC
/** \addtogroup geomutils
@{
*/
#include "common/PxPhysXCommonConfig.h"
#include "geometry/PxHeightFieldFlag.h"
#include "common/PxCoreUtilityTypes.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Descriptor class for #PxHeightField.
\note The heightfield data is *copied* when a PxHeightField object is created from this descriptor. After the call the
user may discard the height data.
@see PxHeightField PxHeightFieldGeometry PxShape PxPhysics.createHeightField() PxCooking.createHeightField()
*/
class PxHeightFieldDesc
{
public:
/**
\brief Number of sample rows in the height field samples array.
\note Local space X-axis corresponds to rows.
<b>Range:</b> &gt;1<br>
<b>Default:</b> 0
*/
PxU32 nbRows;
/**
\brief Number of sample columns in the height field samples array.
\note Local space Z-axis corresponds to columns.
<b>Range:</b> &gt;1<br>
<b>Default:</b> 0
*/
PxU32 nbColumns;
/**
\brief Format of the sample data.
Currently the only supported format is PxHeightFieldFormat::eS16_TM:
<b>Default:</b> PxHeightFieldFormat::eS16_TM
@see PxHeightFormat PxHeightFieldDesc.samples
*/
PxHeightFieldFormat::Enum format;
/**
\brief The samples array.
It is copied to the SDK's storage at creation time.
There are nbRows * nbColumn samples in the array,
which define nbRows * nbColumn vertices and cells,
of which (nbRows - 1) * (nbColumns - 1) cells are actually used.
The array index of sample(row, column) = row * nbColumns + column.
The byte offset of sample(row, column) = sampleStride * (row * nbColumns + column).
The sample data follows at the offset and spans the number of bytes defined by the format.
Then there are zero or more unused bytes depending on sampleStride before the next sample.
<b>Default:</b> NULL
@see PxHeightFormat
*/
PxStridedData samples;
/**
This threshold is used by the collision detection to determine if a height field edge is convex
and can generate contact points.
Usually the convexity of an edge is determined from the angle (or cosine of the angle) between
the normals of the faces sharing that edge.
The height field allows a more efficient approach by comparing height values of neighboring vertices.
This parameter offsets the comparison. Smaller changes than 0.5 will not alter the set of convex edges.
The rule of thumb is that larger values will result in fewer edge contacts.
This parameter is ignored in contact generation with sphere and capsule primitives.
<b>Range:</b> [0, PX_MAX_F32)<br>
<b>Default:</b> 0
*/
PxReal convexEdgeThreshold;
/**
\brief Flags bits, combined from values of the enum ::PxHeightFieldFlag.
<b>Default:</b> 0
@see PxHeightFieldFlag PxHeightFieldFlags
*/
PxHeightFieldFlags flags;
/**
\brief Constructor sets to default.
*/
PX_INLINE PxHeightFieldDesc();
/**
\brief (re)sets the structure to the default.
*/
PX_INLINE void setToDefault();
/**
\brief Returns true if the descriptor is valid.
\return True if the current settings are valid.
*/
PX_INLINE bool isValid() const;
};
PX_INLINE PxHeightFieldDesc::PxHeightFieldDesc() //constructor sets to default
{
nbColumns = 0;
nbRows = 0;
format = PxHeightFieldFormat::eS16_TM;
convexEdgeThreshold = 0.0f;
flags = PxHeightFieldFlags();
}
PX_INLINE void PxHeightFieldDesc::setToDefault()
{
*this = PxHeightFieldDesc();
}
PX_INLINE bool PxHeightFieldDesc::isValid() const
{
if (nbColumns < 2)
return false;
if (nbRows < 2)
return false;
if(format != PxHeightFieldFormat::eS16_TM)
return false;
if (samples.stride < 4)
return false;
if (convexEdgeThreshold < 0)
return false;
if ((flags & PxHeightFieldFlag::eNO_BOUNDARY_EDGES) != flags)
return false;
return true;
}
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@ -0,0 +1,162 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_COLLISION_NXHEIGHTFIELDFLAG
#define PX_COLLISION_NXHEIGHTFIELDFLAG
/** \addtogroup geomutils
@{
*/
#include "foundation/PxFlags.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Describes the format of height field samples.
@see PxHeightFieldDesc.format PxHeightFieldDesc.samples
*/
struct PxHeightFieldFormat
{
enum Enum
{
/**
\brief Height field height data is 16 bit signed integers, followed by triangle materials.
Each sample is 32 bits wide arranged as follows:
\image html heightFieldFormat_S16_TM.png
1) First there is a 16 bit height value.
2) Next, two one byte material indices, with the high bit of each byte reserved for special use.
(so the material index is only 7 bits).
The high bit of material0 is the tess-flag.
The high bit of material1 is reserved for future use.
There are zero or more unused bytes before the next sample depending on PxHeightFieldDesc.sampleStride,
where the application may eventually keep its own data.
This is the only format supported at the moment.
@see PxHeightFieldDesc.format PxHeightFieldDesc.samples
*/
eS16_TM = (1 << 0)
};
};
/**
\brief Determines the tessellation of height field cells.
@see PxHeightFieldDesc.format PxHeightFieldDesc.samples
*/
struct PxHeightFieldTessFlag
{
enum Enum
{
/**
\brief This flag determines which way each quad cell is subdivided.
The flag lowered indicates subdivision like this: (the 0th vertex is referenced by only one triangle)
\image html heightfieldTriMat2.PNG
<pre>
+--+--+--+---> column
| /| /| /|
|/ |/ |/ |
+--+--+--+
| /| /| /|
|/ |/ |/ |
+--+--+--+
|
|
V row
</pre>
The flag raised indicates subdivision like this: (the 0th vertex is shared by two triangles)
\image html heightfieldTriMat1.PNG
<pre>
+--+--+--+---> column
|\ |\ |\ |
| \| \| \|
+--+--+--+
|\ |\ |\ |
| \| \| \|
+--+--+--+
|
|
V row
</pre>
@see PxHeightFieldDesc.format PxHeightFieldDesc.samples
*/
e0TH_VERTEX_SHARED = (1 << 0)
};
};
/**
\brief Enum with flag values to be used in PxHeightFieldDesc.flags.
*/
struct PxHeightFieldFlag
{
enum Enum
{
/**
\brief Disable collisions with height field with boundary edges.
Raise this flag if several terrain patches are going to be placed adjacent to each other,
to avoid a bump when sliding across.
This flag is ignored in contact generation with sphere and capsule shapes.
@see PxHeightFieldDesc.flags
*/
eNO_BOUNDARY_EDGES = (1 << 0)
};
};
/**
\brief collection of set bits defined in PxHeightFieldFlag.
@see PxHeightFieldFlag
*/
typedef PxFlags<PxHeightFieldFlag::Enum,PxU16> PxHeightFieldFlags;
PX_FLAGS_OPERATORS(PxHeightFieldFlag::Enum,PxU16)
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@ -0,0 +1,143 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_NX_HEIGHTFIELD_GEOMETRY
#define PX_PHYSICS_NX_HEIGHTFIELD_GEOMETRY
/** \addtogroup geomutils
@{
*/
#include "geometry/PxTriangleMeshGeometry.h"
#include "common/PxCoreUtilityTypes.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
#define PX_MIN_HEIGHTFIELD_XZ_SCALE 1e-8f
#define PX_MIN_HEIGHTFIELD_Y_SCALE (0.0001f / PxReal(0xFFFF))
class PxHeightField;
/**
\brief Height field geometry class.
This class allows to create a scaled height field geometry instance.
There is a minimum allowed value for Y and XZ scaling - PX_MIN_HEIGHTFIELD_XZ_SCALE, heightfield creation will fail if XZ value is below this value.
*/
class PxHeightFieldGeometry : public PxGeometry
{
public:
PX_INLINE PxHeightFieldGeometry() :
PxGeometry (PxGeometryType::eHEIGHTFIELD),
heightField (NULL),
heightScale (1.0f),
rowScale (1.0f),
columnScale (1.0f),
heightFieldFlags(0)
{}
PX_INLINE PxHeightFieldGeometry(PxHeightField* hf,
PxMeshGeometryFlags flags,
PxReal heightScale_,
PxReal rowScale_,
PxReal columnScale_) :
PxGeometry (PxGeometryType::eHEIGHTFIELD),
heightField (hf) ,
heightScale (heightScale_),
rowScale (rowScale_),
columnScale (columnScale_),
heightFieldFlags (flags)
{
}
/**
\brief Returns true if the geometry is valid.
\return True if the current settings are valid
\note A valid height field has a positive scale value in each direction (heightScale > 0, rowScale > 0, columnScale > 0).
It is illegal to call PxRigidActor::createShape and PxPhysics::createShape with a height field that has zero extents in any direction.
@see PxRigidActor::createShape, PxPhysics::createShape
*/
PX_INLINE bool isValid() const;
public:
/**
\brief The height field data.
*/
PxHeightField* heightField;
/**
\brief The scaling factor for the height field in vertical direction (y direction in local space).
*/
PxReal heightScale;
/**
\brief The scaling factor for the height field in the row direction (x direction in local space).
*/
PxReal rowScale;
/**
\brief The scaling factor for the height field in the column direction (z direction in local space).
*/
PxReal columnScale;
/**
\brief Flags to specify some collision properties for the height field.
*/
PxMeshGeometryFlags heightFieldFlags;
PxPadding<3> paddingFromFlags; //!< padding for mesh flags.
};
PX_INLINE bool PxHeightFieldGeometry::isValid() const
{
if (mType != PxGeometryType::eHEIGHTFIELD)
return false;
if (!PxIsFinite(heightScale) || !PxIsFinite(rowScale) || !PxIsFinite(columnScale))
return false;
if (rowScale < PX_MIN_HEIGHTFIELD_XZ_SCALE || columnScale < PX_MIN_HEIGHTFIELD_XZ_SCALE || heightScale < PX_MIN_HEIGHTFIELD_Y_SCALE)
return false;
if (!heightField)
return false;
return true;
}
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@ -0,0 +1,124 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_NXHEIGHTFIELDSAMPLE
#define PX_PHYSICS_NXHEIGHTFIELDSAMPLE
/** \addtogroup geomutils
@{ */
#include "common/PxPhysXCommonConfig.h"
#include "foundation/PxBitAndData.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Special material index values for height field samples.
@see PxHeightFieldSample.materialIndex0 PxHeightFieldSample.materialIndex1
*/
struct PxHeightFieldMaterial
{
enum Enum
{
eHOLE = 127 //!< A material indicating that the triangle should be treated as a hole in the mesh.
};
};
/**
\brief Heightfield sample format.
This format corresponds to the #PxHeightFieldFormat member PxHeightFieldFormat::eS16_TM.
An array of heightfield samples are used when creating a PxHeightField to specify
the elevation of the heightfield points. In addition the material and tessellation of the adjacent
triangles are specified.
@see PxHeightField PxHeightFieldDesc PxHeightFieldDesc.samples
*/
struct PxHeightFieldSample
{
//= ATTENTION! =====================================================================================
// Changing the data layout of this class breaks the binary serialization format. See comments for
// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
// accordingly.
//==================================================================================================
/**
\brief The height of the heightfield sample
This value is scaled by PxHeightFieldGeometry::heightScale.
@see PxHeightFieldGeometry
*/
PxI16 height;
/**
\brief The triangle material index of the quad's lower triangle + tesselation flag
An index pointing into the material table of the shape which instantiates the heightfield.
This index determines the material of the lower of the quad's two triangles (i.e. the quad whose
upper-left corner is this sample, see the Guide for illustrations).
Special values of the 7 data bits are defined by PxHeightFieldMaterial
The tesselation flag specifies which way the quad is split whose upper left corner is this sample.
If the flag is set, the diagonal of the quad will run from this sample to the opposite vertex; if not,
it will run between the other two vertices (see the Guide for illustrations).
@see PxHeightFieldGeometry materialIndex1 PxShape.setmaterials() PxShape.getMaterials()
*/
PxBitAndByte materialIndex0;
PX_CUDA_CALLABLE PX_FORCE_INLINE PxU8 tessFlag() const { return PxU8(materialIndex0.isBitSet() ? 1 : 0); } // PT: explicit conversion to make sure we don't break the code
PX_CUDA_CALLABLE PX_FORCE_INLINE void setTessFlag() { materialIndex0.setBit(); }
PX_CUDA_CALLABLE PX_FORCE_INLINE void clearTessFlag() { materialIndex0.clearBit(); }
/**
\brief The triangle material index of the quad's upper triangle + reserved flag
An index pointing into the material table of the shape which instantiates the heightfield.
This index determines the material of the upper of the quad's two triangles (i.e. the quad whose
upper-left corner is this sample, see the Guide for illustrations).
@see PxHeightFieldGeometry materialIndex0 PxShape.setmaterials() PxShape.getMaterials()
*/
PxBitAndByte materialIndex1;
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@ -0,0 +1,201 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_GEOMUTILS_PX_MESH_QUERY
#define PX_PHYSICS_GEOMUTILS_PX_MESH_QUERY
/** \addtogroup geomutils
@{
*/
#include "common/PxPhysXCommonConfig.h"
#include "PxQueryReport.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxGeometry;
class PxConvexMeshGeometry;
class PxTriangleMeshGeometry;
class PxHeightFieldGeometry;
class PxTriangle;
class PxMeshQuery
{
public:
/**
\brief Retrieves triangle data from a triangle ID.
This function can be used together with #findOverlapTriangleMesh() to retrieve triangle properties.
\param[in] triGeom Geometry of the triangle mesh to extract the triangle from.
\param[in] transform Transform for the triangle mesh
\param[in] triangleIndex The index of the triangle to retrieve.
\param[out] triangle Triangle points in world space.
\param[out] vertexIndices Returned vertex indices for given triangle
\param[out] adjacencyIndices Returned 3 triangle adjacency internal face indices (0xFFFFFFFF if no adjacency). The mesh must be cooked with cooking param buildTriangleAdjacencies enabled.
\note This function will flip the triangle normal whenever triGeom.scale.hasNegativeDeterminant() is true.
@see PxTriangle PxTriangleFlags PxTriangleID findOverlapTriangleMesh()
*/
PX_PHYSX_COMMON_API static void getTriangle(const PxTriangleMeshGeometry& triGeom, const PxTransform& transform, PxTriangleID triangleIndex, PxTriangle& triangle, PxU32* vertexIndices=NULL, PxU32* adjacencyIndices=NULL);
/**
\brief Retrieves triangle data from a triangle ID.
This function can be used together with #findOverlapHeightField() to retrieve triangle properties.
\param[in] hfGeom Geometry of the height field to extract the triangle from.
\param[in] transform Transform for the height field.
\param[in] triangleIndex The index of the triangle to retrieve.
\param[out] triangle Triangle points in world space.
\param[out] vertexIndices Returned vertex indices for given triangle
\param[out] adjacencyIndices Returned 3 triangle adjacency triangle indices (0xFFFFFFFF if no adjacency).
\note This function will flip the triangle normal whenever triGeom.scale.hasNegativeDeterminant() is true.
\note TriangleIndex is an index used in internal format, which does have an index out of the bounds in last row.
To traverse all tri indices in the HF, the following code can be applied:
for (PxU32 row = 0; row < (nbRows - 1); row++)
{
for (PxU32 col = 0; col < (nbCols - 1); col++)
{
for (PxU32 k = 0; k < 2; k++)
{
const PxU32 triIndex = 2 * (row*nbCols + col) + k;
....
}
}
}
@see PxTriangle PxTriangleFlags PxTriangleID findOverlapHeightField()
*/
PX_PHYSX_COMMON_API static void getTriangle(const PxHeightFieldGeometry& hfGeom, const PxTransform& transform, PxTriangleID triangleIndex, PxTriangle& triangle, PxU32* vertexIndices=NULL, PxU32* adjacencyIndices=NULL);
/**
\brief Find the mesh triangles which touch the specified geometry object.
Returned triangle indices can be used with #getTriangle() to retrieve the triangle properties.
\param[in] geom The geometry object to test for mesh triangle overlaps. Supported geometries are #PxSphereGeometry, #PxCapsuleGeometry and #PxBoxGeometry
\param[in] geomPose Pose of the geometry object
\param[in] meshGeom The triangle mesh geometry to check overlap against
\param[in] meshPose Pose of the triangle mesh
\param[out] results Indices of overlapping triangles
\param[in] maxResults Size of 'results' buffer
\param[in] startIndex Index of first result to be retrieved. Previous indices are skipped.
\param[out] overflow True if a buffer overflow occurred
\return Number of overlaps found, i.e. number of elements written to the results buffer
@see PxTriangleMeshGeometry getTriangle()
*/
PX_PHYSX_COMMON_API static PxU32 findOverlapTriangleMesh( const PxGeometry& geom, const PxTransform& geomPose,
const PxTriangleMeshGeometry& meshGeom, const PxTransform& meshPose,
PxU32* results, PxU32 maxResults, PxU32 startIndex, bool& overflow);
/**
\brief Find the height field triangles which touch the specified geometry object.
Returned triangle indices can be used with #getTriangle() to retrieve the triangle properties.
\param[in] geom The geometry object to test for height field overlaps. Supported geometries are #PxSphereGeometry, #PxCapsuleGeometry and #PxBoxGeometry. The sphere and capsule queries are currently conservative estimates.
\param[in] geomPose Pose of the geometry object
\param[in] hfGeom The height field geometry to check overlap against
\param[in] hfPose Pose of the height field
\param[out] results Indices of overlapping triangles
\param[in] maxResults Size of 'results' buffer
\param[in] startIndex Index of first result to be retrieved. Previous indices are skipped.
\param[out] overflow True if a buffer overflow occurred
\return Number of overlaps found, i.e. number of elements written to the results buffer
@see PxHeightFieldGeometry getTriangle()
*/
PX_PHYSX_COMMON_API static PxU32 findOverlapHeightField(const PxGeometry& geom, const PxTransform& geomPose,
const PxHeightFieldGeometry& hfGeom, const PxTransform& hfPose,
PxU32* results, PxU32 maxResults, PxU32 startIndex, bool& overflow);
/**
\brief Sweep a specified geometry object in space and test for collision with a set of given triangles.
This function simply sweeps input geometry against each input triangle, in the order they are given.
This is an O(N) operation with N = number of input triangles. It does not use any particular acceleration structure.
\param[in] unitDir Normalized direction of the sweep.
\param[in] distance Sweep distance. Needs to be larger than 0. Clamped to PX_MAX_SWEEP_DISTANCE.
\param[in] geom The geometry object to sweep. Supported geometries are #PxSphereGeometry, #PxCapsuleGeometry and #PxBoxGeometry
\param[in] pose Pose of the geometry object to sweep.
\param[in] triangleCount Number of specified triangles
\param[in] triangles Array of triangles to sweep against
\param[out] sweepHit The sweep hit information. See the notes below for limitations about returned results.
\param[in] hitFlags Specification of the kind of information to retrieve on hit. Combination of #PxHitFlag flags. See the notes below for limitations about supported flags.
\param[in] cachedIndex Cached triangle index for subsequent calls. Cached triangle is tested first. Optional parameter.
\param[in] inflation This parameter creates a skin around the swept geometry which increases its extents for sweeping. The sweep will register a hit as soon as the skin touches a shape, and will return the corresponding distance and normal.
\param[in] doubleSided Counterpart of PxMeshGeometryFlag::eDOUBLE_SIDED for input triangles.
\return True if the swept geometry object hits the specified triangles
\note Only the following geometry types are currently supported: PxSphereGeometry, PxCapsuleGeometry, PxBoxGeometry
\note If a shape from the scene is already overlapping with the query shape in its starting position, the hit is returned unless eASSUME_NO_INITIAL_OVERLAP was specified.
\note This function returns a single closest hit across all the input triangles. Multiple hits are not supported.
\note Supported hitFlags are PxHitFlag::eDEFAULT, PxHitFlag::eASSUME_NO_INITIAL_OVERLAP, PxHitFlag::ePRECISE_SWEEP, PxHitFlag::eMESH_BOTH_SIDES, PxHitFlag::eMESH_ANY.
\note ePOSITION is only defined when there is no initial overlap (sweepHit.hadInitialOverlap() == false)
\note The returned normal for initially overlapping sweeps is set to -unitDir.
\note Otherwise the returned normal is the front normal of the triangle even if PxHitFlag::eMESH_BOTH_SIDES is set.
\note The returned PxSweepHit::faceIndex parameter will hold the index of the hit triangle in input array, i.e. the range is [0; triangleCount). For initially overlapping sweeps, this is the index of overlapping triangle.
\note The returned PxSweepHit::actor and PxSweepHit::shape pointers are not filled.
\note The inflation parameter is not compatible with PxHitFlag::ePRECISE_SWEEP.
@see PxTriangle PxSweepHit PxGeometry PxTransform
*/
PX_PHYSX_COMMON_API static bool sweep(const PxVec3& unitDir,
const PxReal distance,
const PxGeometry& geom,
const PxTransform& pose,
PxU32 triangleCount,
const PxTriangle* triangles,
PxSweepHit& sweepHit,
PxHitFlags hitFlags = PxHitFlag::eDEFAULT,
const PxU32* cachedIndex = NULL,
const PxReal inflation = 0.0f,
bool doubleSided = false);
};
#if !PX_DOXYGEN
}
#endif
/** @} */
#endif

View File

@ -0,0 +1,175 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_NX_MESHSCALE
#define PX_PHYSICS_NX_MESHSCALE
/** \addtogroup geomutils
@{
*/
#include "common/PxPhysXCommonConfig.h"
#include "foundation/PxMat33.h"
#include "foundation/PxAssert.h"
/** \brief Minimum allowed absolute magnitude for each of mesh scale's components (x,y,z).
\note Only positive scale values are allowed for convex meshes. */
#define PX_MESH_SCALE_MIN 1e-6f
/** \brief Maximum allowed absolute magnitude for each of mesh scale's components (x,y,z).
\note Only positive scale values are allowed for convex meshes. */
#define PX_MESH_SCALE_MAX 1e6f
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief A class expressing a nonuniform scaling transformation.
The scaling is along arbitrary axes that are specified by PxMeshScale::rotation.
\note Negative scale values are supported for PxTriangleMeshGeometry
with absolute values for each component within [PX_MIN_ABS_MESH_SCALE, PX_MAX_ABS_MESH_SCALE] range.
Negative scale causes a reflection around the specified axis, in addition PhysX will flip the normals
for mesh triangles when scale.x*scale.y*scale.z < 0.
\note Only positive scale values are supported for PxConvexMeshGeometry
with values for each component within [PX_MIN_ABS_MESH_SCALE, PX_MAX_ABS_MESH_SCALE] range).
@see PxConvexMeshGeometry PxTriangleMeshGeometry
*/
class PxMeshScale
{
//= ATTENTION! =====================================================================================
// Changing the data layout of this class breaks the binary serialization format. See comments for
// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
// accordingly.
//==================================================================================================
public:
/**
\brief Constructor initializes to identity scale.
*/
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMeshScale(): scale(1.0f), rotation(PxIdentity)
{
}
/**
\brief Constructor from scalar.
*/
explicit PX_CUDA_CALLABLE PX_FORCE_INLINE PxMeshScale(PxReal r): scale(r), rotation(PxIdentity)
{
}
/**
\brief Constructor to initialize to arbitrary scale and identity scale rotation.
*/
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMeshScale(const PxVec3& s)
{
scale = s;
rotation = PxQuat(PxIdentity);
}
/**
\brief Constructor to initialize to arbitrary scaling.
*/
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMeshScale(const PxVec3& s, const PxQuat& r)
{
PX_ASSERT(r.isUnit());
scale = s;
rotation = r;
}
/**
\brief Returns true if the scaling is an identity transformation.
*/
PX_CUDA_CALLABLE PX_FORCE_INLINE bool isIdentity() const
{
return (scale.x == 1.0f && scale.y == 1.0f && scale.z == 1.0f);
}
/**
\brief Returns the inverse of this scaling transformation.
*/
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMeshScale getInverse() const
{
return PxMeshScale(PxVec3(1.0f/scale.x, 1.0f/scale.y, 1.0f/scale.z), rotation);
}
/**
\brief Converts this transformation to a 3x3 matrix representation.
*/
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat33 toMat33() const
{
PxMat33 rot(rotation);
PxMat33 trans = rot.getTranspose();
trans.column0 *= scale[0];
trans.column1 *= scale[1];
trans.column2 *= scale[2];
return trans * rot;
}
/**
\brief Returns true if combination of negative scale components will cause the triangle normal to flip. The SDK will flip the normals internally.
*/
PX_CUDA_CALLABLE PX_FORCE_INLINE bool hasNegativeDeterminant() const
{
return (scale.x * scale.y * scale.z < 0.0f);
}
PxVec3 transform(const PxVec3& v) const
{
return rotation.rotateInv(scale.multiply(rotation.rotate(v)));
}
bool isValidForTriangleMesh() const
{
PxVec3 absXYZ = scale.abs();
return (absXYZ.maxElement() <= PX_MESH_SCALE_MAX) && (absXYZ.minElement() >= PX_MESH_SCALE_MIN);
}
bool isValidForConvexMesh() const
{
return (scale.maxElement() <= PX_MESH_SCALE_MAX) && (scale.minElement() >= PX_MESH_SCALE_MIN);
}
PxVec3 scale; //!< A nonuniform scaling
PxQuat rotation; //!< The orientation of the scaling axes
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@ -0,0 +1,85 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_NX_PLANE_GEOMETRY
#define PX_PHYSICS_NX_PLANE_GEOMETRY
/** \addtogroup geomutils
@{
*/
#include "foundation/PxPlane.h"
#include "foundation/PxTransform.h"
#include "geometry/PxGeometry.h"
#include "foundation/PxFoundationConfig.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Class describing a plane geometry.
The plane geometry specifies the half-space volume x<=0. As with other geometry types,
when used in a PxShape the collision volume is obtained by transforming the halfspace
by the shape local pose and the actor global pose.
To generate a PxPlane from a PxTransform, transform PxPlane(1,0,0,0).
To generate a PxTransform from a PxPlane, use PxTransformFromPlaneEquation.
@see PxShape.setGeometry() PxShape.getPlaneGeometry() PxTransformFromPlaneEquation
*/
class PxPlaneGeometry : public PxGeometry
{
public:
PX_INLINE PxPlaneGeometry() : PxGeometry(PxGeometryType::ePLANE) {}
/**
\brief Returns true if the geometry is valid.
\return True if the current settings are valid
*/
PX_INLINE bool isValid() const;
};
PX_INLINE bool PxPlaneGeometry::isValid() const
{
if (mType != PxGeometryType::ePLANE)
return false;
return true;
}
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@ -0,0 +1,166 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_GEOMUTILS_NX_SIMPLETRIANGLEMESH
#define PX_PHYSICS_GEOMUTILS_NX_SIMPLETRIANGLEMESH
/** \addtogroup geomutils
@{
*/
#include "foundation/PxVec3.h"
#include "foundation/PxFlags.h"
#include "common/PxCoreUtilityTypes.h"
#include "common/PxPhysXCommonConfig.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Enum with flag values to be used in PxSimpleTriangleMesh::flags.
*/
struct PxMeshFlag
{
enum Enum
{
/**
\brief Specifies if the SDK should flip normals.
The PhysX libraries assume that the face normal of a triangle with vertices [a,b,c] can be computed as:
edge1 = b-a
edge2 = c-a
face_normal = edge1 x edge2.
Note: This is the same as a counterclockwise winding in a right handed coordinate system or
alternatively a clockwise winding order in a left handed coordinate system.
If this does not match the winding order for your triangles, raise the below flag.
*/
eFLIPNORMALS = (1<<0),
e16_BIT_INDICES = (1<<1) //!< Denotes the use of 16-bit vertex indices
};
};
/**
\brief collection of set bits defined in PxMeshFlag.
@see PxMeshFlag
*/
typedef PxFlags<PxMeshFlag::Enum,PxU16> PxMeshFlags;
PX_FLAGS_OPERATORS(PxMeshFlag::Enum,PxU16)
/**
\brief A structure describing a triangle mesh.
*/
class PxSimpleTriangleMesh
{
public:
/**
\brief Pointer to first vertex point.
*/
PxBoundedData points;
/**
\brief Pointer to first triangle.
Caller may add triangleStrideBytes bytes to the pointer to access the next triangle.
These are triplets of 0 based indices:
vert0 vert1 vert2
vert0 vert1 vert2
vert0 vert1 vert2
...
where vertex is either a 32 or 16 bit unsigned integer. There are numTriangles*3 indices.
This is declared as a void pointer because it is actually either an PxU16 or a PxU32 pointer.
*/
PxBoundedData triangles;
/**
\brief Flags bits, combined from values of the enum ::PxMeshFlag
*/
PxMeshFlags flags;
/**
\brief constructor sets to default.
*/
PX_INLINE PxSimpleTriangleMesh();
/**
\brief (re)sets the structure to the default.
*/
PX_INLINE void setToDefault();
/**
\brief returns true if the current settings are valid
*/
PX_INLINE bool isValid() const;
};
PX_INLINE PxSimpleTriangleMesh::PxSimpleTriangleMesh()
{
}
PX_INLINE void PxSimpleTriangleMesh::setToDefault()
{
*this = PxSimpleTriangleMesh();
}
PX_INLINE bool PxSimpleTriangleMesh::isValid() const
{
// Check geometry
if(points.count > 0xffff && flags & PxMeshFlag::e16_BIT_INDICES)
return false;
if(!points.data)
return false;
if(points.stride < sizeof(PxVec3)) //should be at least one point's worth of data
return false;
// Check topology
// The triangles pointer is not mandatory
if(triangles.data)
{
// Indexed mesh
PxU32 limit = (flags & PxMeshFlag::e16_BIT_INDICES) ? sizeof(PxU16)*3 : sizeof(PxU32)*3;
if(triangles.stride < limit)
return false;
}
return true;
}
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@ -0,0 +1,93 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_NX_SPHERE_GEOMETRY
#define PX_PHYSICS_NX_SPHERE_GEOMETRY
/** \addtogroup geomutils
@{
*/
#include "geometry/PxGeometry.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief A class representing the geometry of a sphere.
Spheres are defined by their radius.
\note The scaling of the sphere is expected to be baked into this value, there is no additional scaling parameter.
*/
class PxSphereGeometry : public PxGeometry
{
public:
PX_INLINE PxSphereGeometry() : PxGeometry(PxGeometryType::eSPHERE), radius(0) {}
PX_INLINE PxSphereGeometry(PxReal ir) : PxGeometry(PxGeometryType::eSPHERE), radius(ir) {}
/**
\brief Returns true if the geometry is valid.
\return True if the current settings are valid
\note A valid sphere has radius > 0.
It is illegal to call PxRigidActor::createShape and PxPhysics::createShape with a sphere that has zero radius.
@see PxRigidActor::createShape, PxPhysics::createShape
*/
PX_INLINE bool isValid() const;
public:
/**
\brief The radius of the sphere.
*/
PxReal radius;
};
PX_INLINE bool PxSphereGeometry::isValid() const
{
if (mType != PxGeometryType::eSPHERE)
return false;
if (!PxIsFinite(radius))
return false;
if (radius <= 0.0f)
return false;
return true;
}
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@ -0,0 +1,149 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_GEOMUTILS_PX_TRIANGLE
#define PX_PHYSICS_GEOMUTILS_PX_TRIANGLE
/** \addtogroup geomutils
@{
*/
#include "common/PxPhysXCommonConfig.h"
#include "foundation/PxVec3.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Triangle class.
*/
class PxTriangle
{
public:
/**
\brief Constructor
*/
PX_FORCE_INLINE PxTriangle() {}
/**
\brief Constructor
\param[in] p0 Point 0
\param[in] p1 Point 1
\param[in] p2 Point 2
*/
PX_FORCE_INLINE PxTriangle(const PxVec3& p0, const PxVec3& p1, const PxVec3& p2)
{
verts[0] = p0;
verts[1] = p1;
verts[2] = p2;
}
/**
\brief Copy constructor
\param[in] triangle Tri to copy
*/
PX_FORCE_INLINE PxTriangle(const PxTriangle& triangle)
{
verts[0] = triangle.verts[0];
verts[1] = triangle.verts[1];
verts[2] = triangle.verts[2];
}
/**
\brief Destructor
*/
PX_FORCE_INLINE ~PxTriangle() {}
/**
\brief Assignment operator
*/
PX_FORCE_INLINE void operator=(const PxTriangle& triangle)
{
verts[0] = triangle.verts[0];
verts[1] = triangle.verts[1];
verts[2] = triangle.verts[2];
}
/**
\brief Compute the normal of the Triangle.
\param[out] _normal Triangle normal.
*/
PX_FORCE_INLINE void normal(PxVec3& _normal) const
{
_normal = (verts[1]-verts[0]).cross(verts[2]-verts[0]);
_normal.normalize();
}
/**
\brief Compute the unnormalized normal of the triangle.
\param[out] _normal Triangle normal (not normalized).
*/
PX_FORCE_INLINE void denormalizedNormal(PxVec3& _normal) const
{
_normal = (verts[1]-verts[0]).cross(verts[2]-verts[0]);
}
/**
\brief Compute the area of the triangle.
\return Area of the triangle.
*/
PX_FORCE_INLINE PxReal area() const
{
const PxVec3& p0 = verts[0];
const PxVec3& p1 = verts[1];
const PxVec3& p2 = verts[2];
return ((p0 - p1).cross(p0 - p2)).magnitude() * 0.5f;
}
/**
\return Computes a point on the triangle from u and v barycentric coordinates.
*/
PxVec3 pointFromUV(PxReal u, PxReal v) const { return (1.0f-u-v)*verts[0] + u*verts[1] + v*verts[2]; }
/**
\brief Array of Vertices.
*/
PxVec3 verts[3];
};
#if !PX_DOXYGEN
}
#endif
/** @} */
#endif

View File

@ -0,0 +1,317 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_GEOMUTILS_NX_TRIANGLEMESH
#define PX_PHYSICS_GEOMUTILS_NX_TRIANGLEMESH
/** \addtogroup geomutils
@{ */
#include "foundation/PxVec3.h"
#include "foundation/PxBounds3.h"
#include "common/PxPhysXCommonConfig.h"
#include "common/PxBase.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Enables the dynamic rtree mesh feature. It is recommended to use this feature for scene queries only.
@see PxTriangleMesh::getVerticesForModification
@see PxTriangleMesh::refitBVH
*/
#define PX_ENABLE_DYNAMIC_MESH_RTREE 1
/**
\brief Mesh midphase structure. This enum is used to select the desired acceleration structure for midphase queries
(i.e. raycasts, overlaps, sweeps vs triangle meshes).
The PxMeshMidPhase::eBVH33 structure is the one used in recent PhysX versions (up to PhysX 3.3). It has great performance and is
supported on all platforms.
The PxMeshMidPhase::eBVH34 structure is a revisited implementation introduced in PhysX 3.4. It can be significantly faster both
in terms of cooking performance and runtime performance, but it is currently only available on platforms supporting the
SSE2 instuction set.
*/
struct PxMeshMidPhase
{
enum Enum
{
eBVH33 = 0, //!< Default midphase mesh structure, as used up to PhysX 3.3
eBVH34 = 1, //!< New midphase mesh structure, introduced in PhysX 3.4
eLAST
};
};
/**
\brief Flags for the mesh geometry properties.
Used in ::PxTriangleMeshFlags.
*/
struct PxTriangleMeshFlag
{
enum Enum
{
e16_BIT_INDICES = (1<<1), //!< The triangle mesh has 16bits vertex indices.
eADJACENCY_INFO = (1<<2) //!< The triangle mesh has adjacency information build.
};
};
/**
\brief collection of set bits defined in PxTriangleMeshFlag.
@see PxTriangleMeshFlag
*/
typedef PxFlags<PxTriangleMeshFlag::Enum,PxU8> PxTriangleMeshFlags;
PX_FLAGS_OPERATORS(PxTriangleMeshFlag::Enum,PxU8)
/**
\brief A triangle mesh, also called a 'polygon soup'.
It is represented as an indexed triangle list. There are no restrictions on the
triangle data.
To avoid duplicating data when you have several instances of a particular
mesh positioned differently, you do not use this class to represent a
mesh object directly. Instead, you create an instance of this mesh via
the PxTriangleMeshGeometry and PxShape classes.
<h3>Creation</h3>
To create an instance of this class call PxPhysics::createTriangleMesh(),
and release() to delete it. This is only possible
once you have released all of its PxShape instances.
<h3>Visualizations:</h3>
\li #PxVisualizationParameter::eCOLLISION_AABBS
\li #PxVisualizationParameter::eCOLLISION_SHAPES
\li #PxVisualizationParameter::eCOLLISION_AXES
\li #PxVisualizationParameter::eCOLLISION_FNORMALS
\li #PxVisualizationParameter::eCOLLISION_EDGES
@see PxTriangleMeshDesc PxTriangleMeshGeometry PxShape PxPhysics.createTriangleMesh()
*/
class PxTriangleMesh : public PxBase
{
public:
/**
\brief Returns the number of vertices.
\return number of vertices
@see getVertices()
*/
virtual PxU32 getNbVertices() const = 0;
/**
\brief Returns the vertices.
\return array of vertices
@see getNbVertices()
*/
virtual const PxVec3* getVertices() const = 0;
#if PX_ENABLE_DYNAMIC_MESH_RTREE
/**
\brief Returns all mesh vertices for modification.
This function will return the vertices of the mesh so that their positions can be changed in place.
After modifying the vertices you must call refitBVH for the refitting to actually take place.
This function maintains the old mesh topology (triangle indices).
\return inplace vertex coordinates for each existing mesh vertex.
\note works only for PxMeshMidPhase::eBVH33
\note Size of array returned is equal to the number returned by getNbVertices().
\note This function operates on cooked vertex indices.
\note This means the index mapping and vertex count can be different from what was provided as an input to the cooking routine.
\note To achieve unchanged 1-to-1 index mapping with orignal mesh data (before cooking) please use the following cooking flags:
\note eWELD_VERTICES = 0, eDISABLE_CLEAN_MESH = 1.
\note It is also recommended to make sure that a call to validateTriangleMesh returns true if mesh cleaning is disabled.
@see getNbVertices()
@see refitBVH()
*/
virtual PxVec3* getVerticesForModification() = 0;
/**
\brief Refits BVH for mesh vertices.
This function will refit the mesh BVH to correctly enclose the new positions updated by getVerticesForModification.
Mesh BVH will not be reoptimized by this function so significantly different new positions will cause significantly reduced performance.
\return New bounds for the entire mesh.
\note works only for PxMeshMidPhase::eBVH33
\note PhysX does not keep a mapping from the mesh to mesh shapes that reference it.
\note Call PxShape::setGeometry on each shape which references the mesh, to ensure that internal data structures are updated to reflect the new geometry.
\note PxShape::setGeometry does not guarantee correct/continuous behavior when objects are resting on top of old or new geometry.
\note It is also recommended to make sure that a call to validateTriangleMesh returns true if mesh cleaning is disabled.
\note Active edges information will be lost during refit, the rigid body mesh contact generation might not perform as expected.
@see getNbVertices()
@see getVerticesForModification()
*/
virtual PxBounds3 refitBVH() = 0;
#endif // PX_ENABLE_DYNAMIC_MESH_RTREE
/**
\brief Returns the number of triangles.
\return number of triangles
@see getTriangles() getTrianglesRemap()
*/
virtual PxU32 getNbTriangles() const = 0;
/**
\brief Returns the triangle indices.
The indices can be 16 or 32bit depending on the number of triangles in the mesh.
Call getTriangleMeshFlags() to know if the indices are 16 or 32 bits.
The number of indices is the number of triangles * 3.
\return array of triangles
@see getNbTriangles() getTriangleMeshFlags() getTrianglesRemap()
*/
virtual const void* getTriangles() const = 0;
/**
\brief Reads the PxTriangleMesh flags.
See the list of flags #PxTriangleMeshFlag
\return The values of the PxTriangleMesh flags.
@see PxTriangleMesh
*/
virtual PxTriangleMeshFlags getTriangleMeshFlags() const = 0;
/**
\brief Returns the triangle remapping table.
The triangles are internally sorted according to various criteria. Hence the internal triangle order
does not always match the original (user-defined) order. The remapping table helps finding the old
indices knowing the new ones:
remapTable[ internalTriangleIndex ] = originalTriangleIndex
\return the remapping table (or NULL if 'PxCookingParams::suppressTriangleMeshRemapTable' has been used)
@see getNbTriangles() getTriangles() PxCookingParams::suppressTriangleMeshRemapTable
*/
virtual const PxU32* getTrianglesRemap() const = 0;
/**
\brief Decrements the reference count of a triangle mesh and releases it if the new reference count is zero.
@see PxPhysics.createTriangleMesh()
*/
virtual void release() = 0;
/**
\brief Returns material table index of given triangle
This function takes a post cooking triangle index.
\param[in] triangleIndex (internal) index of desired triangle
\return Material table index, or 0xffff if no per-triangle materials are used
*/
virtual PxMaterialTableIndex getTriangleMaterialIndex(PxTriangleID triangleIndex) const = 0;
/**
\brief Returns the local-space (vertex space) AABB from the triangle mesh.
\return local-space bounds
*/
virtual PxBounds3 getLocalBounds() const = 0;
/**
\brief Returns the reference count for shared meshes.
At creation, the reference count of the mesh is 1. Every shape referencing this mesh increments the
count by 1. When the reference count reaches 0, and only then, the mesh gets destroyed automatically.
\return the current reference count.
*/
virtual PxU32 getReferenceCount() const = 0;
/**
\brief Acquires a counted reference to a triangle mesh.
This method increases the reference count of the triangle mesh by 1. Decrement the reference count by calling release()
*/
virtual void acquireReference() = 0;
protected:
PX_INLINE PxTriangleMesh(PxType concreteType, PxBaseFlags baseFlags) : PxBase(concreteType, baseFlags) {}
PX_INLINE PxTriangleMesh(PxBaseFlags baseFlags) : PxBase(baseFlags) {}
virtual ~PxTriangleMesh() {}
virtual bool isKindOf(const char* name) const { return !::strcmp("PxTriangleMesh", name) || PxBase::isKindOf(name); }
};
/**
\brief A triangle mesh containing the PxMeshMidPhase::eBVH33 structure.
@see PxMeshMidPhase
*/
class PxBVH33TriangleMesh : public PxTriangleMesh
{
public:
protected:
PX_INLINE PxBVH33TriangleMesh(PxType concreteType, PxBaseFlags baseFlags) : PxTriangleMesh(concreteType, baseFlags) {}
PX_INLINE PxBVH33TriangleMesh(PxBaseFlags baseFlags) : PxTriangleMesh(baseFlags) {}
virtual ~PxBVH33TriangleMesh() {}
virtual bool isKindOf(const char* name) const { return !::strcmp("PxBVH33TriangleMesh", name) || PxTriangleMesh::isKindOf(name); }
};
/**
\brief A triangle mesh containing the PxMeshMidPhase::eBVH34 structure.
@see PxMeshMidPhase
*/
class PxBVH34TriangleMesh : public PxTriangleMesh
{
public:
protected:
PX_INLINE PxBVH34TriangleMesh(PxType concreteType, PxBaseFlags baseFlags) : PxTriangleMesh(concreteType, baseFlags) {}
PX_INLINE PxBVH34TriangleMesh(PxBaseFlags baseFlags) : PxTriangleMesh(baseFlags) {}
virtual ~PxBVH34TriangleMesh() {}
virtual bool isKindOf(const char* name) const { return !::strcmp("PxBVH34TriangleMesh", name) || PxTriangleMesh::isKindOf(name); }
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@ -0,0 +1,150 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_NX_TRIANGLEMESH_GEOMETRY
#define PX_PHYSICS_NX_TRIANGLEMESH_GEOMETRY
/** \addtogroup geomutils
@{
*/
#include "geometry/PxGeometry.h"
#include "geometry/PxMeshScale.h"
#include "common/PxCoreUtilityTypes.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxTriangleMesh;
/**
\brief Flags controlling the simulated behavior of the triangle mesh geometry.
Used in ::PxMeshGeometryFlags.
*/
struct PxMeshGeometryFlag
{
enum Enum
{
eDOUBLE_SIDED = (1<<1) //!< Meshes with this flag set are treated as double-sided.
//!< This flag is currently only used for raycasts and sweeps (it is ignored for overlap queries).
//!< For detailed specifications of this flag for meshes and heightfields please refer to the Geometry Query section of the user guide.
};
};
/**
\brief collection of set bits defined in PxMeshGeometryFlag.
@see PxMeshGeometryFlag
*/
typedef PxFlags<PxMeshGeometryFlag::Enum,PxU8> PxMeshGeometryFlags;
PX_FLAGS_OPERATORS(PxMeshGeometryFlag::Enum,PxU8)
/**
\brief Triangle mesh geometry class.
This class unifies a mesh object with a scaling transform, and
lets the combined object be used anywhere a PxGeometry is needed.
The scaling is a transform along arbitrary axes contained in the scale object.
The vertices of the mesh in geometry (or shape) space is the
PxMeshScale::toMat33() transform, multiplied by the vertex space vertices
in the PxConvexMesh object.
*/
class PxTriangleMeshGeometry : public PxGeometry
{
public:
/**
\brief Default constructor.
Creates an empty object with a NULL mesh and identity scale.
*/
PX_INLINE PxTriangleMeshGeometry() :
PxGeometry (PxGeometryType::eTRIANGLEMESH),
triangleMesh(NULL)
{}
/**
\brief Constructor.
\param[in] mesh Mesh pointer. May be NULL, though this will not make the object valid for shape construction.
\param[in] scaling Scale factor.
\param[in] flags Mesh flags.
\
*/
PX_INLINE PxTriangleMeshGeometry( PxTriangleMesh* mesh,
const PxMeshScale& scaling = PxMeshScale(),
PxMeshGeometryFlags flags = PxMeshGeometryFlags()) :
PxGeometry (PxGeometryType::eTRIANGLEMESH),
scale (scaling),
meshFlags (flags),
triangleMesh(mesh)
{}
/**
\brief Returns true if the geometry is valid.
\return True if the current settings are valid for shape creation.
\note A valid triangle mesh has a positive scale value in each direction (scale.scale.x > 0, scale.scale.y > 0, scale.scale.z > 0).
It is illegal to call PxRigidActor::createShape and PxPhysics::createShape with a triangle mesh that has zero extents in any direction.
@see PxRigidActor::createShape, PxPhysics::createShape
*/
PX_INLINE bool isValid() const;
public:
PxMeshScale scale; //!< The scaling transformation.
PxMeshGeometryFlags meshFlags; //!< Mesh flags.
PxPadding<3> paddingFromFlags; //!< padding for mesh flags
PxTriangleMesh* triangleMesh; //!< A reference to the mesh object.
};
PX_INLINE bool PxTriangleMeshGeometry::isValid() const
{
if(mType != PxGeometryType::eTRIANGLEMESH)
return false;
if(!scale.scale.isFinite() || !scale.rotation.isUnit())
return false;
if(!scale.isValidForTriangleMesh())
return false;
if(!triangleMesh)
return false;
return true;
}
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif