#include "HydraTestCubeActor.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" #include "../buffer/HydraMaterialBufferManager.h" #include "../buffer/HydraTextureBufferManager.h" #include "../buffer/HydraMaterialBuffer.h" #include "../mesh/HydraMeshManager.h" #include "../mesh/HydraMesh.h" void HydraTestCubeActor::InitialiseComponents() { // HydraECS* ecs = GetEngine()->ECS(); // HydraID entity_id = ecs->CreateEntity(); _CreatePosition(); // _CreatePhysics(); _CreateMaterial(); _CreateMesh(); _CreateRenderableComponent(); } void HydraTestCubeActor::DeferredInitialiseComponents() { } void HydraTestCubeActor::_CreatePosition() { HydraECS *ecs = GetEngine()->ECS(); HydraPositionComponent position_component; ecs->AddComponent(GetID(), position_component); } void HydraTestCubeActor::_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(GetID()); mesh->vertexes.resize(24); mesh->indexes.resize(36); float scale_x = 1.0f; float scale_y = 1.0f; float scale_z = 1.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 = 1; float min_v = 1; float max_u = 0; float max_v = 0; // 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(GetID(), mesh_comp); } void HydraTestCubeActor::_CreateMaterial() { HydraEngine *engine = GetEngine(); std::string filename = std::string(texture_base) + std::string("/DesignArea/DesignArea_Albedo.png"); HydraID tex_id = engine->TextureBufferManager()->LoadTexture(filename); HydraMaterialBuffer material = {}; material.diffuse_texture_id = tex_id; material.diffuse_colour = glm::vec4(1, 1, 1, 1); material.metalic_rough = glm::vec4(0, 0.5, 0.3, 1); HydraID mat_id = engine->MaterialBufferManager()->CreateMaterial(material); HydraMaterialComponent mat_comp = {}; mat_comp.material_id = mat_id; engine->ECS()->AddComponent(GetID(), mat_comp); } void HydraTestCubeActor::_CreatePhysics() { // HydraECSPhysicsComponent physics_component; // physics_component.physics_state = Hydra_State::Waiting; // physics_component.physics_definition.actor_id = GetID(); // physics_component.physics_definition.physics_type = HydraPhyicsType::Static; // physics_component.physics_definition.physics_shape = HydraPhysicsShape::HydraBoxShape; // physics_component.physics_definition.mass = 100000.0f; // physics_component.physics_definition.extent_x = 1000.0f; // physics_component.physics_definition.extent_y = 0.5f; // physics_component.physics_definition.extent_z = 1000.0f; // physics_component.physics_definition.dynamic_friction = 0.5f; // physics_component.physics_definition.restitution = 0.5f; // HydraECS* ecs = GetEngine()->ECS(); // ecs->AddComponent(GetID(), physics_component); } void HydraTestCubeActor::_CreateRenderableComponent() { HydraRenderableComponent render_comp; HydraECS *ecs = GetEngine()->ECS(); render_comp.renderable_types.set((uint32_t)HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR, true); ecs->AddComponent(GetID(), render_comp); }