Files
HydraV3/HydraEngine/source/actor/HydraPlaneActor.cpp
T

208 lines
6.6 KiB
C++
Raw Normal View History

2026-07-17 15:30:29 +01:00
#include "HydraPlaneActor.h"
#include "../engine/HydraEngine.h"
#include "../actor/HydraActorManager.h"
#include "../task/HydraTask.h"
#include "../ecs/HydraECS.h"
#include "../ecs/components/HydraPositionComponent.h"
#include "../ecs/components/HydraMeshComponent.h"
#include "../ecs/components/HydraRenderableComponent.h"
#include "../ecs/components/HydraMaterialComponent.h"
2026-08-24 20:59:24 +01:00
#include "../ecs/components/HydraPhysicsComponent.h"
2026-07-17 15:30:29 +01:00
#include "../buffer/HydraMaterialBufferManager.h"
#include "../buffer/HydraTextureBufferManager.h"
#include "../buffer/HydraMaterialBuffer.h"
#include "../mesh/HydraMeshManager.h"
#include "../mesh/HydraMesh.h"
void HydraPlaneActor::InitialiseComponents()
{
// HydraECS* ecs = GetEngine()->ECS();
// HydraID entity_id = ecs->CreateEntity();
_CreatePosition();
2026-08-25 22:10:54 +01:00
_CreatePhysics();
2026-07-17 15:30:29 +01:00
_CreateMaterial();
_CreateMesh();
_CreateRenderableComponent();
2026-08-25 22:10:54 +01:00
2026-07-17 15:30:29 +01:00
}
void HydraPlaneActor::DeferredInitialiseComponents()
{
}
void HydraPlaneActor::_CreatePosition()
{
HydraECS *ecs = GetEngine()->ECS();
HydraPositionComponent position_component;
ecs->AddComponent<HydraPositionComponent>(GetID(), position_component);
}
void HydraPlaneActor::_CreateMesh()
{
HydraMeshManager *mesh_manager = GetEngine()->MeshManager();
HydraID mesh_id = mesh_manager->CreateMesh();
HydraMesh *mesh = mesh_manager->GetMesh(mesh_id);
HydraMaterialComponent mat_comp = GetEngine()->ECS()->GetComponent<HydraMaterialComponent>(GetID());
mesh->vertexes.resize(24);
mesh->indexes.resize(36);
float scale_x = 1000.0f;
float scale_y = 1.0f;
float scale_z = 1000.0f;
float min_x = -0.5f * scale_x;
float min_y = -0.5f * scale_y;
float min_z = -0.5f * scale_z;
float max_x = 0.5f * scale_x;
float max_y = 0.5f * scale_y;
float max_z = 0.5f * scale_z;
float min_u = 1000;
float min_v = 0;
float max_u = 0;
float max_v = 1000;
// 1---2 5---6
//| / | | / |
// 0---3 4---7
HydraID actor_id = GetID();
mesh->vertexes[0] = {min_x, min_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[1] = {min_x, max_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[2] = {max_x, max_y, min_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[3] = {max_x, min_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
// Face 0
mesh->indexes[0] = 0;
mesh->indexes[1] = 1;
mesh->indexes[2] = 2;
mesh->indexes[3] = 0;
mesh->indexes[4] = 2;
mesh->indexes[5] = 3;
mesh->vertexes[4] = {max_x, min_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[5] = {max_x, max_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[6] = {max_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[7] = {max_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->indexes[6] = 4;
mesh->indexes[7] = 5;
mesh->indexes[8] = 6;
mesh->indexes[9] = 4;
mesh->indexes[10] = 6;
mesh->indexes[11] = 7;
// Back Face
mesh->vertexes[8] = {max_x, min_y, max_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[9] = {max_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[10] = {min_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[11] = {min_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->indexes[12] = 8;
mesh->indexes[13] = 9;
mesh->indexes[14] = 10;
mesh->indexes[15] = 8;
mesh->indexes[16] = 10;
mesh->indexes[17] = 11;
mesh->vertexes[12] = {min_x, min_y, max_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[13] = {min_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[14] = {min_x, max_y, min_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[15] = {min_x, min_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->indexes[18] = 12;
mesh->indexes[19] = 13;
mesh->indexes[20] = 14;
mesh->indexes[21] = 12;
mesh->indexes[22] = 14;
mesh->indexes[23] = 15;
mesh->vertexes[16] = {min_x, max_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[17] = {min_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[18] = {max_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[19] = {max_x, max_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->indexes[24] = 16;
mesh->indexes[25] = 17;
mesh->indexes[26] = 18;
mesh->indexes[27] = 16;
mesh->indexes[28] = 18;
mesh->indexes[29] = 19;
mesh->vertexes[20] = {min_x, min_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[21] = {max_x, min_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[22] = {max_x, min_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[23] = {min_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->indexes[30] = 20;
mesh->indexes[31] = 21;
mesh->indexes[32] = 22;
mesh->indexes[33] = 20;
mesh->indexes[34] = 22;
mesh->indexes[35] = 23;
mesh_manager->CalculateNormals(mesh->mesh_id);
HydraECS *ecs = GetEngine()->ECS();
HydraMeshComponent mesh_comp;
mesh_comp.mesh_id = mesh_id;
mesh_comp.mesh_state = HYDRA_STATE::Waiting;
ecs->AddComponent<HydraMeshComponent>(GetID(), mesh_comp);
}
void HydraPlaneActor::_CreateMaterial()
{
HydraEngine *engine = GetEngine();
2026-08-17 14:12:11 +01:00
std::string filename = std::string(texture_base) + std::string("/DesignArea/DesignArea_Albedo_white.png");
2026-07-17 15:30:29 +01:00
HydraID tex_id = engine->TextureBufferManager()->LoadTexture(filename);
HydraMaterialBuffer material = {};
material.diffuse_texture_id = tex_id;
material.diffuse_colour = glm::vec4(1, 1, 1, 1);
2026-08-28 16:36:25 +01:00
material.emmissive_metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
2026-07-17 15:30:29 +01:00
HydraID mat_id = engine->MaterialBufferManager()->CreateMaterial(material);
HydraMaterialComponent mat_comp = {};
mat_comp.material_id = mat_id;
engine->ECS()->AddComponent<HydraMaterialComponent>(GetID(), mat_comp);
}
void HydraPlaneActor::_CreatePhysics()
{
2026-08-24 20:59:24 +01:00
HydraEngine *engine = GetEngine();
HydraPhysicsComponent phys_comp = {};
phys_comp.mass = 0;
phys_comp.phyics_type = HYDRA_PHYSICS_TYPE::HYDRA_STATIC_BODY;
phys_comp.physics_shape = HYDRA_PHYSICS_SHAPE::HYDRA_PHYSICS_BOX;
2026-07-17 15:30:29 +01:00
2026-08-24 20:59:24 +01:00
phys_comp.depth = 1000.0f;
phys_comp.height = 1.0f;
phys_comp.width = 1000.0f;
2026-07-17 15:30:29 +01:00
2026-08-24 20:59:24 +01:00
engine->ECS()->AddComponent<HydraPhysicsComponent>(GetID(), phys_comp);
2026-07-17 15:30:29 +01:00
}
void HydraPlaneActor::_CreateRenderableComponent()
{
HydraRenderableComponent render_comp;
HydraECS *ecs = GetEngine()->ECS();
render_comp.renderable_types.set((uint32_t)HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR, true);
ecs->AddComponent<HydraRenderableComponent>(GetID(), render_comp);
}