diff options
| author | quou <quou@disroot.org> | 2025-01-14 23:40:12 +1100 | 
|---|---|---|
| committer | quou <quou@disroot.org> | 2025-01-14 23:40:12 +1100 | 
| commit | bec63db9dd8ae5a244271d3c772773e26275c4ae (patch) | |
| tree | faea814d6d7023d7511114d4b8d8877343843b15 | |
| parent | 2b1af353bfead225e7afc10c5b6d3f6ecd44068b (diff) | |
editor bindings for material roughness and ao
| -rw-r--r-- | editor.cpp | 77 | 
1 files changed, 56 insertions, 21 deletions
| @@ -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; |