feat(physics): wire physx sdk into build

This commit is contained in:
2026-04-15 12:22:15 +08:00
parent 5bf258df6d
commit 31f40e2cbb
2044 changed files with 752623 additions and 1 deletions

View File

@@ -0,0 +1,110 @@
// 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-2025 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_BVH_33_MIDPHASE_DESC_H
#define PX_BVH_33_MIDPHASE_DESC_H
#include "foundation/PxPreprocessor.h"
#include "foundation/PxSimpleTypes.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\deprecated This is only used for BVH33 which is deprecated and will be removed in a future version. Use BVH34 instead.
\brief Enumeration for mesh cooking hints.
*/
struct PX_DEPRECATED PxMeshCookingHint
{
enum Enum
{
eSIM_PERFORMANCE = 0, //!< Default value. Favors higher quality hierarchy with higher runtime performance over cooking speed.
eCOOKING_PERFORMANCE = 1 //!< Enables fast cooking path at the expense of somewhat lower quality hierarchy construction.
};
};
/**
\deprecated BVH33 is deprecated and will be removed in a future version. Use BVH34 instead.
\brief Structure describing parameters affecting BVH33 midphase mesh structure.
\see PxCookingParams, PxMidphaseDesc
*/
struct PX_DEPRECATED PxBVH33MidphaseDesc
{
/**
\brief Controls the trade-off between mesh size and runtime performance.
Using a value of 1.0 will produce a larger cooked mesh with generally higher runtime performance,
using 0.0 will produce a smaller cooked mesh, with generally lower runtime performance.
Values outside of [0,1] range will be clamped and cause a warning when any mesh gets cooked.
<b>Default value:</b> 0.55
<b>Range:</b> [0.0f, 1.0f]
*/
PxF32 meshSizePerformanceTradeOff;
/**
\brief Mesh cooking hint. Used to specify mesh hierarchy construction preference.
<b>Default value:</b> PxMeshCookingHint::eSIM_PERFORMANCE
*/
PxMeshCookingHint::Enum meshCookingHint;
/**
\brief Desc initialization to default value.
*/
void setToDefault()
{
meshSizePerformanceTradeOff = 0.55f;
meshCookingHint = PxMeshCookingHint::eSIM_PERFORMANCE;
}
/**
\brief Returns true if the descriptor is valid.
\return true if the current settings are valid.
*/
bool isValid() const
{
if(meshSizePerformanceTradeOff < 0.0f || meshSizePerformanceTradeOff > 1.0f)
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-2025 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_BVH_34_MIDPHASE_DESC_H
#define PX_BVH_34_MIDPHASE_DESC_H
#include "foundation/PxPreprocessor.h"
#include "foundation/PxSimpleTypes.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Desired build strategy for PxMeshMidPhase::eBVH34
*/
struct PxBVH34BuildStrategy
{
enum Enum
{
eFAST = 0, //!< Fast build strategy. Fast build speed, good runtime performance in most cases. Recommended for runtime mesh cooking.
eDEFAULT = 1, //!< Default build strategy. Medium build speed, good runtime performance in all cases.
eSAH = 2, //!< SAH build strategy. Slower builds, slightly improved runtime performance in some cases.
eLAST
};
};
/**
\brief Structure describing parameters affecting BVH34 midphase mesh structure.
\see PxCookingParams, PxMidphaseDesc
*/
struct PxBVH34MidphaseDesc
{
/**
\brief Mesh cooking hint for max primitives per leaf limit.
Less primitives per leaf produces larger meshes with better runtime performance
and worse cooking performance. More triangles per leaf results in faster cooking speed and
smaller mesh sizes, but with worse runtime performance.
<b>Default value:</b> 4
<b>Range:</b> <2, 15>
*/
PxU32 numPrimsPerLeaf;
/**
\brief Desired build strategy for the BVH
<b>Default value:</b> eDEFAULT
*/
PxBVH34BuildStrategy::Enum buildStrategy;
/**
\brief Whether the tree should be quantized or not
Quantized trees use up less memory, but the runtime dequantization (to retrieve the node bounds) might have
a measurable performance cost. In most cases the cost is too small to matter, and using less memory is more
important. Hence, the default is true.
One important use case for non-quantized trees is deformable meshes. The refit function for the BVH is not
supported for quantized trees.
<b>Default value:</b> true
*/
bool quantized;
/**
\brief Desc initialization to default value.
*/
void setToDefault()
{
numPrimsPerLeaf = 4;
buildStrategy = PxBVH34BuildStrategy::eDEFAULT;
quantized = true;
}
/**
\brief Returns true if the descriptor is valid.
\return true if the current settings are valid.
*/
bool isValid() const
{
if(numPrimsPerLeaf < 2 || numPrimsPerLeaf > 15)
return false;
return true;
}
};
#if !PX_DOXYGEN
} // namespace physx
#endif
#endif

View File

@@ -0,0 +1,135 @@
// 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-2025 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_BVH_DESC_H
#define PX_BVH_DESC_H
#include "common/PxCoreUtilityTypes.h"
#include "foundation/PxTransform.h"
#include "foundation/PxBounds3.h"
#include "geometry/PxBVHBuildStrategy.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Descriptor class for #PxBVH.
\see PxBVH
*/
class PxBVHDesc
{
public:
PX_INLINE PxBVHDesc();
/**
\brief Pointer to first bounding box.
*/
PxBoundedData bounds;
/**
\brief Bounds enlargement
Passed bounds are slightly enlarged before creating the BVH. This is done to avoid numerical issues when
e.g. raycasts just graze the bounds. The performed operation is:
extents = (bounds.maximum - bounds.minimum)/2
enlagedBounds.minimum = passedBounds.minium - extents * enlargement
enlagedBounds.maximum = passedBounds.maxium + extents * enlargement
Users can pass pre-enlarged bounds to the BVH builder, in which case just set the enlargement value to zero.
<b>Default value:</b> 0.01
*/
float enlargement;
/**
\brief Max primitives per leaf limit.
<b>Range:</b> [0, 16)<br>
<b>Default value:</b> 4
*/
PxU32 numPrimsPerLeaf;
/**
\brief Desired build strategy for the BVH
<b>Default value:</b> eDEFAULT
*/
PxBVHBuildStrategy::Enum buildStrategy;
/**
\brief Initialize the BVH descriptor
*/
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;
protected:
};
PX_INLINE PxBVHDesc::PxBVHDesc() : enlargement(0.01f), numPrimsPerLeaf(4), buildStrategy(PxBVHBuildStrategy::eDEFAULT)
{
}
PX_INLINE void PxBVHDesc::setToDefault()
{
*this = PxBVHDesc();
}
PX_INLINE bool PxBVHDesc::isValid() const
{
// Check BVH desc data
if(!bounds.data)
return false;
if(bounds.stride < sizeof(PxBounds3)) //should be at least one bounds' worth of data
return false;
if(bounds.count == 0)
return false;
if(enlargement<0.0f)
return false;
if(numPrimsPerLeaf>=16)
return false;
return true;
}
#if !PX_DOXYGEN
} // namespace physx
#endif
#endif

View File

@@ -0,0 +1,333 @@
// 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-2025 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_CONVEX_MESH_DESC_H
#define PX_CONVEX_MESH_DESC_H
#include "foundation/PxVec3.h"
#include "foundation/PxFlags.h"
#include "common/PxCoreUtilityTypes.h"
#include "geometry/PxConvexMesh.h"
#include "PxSDFDesc.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Flags which describe the format and behavior of a convex mesh.
*/
struct PxConvexFlag
{
enum Enum
{
/**
Denotes the use of 16-bit vertex indices in PxConvexMeshDesc::triangles or PxConvexMeshDesc::polygons.
(otherwise, 32-bit indices are assumed)
\see #PxConvexMeshDesc.indices
*/
e16_BIT_INDICES = (1<<0),
/**
Automatically recomputes the hull from the vertices. If this flag is not set, you must provide the entire geometry manually.
\note For the specific algorithm used in hull computation, please see PxConvexMeshCookingType.
\see PxConvexMeshCookingType
*/
eCOMPUTE_CONVEX = (1<<1),
/**
\brief Checks and removes almost zero-area triangles during convex hull computation.
The rejected area size is specified in PxCookingParams::areaTestEpsilon
\note This flag is only used in combination with eCOMPUTE_CONVEX.
\see PxCookingParams PxCookingParams::areaTestEpsilon
*/
eCHECK_ZERO_AREA_TRIANGLES = (1<<2),
/**
\brief Quantizes the input vertices using the k-means clustering
\note The input vertices are quantized to PxConvexMeshDesc::quantizedCount
see http://en.wikipedia.org/wiki/K-means_clustering
*/
eQUANTIZE_INPUT = (1 << 3),
/**
\brief Disables the convex mesh validation to speed-up hull creation. Please use separate validation
function in checked/debug builds. Creating a convex mesh with invalid input data without prior validation
may result in undefined behavior.
\see PxCooking::validateConvexMesh
*/
eDISABLE_MESH_VALIDATION = (1 << 4),
/**
\brief Enables plane shifting vertex limit algorithm.
Plane shifting is an alternative algorithm for the case when the computed hull has more vertices
than the specified vertex limit.
The default algorithm computes the full hull, and an OBB around the input vertices. This OBB is then sliced
with the hull planes until the vertex limit is reached.The default algorithm requires the vertex limit
to be set to at least 8, and typically produces results that are much better quality than are produced
by plane shifting.
When plane shifting is enabled, the hull computation stops when vertex limit is reached. The hull planes
are then shifted to contain all input vertices, and the new plane intersection points are then used to
generate the final hull with the given vertex limit.Plane shifting may produce sharp edges to vertices
very far away from the input cloud, and does not guarantee that all input vertices are inside the resulting
hull.However, it can be used with a vertex limit as low as 4.
*/
ePLANE_SHIFTING = (1 << 5),
/**
\brief Inertia tensor computation is faster using SIMD code, but the precision is lower, which may result
in incorrect inertia for very thin hulls.
*/
eFAST_INERTIA_COMPUTATION = (1 << 6),
/**
\brief Convex hull input vertices are shifted to be around origin to provide better computation stability.
It is recommended to provide input vertices around the origin, otherwise use this flag to improve
numerical stability.
\note Is used only with eCOMPUTE_CONVEX flag.
*/
eSHIFT_VERTICES = (1 << 8)
};
};
/**
\brief collection of set bits defined in PxConvexFlag.
\see PxConvexFlag
*/
typedef PxFlags<PxConvexFlag::Enum,PxU16> PxConvexFlags;
PX_FLAGS_OPERATORS(PxConvexFlag::Enum,PxU16)
/**
\brief Descriptor class for #PxConvexMesh.
\note The number of vertices and the number of convex polygons in a cooked convex mesh is limited to 256.
\note The number of vertices and the number of convex polygons in a GPU compatible convex mesh is limited to 64,
and the number of faces per vertex is limited to 32.
\see PxConvexMesh PxConvexMeshGeometry PxShape PxPhysics.createConvexMesh()
*/
class PxConvexMeshDesc
{
public:
/**
\brief Vertex positions data in PxBoundedData format.
<b>Default:</b> NULL
*/
PxBoundedData points;
/**
\brief Polygons data in PxBoundedData format.
<p>Pointer to first polygon. </p>
<b>Default:</b> NULL
\see PxHullPolygon
*/
PxBoundedData polygons;
/**
\brief Polygon indices data in PxBoundedData format.
<p>Pointer to first index.</p>
<b>Default:</b> NULL
<p>This is declared as a void pointer because it is actually either an PxU16 or a PxU32 pointer.</p>
\see PxHullPolygon PxConvexFlag::e16_BIT_INDICES
*/
PxBoundedData indices;
/**
\brief Flags bits, combined from values of the enum ::PxConvexFlag
<b>Default:</b> 0
*/
PxConvexFlags flags;
/**
\brief Limits the number of vertices of the result convex mesh. Hard maximum limit is 255
and minimum limit is 4 if PxConvexFlag::ePLANE_SHIFTING is used, otherwise the minimum
limit is 8.
\note The please see PxConvexFlag::ePLANE_SHIFTING for algorithm explanation
\note The maximum limit for GPU compatible convex meshes is 64.
\see PxConvexFlag::ePLANE_SHIFTING
<b>Range:</b> [4, 255]<br>
<b>Default:</b> 255
*/
PxU16 vertexLimit;
/**
\brief Limits the number of polygons of the result convex mesh. Hard maximum limit is 255
and minimum limit is 4.
\note The maximum limit for GPU compatible convex meshes is 64.
<b>Range:</b> [4, 255]<br>
<b>Default:</b> 255
*/
PxU16 polygonLimit;
/**
\brief Maximum number of vertices after quantization. The quantization is done during the vertex cleaning phase.
The quantization is applied when PxConvexFlag::eQUANTIZE_INPUT is specified.
\see PxConvexFlag::eQUANTIZE_INPUT
<b>Range:</b> [4, 65535]<br>
<b>Default:</b> 255
*/
PxU16 quantizedCount;
/**
\brief SDF descriptor. When this descriptor is set, signed distance field is calculated for this convex mesh.
<b>Default:</b> NULL
*/
PxSDFDesc* sdfDesc;
/**
\brief constructor sets to default.
*/
PX_INLINE PxConvexMeshDesc();
/**
\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 PxConvexMeshDesc::PxConvexMeshDesc() //constructor sets to default
: vertexLimit(255), polygonLimit(255), quantizedCount(255), sdfDesc(NULL)
{
}
PX_INLINE void PxConvexMeshDesc::setToDefault()
{
*this = PxConvexMeshDesc();
}
PX_INLINE bool PxConvexMeshDesc::isValid() const
{
// Check geometry
if(points.count < 3 || //at least 1 trig's worth of points
(points.count > 0xffff && flags & PxConvexFlag::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;
if (quantizedCount < 4)
return false;
// Check topology
if(polygons.data)
{
if(polygons.count < 4) // we require 2 neighbors for each vertex - 4 polygons at least
return false;
if(!indices.data) // indices must be provided together with polygons
return false;
PxU32 limit = (flags & PxConvexFlag::e16_BIT_INDICES) ? sizeof(PxU16) : sizeof(PxU32);
if(indices.stride < limit)
return false;
limit = sizeof(PxHullPolygon);
if(polygons.stride < limit)
return false;
}
else
{
// We can compute the hull from the vertices
if(!(flags & PxConvexFlag::eCOMPUTE_CONVEX))
return false; // If the mesh is convex and we're not allowed to compute the hull,
// you have to provide it completely (geometry & topology).
}
if((flags & PxConvexFlag::ePLANE_SHIFTING) && vertexLimit < 4)
{
return false;
}
if (!(flags & PxConvexFlag::ePLANE_SHIFTING) && vertexLimit < 8)
{
return false;
}
if(vertexLimit > 255)
{
return false;
}
if (polygonLimit < 4)
{
return false;
}
if (polygonLimit > 255)
{
return false;
}
if (sdfDesc && !sdfDesc->isValid())
{
return false;
}
return true;
}
#if !PX_DOXYGEN
} // namespace physx
#endif
#endif

View File

@@ -0,0 +1,908 @@
// 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-2025 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_COOKING_H
#define PX_COOKING_H
#include "common/PxPhysXCommonConfig.h"
#include "common/PxTolerancesScale.h"
#include "cooking/Pxc.h"
#include "cooking/PxConvexMeshDesc.h"
#include "cooking/PxTriangleMeshDesc.h"
#include "cooking/PxTetrahedronMeshDesc.h"
#include "cooking/PxMidphaseDesc.h"
#include "cooking/PxBVHDesc.h"
#include "geometry/PxTriangleMesh.h"
#include "geometry/PxTetrahedronMesh.h"
#include "geometry/PxBVH.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxInsertionCallback;
class PxFoundation;
class PxAllocatorCallback;
class PxHeightFieldDesc;
/**
\brief Result from convex cooking.
*/
struct PxConvexMeshCookingResult
{
enum Enum
{
/**
\brief Convex mesh cooking succeeded.
*/
eSUCCESS,
/**
\brief Convex mesh cooking failed, algorithm couldn't find 4 initial vertices without a small triangle.
\see PxCookingParams::areaTestEpsilon PxConvexFlag::eCHECK_ZERO_AREA_TRIANGLES
*/
eZERO_AREA_TEST_FAILED,
/**
\brief Convex mesh cooking succeeded, but the algorithm has reached the 255 polygons limit.
The produced hull does not contain all input vertices. Try to simplify the input vertices
or try to use the eINFLATE_CONVEX or the eQUANTIZE_INPUT flags.
\see PxConvexFlag::eINFLATE_CONVEX PxConvexFlag::eQUANTIZE_INPUT
*/
ePOLYGONS_LIMIT_REACHED,
/**
\brief Something unrecoverable happened. Check the error stream to find out what.
*/
eFAILURE,
/**
\brief Convex mesh cooking succeeded, but the algorithm could not make the mesh GPU compatible because the
in-sphere radius is more than 100x smaller than the largest extent. Collision detection for any pair involving
this convex mesh will fall back to CPU.
*/
eNON_GPU_COMPATIBLE
};
};
/** \brief Enumeration for convex mesh cooking algorithms. */
struct PxConvexMeshCookingType
{
enum Enum
{
/**
\brief The Quickhull algorithm constructs the hull from the given input points. The resulting hull
will only contain a subset of the input points.
*/
eQUICKHULL
};
};
/**
\brief Result from triangle mesh cooking
*/
struct PxTriangleMeshCookingResult
{
enum Enum
{
/**
\brief Everything is A-OK.
*/
eSUCCESS = 0,
/**
\brief A triangle is too large for well-conditioned results. Tessellate the mesh for better behavior, see the user guide section on cooking for more details.
*/
eLARGE_TRIANGLE,
/**
\brief The mesh cleaning operation removed all triangles, resulting in an empty mesh.
*/
eEMPTY_MESH,
/**
\brief Something unrecoverable happened. Check the error stream to find out what.
*/
eFAILURE
};
};
/**
\brief Enum for the set of mesh pre-processing parameters.
*/
struct PxMeshPreprocessingFlag
{
enum Enum
{
/**
\brief When set, mesh welding is performed. See PxCookingParams::meshWeldTolerance. Mesh cleaning must be enabled.
*/
eWELD_VERTICES = 1 << 0,
/**
\brief When set, mesh cleaning is disabled. This makes cooking faster.
When mesh cleaning is disabled, mesh welding is also disabled.
It is recommended to use only meshes that passed during validateTriangleMesh.
*/
eDISABLE_CLEAN_MESH = 1 << 1,
/**
\brief When set, active edges are not computed and just enabled for all edges. This makes cooking faster but contact generation slower.
*/
eDISABLE_ACTIVE_EDGES_PRECOMPUTE = 1 << 2,
/**
\brief When set, 32-bit indices will always be created regardless of triangle count.
\note By default mesh will be created with 16-bit indices for triangle count <= 0xFFFF and 32-bit otherwise.
*/
eFORCE_32BIT_INDICES = 1 << 3,
/**
\brief When set, a list of triangles will be created for each associated vertex in the mesh.
*/
eENABLE_VERT_MAPPING = 1 << 4,
/**
\brief When set, inertia data is calculated for the mesh, assuming unit density.
*/
eENABLE_INERTIA = 1 << 5
};
};
typedef PxFlags<PxMeshPreprocessingFlag::Enum,PxU32> PxMeshPreprocessingFlags;
/**
\brief Structure describing parameters affecting mesh cooking.
\see PxSetCookingParams() PxGetCookingParams()
*/
struct PxCookingParams
{
/**
\brief Zero-size area epsilon used in convex hull computation.
If the area of a triangle of the hull is below this value, the triangle will be rejected. This test
is done only if PxConvexFlag::eCHECK_ZERO_AREA_TRIANGLES is used.
\see PxConvexFlag::eCHECK_ZERO_AREA_TRIANGLES
<b>Default value:</b> 0.06f*PxTolerancesScale.length*PxTolerancesScale.length
<b>Range:</b> (0.0f, PX_MAX_F32)
*/
float areaTestEpsilon;
/**
\brief Plane tolerance used in convex hull computation.
The value is used during hull construction. When a new point is about to be added to the hull it
gets dropped when the point is closer to the hull than the planeTolerance. The planeTolerance
is increased according to the hull size.
If 0.0f is set all points are accepted when the convex hull is created. This may lead to edge cases
where the new points may be merged into an existing polygon and the polygons plane equation might
slightly change therefore. This might lead to failures during polygon merging phase in the hull computation.
It is recommended to use the default value, however if it is required that all points needs to be
accepted or huge thin convexes are created, it might be required to lower the default value.
\note The plane tolerance is used only within PxConvexMeshCookingType::eQUICKHULL algorithm.
<b>Default value:</b> 0.0007f
<b>Range:</b> <0.0f, PX_MAX_F32)
*/
float planeTolerance;
/**
\brief Convex hull creation algorithm.
<b>Default value:</b> PxConvexMeshCookingType::eQUICKHULL
\see PxConvexMeshCookingType
*/
PxConvexMeshCookingType::Enum convexMeshCookingType;
/**
\brief When true, the face remap table is not created. This saves a significant amount of memory, but the SDK will
not be able to provide the remap information for internal mesh triangles returned by collisions,
sweeps or raycasts hits.
<b>Default value:</b> false
*/
bool suppressTriangleMeshRemapTable;
/**
\brief When true, the triangle adjacency information is created. You can get the adjacency triangles
for a given triangle from getTriangle.
<b>Default value:</b> false
*/
bool buildTriangleAdjacencies;
/**
\brief When true, additional information required for GPU-accelerated rigid body simulation is created. This can increase memory usage and cooking times for convex meshes and triangle meshes.
<b>Default value:</b> false
*/
bool buildGPUData;
/**
\brief Tolerance scale is used to check if cooked triangles are not too huge. This check will help with simulation stability.
\note The PxTolerancesScale values have to match the values used when creating a PxPhysics or PxScene instance.
\see PxTolerancesScale
*/
PxTolerancesScale scale;
/**
\brief Mesh pre-processing parameters. Used to control options like whether the mesh cooking performs vertex welding before cooking.
<b>Default value:</b> 0
*/
PxMeshPreprocessingFlags meshPreprocessParams;
/**
\brief Mesh weld tolerance. If mesh welding is enabled, this controls the distance at which vertices are welded.
If mesh welding is not enabled, this value defines the acceptance distance for mesh validation. Provided no two vertices are within this distance, the mesh is considered to be
clean. If not, a warning will be emitted. Having a clean, welded mesh is required to achieve the best possible performance.
The default vertex welding uses a snap-to-grid approach. This approach effectively truncates each vertex to integer values using meshWeldTolerance.
Once these snapped vertices are produced, all vertices that snap to a given vertex on the grid are remapped to reference a single vertex. Following this,
all triangles' indices are remapped to reference this subset of clean vertices. It should be noted that the vertices that we do not alter the
position of the vertices; the snap-to-grid is only performed to identify nearby vertices.
The mesh validation approach also uses the same snap-to-grid approach to identify nearby vertices. If more than one vertex snaps to a given grid coordinate,
we ensure that the distance between the vertices is at least meshWeldTolerance. If this is not the case, a warning is emitted.
<b>Default value:</b> 0.0
*/
PxReal meshWeldTolerance;
/**
\brief "Zero-area" epsilon used in mesh cleaning.
This is similar to areaTestEpsilon, but for the mesh cleaning operation.
If the area of a triangle is below this value, the triangle will be removed. This is only done when mesh cleaning is enabled,
i.e. when PxMeshPreprocessingFlag::eDISABLE_CLEAN_MESH is not set.
Default value is 0.0f to be consistent with previous PhysX versions, which only removed triangles whose area
was exactly zero.
\see PxMeshPreprocessingFlag::eDISABLE_CLEAN_MESH
<b>Default value:</b> 0.0f
<b>Range:</b> (0.0f, PX_MAX_F32)
*/
PxReal meshAreaMinLimit;
/**
\brief Maximum edge length.
If an edge of a triangle is above this value, a warning is sent to the error stream. This is only a check,
corresponding triangles are not removed.
This is only done when mesh cleaning is enabled, i.e. when PxMeshPreprocessingFlag::eDISABLE_CLEAN_MESH is not set.
Default value is 500.0f to be consistent with previous PhysX versions. This value is internally multiplied by
PxTolerancesScale::length before being used. Use 0.0f to disable the checks.
\see PxMeshPreprocessingFlag::eDISABLE_CLEAN_MESH
<b>Default value:</b> 500.0f
<b>Range:</b> (0.0f, PX_MAX_F32)
*/
PxReal meshEdgeLengthMaxLimit;
/**
\brief Controls the desired midphase desc structure for triangle meshes.
\see PxBVH33MidphaseDesc, PxBVH34MidphaseDesc, PxMidphaseDesc
<b>Default value:</b> PxMeshMidPhase::eBVH34
*/
PxMidphaseDesc midphaseDesc;
/**
\brief Vertex limit beyond which additional acceleration structures are computed for each convex mesh. Increase that limit to reduce memory usage.
Computing the extra structures all the time does not guarantee optimal performance. There is a per-platform break-even point below which the
extra structures actually hurt performance.
<b>Default value:</b> 32
*/
PxU32 gaussMapLimit;
/**
\brief Maximum mass ratio allowed on vertices touched by a single tet. If a any tetrahedron exceeds the mass ratio, the masses will get smoothed locally
until the maximum mass ratio is matched. Value should not be below 1. Smoothing might not fully converge for values <1.5. The smaller the maximum
allowed ratio, the better the stability during simulation.
<b>Default value:</b> FLT_MAX
*/
PxReal maxWeightRatioInTet;
PxCookingParams(const PxTolerancesScale& sc):
areaTestEpsilon (0.06f*sc.length*sc.length),
planeTolerance (0.0007f),
convexMeshCookingType (PxConvexMeshCookingType::eQUICKHULL),
suppressTriangleMeshRemapTable (false),
buildTriangleAdjacencies (false),
buildGPUData (false),
scale (sc),
meshPreprocessParams (0),
meshWeldTolerance (0.0f),
meshAreaMinLimit (0.0f),
meshEdgeLengthMaxLimit (500.0f),
gaussMapLimit (32),
maxWeightRatioInTet (FLT_MAX)
{
}
};
#if !PX_DOXYGEN
} // namespace physx
#endif
// Immediate cooking
/**
\brief Gets standalone object insertion interface.
This interface allows the creation of standalone objects that can exist without a PxPhysics or PxScene object.
\see PxCreateTriangleMesh PxCreateHeightfield PxCreateTetrahedronMesh PxCreateBVH
*/
PX_C_EXPORT PX_PHYSX_COOKING_API physx::PxInsertionCallback* PxGetStandaloneInsertionCallback();
// ==== BVH ====
/**
\brief Cooks a bounding volume hierarchy. The results are written to the stream.
PxCookBVH() allows a BVH description to be cooked into a binary stream
suitable for loading and performing BVH detection at runtime.
\param[in] desc The BVH descriptor.
\param[in] stream User stream to output the cooked data.
\return true on success.
\see PxBVH PxRigidActorExt::getRigidActorShapeLocalBoundsList
*/
PX_C_EXPORT PX_PHYSX_COOKING_API bool PxCookBVH(const physx::PxBVHDesc& desc, physx::PxOutputStream& stream);
/**
\brief Cooks and creates a bounding volume hierarchy without going through a stream.
\note This method does the same as PxCookBVH, but the produced BVH is not stored
into a stream but is either directly inserted in PxPhysics, or created as a standalone
object. Use this method if you are unable to cook offline.
\note PxInsertionCallback can be obtained through PxPhysics::getPhysicsInsertionCallback()
or PxGetStandaloneInsertionCallback().
\param[in] desc The BVH descriptor.
\param[in] insertionCallback The insertion interface.
\return PxBVH pointer on success
\see PxCookBVH() PxInsertionCallback
*/
PX_C_EXPORT PX_PHYSX_COOKING_API physx::PxBVH* PxCreateBVH(const physx::PxBVHDesc& desc, physx::PxInsertionCallback& insertionCallback);
/**
\brief Cooks and creates a bounding volume hierarchy without going through a stream. Convenience function for standalone objects.
\note This method does the same as PxCookBVH, but the produced BVH is not stored
into a stream but is either directly inserted in PxPhysics, or created as a standalone
object. Use this method if you are unable to cook offline.
\param[in] desc The BVH descriptor.
\return PxBVH pointer on success
\see PxCookBVH() PxInsertionCallback
*/
PX_FORCE_INLINE physx::PxBVH* PxCreateBVH(const physx::PxBVHDesc& desc)
{
return PxCreateBVH(desc, *PxGetStandaloneInsertionCallback());
}
// ==== Heightfield ====
/**
\brief Cooks a heightfield. The results are written to the stream.
To create a heightfield object there is an option to precompute some of calculations done while loading the heightfield data.
PxCookHeightField() allows a heightfield description to be cooked into a binary stream
suitable for loading and performing collision detection at runtime.
\param[in] desc The heightfield descriptor to read the HF from.
\param[in] stream User stream to output the cooked data.
\return true on success
\see PxPhysics.createHeightField()
*/
PX_C_EXPORT PX_PHYSX_COOKING_API bool PxCookHeightField(const physx::PxHeightFieldDesc& desc, physx::PxOutputStream& stream);
/**
\brief Cooks and creates a heightfield mesh and inserts it into PxPhysics.
\param[in] desc The heightfield descriptor to read the HF from.
\param[in] insertionCallback The insertion interface from PxPhysics.
\return PxHeightField pointer on success
\see PxCookHeightField() PxPhysics.createHeightField() PxInsertionCallback
*/
PX_C_EXPORT PX_PHYSX_COOKING_API physx::PxHeightField* PxCreateHeightField(const physx::PxHeightFieldDesc& desc, physx::PxInsertionCallback& insertionCallback);
/**
\brief Cooks and creates a heightfield mesh and inserts it into PxPhysics. Convenience function for standalone objects.
\param[in] desc The heightfield descriptor to read the HF from.
\return PxHeightField pointer on success
\see PxCookHeightField() PxPhysics.createHeightField() PxInsertionCallback
*/
PX_FORCE_INLINE physx::PxHeightField* PxCreateHeightField(const physx::PxHeightFieldDesc& desc)
{
return PxCreateHeightField(desc, *PxGetStandaloneInsertionCallback());
}
// ==== Convex meshes ====
/**
\brief Cooks a convex mesh. The results are written to the stream.
To create a triangle mesh object it is necessary to first 'cook' the mesh data into
a form which allows the SDK to perform efficient collision detection.
PxCookConvexMesh() allows a mesh description to be cooked into a binary stream
suitable for loading and performing collision detection at runtime.
\note The number of vertices and the number of convex polygons in a cooked convex mesh is limited to 255.
\note If those limits are exceeded in either the user-provided data or the final cooked mesh, an error is reported.
\param[in] params The cooking parameters
\param[in] desc The convex mesh descriptor to read the mesh from.
\param[in] stream User stream to output the cooked data.
\param[out] condition Result from convex mesh cooking.
\return true on success.
\see PxCookTriangleMesh() PxConvexMeshCookingResult::Enum
*/
PX_C_EXPORT PX_PHYSX_COOKING_API bool PxCookConvexMesh(const physx::PxCookingParams& params, const physx::PxConvexMeshDesc& desc, physx::PxOutputStream& stream, physx::PxConvexMeshCookingResult::Enum* condition=NULL);
/**
\brief Cooks and creates a convex mesh without going through a stream.
\note This method does the same as PxCookConvexMesh, but the produced mesh is not stored
into a stream but is either directly inserted in PxPhysics, or created as a standalone
object. Use this method if you are unable to cook offline.
\note PxInsertionCallback can be obtained through PxPhysics::getPhysicsInsertionCallback()
or PxGetStandaloneInsertionCallback().
\param[in] params The cooking parameters
\param[in] desc The convex mesh descriptor to read the mesh from.
\param[in] insertionCallback The insertion interface from PxPhysics.
\param[out] condition Result from convex mesh cooking.
\return PxConvexMesh pointer on success
\see PxCookConvexMesh() PxInsertionCallback
*/
PX_C_EXPORT PX_PHYSX_COOKING_API physx::PxConvexMesh* PxCreateConvexMesh(const physx::PxCookingParams& params, const physx::PxConvexMeshDesc& desc, physx::PxInsertionCallback& insertionCallback, physx::PxConvexMeshCookingResult::Enum* condition=NULL);
/**
\brief Cooks and creates a convex mesh without going through a stream. Convenience function for standalone objects.
\note This method does the same as cookConvexMesh, but the produced mesh is not stored
into a stream but is either directly inserted in PxPhysics, or created as a standalone
object. Use this method if you are unable to cook offline.
\param[in] params The cooking parameters
\param[in] desc The convex mesh descriptor to read the mesh from.
\return PxConvexMesh pointer on success
\see PxCookConvexMesh() PxInsertionCallback
*/
PX_FORCE_INLINE physx::PxConvexMesh* PxCreateConvexMesh(const physx::PxCookingParams& params, const physx::PxConvexMeshDesc& desc)
{
return PxCreateConvexMesh(params, desc, *PxGetStandaloneInsertionCallback());
}
/**
\brief Verifies if the convex mesh is valid. Prints an error message for each inconsistency found.
The convex mesh descriptor must contain an already created convex mesh - the vertices, indices and polygons must be provided.
\note This function should be used if PxConvexFlag::eDISABLE_MESH_VALIDATION is planned to be used in release builds.
\param[in] params The cooking parameters
\param[in] desc The convex mesh descriptor to read the mesh from.
\return true if all the validity conditions hold, false otherwise.
\see PxCookConvexMesh()
*/
PX_C_EXPORT PX_PHYSX_COOKING_API bool PxValidateConvexMesh(const physx::PxCookingParams& params, const physx::PxConvexMeshDesc& desc);
/**
\brief Compute hull polygons from given vertices and triangles. Polygons are needed for PxConvexMeshDesc rather than triangles.
Please note that the resulting polygons may have different number of vertices. Some vertices may be removed.
The output vertices, indices and polygons must be used to construct a hull.
The provided PxAllocatorCallback does allocate the out arrays. It is the user responsibility to deallocated those arrays.
\param[in] params The cooking parameters
\param[in] mesh Simple triangle mesh containing vertices and triangles used to compute polygons.
\param[in] inCallback Memory allocator for out array allocations.
\param[out] nbVerts Number of vertices used by polygons.
\param[out] vertices Vertices array used by polygons.
\param[out] nbIndices Number of indices used by polygons.
\param[out] indices Indices array used by polygons.
\param[out] nbPolygons Number of created polygons.
\param[out] hullPolygons Polygons array.
\return true on success
\see PxCookConvexMesh() PxConvexFlags PxConvexMeshDesc PxSimpleTriangleMesh
*/
PX_C_EXPORT PX_PHYSX_COOKING_API bool PxComputeHullPolygons(const physx::PxCookingParams& params, const physx::PxSimpleTriangleMesh& mesh, physx::PxAllocatorCallback& inCallback, physx::PxU32& nbVerts, physx::PxVec3*& vertices,
physx::PxU32& nbIndices, physx::PxU32*& indices, physx::PxU32& nbPolygons, physx::PxHullPolygon*& hullPolygons);
// ==== Triangle meshes ====
/**
\brief Verifies if the triangle mesh is valid. Prints an error message for each inconsistency found.
The following conditions are true for a valid triangle mesh:
1. There are no duplicate vertices (within specified vertexWeldTolerance. See PxCookingParams::meshWeldTolerance)
2. There are no large triangles (within specified PxTolerancesScale.)
\param[in] params The cooking parameters
\param[in] desc The triangle mesh descriptor to read the mesh from.
\return true if all the validity conditions hold, false otherwise.
\see PxCookTriangleMesh()
*/
PX_C_EXPORT PX_PHYSX_COOKING_API bool PxValidateTriangleMesh(const physx::PxCookingParams& params, const physx::PxTriangleMeshDesc& desc);
/**
\brief Cooks a triangle mesh. The results are written to the stream.
To create a triangle mesh object it is necessary to first 'cook' the mesh data into
a form which allows the SDK to perform efficient collision detection.
PxCookTriangleMesh() allows a mesh description to be cooked into a binary stream
suitable for loading and performing collision detection at runtime.
\param[in] params The cooking parameters
\param[in] desc The triangle mesh descriptor to read the mesh from.
\param[in] stream User stream to output the cooked data.
\param[out] condition Result from triangle mesh cooking.
\return true on success
\see PxCookConvexMesh() PxPhysics.createTriangleMesh() PxTriangleMeshCookingResult::Enum
*/
PX_C_EXPORT PX_PHYSX_COOKING_API bool PxCookTriangleMesh(const physx::PxCookingParams& params, const physx::PxTriangleMeshDesc& desc, physx::PxOutputStream& stream, physx::PxTriangleMeshCookingResult::Enum* condition=NULL);
/**
\brief Cooks and creates a triangle mesh without going through a stream.
\note This method does the same as PxCookTriangleMesh, but the produced mesh is not stored
into a stream but is either directly inserted in PxPhysics, or created as a standalone
object. Use this method if you are unable to cook offline.
\note PxInsertionCallback can be obtained through PxPhysics::getPhysicsInsertionCallback()
or PxGetStandaloneInsertionCallback().
\param[in] params The cooking parameters
\param[in] desc The triangle mesh descriptor to read the mesh from.
\param[in] insertionCallback The insertion interface from PxPhysics.
\param[out] condition Result from triangle mesh cooking.
\return PxTriangleMesh pointer on success.
\see PxCookTriangleMesh() PxPhysics.createTriangleMesh() PxInsertionCallback
*/
PX_C_EXPORT PX_PHYSX_COOKING_API physx::PxTriangleMesh* PxCreateTriangleMesh(const physx::PxCookingParams& params, const physx::PxTriangleMeshDesc& desc, physx::PxInsertionCallback& insertionCallback, physx::PxTriangleMeshCookingResult::Enum* condition=NULL);
/**
\brief Cooks and creates a triangle mesh without going through a stream. Convenience function for standalone objects.
\note This method does the same as cookTriangleMesh, but the produced mesh is not stored
into a stream but is either directly inserted in PxPhysics, or created as a standalone
object. Use this method if you are unable to cook offline.
\return PxTriangleMesh pointer on success.
\param[in] params The cooking parameters
\param[in] desc The triangle mesh descriptor to read the mesh from.
\see PxCookTriangleMesh() PxPhysics.createTriangleMesh() PxInsertionCallback
*/
PX_FORCE_INLINE physx::PxTriangleMesh* PxCreateTriangleMesh(const physx::PxCookingParams& params, const physx::PxTriangleMeshDesc& desc)
{
return PxCreateTriangleMesh(params, desc, *PxGetStandaloneInsertionCallback());
}
// ==== Tetrahedron & deformable volume meshes ====
/**
\brief Cooks a tetrahedron mesh. The results are written to the stream.
To create a tetrahedron mesh object it is necessary to first 'cook' the mesh data into
a form which allows the SDK to perform efficient collision detection.
PxCookTetrahedronMesh() allows a mesh description to be cooked into a binary stream
suitable for loading and performing collision detection at runtime.
\param[in] params The cooking parameters
\param[in] meshDesc The tetrahedron mesh descriptor to read the mesh from.
\param[in] stream User stream to output the cooked data.
\return true on success
\see PxCookConvexMesh() PxPhysics.createTetrahedronMesh()
*/
PX_C_EXPORT PX_PHYSX_COOKING_API bool PxCookTetrahedronMesh(const physx::PxCookingParams& params, const physx::PxTetrahedronMeshDesc& meshDesc, physx::PxOutputStream& stream);
/**
\brief Cooks and creates a tetrahedron mesh without going through a stream.
\note This method does the same as PxCookTetrahedronMesh, but the produced mesh is not stored
into a stream but is either directly inserted in PxPhysics, or created as a standalone
object. Use this method if you are unable to cook offline.
\note PxInsertionCallback can be obtained through PxPhysics::getPhysicsInsertionCallback()
or PxGetStandaloneInsertionCallback().
\param[in] params The cooking parameters
\param[in] meshDesc The tetrahedron mesh descriptor to read the mesh from.
\param[in] insertionCallback The insertion interface from PxPhysics.
\return PxTetrahedronMesh pointer on success.
\see PxCookTetrahedronMesh() PxInsertionCallback
*/
PX_C_EXPORT PX_PHYSX_COOKING_API physx::PxTetrahedronMesh* PxCreateTetrahedronMesh(const physx::PxCookingParams& params, const physx::PxTetrahedronMeshDesc& meshDesc, physx::PxInsertionCallback& insertionCallback);
/**
\brief Cooks and creates a tetrahedron mesh without going through a stream. Convenience function for standalone objects.
\note This method does the same as PxCookTetrahedronMesh, but the produced mesh is not stored
into a stream but is either directly inserted in PxPhysics, or created as a standalone
object. Use this method if you are unable to cook offline.
\param[in] params The cooking parameters
\param[in] meshDesc The tetrahedron mesh descriptor to read the mesh from.
\return PxTetrahedronMesh pointer on success.
\see PxCookTetrahedronMesh() PxInsertionCallback
*/
PX_FORCE_INLINE physx::PxTetrahedronMesh* PxCreateTetrahedronMesh(const physx::PxCookingParams& params, const physx::PxTetrahedronMeshDesc& meshDesc)
{
return PxCreateTetrahedronMesh(params, meshDesc, *PxGetStandaloneInsertionCallback());
}
/**
\brief Cooks a deformable volume mesh. The results are written to the stream.
To create a deformable volume mesh object it is necessary to first 'cook' the mesh data into
a form which allows the SDK to perform efficient collision detection and to store data
used during the FEM calculations.
PxCookDeformableVolumeMesh() allows a mesh description to be cooked into a binary stream
suitable for loading and performing collision detection at runtime.
\param[in] params The cooking parameters
\param[in] simulationMeshDesc The tetrahedron mesh descriptor to read the simulation mesh from.
\param[in] collisionMeshDesc The tetrahedron mesh descriptor to read the collision mesh from.
\param[in] simulationDataDesc The deformable volume data descriptor to read mapping information from.
\param[in] stream User stream to output the cooked data.
\return true on success
\see PxCookConvexMesh() PxPhysics.createTriangleMesh() PxTriangleMeshCookingResult::Enum
*/
PX_C_EXPORT PX_PHYSX_COOKING_API bool PxCookDeformableVolumeMesh(const physx::PxCookingParams& params,
const physx::PxTetrahedronMeshDesc& simulationMeshDesc, const physx::PxTetrahedronMeshDesc& collisionMeshDesc,
const physx::PxDeformableVolumeSimulationDataDesc& simulationDataDesc, physx::PxOutputStream& stream);
/**
\brief Deprecated
\see PxCookDeformableVolumeMesh
*/
PX_DEPRECATED PX_FORCE_INLINE bool PxCookSoftBodyMesh(const physx::PxCookingParams& params,
const physx::PxTetrahedronMeshDesc& simulationMeshDesc, const physx::PxTetrahedronMeshDesc& collisionMeshDesc,
const physx::PxDeformableVolumeSimulationDataDesc& simulationDataDesc, physx::PxOutputStream& stream)
{
return PxCookDeformableVolumeMesh(params, simulationMeshDesc, collisionMeshDesc, simulationDataDesc, stream);
}
/**
\brief Cooks and creates a deformable volume mesh without going through a stream.
\note This method does the same as PxCookDeformableVolumeMesh, but the produced mesh is not stored
into a stream but is either directly inserted in PxPhysics, or created as a standalone
object. Use this method if you are unable to cook offline.
\note PxInsertionCallback can be obtained through PxPhysics::getPhysicsInsertionCallback()
or PxGetStandaloneInsertionCallback().
\param[in] params The cooking parameters
\param[in] simulationMeshDesc The tetrahedron mesh descriptor to read the simulation mesh from.
\param[in] collisionMeshDesc The tetrahedron mesh descriptor to read the collision mesh from.
\param[in] simulationDataDesc The deformable volume data descriptor to read mapping information from.
\param[in] insertionCallback The insertion interface from PxPhysics.
\return PxDeformableVolumeMesh pointer on success.
\see PxCookTriangleMesh() PxPhysics.createTriangleMesh() PxInsertionCallback
*/
PX_C_EXPORT PX_PHYSX_COOKING_API physx::PxDeformableVolumeMesh* PxCreateDeformableVolumeMesh(const physx::PxCookingParams& params,
const physx::PxTetrahedronMeshDesc& simulationMeshDesc, const physx::PxTetrahedronMeshDesc& collisionMeshDesc,
const physx::PxDeformableVolumeSimulationDataDesc& simulationDataDesc, physx::PxInsertionCallback& insertionCallback);
/**
\brief Deprecated
\see PxCreateDeformableVolumeMesh
*/
PX_DEPRECATED PX_FORCE_INLINE physx::PxDeformableVolumeMesh* PxCreateSoftBodyMesh(const physx::PxCookingParams& params,
const physx::PxTetrahedronMeshDesc& simulationMeshDesc, const physx::PxTetrahedronMeshDesc& collisionMeshDesc,
const physx::PxDeformableVolumeSimulationDataDesc& simulationDataDesc, physx::PxInsertionCallback& insertionCallback)
{
return PxCreateDeformableVolumeMesh(params, simulationMeshDesc, collisionMeshDesc, simulationDataDesc, insertionCallback);
}
/**
\brief Cooks and creates a deformable volume mesh without going through a stream. Convenience function for standalone objects.
\note This method does the same as PxCreateDeformableVolumeMesh, but the produced mesh is not stored
into a stream but is either directly inserted in PxPhysics, or created as a standalone
object. Use this method if you are unable to cook offline.
\param[in] params The cooking parameters
\param[in] simulationMeshDesc The tetrahedron mesh descriptor to read the simulation mesh from.
\param[in] collisionMeshDesc The tetrahedron mesh descriptor to read the collision mesh from.
\param[in] simulationDataDesc The deformable volume data descriptor to read mapping information from.
\return PxDeformableVolumeMesh pointer on success.
\see PxCookTriangleMesh() PxPhysics.createTriangleMesh() PxInsertionCallback
*/
PX_FORCE_INLINE physx::PxDeformableVolumeMesh* PxCreateDeformableVolumeMesh(const physx::PxCookingParams& params,
const physx::PxTetrahedronMeshDesc& simulationMeshDesc, const physx::PxTetrahedronMeshDesc& collisionMeshDesc,
const physx::PxDeformableVolumeSimulationDataDesc& simulationDataDesc)
{
return PxCreateDeformableVolumeMesh(params, simulationMeshDesc, collisionMeshDesc, simulationDataDesc, *PxGetStandaloneInsertionCallback());
}
/**
\brief Deprecated
\see PxCreateDeformableVolumeMesh
*/
PX_DEPRECATED PX_FORCE_INLINE physx::PxDeformableVolumeMesh* PxCreateSoftBodyMesh(const physx::PxCookingParams& params,
const physx::PxTetrahedronMeshDesc& simulationMeshDesc, const physx::PxTetrahedronMeshDesc& collisionMeshDesc,
const physx::PxDeformableVolumeSimulationDataDesc& simulationDataDesc)
{
return PxCreateDeformableVolumeMesh(params, simulationMeshDesc, collisionMeshDesc, simulationDataDesc, *PxGetStandaloneInsertionCallback());
}
/**
\brief Computes the mapping between collision and simulation mesh
The deformable volume deformation is computed on the simulation mesh. To deform the collision mesh accordingly
it needs to be specified how its vertices need to be placed and updated inside the deformation mesh.
This method computes that embedding information.
\param[in] params The cooking parameters
\param[in] simulationMesh A tetrahedral mesh that defines the shape of the simulation mesh which is used to compute the body's deformation
\param[in] collisionMesh A tetrahedral mesh that defines the shape of the collision mesh which is used for collision detection
\param[in] collisionData A data container that contains acceleration structures and surface information of the collision mesh
\param[in] vertexToTet Optional indices (array of integers) that specifies the index of the tetrahedron in the simulation mesh that
contains a collision mesh vertex. If not provided, the embedding will be computed internally. If the simulation mesh is obtained from
PxTetMaker::createVoxelTetrahedronMesh, then the vertexToTet map createVoxelTetrahedronMesh returned should be used here.
\return PxCollisionMeshMappingData pointer that describes how the collision mesh is embedded into the simulation mesh
\see PxTetMaker::createVoxelTetrahedronMesh
*/
PX_C_EXPORT PX_PHYSX_COOKING_API physx::PxCollisionMeshMappingData* PxComputeModelsMapping(const physx::PxCookingParams& params,
physx::PxTetrahedronMeshData& simulationMesh, const physx::PxTetrahedronMeshData& collisionMesh,
const physx::PxDeformableVolumeCollisionData& collisionData, const physx::PxBoundedData* vertexToTet = NULL);
/**
\brief Computes data to accelerate collision detection of tetrahedral meshes
Computes data structures to speed up collision detection with tetrahedral meshes.
\param[in] params The cooking parameters
\param[in] collisionMeshDesc Raw tetrahedral mesh descriptor which will be used for collision detection
\return PxCollisionTetrahedronMeshData pointer that describes the collision mesh
*/
PX_C_EXPORT PX_PHYSX_COOKING_API physx::PxCollisionTetrahedronMeshData* PxComputeCollisionData(const physx::PxCookingParams& params,
const physx::PxTetrahedronMeshDesc& collisionMeshDesc);
/**
\brief Computes data to accelerate collision detection of tetrahedral meshes
Computes data to compute and store a deformable volume's deformation using FEM.
\param[in] params The cooking parameters
\param[in] simulationMeshDesc Raw tetrahedral mesh descriptor which will be used for FEM simulation
\return PxSimulationTetrahedronMeshData pointer that describes the simulation mesh
*/
PX_C_EXPORT PX_PHYSX_COOKING_API physx::PxSimulationTetrahedronMeshData* PxComputeSimulationData(const physx::PxCookingParams& params,
const physx::PxTetrahedronMeshDesc& simulationMeshDesc);
/**
\brief Bundles all data required for deformable volume simulation
Creates a container that provides everything to create a PxDeformableVolume
\param[in] simulationMesh The geometry (tetrahedral mesh) to be used as simulation mesh
\param[in] simulationData Additional non-tetmesh data that contains mass information etc. for the simulation mesh
\param[in] collisionMesh The geometry (tetrahedral mesh) to be used for collision detection
\param[in] collisionData Additional non-tetmesh data that contains surface information, acceleration structures etc. for the simulation mesh
\param[in] mappingData Mapping that describes how the collision mesh's vertices are embedded into the simulation mesh
\param[in] insertionCallback The insertion interface from PxPhysics.
\return PxDeformableVolumeMesh pointer that represents a deformable volume mesh bundling all data (simulation mesh, collision mesh etc.)
\see PxDeformableVolume createDeformableVolume()
*/
PX_C_EXPORT PX_PHYSX_COOKING_API physx::PxDeformableVolumeMesh* PxAssembleDeformableVolumeMesh(physx::PxTetrahedronMeshData& simulationMesh,
physx::PxDeformableVolumeSimulationData& simulationData, physx::PxTetrahedronMeshData& collisionMesh, physx::PxDeformableVolumeCollisionData& collisionData,
physx::PxCollisionMeshMappingData& mappingData, physx::PxInsertionCallback& insertionCallback);
/**
\brief Deprecated
\see PxAssembleDeformableVolumeMesh
*/
PX_DEPRECATED PX_FORCE_INLINE physx::PxDeformableVolumeMesh* PxAssembleSoftBodyMesh(physx::PxTetrahedronMeshData& simulationMesh,
physx::PxDeformableVolumeSimulationData& simulationData, physx::PxTetrahedronMeshData& collisionMesh, physx::PxDeformableVolumeCollisionData& collisionData,
physx::PxCollisionMeshMappingData& mappingData, physx::PxInsertionCallback& insertionCallback)
{
return PxAssembleDeformableVolumeMesh(simulationMesh, simulationData, collisionMesh, collisionData, mappingData, insertionCallback);
}
/**
\brief Deprecated
\see PxAssembleDeformableVolumeMesh
*/
PX_DEPRECATED PX_FORCE_INLINE physx::PxDeformableVolumeMesh* PxAssembleSoftBodyMesh_Sim(physx::PxSimulationTetrahedronMeshData& simulationMesh,
physx::PxCollisionTetrahedronMeshData& collisionMesh, physx::PxCollisionMeshMappingData& mappingData, physx::PxInsertionCallback& insertionCallback)
{
return PxAssembleDeformableVolumeMesh(*simulationMesh.getMesh(), *simulationMesh.getData(),
*collisionMesh.getMesh(), *collisionMesh.getData(), mappingData, insertionCallback);
}
#endif

View File

@@ -0,0 +1,52 @@
// 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-2025 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_COOKING_INTERNAL_H
#define PX_COOKING_INTERNAL_H
#include "cooking/PxCooking.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
struct PxTriangleMeshInternalData;
struct PxBVHInternalData;
class PxTriangleMesh;
class PxBVH;
#if !PX_DOXYGEN
} // namespace physx
#endif
PX_C_EXPORT PX_PHYSX_COOKING_API physx::PxTriangleMesh* PX_CALL_CONV PxCreateTriangleMeshInternal(const physx::PxTriangleMeshInternalData& data);
PX_C_EXPORT PX_PHYSX_COOKING_API physx::PxBVH* PX_CALL_CONV PxCreateBVHInternal(const physx::PxBVHInternalData& data);
#endif

View File

@@ -0,0 +1,118 @@
// 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-2025 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_MIDPHASE_DESC_H
#define PX_MIDPHASE_DESC_H
#include "geometry/PxTriangleMesh.h"
#include "cooking/PxBVH33MidphaseDesc.h"
#include "cooking/PxBVH34MidphaseDesc.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Structure describing parameters affecting midphase mesh structure.
\see PxCookingParams, PxBVH33MidphaseDesc, PxBVH34MidphaseDesc
*/
class PxMidphaseDesc
{
public:
PX_FORCE_INLINE PxMidphaseDesc() { setToDefault(PxMeshMidPhase::eBVH34); }
/**
\brief Returns type of midphase mesh structure.
\return PxMeshMidPhase::Enum
\see PxMeshMidPhase::Enum
*/
PX_FORCE_INLINE PxMeshMidPhase::Enum getType() const { return mType; }
/**
\brief Midphase descriptors union
\see PxBV33MidphaseDesc, PxBV34MidphaseDesc
*/
union {
PxBVH33MidphaseDesc mBVH33Desc;
PxBVH34MidphaseDesc mBVH34Desc;
};
/**
\brief Initialize the midphase mesh structure descriptor
\param[in] type Midphase mesh structure descriptor
\see PxBV33MidphaseDesc, PxBV34MidphaseDesc
*/
void setToDefault(PxMeshMidPhase::Enum type)
{
mType = type;
if(type==PxMeshMidPhase::eBVH33)
mBVH33Desc.setToDefault();
else if(type==PxMeshMidPhase::eBVH34)
mBVH34Desc.setToDefault();
}
/**
\brief Returns true if the descriptor is valid.
\return true if the current settings are valid.
*/
bool isValid() const
{
if(mType==PxMeshMidPhase::eBVH33)
return mBVH33Desc.isValid();
else if(mType==PxMeshMidPhase::eBVH34)
return mBVH34Desc.isValid();
return false;
}
/**
\brief Assignment operator
\return this
*/
PX_FORCE_INLINE PxMidphaseDesc& operator=(PxMeshMidPhase::Enum descType)
{
setToDefault(descType);
return *this;
}
protected:
PxMeshMidPhase::Enum mType;
};
#if !PX_DOXYGEN
} // namespace physx
#endif
#endif

View File

@@ -0,0 +1,207 @@
// 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-2025 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_SDF_DESC_H
#define PX_SDF_DESC_H
#include "PxPhysXConfig.h"
#include "geometry/PxSimpleTriangleMesh.h"
#include "foundation/PxBounds3.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxSDFBuilder;
/**
\brief A helper structure to define dimensions in 3D
*/
struct PxDim3
{
PxU32 x, y, z;
};
/**
\brief Defines the number of bits per subgrid pixel
*/
class PxSdfBitsPerSubgridPixel
{
public:
enum Enum
{
e8_BIT_PER_PIXEL = 1, //!< 8 bit per subgrid pixel (values will be stored as normalized integers)
e16_BIT_PER_PIXEL = 2, //!< 16 bit per subgrid pixel (values will be stored as normalized integers)
e32_BIT_PER_PIXEL = 4 //!< 32 bit per subgrid pixel (values will be stored as floats in world scale units)
};
};
/**
\brief A structure describing signed distance fields (SDF) for triangle meshes. SDF colliders only work when the GPU solver is
used to run the simulation. The GPU solver is enabled by setting the flag PxSceneFlag::eENABLE_GPU_DYNAMICS in the scene description.
*/
class PxSDFDesc
{
public:
/**
\brief Pointer to first sdf array element.
*/
PxBoundedData sdf;
/**
\brief Dimensions of sdf
*/
PxDim3 dims;
/**
\brief The Lower bound of the original mesh
*/
PxVec3 meshLower;
/**
\brief The spacing of each sdf voxel
*/
PxReal spacing;
/**
\brief The number of cells in a sparse subgrid block (full block has subgridSize^3 cells and (subgridSize+1)^3 samples). If set to zero, this indicates that only a dense background grid SDF is used without sparse blocks
*/
PxU32 subgridSize;
/**
\brief Enumeration that defines the number of bits per subgrid pixel (either 32, 16 or 8bits)
*/
PxSdfBitsPerSubgridPixel::Enum bitsPerSubgridPixel;
/**
\brief Number of subgrid blocks in the 3d texture. The full texture dimension will be sdfSubgrids3DTexBlockDim*(subgridSize+1).
*/
PxDim3 sdfSubgrids3DTexBlockDim;
/**
\brief The data to create the 3d texture containg the packed subgrid blocks. Stored as PxU8 to support multiple formats (8, 16 and 32 bits per pixel)
*/
PxBoundedData sdfSubgrids;
/**
\brief Array with start indices into the subgrid texture for every subgrid block. 10bits for z coordinate, 10bits for y and 10bits for x. Encoding is as follows: slot = (z << 20) | (y << 10) | x
*/
PxBoundedData sdfStartSlots;
/**
\brief The minimum value over all subgrid blocks. Used if normalized textures are used which is the case for 8 and 16bit formats
*/
PxReal subgridsMinSdfValue;
/**
\brief The maximum value over all subgrid blocks. Used if normalized textures are used which is the case for 8 and 16bit formats
*/
PxReal subgridsMaxSdfValue;
/**
\brief The bounds of the sdf. If left unassigned (empty), the bounds of the mesh will be used
*/
PxBounds3 sdfBounds;
/**
\brief Narrow band thickness as a fraction of the bounds diagonal length. Every subgrid block that
overlaps with the narrow band around the mesh surface will be kept providing high resolution around the mesh surface.
The valid range of this parameter is (0, 1). The higher the value, the more subgrids will get created, the more memory will be required.
*/
PxReal narrowBandThicknessRelativeToSdfBoundsDiagonal;
/**
\brief The number of threads that are launched to compute the signed distance field
*/
PxU32 numThreadsForSdfConstruction;
/**
\brief Optional pointer to the geometry of the mesh that is used to compute the SDF. If it is not set, the geometry of the mesh, that this descriptor is passed to during cooking, will be taken.
The mesh data must only be available during cooking. It can be released once cooking completed.
*/
PxSimpleTriangleMesh baseMesh;
/**
\brief Optional pointer to an instance of a SDF builder. This significantly speeds up the construction of the SDF since the default SDF builder will do almost all computations directly on the GPU.
The user must release the instance of the SDF builder once cooking completed.
*/
PxSDFBuilder* sdfBuilder;
/**
\brief Constructor
*/
PX_INLINE PxSDFDesc();
/**
\brief Returns true if the descriptor is valid.
\return true if the current settings are valid
*/
PX_INLINE bool isValid() const;
};
PX_INLINE PxSDFDesc::PxSDFDesc()
{
sdf.data = NULL;
dims.x = 0;
dims.y = 0;
dims.z = 0;
spacing = 0;
meshLower = PxVec3(PxZero);
subgridSize = 0;
subgridsMinSdfValue = 0.0f;
subgridsMaxSdfValue = 0.0f;
sdfBounds = PxBounds3::empty();
bitsPerSubgridPixel = PxSdfBitsPerSubgridPixel::e16_BIT_PER_PIXEL;
narrowBandThicknessRelativeToSdfBoundsDiagonal = 0.01f;
numThreadsForSdfConstruction = 1;
sdfBuilder = NULL;
}
PX_INLINE bool PxSDFDesc::isValid() const
{
// Check validity of user's input(if any)
if (sdf.data)
{
if (dims.x < 1 || dims.y < 1 || dims.z < 1)
return false;
if (!meshLower.isFinite())
return false;
if (spacing <= 0)
return false;
}
return true;
}
#if !PX_DOXYGEN
} // namespace physx
#endif
#endif

View File

@@ -0,0 +1,232 @@
// 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-2025 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_TETRAHEDRON_MESH_DESC_H
#define PX_TETRAHEDRON_MESH_DESC_H
#include "PxPhysXConfig.h"
#include "foundation/PxVec3.h"
#include "foundation/PxFlags.h"
#include "common/PxCoreUtilityTypes.h"
#include "geometry/PxSimpleTriangleMesh.h"
#include "foundation/PxArray.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Descriptor class for #PxTetrahedronMesh (contains only pure geometric data).
\see PxTetrahedronMesh PxShape
*/
class PxTetrahedronMeshDesc
{
public:
/**
\brief Defines the tetrahedron structure of a mesh.
*/
enum PxMeshFormat
{
eTET_MESH, //!< Normal tetmesh with arbitrary tetrahedra
eHEX_MESH //!< 5 or 6 tetrahedra in a row will form a hexahedron
};
/**
Optional pointer to first material index, or NULL. There are PxTetrahedronMesh::numTriangles indices in total.
Caller may add materialIndexStride bytes to the pointer to access the next triangle.
When a tetrahedron mesh collides with another object, a material is required at the collision point.
If materialIndices is NULL, then the material of the PxShape instance is used.
Otherwise, if the point of contact is on a tetrahedron with index i, then the material index is determined as:
PxDeformableMaterialTableIndex index = *(PxDeformableMaterialTableIndex *)(((PxU8*)materialIndices) + materialIndexStride * i);
If the contact point falls on a vertex or an edge, a tetrahedron adjacent to the vertex or edge is selected, and its index
used to look up a material. The selection is arbitrary but consistent over time.
<b>Default:</b> NULL
\see materialIndexStride
*/
PxTypedBoundedData<PxDeformableMaterialTableIndex> materialIndices;
/**
\brief Pointer to first vertex point.
*/
PxBoundedData points;
/**
\brief Pointer to first tetrahedron.
Caller may add tetrhedronStrideBytes bytes to the pointer to access the next tetrahedron.
These are quadruplets of 0 based indices:
vert0 vert1 vert2 vert3
vert0 vert1 vert2 vert3
vert0 vert1 vert2 vert3
...
where vertex is either a 32 or 16 bit unsigned integer. There are numTetrahedrons*4 indices.
This is declared as a void pointer because it is actually either an PxU16 or a PxU32 pointer.
*/
PxBoundedData tetrahedrons;
/**
\brief Flags bits, combined from values of the enum ::PxMeshFlag
*/
PxMeshFlags flags;
/**
\brief Used for simulation meshes only. Defines if this tet mesh should be simulated as a tet mesh,
or if a set of tetrahedra should be used to represent another shape, e.g. a hexahedral mesh constructed
from 5 or 6 elements.
*/
PxU16 tetsPerElement;
/**
\brief Constructor to build an empty tetmesh description
*/
PxTetrahedronMeshDesc()
{
points.count = 0;
points.stride = 0;
points.data = NULL;
tetrahedrons.count = 0;
tetrahedrons.stride = 0;
tetrahedrons.data = NULL;
tetsPerElement = 1;
}
/**
\brief Constructor to build a tetmeshdescription that links to the vertices and indices provided
*/
PxTetrahedronMeshDesc(physx::PxArray<physx::PxVec3>& meshVertices, physx::PxArray<physx::PxU32>& meshTetIndices,
const PxTetrahedronMeshDesc::PxMeshFormat meshFormat = eTET_MESH, PxU16 numberOfTetsPerHexElement = 5)
{
points.count = meshVertices.size();
points.stride = sizeof(float) * 3;
points.data = meshVertices.begin();
tetrahedrons.count = meshTetIndices.size() / 4;
tetrahedrons.stride = sizeof(int) * 4;
tetrahedrons.data = meshTetIndices.begin();
if (meshFormat == eTET_MESH)
tetsPerElement = 1;
else
tetsPerElement = numberOfTetsPerHexElement;
}
PX_INLINE bool isValid() const
{
// Check geometry of the collision mesh
if (points.count < 4) //at least 1 tetrahedron's worth of points
return false;
if ((!tetrahedrons.data) && (points.count % 4)) // Non-indexed mesh => we must ensure the geometry defines an implicit number of tetrahedrons // i.e. numVertices can't be divided by 4
return false;
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;
//add more validity checks here
if (materialIndices.data && materialIndices.stride < sizeof(PxDeformableMaterialTableIndex))
return false;
// The tetrahedrons pointer is not mandatory
if (tetrahedrons.data)
{
// Indexed collision mesh
PxU32 limit = (flags & PxMeshFlag::e16_BIT_INDICES) ? sizeof(PxU16) * 4 : sizeof(PxU32) * 4;
if (tetrahedrons.stride < limit)
return false;
}
//The model can only be either a tetmesh (1 tet per element), or have 5 or 6 tets per hex element, otherwise invalid.
if (tetsPerElement != 1 && tetsPerElement != 5 && tetsPerElement != 6)
return false;
return true;
}
};
/**
\brief Descriptor class for #PxDeformableVolumeMesh (contains only additional data used for deformable volume simulation).
\see PxDeformableVolumeMesh PxShape
*/
class PxDeformableVolumeSimulationDataDesc
{
public:
/**
\brief Pointer to first index of tetrahedron that contains the vertex at the same location in the vertex buffer.
if left unassigned it will be computed automatically. If a point is inside multiple tetrahedra (ambiguous case), the frist one found will be taken.
*/
PxBoundedData vertexToTet;
/**
\brief Constructor to build an empty simulation description
*/
PxDeformableVolumeSimulationDataDesc()
{
vertexToTet.count = 0;
vertexToTet.stride = 0;
vertexToTet.data = NULL;
}
/**
\brief Constructor to build a simulation description with a defined vertex to tetrahedron mapping
*/
PxDeformableVolumeSimulationDataDesc(physx::PxArray<physx::PxI32>& vertToTet)
{
vertexToTet.count = vertToTet.size();
vertexToTet.stride = sizeof(PxI32);
vertexToTet.data = vertToTet.begin();
}
PX_INLINE bool isValid() const
{
return true;
}
};
typedef PX_DEPRECATED PxDeformableVolumeSimulationDataDesc PxSoftBodySimulationDataDesc;
#if !PX_DOXYGEN
} // namespace physx
#endif
#endif

View File

@@ -0,0 +1,131 @@
// 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-2025 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_TRIANGLE_MESH_DESC_H
#define PX_TRIANGLE_MESH_DESC_H
#include "PxPhysXConfig.h"
#include "geometry/PxSimpleTriangleMesh.h"
#include "PxSDFDesc.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Descriptor class for #PxTriangleMesh.
Note that this class is derived from PxSimpleTriangleMesh which contains the members that describe the basic mesh.
The mesh data is *copied* when an PxTriangleMesh object is created from this descriptor. After the call the
user may discard the triangle data.
\see PxTriangleMesh PxTriangleMeshGeometry PxShape
*/
class PxTriangleMeshDesc : public PxSimpleTriangleMesh
{
public:
/**
Optional pointer to first material index, or NULL. There are PxSimpleTriangleMesh::numTriangles indices in total.
Caller may add materialIndexStride bytes to the pointer to access the next triangle.
When a triangle mesh collides with another object, a material is required at the collision point.
If materialIndices is NULL, then the material of the PxShape instance is used.
Otherwise, if the point of contact is on a triangle with index i, then the material index is determined as:
PxMaterialTableIndex index = *(PxMaterialTableIndex *)(((PxU8*)materialIndices) + materialIndexStride * i);
If the contact point falls on a vertex or an edge, a triangle adjacent to the vertex or edge is selected, and its index
used to look up a material. The selection is arbitrary but consistent over time.
<b>Default:</b> NULL
\see materialIndexStride
*/
PxTypedBoundedData<const PxMaterialTableIndex> materialIndices;
/**
\brief SDF descriptor. When this descriptor is set, a signed distance field (SDF) is calculated. SDF collisions only
work when the GPU solver is used to run the simulation. The GPU solver is enabled by setting the flag PxSceneFlag::eENABLE_GPU_DYNAMICS in the scene description.
<b>Default:</b> NULL
*/
PxSDFDesc* sdfDesc;
/**
\brief Constructor sets to default.
*/
PX_INLINE PxTriangleMeshDesc();
/**
\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 PxTriangleMeshDesc::PxTriangleMeshDesc() //constructor sets to default
{
PxSimpleTriangleMesh::setToDefault();
sdfDesc = NULL;
}
PX_INLINE void PxTriangleMeshDesc::setToDefault()
{
*this = PxTriangleMeshDesc();
}
PX_INLINE bool PxTriangleMeshDesc::isValid() const
{
if(points.count < 3) //at least 1 trig's worth of points
return false;
if ((!triangles.data) && (points.count%3)) // Non-indexed mesh => we must ensure the geometry defines an implicit number of triangles // i.e. numVertices can't be divided by 3
return false;
//add more validity checks here
if (materialIndices.data && materialIndices.stride < sizeof(PxMaterialTableIndex))
return false;
if (sdfDesc && !sdfDesc->isValid())
return false;
return PxSimpleTriangleMesh::isValid();
}
#if !PX_DOXYGEN
} // namespace physx
#endif
#endif

View File

@@ -0,0 +1,55 @@
// 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-2025 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 PXC_H
#define PXC_H
#include "foundation/PxPreprocessor.h"
// define API function declaration
#if !defined PX_PHYSX_STATIC_LIB
#if PX_WINDOWS_FAMILY
#if defined PX_PHYSX_COOKING_EXPORTS
#define PX_PHYSX_COOKING_API __declspec(dllexport)
#else
#define PX_PHYSX_COOKING_API __declspec(dllimport)
#endif
#elif PX_UNIX_FAMILY
#define PX_PHYSX_COOKING_API PX_UNIX_EXPORT
#endif
#endif
#if !defined(PX_PHYSX_COOKING_API)
#define PX_PHYSX_COOKING_API
#endif
#ifndef PX_C_EXPORT
#define PX_C_EXPORT extern "C"
#endif
#endif