| 1510 | } |
| 1511 | |
| 1512 | bool CollisionCooking::CookConvexMesh(CookingInput& input, BytesContainer& output) |
| 1513 | { |
| 1514 | PROFILE_CPU(); |
| 1515 | ENSURE_CAN_COOK; |
| 1516 | if (input.VertexCount == 0) |
| 1517 | LOG(Warning, "Empty mesh data for collision cooking."); |
| 1518 | |
| 1519 | // Init options |
| 1520 | PxConvexMeshDesc desc; |
| 1521 | desc.points.count = input.VertexCount; |
| 1522 | desc.points.stride = sizeof(Float3); |
| 1523 | desc.points.data = input.VertexData; |
| 1524 | desc.flags = PxConvexFlag::eCOMPUTE_CONVEX; |
| 1525 | if (input.ConvexVertexLimit == 0) |
| 1526 | desc.vertexLimit = CONVEX_VERTEX_MAX; |
| 1527 | else |
| 1528 | desc.vertexLimit = (PxU16)Math::Clamp(input.ConvexVertexLimit, CONVEX_VERTEX_MIN, CONVEX_VERTEX_MAX); |
| 1529 | if (EnumHasAnyFlags(input.ConvexFlags, ConvexMeshGenerationFlags::SkipValidation)) |
| 1530 | desc.flags |= PxConvexFlag::Enum::eDISABLE_MESH_VALIDATION; |
| 1531 | if (EnumHasAnyFlags(input.ConvexFlags, ConvexMeshGenerationFlags::UsePlaneShifting)) |
| 1532 | desc.flags |= PxConvexFlag::Enum::ePLANE_SHIFTING; |
| 1533 | if (EnumHasAnyFlags(input.ConvexFlags, ConvexMeshGenerationFlags::UseFastInteriaComputation)) |
| 1534 | desc.flags |= PxConvexFlag::Enum::eFAST_INERTIA_COMPUTATION; |
| 1535 | if (EnumHasAnyFlags(input.ConvexFlags, ConvexMeshGenerationFlags::ShiftVertices)) |
| 1536 | desc.flags |= PxConvexFlag::Enum::eSHIFT_VERTICES; |
| 1537 | PxCookingParams cookingParams = cooking->getParams(); |
| 1538 | cookingParams.suppressTriangleMeshRemapTable = EnumHasAnyFlags(input.ConvexFlags, ConvexMeshGenerationFlags::SuppressFaceRemapTable); |
| 1539 | cooking->setParams(cookingParams); |
| 1540 | |
| 1541 | // Perform cooking |
| 1542 | PxDefaultMemoryOutputStream outputStream; |
| 1543 | PxConvexMeshCookingResult::Enum result; |
| 1544 | if (!cooking->cookConvexMesh(desc, outputStream, &result)) |
| 1545 | { |
| 1546 | LOG(Warning, "Convex Mesh cooking failed. Error code: {0}, Input vertices count: {1}", (int32)result, input.VertexCount); |
| 1547 | return true; |
| 1548 | } |
| 1549 | |
| 1550 | // Copy result |
| 1551 | output.Copy(outputStream.getData(), outputStream.getSize()); |
| 1552 | |
| 1553 | return false; |
| 1554 | } |
| 1555 | |
| 1556 | bool CollisionCooking::CookTriangleMesh(CookingInput& input, BytesContainer& output) |
| 1557 | { |