summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editor.cpp77
1 files changed, 56 insertions, 21 deletions
diff --git a/editor.cpp b/editor.cpp
index a51c421..8bf0c4a 100644
--- a/editor.cpp
+++ b/editor.cpp
@@ -10,6 +10,8 @@ static struct {
UI::Modal* mat_win;
UI::Label* mat_name;
UI::Slider* metalness_input;
+ UI::Slider* roughness_input;
+ UI::Slider* ao_input;
Model_Instance* selected_inst;
int selected_mesh;
} editor;
@@ -30,9 +32,15 @@ static void setup_mat_edit() {
Material* mat = msh.material;
editor.metalness_input->enable();
editor.metalness_input->input->set_val(mat->metalness);
+ editor.roughness_input->enable();
+ editor.roughness_input->input->set_val(mat->roughness);
+ editor.ao_input->enable();
+ editor.ao_input->input->set_val(mat->ao);
editor.mat_name->set_text(mat->name);
} else {
editor.metalness_input->disable();
+ editor.roughness_input->disable();
+ editor.ao_input->disable();
editor.mat_name->set_text("<no material>");
}
}
@@ -44,33 +52,60 @@ 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
- );
+ int rows[] = { 200, 250, 0 };
editor.mat_win->handler = mat_win_handler;
editor.mat_btn->disable();
editor.mat_name = editor.ui->create_element<UI::Label>(
- container,
+ editor.mat_win->contents,
""
);
- editor.metalness_input = editor.ui->create_element<UI::Slider>(
- container,
- 0.0f,
- 1.0f
+ auto container = editor.ui->create_element<UI::Table>(
+ editor.mat_win->contents,
+ rows
+ );
+
+#define bind_mat_float(el, name, point) \
+ editor.ui->create_element<UI::Label>( \
+ container, \
+ name \
+ ); \
+ el = editor.ui->create_element<UI::Slider>( \
+ container, \
+ 0.0f, \
+ 1.0f \
+ ); \
+ el->input->handler = []( \
+ UI::Element* e, \
+ const UI::Message& m \
+ ) { \
+ if ( \
+ m.type == UI::Message::Type::input_changed && \
+ 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->point = in->val; \
+ } \
+ return 0; \
+ };
+ bind_mat_float(
+ editor.metalness_input,
+ "Metalness",
+ metalness
+ );
+ bind_mat_float(
+ editor.roughness_input,
+ "Roughness",
+ roughness
+ );
+ bind_mat_float(
+ editor.ao_input,
+ "Ambient Occlusion",
+ ao
);
- 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;
- };
+#undef bind_mat_float
setup_mat_edit();
}
return 0;