summaryrefslogtreecommitdiff
path: root/editor.cpp
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2025-01-14 21:46:40 +1100
committerquou <quou@disroot.org>2025-01-14 21:46:40 +1100
commitbb819ec130d2170d39a11fc898a5c88eeba924d0 (patch)
treef9530e0b4ed83021c2faece8a75b64f1359250a7 /editor.cpp
parent729b5a2887912b440b764f967be3949838b78605 (diff)
editing the metalness of materials
Diffstat (limited to 'editor.cpp')
-rw-r--r--editor.cpp40
1 files changed, 38 insertions, 2 deletions
diff --git a/editor.cpp b/editor.cpp
index b4555f3..05362e5 100644
--- a/editor.cpp
+++ b/editor.cpp
@@ -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) {