Added Hulls to BSP component and collision creation

This commit is contained in:
antopilo
2023-03-14 22:41:06 -04:00
parent 7186ae001e
commit ea3f67a365
3 changed files with 32 additions and 17 deletions

View File

@@ -11,6 +11,8 @@ namespace Nuake {
{
public:
std::vector<Ref<Mesh>> Meshes;
std::vector<std::vector<Vector3>> Hulls;
std::vector<Ref<Material>> Materials;
std::vector<Ref<Physics::RigidBody>> Rigidbody;

View File

@@ -88,23 +88,25 @@ namespace Nuake
// PhysicsManager::Get()->RegisterCharacterController(cc.CharacterController);
//}
//auto bspView = m_Scene->m_Registry.view<TransformComponent, BSPBrushComponent>();
//for (auto e : bspView)
//{
// auto [transform, brush] = bspView.get<TransformComponent, BSPBrushComponent>(e);
auto bspView = m_Scene->m_Registry.view<TransformComponent, BSPBrushComponent, ModelComponent>();
for (auto e : bspView)
{
Entity ent = Entity({ e, m_Scene });
auto [transform, brush, model] = bspView.get<TransformComponent, BSPBrushComponent, ModelComponent>(e);
// if (!brush.IsSolid)
// continue;
if (!brush.IsSolid)
continue;
// for (auto m : brush.Meshes)
// {
// Ref<Physics::MeshShape> meshShape = CreateRef<Physics::MeshShape>(m);
// Ref<Physics::RigidBody> btRigidbody = CreateRef<Physics::RigidBody>(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<Physics::ConvexHullShape> meshShape = CreateRef<Physics::ConvexHullShape>(h);
Ref<Physics::RigidBody> btRigidbody = CreateRef<Physics::RigidBody>(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<TransformComponent, BSPBrushComponent, TriggerZone>();
//for (auto e : bspTriggerView)

View File

@@ -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<Vertex> 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<Vector3> 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];