#include "stdafx.h" #include "Scene.h" #include "ryml/ryml.hpp" #include "ryml/ryml_std.hpp" namespace fpr { Scene::Scene(const char* file_name) { std::vector<char> yaml_bytes = ReadFile(file_name); std::string yaml(yaml_bytes.begin(), yaml_bytes.end()); ryml::Tree tree = ryml::parse(ryml::to_csubstr(yaml)); ryml::NodeRef model_data = tree["Models"]; for(auto child : tree["Models"].children()) { std::string file; child["File"] >> file; std::string model_file_name(child["File"].val().str, child["File"].val().len); glm::vec3 model_pos; glm::quat model_rot; glm::vec3 model_scale; child["Position"]["X"] >> model_pos.x ; child["Position"]["Y"] >> model_pos.y ; child["Position"]["Z"] >> model_pos.z ; child["Rotation"]["W"] >> model_rot.w; child["Rotation"]["X"] >> model_rot.x; child["Rotation"]["Y"] >> model_rot.y; child["Rotation"]["Z"] >> model_rot.z; child["Scale"]["X"] >> model_scale.x; child["Scale"]["Y"] >> model_scale.y; child["Scale"]["Z"] >> model_scale.z; glm::mat4 model_matrix(1.0f); model_matrix = glm::translate(model_matrix, model_pos); model_matrix *= glm::toMat4(model_rot); model_matrix = glm::scale(model_matrix, model_scale); m_models.emplace_back(std::make_shared<Model>(file.c_str(), model_matrix)); } } void Scene::AddModel(std::shared_ptr<Model>& new_model) { m_models.emplace_back(std::move(new_model)); } void Scene::AddModels(std::vector<std::shared_ptr<Model>>& new_models) { m_models.insert(m_models.end(), new_models.begin(), new_models.end()); } void fpr::Scene::AddLight(PointLight new_light) { m_lights.emplace_back(new_light); } void fpr::Scene::AddLights(std::vector<PointLight>& new_lights) { m_lights.insert(m_lights.end(), new_lights.begin(), new_lights.end()); } const std::vector<std::shared_ptr<Model>>& Scene::GetModels() const FPR_NOEXCEPT { return m_models; } const std::vector<PointLight>& Scene::GetLights() const FPR_NOEXCEPT { return m_lights; } } // namespace fpr