diff --git a/src/Nazara/BulletPhysics3D/BulletCollider3D.cpp b/src/Nazara/BulletPhysics3D/BulletCollider3D.cpp index 1deb14f82..9952b2e7f 100644 --- a/src/Nazara/BulletPhysics3D/BulletCollider3D.cpp +++ b/src/Nazara/BulletPhysics3D/BulletCollider3D.cpp @@ -308,7 +308,7 @@ namespace Nz UInt16 index = SafeCast(vertices.size()); - vertices.push_back(position); + vertices.push_back(offsetMatrix * position); vertexCache.emplace(position, index); return index; @@ -320,8 +320,8 @@ namespace Nz btVector3 from, to; m_shape->getEdge(i, from, to); - indices.push_back(InsertVertex(offsetMatrix * FromBullet(from))); - indices.push_back(InsertVertex(offsetMatrix * FromBullet(to))); + indices.push_back(InsertVertex(FromBullet(from))); + indices.push_back(InsertVertex(FromBullet(to))); } } diff --git a/src/Nazara/JoltPhysics3D/JoltCollider3D.cpp b/src/Nazara/JoltPhysics3D/JoltCollider3D.cpp index 77885fc60..1887b7be1 100644 --- a/src/Nazara/JoltPhysics3D/JoltCollider3D.cpp +++ b/src/Nazara/JoltPhysics3D/JoltCollider3D.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -302,24 +303,24 @@ namespace Nz void JoltConvexHullCollider3D::BuildDebugMesh(std::vector& vertices, std::vector& indices, const Matrix4f& offsetMatrix) const { - std::unordered_map vertexCache; - auto InsertVertex = [&](const Vector3f& position) -> UInt16 + const JPH::ConvexHullShapeSettings* settings = GetShapeSettingsAs(); + const JPH::ConvexHullShape* shape = SafeCast(settings->Create().Get().GetPtr()); + + std::unordered_map vertexCache; + auto InsertVertex = [&](unsigned int vertexIndex) -> UInt16 { - auto it = vertexCache.find(position); + auto it = vertexCache.find(vertexIndex); if (it != vertexCache.end()) return it->second; UInt16 index = SafeCast(vertices.size()); - vertices.push_back(position); - vertexCache.emplace(position, index); + vertices.push_back(offsetMatrix * FromJolt(shape->GetPoint(vertexIndex))); + vertexCache.emplace(vertexIndex, index); return index; }; - const JPH::ConvexHullShapeSettings* settings = GetShapeSettingsAs(); - const JPH::ConvexHullShape* shape = SafeCast(settings->Create().Get().GetPtr()); - unsigned int faceCount = shape->GetNumFaces(); unsigned int maxVerticesInFace = 0; for (unsigned int i = 0; i < faceCount; ++i) @@ -329,16 +330,19 @@ namespace Nz for (unsigned int i = 0; i < faceCount; ++i) { unsigned int vertexCount = shape->GetFaceVertices(i, maxVerticesInFace, faceVertices.data()); - if (vertexCount > 2) + if NAZARA_LIKELY(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(faceVertices[i - 1])); + indices.push_back(InsertVertex(faceVertices[i])); } - indices.push_back(InsertVertex(offsetMatrix * FromJolt(shape->GetPoint(faceVertices[vertexCount - 1])))); - indices.push_back(InsertVertex(offsetMatrix * FromJolt(shape->GetPoint(faceVertices[0])))); + if NAZARA_LIKELY(vertexCount > 2) + { + indices.push_back(InsertVertex(faceVertices[vertexCount - 1])); + indices.push_back(InsertVertex(faceVertices[0])); + } } } }