diff --git a/include/Nazara/Physics/Geom.hpp b/include/Nazara/Physics/Geom.hpp index 489043f3a..d85077b9d 100644 --- a/include/Nazara/Physics/Geom.hpp +++ b/include/Nazara/Physics/Geom.hpp @@ -118,9 +118,13 @@ class NAZARA_API NzCompoundGeom : public NzPhysGeom public: NzCompoundGeom(NzPhysWorld* physWorld, NzPhysGeom** geoms, unsigned int geomCount); + const std::vector& GetGeoms() const; nzGeomType GetType() const override; template static NzCompoundGeomRef New(Args&&... args); + + private: + std::vector m_geoms; }; class NzConeGeom; diff --git a/src/Nazara/Physics/Geom.cpp b/src/Nazara/Physics/Geom.cpp index 9e2f59e99..681628a9a 100644 --- a/src/Nazara/Physics/Geom.cpp +++ b/src/Nazara/Physics/Geom.cpp @@ -178,17 +178,29 @@ NzPhysGeom(physWorld) m_collision = NewtonCreateCompoundCollision(physWorld->GetHandle(), 0); NewtonCompoundCollisionBeginAddRemove(m_collision); + m_geoms.reserve(geomCount); for (unsigned int i = 0; i < geomCount; ++i) { if (geoms[i]->GetType() == nzGeomType_Compound) - NazaraError("Cannot add compound geoms to other compound geoms"); + { + NzCompoundGeom* compoundGeom = static_cast(geoms[i]); + for (const NzPhysGeomRef& geom : compoundGeom->GetGeoms()) + NewtonCompoundCollisionAddSubCollision(m_collision, geom->GetHandle()); + } else NewtonCompoundCollisionAddSubCollision(m_collision, geoms[i]->GetHandle()); + + m_geoms.emplace_back(geoms[i]); } NewtonCompoundCollisionEndAddRemove(m_collision); } +const std::vector& NzCompoundGeom::GetGeoms() const +{ + return m_geoms; +} + nzGeomType NzCompoundGeom::GetType() const { return nzGeomType_Compound;