Commit 62514c17 authored by Johannes Braun's avatar Johannes Braun
Browse files

Cleaned up scene gui0

parent 9af471af
......@@ -37,11 +37,22 @@ namespace glare
m_flag_delete = true;
}
uint64_t id()
{
if (m_id == 0)
{
static uint64_t m_current_id = 1;
m_id = m_current_id++;
}
return m_id;
}
protected:
std::weak_ptr<GraphNode> m_owner;
private:
bool m_flag_delete = false;
uint64_t m_id = 0;
};
}
}
......
......@@ -12,6 +12,83 @@ namespace glare
}
void GraphNode::gui()
{
ImGui::Begin("Scene");
auto cached_indent = ImGui::GetStyle().IndentSpacing;
ImGui::GetStyle().IndentSpacing = 10;
ImGui::PushID(("Node::" + m_name).c_str());
if (ImGui::TreeNode(m_name.c_str()))
{
ImGui::PushItemWidth(200);
if (ImGui::TreeNode("Transform"))
{
bool changed = false;
// Pos
glm::vec3 position = m_transform.position;
changed |= ImGui::DragFloat3("Position", reinterpret_cast<float*>(&position), 0.01f);
m_transform.position = position;
// Rotation
glm::vec3 rotation = glm::degrees(glm::eulerAngles(m_transform.rotation));
changed |= ImGui::DragFloat3("Rotation", reinterpret_cast<float*>(&rotation), 0.1f);
m_transform.rotation = glm::quat(glm::radians(rotation));
// Scale
glm::vec3 scale = m_transform.scale;
changed |= ImGui::DragFloat3("Scale", reinterpret_cast<float*>(&scale), 0.01f);
m_transform.scale = scale;
if (changed)
{
messaging::Handler::getInstance().submit(tags::graph_transform, m_transform);
onAbsoluteTransformChanged();
}
ImGui::TreePop();
}
if (!m_components.empty() && ImGui::TreeNode("Components"))
{
for (auto &&component_list : m_components)
{
for (auto&& component_iterator = component_list.second.begin(); component_iterator != component_list.second.end();)
{
auto&& component = *component_iterator;
if (component) component->gui();
//No else, because it might have been deleted in gui() or update();
if (!component || component->m_flag_delete)
{
component_iterator = component_list.second.erase(component_iterator);
}
else
{
++component_iterator;
}
}
}
ImGui::TreePop();
}
if (!m_children.empty() && ImGui::TreeNode("Children"))
{
for (auto && child : m_children)
{
child->gui();
}
ImGui::TreePop();
}
ImGui::PopItemWidth();
ImGui::TreePop();
}
ImGui::PopID();
ImGui::GetStyle().IndentSpacing = cached_indent;
ImGui::End();
}
void GraphNode::update(const glm::mat4 &parent_transform)
{
const glm::mat4 absolute_transform = parent_transform * m_transform.matrix();
......@@ -23,13 +100,11 @@ namespace glare
{
auto&& component = *component_iterator;
if (component) component->gui();
//If not deleted in gui()
if (component) component->update();
//No else, because it might have been deleted in gui() or update();
if (!component || component->m_flag_delete)
if (!component || component->m_flag_delete)
{
component_iterator = component_list.second.erase(component_iterator);
}
......@@ -77,7 +152,7 @@ namespace glare
Transaction<math::Transform> GraphNode::transform()
{
const math::Transform old = m_transform;
return {
return{
m_transform, [this, old](auto &&obj) {
if (obj != old) {
messaging::Handler::getInstance().submit(tags::graph_transform, obj);
......
......@@ -36,6 +36,7 @@ namespace glare
public:
GraphNode(std::string name);
void gui();
void update(const glm::mat4 &parent_transform = glm::mat4(1));
void draw(DrawMode mode = DrawMode::eShaded);
......
......@@ -27,9 +27,8 @@ namespace glare
}
void Camera::gui()
{
ImGui::Begin("Cameras");
if (ImGui::CollapsingHeader(getOwner()->name().c_str()))
{
if (ImGui::TreeNode(("<Camera id=" + std::to_string(id()) + "> " + getOwner()->name()).c_str()))
{
ImGui::PushID(getOwner()->name().c_str());
if (ImGui::DragFloat("Focus Distance", &m_focus_distance, 0.05f, 0.05f, 10000.f))
......@@ -43,8 +42,8 @@ namespace glare
messaging::Handler::getInstance().submit(tags::camera, 1);
}
ImGui::PopID();
ImGui::TreePop();
}
ImGui::End();
}
float Camera::getFocusDistance() const
......
......@@ -43,12 +43,13 @@ namespace glare
void LightComponent::gui()
{
ImGui::Begin("Lights");
if (ImGui::CollapsingHeader(getOwner()->name().c_str()))
if (ImGui::TreeNode(("<LightComponent id=" + std::to_string(id()) + "> " + getOwner()->name()).c_str()))
{
bool changed = false;
auto old_color = m_color;
ImGui::PushID(getOwner()->name().c_str());
ImGui::ColorButton(*reinterpret_cast<ImVec4*>(&m_color));
ImGui::SameLine();
changed |= ImGui::DragFloat3("Color", reinterpret_cast<float*>(&m_color), 0.01f, 0, 10000);
ImGui::PopID();
......@@ -58,10 +59,9 @@ namespace glare
Log_Info << m_color.r << ", " << m_color.g << ", " << m_color.b;
messaging::Handler::getInstance().submit(tags::light, LightUpdate{ m_id, this });
}
}
ImGui::End();
ImGui::TreePop();
}
}
void LightComponent::draw(DrawMode mode)
......
......@@ -30,26 +30,34 @@ namespace glare
void Material::gui()
{
ImGui::Begin("Materials");
if (ImGui::CollapsingHeader(m_name.c_str()))
{
ImGui::PushID(m_name.c_str());
if (ImGui::DragFloat3("Diffuse Color", reinterpret_cast<float*>(&color_diffuse), 0.01f, 0, 10000))
messaging::Handler::getInstance().submit(tags::material, 1);
if (ImGui::DragFloat3("Specular Color", reinterpret_cast<float*>(&color_specular), 0.01f, 0, 10000))
messaging::Handler::getInstance().submit(tags::material, 1);
if (ImGui::DragFloat3("Transparent Color", reinterpret_cast<float*>(&color_transparent), 0.01f, 0, 10000))
messaging::Handler::getInstance().submit(tags::material, 1);
if (ImGui::DragFloat3("Ambient Color", reinterpret_cast<float*>(&color_ambient), 0.01f, 0, 10000))
messaging::Handler::getInstance().submit(tags::material, 1);
if (ImGui::DragFloat3("Emissive Color", reinterpret_cast<float*>(&color_emissive), 0.01f, 0, 10000))
messaging::Handler::getInstance().submit(tags::material, 1);
if (ImGui::DragFloat("Specular Exponent", &specular_exponent, 1.f, 1, 100))
messaging::Handler::getInstance().submit(tags::material, 1);
ImGui::PopID();
}
ImGui::End();
//ImGui::Begin("Materials");
ImGui::PushID(m_name.c_str());
bool changed = false;
ImGui::ColorButton(*reinterpret_cast<ImVec4*>(&glm::vec4(color_diffuse, 1)));
ImGui::SameLine();
changed |= ImGui::DragFloat3("Diffuse Color", reinterpret_cast<float*>(&color_diffuse), 0.01f, 0, 10000);
ImGui::ColorButton(*reinterpret_cast<ImVec4*>(&glm::vec4(color_specular, 1)));
ImGui::SameLine();
changed |= ImGui::DragFloat3("Specular Color", reinterpret_cast<float*>(&color_specular), 0.01f, 0, 10000);
ImGui::ColorButton(*reinterpret_cast<ImVec4*>(&glm::vec4(color_transparent, 1)));
ImGui::SameLine();
changed |= ImGui::DragFloat3("Transparent Color", reinterpret_cast<float*>(&color_transparent), 0.01f, 0, 10000);
ImGui::ColorButton(*reinterpret_cast<ImVec4*>(&glm::vec4(color_ambient, 1)));
ImGui::SameLine();
changed |= ImGui::DragFloat3("Ambient Color", reinterpret_cast<float*>(&color_ambient), 0.01f, 0, 10000);
ImGui::ColorButton(*reinterpret_cast<ImVec4*>(&glm::vec4(color_emissive, 1)));
ImGui::SameLine();
changed |= ImGui::DragFloat3("Emissive Color", reinterpret_cast<float*>(&color_emissive), 0.01f, 0, 10000);
if (ImGui::DragFloat("Specular Exponent", &specular_exponent, 1.f, 1, 100) || changed)
messaging::Handler::getInstance().submit(tags::material, 1);
ImGui::PopID();
//ImGui::End();
}
void Material::activate() const
......
......@@ -45,7 +45,12 @@ namespace glare
void MeshRenderer::gui()
{
m_material->gui();
if (ImGui::TreeNode(("<MeshRenderer id=" + std::to_string(m_renderer_id) + "> " + getOwner()->name()).c_str()))
{
ImGui::Title("Material");
m_material->gui();
ImGui::TreePop();
}
}
uint64_t MeshRenderer::id() const
......
......@@ -124,8 +124,11 @@ namespace glare
camera->update();
if(animation_manager)
animation_manager->update();
if(graph_root)
if (graph_root)
{
graph_root->gui();
graph_root->update();
}
}
void quit()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment