#include "controller.h" #include "components/name.h" #include "components/transform.h" #include "core/camera.h" #include "core/light.h" #include "spdlog/spdlog.h" #include "window/window.h" using namespace entt::literals; Controller::Controller(std::string_view path) { spdlog::info("Open {}", path); std::filesystem::path document_path(path); entt::hashed_string document_hash(document_path.string().c_str()); entt::resource gltf_document = gltf_cache.load(document_hash, document_path).first->second; gltf_document->spawn_default_scene(registry(), gltf_node_cache); // Convert meshes auto mesh_view = registry().view>(); for (auto [entity, mesh] : mesh_view.each()) { registry().emplace(entity, GpuMesh(mesh)); // Remove Mesh resource as it is no longer needed. registry().erase>(entity); } // Convert materials auto material_view = registry().view>(); for (auto [entity, material] : material_view.each()) { registry().emplace(entity, GpuMaterial(material)); // Remove Material resource as it is no longer needed. registry().erase>(entity); } // Spawn default lights auto directional_light = registry().create(); registry().emplace(directional_light, "Directional Light"); registry().emplace( directional_light, Transform{.orientation = glm::toQuat( glm::lookAt({}, DirectionalLight::DEFAULT_DIRECTION, Camera::UP_VECTOR))}); registry().emplace(directional_light, GlobalTransform{}); registry().emplace( directional_light, DirectionalLight{.illuminance = DirectionalLight::DEFAULT_ILLUMINANCE}); auto point_light = registry().create(); registry().emplace(point_light, "Point Light"); registry().emplace(point_light, Transform{.translation = PointLight::DEFAULT_POSITION}); registry().emplace(point_light, GlobalTransform{}); registry().emplace(point_light, PointLight{.intensity = PointLight::DEFAULT_INTENSITY}); } void Controller::update() { Camera::keyboard_movement(registry()); if (registry().ctx().get().catched) { Camera::mouse_orientation(registry()); } }