1#include "hellfire/graphics/geometry/Cube.h"
5#include "hellfire/ecs/RenderableComponent.h"
6#include "hellfire/ecs/TransformComponent.h"
7#include "hellfire/ecs/components/MeshComponent.h"
8#include "hellfire/graphics/Mesh.h"
9#include "hellfire/scene/Scene.h"
53 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f,
55 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
57 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f,
59 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
61 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f,
63 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f
74 13, 12, 15, 13, 15, 14,
76 16, 17, 18, 16, 18, 19,
78 23, 22, 21, 23, 21, 20
86 auto* mesh_comp = entity->add_component<MeshComponent>();
87 std::vector<Vertex> vertices;
88 std::vector<
unsigned int> indices;
89 get_cube_data(vertices, indices, config.color);
90 mesh_comp->set_mesh(std::make_shared<
Mesh>(vertices, indices));
94 auto* renderable = entity->add_component<RenderableComponent>();
95 if (config.material) {
96 renderable->set_material(config.material);
99 renderable->set_material(material);
111 std::vector<Vertex> vertices;
112 std::vector<
unsigned int> indices;
113 get_cube_data(vertices, indices);
114 return std::make_shared<
Mesh>(vertices, indices);
117 void Cube::get_cube_data(std::vector<Vertex>& vertices, std::vector<
unsigned int>& indices,
118 const glm::vec3& color) {
122 vertices.reserve(24);
123 indices.assign(indices_.begin(), indices_.end());
126 for (size_t i = 0; i < 24; ++i) {
128 v.position = glm::vec3(vertices_[i * 3], vertices_[i * 3 + 1], vertices_[i * 3 + 2]);
134 case 0: v.normal = glm::vec3(0.0f, 0.0f, 1.0f);
break;
135 case 1: v.normal = glm::vec3(0.0f, 0.0f, -1.0f);
break;
136 case 2: v.normal = glm::vec3(-1.0f, 0.0f, 0.0f);
break;
137 case 3: v.normal = glm::vec3(1.0f, 0.0f, 0.0f);
break;
138 case 4: v.normal = glm::vec3(0.0f, -1.0f, 0.0f);
break;
139 case 5: v.normal = glm::vec3(0.0f, 1.0f, 0.0f);
break;
140 default: v.normal = glm::vec3(0.0f, 1.0f, 0.0f);
break;
143 v.texCoords = glm::vec2(uvs_[i * 2], uvs_[i * 2 + 1]);
144 vertices.push_back(v);
static const std::vector< unsigned int > indices_
static EntityID create(Scene *scene, const std::string &name, const Config &config)
static const std::vector< float > vertices_
static const std::vector< float > uvs_
static std::shared_ptr< Mesh > create_mesh()
TransformComponent * transform()
Manages a collection of entities and their hierarchical relationships.
Entity * get_entity(EntityID id)
Retrieves an entity by its ID.
EntityID create_entity(const std::string &name="GameObject")
Creates a new entity in the scene.