diff --git a/include/core/ecs/entity.hpp b/include/core/ecs/entity.hpp index 6d3681b..08c501d 100644 --- a/include/core/ecs/entity.hpp +++ b/include/core/ecs/entity.hpp @@ -3,6 +3,7 @@ #include #include +#include #include "core/ecs/component.hpp" @@ -14,7 +15,7 @@ namespace Engine { std::string name; std::unique_ptr transform = std::make_unique(); std::unique_ptr material; - std::unique_ptr mesh; + std::vector> meshes; std::unique_ptr light; std::unique_ptr camera; @@ -28,7 +29,7 @@ namespace Engine { case Component::Type::MATERIAL: return material != nullptr; case Component::Type::MESH: - return mesh != nullptr; + return meshes.size() > 0; case Component::Type::LIGHT: return light != nullptr; case Component::Type::CAMERA: diff --git a/include/core/geometry/primitives.hpp b/include/core/geometry/primitives.hpp index be8e179..61fcd7b 100644 --- a/include/core/geometry/primitives.hpp +++ b/include/core/geometry/primitives.hpp @@ -11,17 +11,16 @@ namespace Engine { namespace Geometry { class Primitive : public Object { public: - Primitive() : Object() { - mesh = std::make_unique(); - } + Primitive() : Object() {}; }; class Plane : public Primitive { public: Plane() : Primitive() { - name = std::string("Plane"); + std::unique_ptr mesh = std::make_unique(); + name = std::string("Plane"); mesh->vertices = { -0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, @@ -31,6 +30,7 @@ namespace Engine { -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f }; mesh->Initialize(); + meshes.push_back(std::move(mesh)); } }; @@ -38,8 +38,9 @@ namespace Engine { class Cube : public Primitive { public: Cube() : Primitive() { - name = std::string("Cube"); + std::unique_ptr mesh = std::make_unique(); + name = std::string("Cube"); mesh->vertices = { -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, @@ -84,6 +85,7 @@ namespace Engine { -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f }; mesh->Initialize(); + meshes.push_back(std::move(mesh)); } }; } diff --git a/src/core/render/api.cpp b/src/core/render/api.cpp index 6e2492e..1a06aef 100644 --- a/src/core/render/api.cpp +++ b/src/core/render/api.cpp @@ -135,10 +135,12 @@ void Render::RenderScene(const Engine::Scene::Scene *scene) { shader->UniformFloat("material.shininess", object->material->shininess); } - object->mesh->VAO->bind(); - // TODO: Add calculation of the number of lines to the mesh method - glDrawArrays(GL_TRIANGLES, 0, object->mesh->vertices.size() / 6); - object->mesh->VAO->unbind(); + for (auto const &mesh : object->meshes) { + mesh->VAO->bind(); + // TODO: Add calculation of the number of lines to the mesh method + glDrawArrays(GL_TRIANGLES, 0, mesh->vertices.size() / 6); + mesh->VAO->unbind(); + } } } @@ -154,9 +156,11 @@ void Render::RenderScene(const Engine::Scene::Scene *scene) { lightingShader->UniformMatrix("projection", projection); // If the editor is enabled, then draw where the light source is - light->mesh->VAO->bind(); - glDrawArrays(GL_TRIANGLES, 0, light->mesh->vertices.size() / 6); - light->mesh->VAO->unbind(); + for (auto const &mesh : light->meshes) { + mesh->VAO->bind(); + glDrawArrays(GL_TRIANGLES, 0, mesh->vertices.size() / 6); + mesh->VAO->unbind(); + } } scene->environment->skybox->update(projection * view); diff --git a/src/editor.cpp b/src/editor.cpp index 1a224cd..9dc09a9 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -162,7 +162,7 @@ namespace Engine { if (selectedEntity->HasComponent(Ecs::Component::Type::MESH)) { if (ImGui::CollapsingHeader("Mesh", ImGuiTreeNodeFlags_None)) { - ImGui::Text("vertices: %ld", selectedEntity->mesh->vertices.size()); + ImGui::Text("meshes: %ld", selectedEntity->meshes.size()); } }