diff --git a/examples/PhysicsPlayground/main.cpp b/examples/PhysicsPlayground/main.cpp index 76972cbaa..728315efc 100644 --- a/examples/PhysicsPlayground/main.cpp +++ b/examples/PhysicsPlayground/main.cpp @@ -279,7 +279,7 @@ int main() Nz::SparsePtr vertices = vertexMapper.GetComponentPtr(Nz::VertexComponent::Position); #if USE_JOLT - auto shipCollider = std::make_shared(vertices, vertexMapper.GetVertexCount()); + auto shipCollider = std::make_shared(vertices, vertexMapper.GetVertexCount(), 0.1f); #else auto shipCollider = std::make_shared(vertices, vertexMapper.GetVertexCount()); #endif diff --git a/src/Nazara/JoltPhysics3D/JoltCollider3D.cpp b/src/Nazara/JoltPhysics3D/JoltCollider3D.cpp index 51b519bb7..da0a6952f 100644 --- a/src/Nazara/JoltPhysics3D/JoltCollider3D.cpp +++ b/src/Nazara/JoltPhysics3D/JoltCollider3D.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include @@ -320,14 +320,27 @@ namespace Nz const JPH::ConvexHullShapeSettings* settings = GetShapeSettingsAs(); const JPH::ConvexHullShape* shape = SafeCast(settings->Create().Get().GetPtr()); - unsigned int pointCount = shape->GetNumPoints(); - for (int i = 1; i < pointCount; ++i) + unsigned int faceCount = shape->GetNumFaces(); + unsigned int maxVerticesInFace = 0; + for (unsigned int i = 0; i < faceCount; ++i) + maxVerticesInFace = std::max(maxVerticesInFace, shape->GetNumVerticesInFace(i)); + + StackArray faceVertices = NazaraStackArrayNoInit(unsigned int, maxVerticesInFace); + for (unsigned int i = 0; i < faceCount; ++i) { - indices.push_back(InsertVertex(offsetMatrix * FromJolt(shape->GetPoint(i - 1)))); - indices.push_back(InsertVertex(offsetMatrix * FromJolt(shape->GetPoint(i)))); + unsigned int vertexCount = shape->GetFaceVertices(i, maxVerticesInFace, faceVertices.data()); + if (vertexCount > 2) + { + for (unsigned int i = 1; i < vertexCount; ++i) + { + indices.push_back(InsertVertex(offsetMatrix * FromJolt(shape->GetPoint(faceVertices[i - 1])))); + indices.push_back(InsertVertex(offsetMatrix * FromJolt(shape->GetPoint(faceVertices[i])))); + } + + indices.push_back(InsertVertex(offsetMatrix * FromJolt(shape->GetPoint(faceVertices[vertexCount - 1])))); + indices.push_back(InsertVertex(offsetMatrix * FromJolt(shape->GetPoint(faceVertices[0])))); + } } - indices.push_back(InsertVertex(offsetMatrix* FromJolt(shape->GetPoint(pointCount - 1)))); - indices.push_back(InsertVertex(offsetMatrix* FromJolt(shape->GetPoint(0)))); } JoltColliderType3D JoltConvexHullCollider3D::GetType() const diff --git a/xmake.lua b/xmake.lua index 0563ca0bb..8253067cb 100644 --- a/xmake.lua +++ b/xmake.lua @@ -238,7 +238,7 @@ add_requires( "minimp3", "ordered_map", "stb") -add_requires("joltphysics 352550fdd562ce6034b27ab12d1470840e879b56", { configs = { debug = is_mode("debug") }}) +add_requires("joltphysics 24147a6936c63f4f09c6c37173169d8f366f9fb4", { configs = { debug = is_mode("debug") }}) add_requires("freetype", { configs = { bzip2 = true, png = true, woff2 = true, zlib = true, debug = is_mode("debug") } }) add_requires("libvorbis", { configs = { with_vorbisenc = false } })