diff --git a/Nuake/src/Scene/Components/BSPBrushComponent.h b/Nuake/src/Scene/Components/BSPBrushComponent.h index 98d4ec17..7edc9cf7 100644 --- a/Nuake/src/Scene/Components/BSPBrushComponent.h +++ b/Nuake/src/Scene/Components/BSPBrushComponent.h @@ -11,6 +11,8 @@ namespace Nuake { { public: std::vector> Meshes; + std::vector> Hulls; + std::vector> Materials; std::vector> Rigidbody; diff --git a/Nuake/src/Scene/Systems/PhysicsSystem.cpp b/Nuake/src/Scene/Systems/PhysicsSystem.cpp index 59ccd449..038e96b3 100644 --- a/Nuake/src/Scene/Systems/PhysicsSystem.cpp +++ b/Nuake/src/Scene/Systems/PhysicsSystem.cpp @@ -88,23 +88,25 @@ namespace Nuake // PhysicsManager::Get()->RegisterCharacterController(cc.CharacterController); //} - //auto bspView = m_Scene->m_Registry.view(); - //for (auto e : bspView) - //{ - // auto [transform, brush] = bspView.get(e); + auto bspView = m_Scene->m_Registry.view(); + for (auto e : bspView) + { + Entity ent = Entity({ e, m_Scene }); + auto [transform, brush, model] = bspView.get(e); - // if (!brush.IsSolid) - // continue; + if (!brush.IsSolid) + continue; - // for (auto m : brush.Meshes) - // { - // Ref meshShape = CreateRef(m); - // Ref btRigidbody = CreateRef(0.0f, transform.GetGlobalPosition(), meshShape); - // btRigidbody->SetEntityID(Entity{ e, m_Scene }); - // brush.Rigidbody.push_back(btRigidbody); - // PhysicsManager::Get()->RegisterBody(btRigidbody); - // } - //} + for (const auto& h : brush.Hulls) + { + Ref meshShape = CreateRef(h); + Ref btRigidbody = CreateRef(0.0f, transform.GetGlobalPosition(), transform.GetGlobalTransform(), meshShape, ent); + + btRigidbody->SetEntityID(Entity{ e, m_Scene }); + brush.Rigidbody.push_back(btRigidbody); + PhysicsManager::Get()->RegisterBody(btRigidbody); + } + } //auto bspTriggerView = m_Scene->m_Registry.view(); //for (auto e : bspTriggerView) diff --git a/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp b/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp index 3dc71618..c1cf8ac9 100644 --- a/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp +++ b/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp @@ -532,8 +532,7 @@ namespace Nuake { currentMaterial = MaterialManager::Get()->GetMaterial("resources/Textures/default/Default.png"); texture->height = texture->width = 1; } - - + face_geometry* face_geo_inst = &brush_geo_inst->faces[f]; std::vector vertices; @@ -569,6 +568,18 @@ namespace Nuake { }); } + // We need to push the hull points because the batching + // will create 1 model per material, this prevents us from + // having 1 collision shape per brush(convex). + std::vector hullPoints; + hullPoints.reserve(vertices.size()); + for (const auto& v : vertices) + { + hullPoints.push_back(v.position); + } + + bsp.Hulls.push_back(hullPoints); + for (int i = 0; i < (face_geo_inst->vertex_count - 2) * 3; ++i) { uint32_t index = face_geo_inst->indices[i];