Improve CollisionCooking
This commit is contained in:
@@ -10,6 +10,8 @@
|
|||||||
#include <ThirdParty/PhysX/cooking/PxCooking.h>
|
#include <ThirdParty/PhysX/cooking/PxCooking.h>
|
||||||
#include <ThirdParty/PhysX/extensions/PxDefaultStreams.h>
|
#include <ThirdParty/PhysX/extensions/PxDefaultStreams.h>
|
||||||
|
|
||||||
|
#define CONVEX_VERTEX_MIN 8
|
||||||
|
#define CONVEX_VERTEX_MAX 255
|
||||||
#define ENSURE_CAN_COOK \
|
#define ENSURE_CAN_COOK \
|
||||||
if (Physics::GetCooking() == nullptr) \
|
if (Physics::GetCooking() == nullptr) \
|
||||||
{ \
|
{ \
|
||||||
@@ -27,7 +29,10 @@ bool CollisionCooking::CookConvexMesh(CookingInput& input, BytesContainer& outpu
|
|||||||
desc.points.stride = sizeof(Vector3);
|
desc.points.stride = sizeof(Vector3);
|
||||||
desc.points.data = input.VertexData;
|
desc.points.data = input.VertexData;
|
||||||
desc.flags = PxConvexFlag::eCOMPUTE_CONVEX;
|
desc.flags = PxConvexFlag::eCOMPUTE_CONVEX;
|
||||||
desc.vertexLimit = input.ConvexVertexLimit;
|
if (input.ConvexVertexLimit == 0)
|
||||||
|
desc.vertexLimit = CONVEX_VERTEX_MAX;
|
||||||
|
else
|
||||||
|
desc.vertexLimit = (PxU16)Math::Clamp(input.ConvexVertexLimit, CONVEX_VERTEX_MIN, CONVEX_VERTEX_MAX);
|
||||||
if (input.ConvexFlags & ConvexMeshGenerationFlags::SkipValidation)
|
if (input.ConvexFlags & ConvexMeshGenerationFlags::SkipValidation)
|
||||||
desc.flags |= PxConvexFlag::Enum::eDISABLE_MESH_VALIDATION;
|
desc.flags |= PxConvexFlag::Enum::eDISABLE_MESH_VALIDATION;
|
||||||
if (input.ConvexFlags & ConvexMeshGenerationFlags::UsePlaneShifting)
|
if (input.ConvexFlags & ConvexMeshGenerationFlags::UsePlaneShifting)
|
||||||
@@ -83,9 +88,9 @@ bool CollisionCooking::CookTriangleMesh(CookingInput& input, BytesContainer& out
|
|||||||
|
|
||||||
bool CollisionCooking::CookCollision(const Argument& arg, CollisionData::SerializedOptions& outputOptions, BytesContainer& outputData)
|
bool CollisionCooking::CookCollision(const Argument& arg, CollisionData::SerializedOptions& outputOptions, BytesContainer& outputData)
|
||||||
{
|
{
|
||||||
int32 convexVertexLimit = Math::Clamp(arg.ConvexVertexLimit, 8, 255);
|
int32 convexVertexLimit = Math::Clamp(arg.ConvexVertexLimit, CONVEX_VERTEX_MIN, CONVEX_VERTEX_MAX);
|
||||||
if (arg.ConvexVertexLimit == 0)
|
if (arg.ConvexVertexLimit == 0)
|
||||||
convexVertexLimit = 255;
|
convexVertexLimit = CONVEX_VERTEX_MAX;
|
||||||
|
|
||||||
DataContainer<Vector3> finalVertexData;
|
DataContainer<Vector3> finalVertexData;
|
||||||
DataContainer<uint32> finalIndexData;
|
DataContainer<uint32> finalIndexData;
|
||||||
@@ -106,19 +111,19 @@ bool CollisionCooking::CookCollision(const Argument& arg, CollisionData::Seriali
|
|||||||
auto lod = &arg.OverrideModelData->LODs[lodIndex];
|
auto lod = &arg.OverrideModelData->LODs[lodIndex];
|
||||||
const int32 meshesCount = lod->Meshes.Count();
|
const int32 meshesCount = lod->Meshes.Count();
|
||||||
|
|
||||||
// Count vertex/index buffer sizes
|
// Count vertex/index buffer sizes
|
||||||
int32 vCount = 0;
|
int32 vCount = 0;
|
||||||
int32 iCount = 0;
|
int32 iCount = 0;
|
||||||
for (int32 i = 0; i < meshesCount; i++)
|
for (int32 i = 0; i < meshesCount; i++)
|
||||||
{
|
{
|
||||||
const auto mesh = lod->Meshes[i];
|
const auto mesh = lod->Meshes[i];
|
||||||
vCount += mesh->Positions.Count();
|
vCount += mesh->Positions.Count();
|
||||||
|
|
||||||
if (needIndexBuffer)
|
if (needIndexBuffer)
|
||||||
{
|
{
|
||||||
iCount += mesh->Indices.Count() * 3;
|
iCount += mesh->Indices.Count() * 3;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (meshesCount == 1)
|
if (meshesCount == 1)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ public:
|
|||||||
|
|
||||||
struct CookingInput
|
struct CookingInput
|
||||||
{
|
{
|
||||||
int32 VertexCount;
|
int32 VertexCount = 0;
|
||||||
Vector3* VertexData;
|
Vector3* VertexData = nullptr;
|
||||||
int32 IndexCount;
|
int32 IndexCount = 0;
|
||||||
void* IndexData;
|
void* IndexData = nullptr;
|
||||||
bool Is16bitIndexData;
|
bool Is16bitIndexData = false;
|
||||||
ConvexMeshGenerationFlags ConvexFlags;
|
ConvexMeshGenerationFlags ConvexFlags = ConvexMeshGenerationFlags::None;
|
||||||
int32 ConvexVertexLimit;
|
int32 ConvexVertexLimit = 255;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -38,21 +38,12 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
struct Argument
|
struct Argument
|
||||||
{
|
{
|
||||||
CollisionDataType Type;
|
CollisionDataType Type = CollisionDataType::None;
|
||||||
ModelData* OverrideModelData;
|
ModelData* OverrideModelData = nullptr;
|
||||||
AssetReference<Model> Model;
|
AssetReference<Model> Model;
|
||||||
int32 ModelLodIndex;
|
int32 ModelLodIndex = 0;
|
||||||
ConvexMeshGenerationFlags ConvexFlags;
|
ConvexMeshGenerationFlags ConvexFlags = ConvexMeshGenerationFlags::None;
|
||||||
int32 ConvexVertexLimit;
|
int32 ConvexVertexLimit = 255;
|
||||||
|
|
||||||
Argument()
|
|
||||||
{
|
|
||||||
Type = CollisionDataType::None;
|
|
||||||
OverrideModelData = nullptr;
|
|
||||||
ModelLodIndex = 0;
|
|
||||||
ConvexFlags = ConvexMeshGenerationFlags::None;
|
|
||||||
ConvexVertexLimit = 255;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user