1212
1313namespace atta ::component {
1414
15- void renderComboImage (std::string attribute, StringId& image) {
16- bool isImage = (image != resource::Material::emptyImage);
15+ bool renderComboImage (std::string attribute, StringId& image) {
16+ bool isImage = (image != StringId ());
17+ bool updated = false ;
1718 std::string imguiId = attribute;
1819 if (isImage) {
1920 std::string selectedName = image.getString ();
@@ -24,17 +25,22 @@ void renderComboImage(std::string attribute, StringId& image) {
2425 if (imageStr == " " )
2526 imageStr = " ##" ;
2627 const bool selected = (rImage == image);
27- if (ImGui::Selectable (imageStr.c_str (), selected))
28+ if (ImGui::Selectable (imageStr.c_str (), selected)) {
2829 image = rImage;
30+ updated = true ;
31+ }
2932 if (selected)
3033 ImGui::SetItemDefaultFocus ();
3134 }
3235 ImGui::EndCombo ();
3336 }
3437 }
3538
36- if (ImGui::Checkbox ((" Is image##IsImage" + imguiId).c_str (), &isImage))
37- image = isImage ? " textures/white.jpg" _sid : resource::Material::emptyImage;
39+ if (ImGui::Checkbox ((" Is image##IsImage" + imguiId).c_str (), &isImage)) {
40+ image = isImage ? " textures/white.png" _sid : StringId ();
41+ updated = true ;
42+ }
43+ return updated;
3844}
3945
4046void materialRenderImGui (void * data, std::string imguiId) {
@@ -132,29 +138,50 @@ void materialRenderImGui(void* data, std::string imguiId) {
132138 // ---------- Edit ----------//
133139 ImGui::Text (" Color" );
134140 if (!m->colorIsImage ()) {
135- ImGui::SliderFloat (" R##ColorR" , &m->color .x , 0 .0f , 1 .0f );
136- ImGui::SliderFloat (" G##ColorG" , &m->color .y , 0 .0f , 1 .0f );
137- ImGui::SliderFloat (" B##ColorB" , &m->color .z , 0 .0f , 1 .0f );
141+ vec3 color = m->getColor ();
142+ bool updated = false ;
143+ if (ImGui::SliderFloat (" R##ColorR" , &color.x , 0 .0f , 1 .0f ))
144+ updated = true ;
145+ if (ImGui::SliderFloat (" G##ColorG" , &color.y , 0 .0f , 1 .0f ))
146+ updated = true ;
147+ if (ImGui::SliderFloat (" B##ColorB" , &color.z , 0 .0f , 1 .0f ))
148+ updated = true ;
149+ if (updated)
150+ m->setColor (color);
138151 }
139- renderComboImage (" Color" , m->colorImage );
152+ StringId colorImage = m->getColorImage ();
153+ if (renderComboImage (" Color" , colorImage))
154+ m->setColorImage (colorImage);
140155
141156 ImGui::Text (" Roughness" );
142157 if (!m->roughnessIsImage ()) {
143- ImGui::SliderFloat (" ##Roughness" , &m->roughness , 0 .0f , 1 .0f );
158+ float roughness = m->getRoughness ();
159+ if (ImGui::SliderFloat (" ##Roughness" , &roughness, 0 .0f , 1 .0f ))
160+ m->setRoughness (roughness);
144161 }
145- renderComboImage (" Roughness" , m->roughnessImage );
162+ StringId roughnessImage = m->getRoughnessImage ();
163+ if (renderComboImage (" Roughness" , roughnessImage))
164+ m->setRoughnessImage (roughnessImage);
146165
147166 ImGui::Text (" Metallic" );
148167 if (!m->metallicIsImage ()) {
149- ImGui::SliderFloat (" ##Metallic" , &m->metallic , 0 .0f , 1 .0f );
168+ float metallic = m->getMetallic ();
169+ if (ImGui::SliderFloat (" ##Metallic" , &metallic, 0 .0f , 1 .0f ))
170+ m->setMetallic (metallic);
150171 }
151- renderComboImage (" Metallic" , m->metallicImage );
172+ StringId metallicImage = m->getMetallicImage ();
173+ if (renderComboImage (" Metallic" , metallicImage))
174+ m->setMetallicImage (metallicImage);
152175
153176 ImGui::Text (" AO" );
154177 if (!m->aoIsImage ()) {
155- ImGui::SliderFloat (" ##AO" , &m->ao , 0 .0f , 1 .0f );
178+ float ao = m->getAo ();
179+ if (ImGui::SliderFloat (" ##AO" , &ao, 0 .0f , 1 .0f ))
180+ m->setAo (ao);
156181 }
157- renderComboImage (" AO" , m->aoImage );
182+ StringId aoImage = m->getAoImage ();
183+ if (renderComboImage (" AO" , aoImage))
184+ m->setAoImage (aoImage);
158185}
159186
160187template <>
0 commit comments