diff options
author | quou <quou@disroot.org> | 2025-01-14 21:46:40 +1100 |
---|---|---|
committer | quou <quou@disroot.org> | 2025-01-14 21:46:40 +1100 |
commit | bb819ec130d2170d39a11fc898a5c88eeba924d0 (patch) | |
tree | f9530e0b4ed83021c2faece8a75b64f1359250a7 | |
parent | 729b5a2887912b440b764f967be3949838b78605 (diff) |
editing the metalness of materials
-rw-r--r-- | editor.cpp | 40 |
1 files changed, 38 insertions, 2 deletions
@@ -8,6 +8,7 @@ static struct { UI::Toolbar* toolbar; UI::Button* mat_btn; UI::Modal* mat_win; + UI::Slider* metalness_input; Model_Instance* selected_inst; int selected_mesh; } editor; @@ -26,8 +27,31 @@ static int mat_btn_handler(UI::Element* e, const UI::Message& m) { editor.ui->root, "Material Editor" ); + auto container = editor.ui->create_element<UI::Container>( + editor.mat_win->contents + ); editor.mat_win->handler = mat_win_handler; editor.mat_btn->disable(); + editor.metalness_input = editor.ui->create_element<UI::Slider>( + container, + 0.0f, + 1.0f + ); + if (!editor.selected_inst) + editor.metalness_input->disable(); + editor.metalness_input->input->handler = []( + UI::Element* e, + const UI::Message& m + ) { + if (editor.selected_inst) { + UI::Float_Input* in = (UI::Float_Input*)e; + Mesh* meshes = editor.selected_inst->m->get_meshes(); + Mesh& mesh = meshes[editor.selected_mesh]; + Material* mat = mesh.material; + mat->metalness = in->val; + } + return 0; + }; } return 0; } @@ -48,8 +72,20 @@ void deinit_editor() { } void editor_on_select(Model_Instance* instance, int mesh) { - editor.selected_inst = instance; - editor.selected_mesh = mesh; + if (!editor.ui->hovered) { + editor.selected_inst = instance; + editor.selected_mesh = mesh; + if (editor.mat_win) { + if (instance) { + Mesh* meshes = instance->m->get_meshes(); + Mesh& msh = meshes[mesh]; + Material* mat = msh.material; + editor.metalness_input->enable(); + editor.metalness_input->input->set_val(mat->metalness); + } else + editor.metalness_input->disable(); + } + } } void editor_draw(Line_Renderer& lr) { |