diff --git a/Source/Engine/Physics/CollisionCooking.cpp b/Source/Engine/Physics/CollisionCooking.cpp index 28fa32ee0..2001fb7fe 100644 --- a/Source/Engine/Physics/CollisionCooking.cpp +++ b/Source/Engine/Physics/CollisionCooking.cpp @@ -15,7 +15,8 @@ #define CONVEX_VERTEX_MIN 8 #define CONVEX_VERTEX_MAX 255 #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."); \ return true; \ @@ -45,11 +46,14 @@ bool CollisionCooking::CookConvexMesh(CookingInput& input, BytesContainer& outpu desc.flags |= PxConvexFlag::Enum::eFAST_INERTIA_COMPUTATION; if (input.ConvexFlags & ConvexMeshGenerationFlags::ShiftVertices) desc.flags |= PxConvexFlag::Enum::eSHIFT_VERTICES; + PxCookingParams cookingParams = cooking->getParams(); + cookingParams.suppressTriangleMeshRemapTable = input.ConvexFlags & ConvexMeshGenerationFlags::SuppressFaceRemapTable; + cooking->setParams(cookingParams); // Perform cooking PxDefaultMemoryOutputStream outputStream; 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); 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.data = input.IndexData; 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 PxDefaultMemoryOutputStream outputStream; 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); return true; diff --git a/Source/Engine/Physics/CollisionData.h b/Source/Engine/Physics/CollisionData.h index 19c1efa03..b0cf9b9ba 100644 --- a/Source/Engine/Physics/CollisionData.h +++ b/Source/Engine/Physics/CollisionData.h @@ -47,9 +47,7 @@ API_ENUM(Attributes="Flags") enum class ConvexMeshGenerationFlags None = 0, /// - /// 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. + /// 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. /// SkipValidation = 1, @@ -73,17 +71,25 @@ API_ENUM(Attributes="Flags") enum class ConvexMeshGenerationFlags UsePlaneShifting = 2, /// - /// Inertia tensor computation is faster using SIMD code, but the precision is lower, which may result - /// in incorrect inertia for very thin hulls. + /// Inertia tensor computation is faster using SIMD code, but the precision is lower, which may result in incorrect inertia for very thin hulls. /// UseFastInteriaComputation = 4, /// /// 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. + /// It is recommended to provide input vertices around the origin, otherwise use this flag to improve numerical stability. /// ShiftVertices = 8, + + /// + /// 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. + /// + SuppressFaceRemapTable = 16, + + /// + /// 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. + /// + FastCook = SkipValidation | UseFastInteriaComputation | SuppressFaceRemapTable, }; DECLARE_ENUM_OPERATORS(ConvexMeshGenerationFlags); @@ -170,7 +176,6 @@ public: /// /// Gets the options. /// - /// The options. API_PROPERTY() FORCE_INLINE const CollisionDataOptions& GetOptions() const { return _options; @@ -208,6 +213,7 @@ public: /// The source model material slots mask. One bit per-slot. Can be used to exclude particular material slots from collision cooking. /// The convex mesh generation flags. /// The convex mesh vertex limit. Use values in range [8;255] + /// True if failed, otherwise false. API_FUNCTION() bool CookCollision(CollisionDataType type, ModelBase* model, int32 modelLodIndex = 0, uint32 materialSlotsMask = MAX_uint32, ConvexMeshGenerationFlags convexFlags = ConvexMeshGenerationFlags::None, int32 convexVertexLimit = 255); /// @@ -221,6 +227,7 @@ public: /// 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). /// The convex mesh generation flags. /// The convex mesh vertex limit. Use values in range [8;255] + /// True if failed, otherwise false. API_FUNCTION() bool CookCollision(CollisionDataType type, const Span& vertices, const Span& triangles, ConvexMeshGenerationFlags convexFlags = ConvexMeshGenerationFlags::None, int32 convexVertexLimit = 255); /// @@ -234,6 +241,7 @@ public: /// 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). /// The convex mesh generation flags. /// The convex mesh vertex limit. Use values in range [8;255] + /// True if failed, otherwise false. API_FUNCTION() bool CookCollision(CollisionDataType type, const Span& vertices, const Span& triangles, ConvexMeshGenerationFlags convexFlags = ConvexMeshGenerationFlags::None, int32 convexVertexLimit = 255); /// @@ -246,6 +254,7 @@ public: /// The custom geometry. /// The convex mesh generation flags. /// The convex mesh vertex limit. Use values in range [8;255] + /// True if failed, otherwise false. bool CookCollision(CollisionDataType type, ModelData* modelData, ConvexMeshGenerationFlags convexFlags, int32 convexVertexLimit); #endif