Add SuppressFaceRemapTable option for collision cooking
This commit is contained in:
@@ -15,7 +15,8 @@
|
|||||||
#define CONVEX_VERTEX_MIN 8
|
#define CONVEX_VERTEX_MIN 8
|
||||||
#define CONVEX_VERTEX_MAX 255
|
#define CONVEX_VERTEX_MAX 255
|
||||||
#define ENSURE_CAN_COOK \
|
#define ENSURE_CAN_COOK \
|
||||||
if (Physics::GetCooking() == nullptr) \
|
auto cooking = Physics::GetCooking(); \
|
||||||
|
if (cooking == nullptr) \
|
||||||
{ \
|
{ \
|
||||||
LOG(Warning, "Physics collisions cooking is disabled at runtime. Enable Physics Settings option SupportCookingAtRuntime to use collision generation at runtime."); \
|
LOG(Warning, "Physics collisions cooking is disabled at runtime. Enable Physics Settings option SupportCookingAtRuntime to use collision generation at runtime."); \
|
||||||
return true; \
|
return true; \
|
||||||
@@ -45,11 +46,14 @@ bool CollisionCooking::CookConvexMesh(CookingInput& input, BytesContainer& outpu
|
|||||||
desc.flags |= PxConvexFlag::Enum::eFAST_INERTIA_COMPUTATION;
|
desc.flags |= PxConvexFlag::Enum::eFAST_INERTIA_COMPUTATION;
|
||||||
if (input.ConvexFlags & ConvexMeshGenerationFlags::ShiftVertices)
|
if (input.ConvexFlags & ConvexMeshGenerationFlags::ShiftVertices)
|
||||||
desc.flags |= PxConvexFlag::Enum::eSHIFT_VERTICES;
|
desc.flags |= PxConvexFlag::Enum::eSHIFT_VERTICES;
|
||||||
|
PxCookingParams cookingParams = cooking->getParams();
|
||||||
|
cookingParams.suppressTriangleMeshRemapTable = input.ConvexFlags & ConvexMeshGenerationFlags::SuppressFaceRemapTable;
|
||||||
|
cooking->setParams(cookingParams);
|
||||||
|
|
||||||
// Perform cooking
|
// Perform cooking
|
||||||
PxDefaultMemoryOutputStream outputStream;
|
PxDefaultMemoryOutputStream outputStream;
|
||||||
PxConvexMeshCookingResult::Enum result;
|
PxConvexMeshCookingResult::Enum result;
|
||||||
if (!Physics::GetCooking()->cookConvexMesh(desc, outputStream, &result))
|
if (!cooking->cookConvexMesh(desc, outputStream, &result))
|
||||||
{
|
{
|
||||||
LOG(Warning, "Convex Mesh cooking failed. Error code: {0}, Input vertices count: {1}", result, input.VertexCount);
|
LOG(Warning, "Convex Mesh cooking failed. Error code: {0}, Input vertices count: {1}", result, input.VertexCount);
|
||||||
return true;
|
return true;
|
||||||
@@ -76,11 +80,14 @@ bool CollisionCooking::CookTriangleMesh(CookingInput& input, BytesContainer& out
|
|||||||
desc.triangles.stride = 3 * (input.Is16bitIndexData ? sizeof(uint16) : sizeof(uint32));
|
desc.triangles.stride = 3 * (input.Is16bitIndexData ? sizeof(uint16) : sizeof(uint32));
|
||||||
desc.triangles.data = input.IndexData;
|
desc.triangles.data = input.IndexData;
|
||||||
desc.flags = input.Is16bitIndexData ? PxMeshFlag::e16_BIT_INDICES : (PxMeshFlag::Enum)0;
|
desc.flags = input.Is16bitIndexData ? PxMeshFlag::e16_BIT_INDICES : (PxMeshFlag::Enum)0;
|
||||||
|
PxCookingParams cookingParams = cooking->getParams();
|
||||||
|
cookingParams.suppressTriangleMeshRemapTable = input.ConvexFlags & ConvexMeshGenerationFlags::SuppressFaceRemapTable;
|
||||||
|
cooking->setParams(cookingParams);
|
||||||
|
|
||||||
// Perform cooking
|
// Perform cooking
|
||||||
PxDefaultMemoryOutputStream outputStream;
|
PxDefaultMemoryOutputStream outputStream;
|
||||||
PxTriangleMeshCookingResult::Enum result;
|
PxTriangleMeshCookingResult::Enum result;
|
||||||
if (!Physics::GetCooking()->cookTriangleMesh(desc, outputStream, &result))
|
if (!cooking->cookTriangleMesh(desc, outputStream, &result))
|
||||||
{
|
{
|
||||||
LOG(Warning, "Triangle Mesh cooking failed. Error code: {0}, Input vertices count: {1}, indices count: {2}", result, input.VertexCount, input.IndexCount);
|
LOG(Warning, "Triangle Mesh cooking failed. Error code: {0}, Input vertices count: {1}, indices count: {2}", result, input.VertexCount, input.IndexCount);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -47,9 +47,7 @@ API_ENUM(Attributes="Flags") enum class ConvexMeshGenerationFlags
|
|||||||
None = 0,
|
None = 0,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disables the convex mesh validation to speed-up hull creation.
|
/// Disables the convex mesh validation to speed-up hull creation. Creating a convex mesh with invalid input data without prior validation may result in undefined behavior.
|
||||||
/// Creating a convex mesh with invalid input data without prior validation
|
|
||||||
/// may result in undefined behavior.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
SkipValidation = 1,
|
SkipValidation = 1,
|
||||||
|
|
||||||
@@ -73,17 +71,25 @@ API_ENUM(Attributes="Flags") enum class ConvexMeshGenerationFlags
|
|||||||
UsePlaneShifting = 2,
|
UsePlaneShifting = 2,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Inertia tensor computation is faster using SIMD code, but the precision is lower, which may result
|
/// Inertia tensor computation is faster using SIMD code, but the precision is lower, which may result in incorrect inertia for very thin hulls.
|
||||||
/// in incorrect inertia for very thin hulls.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
UseFastInteriaComputation = 4,
|
UseFastInteriaComputation = 4,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convex hull input vertices are shifted to be around origin to provide better computation stability.
|
/// 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
|
/// It is recommended to provide input vertices around the origin, otherwise use this flag to improve numerical stability.
|
||||||
/// numerical stability.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ShiftVertices = 8,
|
ShiftVertices = 8,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If checked, the face remap table is not created. This saves a significant amount of memory, but disabled ability to remap the cooked collision geometry into original mesh using raycast hit info.
|
||||||
|
/// </summary>
|
||||||
|
SuppressFaceRemapTable = 16,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The combination of flags that improve the collision data cooking performance at the cost of quality and features. Recommend for runtime dynamic or deformable objects that need quick collision updates.
|
||||||
|
/// </summary>
|
||||||
|
FastCook = SkipValidation | UseFastInteriaComputation | SuppressFaceRemapTable,
|
||||||
};
|
};
|
||||||
|
|
||||||
DECLARE_ENUM_OPERATORS(ConvexMeshGenerationFlags);
|
DECLARE_ENUM_OPERATORS(ConvexMeshGenerationFlags);
|
||||||
@@ -170,7 +176,6 @@ public:
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the options.
|
/// Gets the options.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The options.</returns>
|
|
||||||
API_PROPERTY() FORCE_INLINE const CollisionDataOptions& GetOptions() const
|
API_PROPERTY() FORCE_INLINE const CollisionDataOptions& GetOptions() const
|
||||||
{
|
{
|
||||||
return _options;
|
return _options;
|
||||||
@@ -208,6 +213,7 @@ public:
|
|||||||
/// <param name="materialSlotsMask">The source model material slots mask. One bit per-slot. Can be used to exclude particular material slots from collision cooking.</param>
|
/// <param name="materialSlotsMask">The source model material slots mask. One bit per-slot. Can be used to exclude particular material slots from collision cooking.</param>
|
||||||
/// <param name="convexFlags">The convex mesh generation flags.</param>
|
/// <param name="convexFlags">The convex mesh generation flags.</param>
|
||||||
/// <param name="convexVertexLimit">The convex mesh vertex limit. Use values in range [8;255]</param>
|
/// <param name="convexVertexLimit">The convex mesh vertex limit. Use values in range [8;255]</param>
|
||||||
|
/// <returns>True if failed, otherwise false.</returns>
|
||||||
API_FUNCTION() bool CookCollision(CollisionDataType type, ModelBase* model, int32 modelLodIndex = 0, uint32 materialSlotsMask = MAX_uint32, ConvexMeshGenerationFlags convexFlags = ConvexMeshGenerationFlags::None, int32 convexVertexLimit = 255);
|
API_FUNCTION() bool CookCollision(CollisionDataType type, ModelBase* model, int32 modelLodIndex = 0, uint32 materialSlotsMask = MAX_uint32, ConvexMeshGenerationFlags convexFlags = ConvexMeshGenerationFlags::None, int32 convexVertexLimit = 255);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -221,6 +227,7 @@ public:
|
|||||||
/// <param name="triangles">The source data index buffer (triangles list). Uses 32-bit stride buffer. Cannot be empty. Length must be multiple of 3 (as 3 vertices build a triangle).</param>
|
/// <param name="triangles">The source data index buffer (triangles list). Uses 32-bit stride buffer. Cannot be empty. Length must be multiple of 3 (as 3 vertices build a triangle).</param>
|
||||||
/// <param name="convexFlags">The convex mesh generation flags.</param>
|
/// <param name="convexFlags">The convex mesh generation flags.</param>
|
||||||
/// <param name="convexVertexLimit">The convex mesh vertex limit. Use values in range [8;255]</param>
|
/// <param name="convexVertexLimit">The convex mesh vertex limit. Use values in range [8;255]</param>
|
||||||
|
/// <returns>True if failed, otherwise false.</returns>
|
||||||
API_FUNCTION() bool CookCollision(CollisionDataType type, const Span<Vector3>& vertices, const Span<uint32>& triangles, ConvexMeshGenerationFlags convexFlags = ConvexMeshGenerationFlags::None, int32 convexVertexLimit = 255);
|
API_FUNCTION() bool CookCollision(CollisionDataType type, const Span<Vector3>& vertices, const Span<uint32>& triangles, ConvexMeshGenerationFlags convexFlags = ConvexMeshGenerationFlags::None, int32 convexVertexLimit = 255);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -234,6 +241,7 @@ public:
|
|||||||
/// <param name="triangles">The source data index buffer (triangles list). Uses 32-bit stride buffer. Cannot be empty. Length must be multiple of 3 (as 3 vertices build a triangle).</param>
|
/// <param name="triangles">The source data index buffer (triangles list). Uses 32-bit stride buffer. Cannot be empty. Length must be multiple of 3 (as 3 vertices build a triangle).</param>
|
||||||
/// <param name="convexFlags">The convex mesh generation flags.</param>
|
/// <param name="convexFlags">The convex mesh generation flags.</param>
|
||||||
/// <param name="convexVertexLimit">The convex mesh vertex limit. Use values in range [8;255]</param>
|
/// <param name="convexVertexLimit">The convex mesh vertex limit. Use values in range [8;255]</param>
|
||||||
|
/// <returns>True if failed, otherwise false.</returns>
|
||||||
API_FUNCTION() bool CookCollision(CollisionDataType type, const Span<Vector3>& vertices, const Span<int32>& triangles, ConvexMeshGenerationFlags convexFlags = ConvexMeshGenerationFlags::None, int32 convexVertexLimit = 255);
|
API_FUNCTION() bool CookCollision(CollisionDataType type, const Span<Vector3>& vertices, const Span<int32>& triangles, ConvexMeshGenerationFlags convexFlags = ConvexMeshGenerationFlags::None, int32 convexVertexLimit = 255);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -246,6 +254,7 @@ public:
|
|||||||
/// <param name="modelData">The custom geometry.</param>
|
/// <param name="modelData">The custom geometry.</param>
|
||||||
/// <param name="convexFlags">The convex mesh generation flags.</param>
|
/// <param name="convexFlags">The convex mesh generation flags.</param>
|
||||||
/// <param name="convexVertexLimit">The convex mesh vertex limit. Use values in range [8;255]</param>
|
/// <param name="convexVertexLimit">The convex mesh vertex limit. Use values in range [8;255]</param>
|
||||||
|
/// <returns>True if failed, otherwise false.</returns>
|
||||||
bool CookCollision(CollisionDataType type, ModelData* modelData, ConvexMeshGenerationFlags convexFlags, int32 convexVertexLimit);
|
bool CookCollision(CollisionDataType type, ModelData* modelData, ConvexMeshGenerationFlags convexFlags, int32 convexVertexLimit);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user