Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion Tetragrama/src/Components/InspectorViewUIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,44 @@ namespace Tetragrama::Components {

if (m_scene_entity->HasComponent<MaterialComponent>()) {

if (ImGui::TreeNodeEx(reinterpret_cast<void*>(typeid(MaterialComponent).hash_code()), ImGuiTreeNodeFlags_DefaultOpen, "%s", "Material")) {
if (ImGui::TreeNodeEx(reinterpret_cast<void*>(typeid(MaterialComponent).hash_code()), ImGuiTreeNodeFlags_DefaultOpen, "%s", "Materials")) {
auto& component = m_scene_entity->GetComponent<MaterialComponent>();
auto material = component.GetMaterial();
auto material_shader_type = material->GetShaderBuiltInType();

const char* built_in_shader_type[] = {"Basic", "Standard"};

auto material_name = fmt::format("{0} Material", built_in_shader_type[(int) material_shader_type]);
ImGui::Dummy(ImVec2(0, 3));
Helpers::DrawInputTextControl("Name", material_name, nullptr, true);

if (material_shader_type == ZEngine::Rendering::Shaders::ShaderBuiltInType::STANDARD) {
auto standard_material = reinterpret_cast<ZEngine::Rendering::Materials::StandardMaterial*>(material.get());

ImGui::Dummy(ImVec2(0, 0.5f));

float tile_factor = standard_material->GetTileFactor();
Helpers::DrawDragFloatControl(
"Tile Factor", tile_factor, 0.2f, 0.0f, 0.0f, "%.2f", [standard_material](float value) { standard_material->SetTileFactor(value); });
ImGui::Dummy(ImVec2(0, 0.5f));

float shininess = standard_material->GetShininess();
Helpers::DrawDragFloatControl(
"Shininess", shininess, 0.2f, 0.0f, 0.0f, "%.2f", [standard_material](float value) { standard_material->SetShininess(value); });
ImGui::Dummy(ImVec2(0, 0.5f));

auto tint_color = standard_material->GetTintColor();
auto diffuse_texture = standard_material->GetDiffuseMap();
Helpers::DrawTextureColorControl("Diffuse Map", reinterpret_cast<ImTextureID>(diffuse_texture->GetIdentifier()), tint_color, true, nullptr,
[standard_material](auto& value) { standard_material->SetTintColor(value); });
ImGui::Dummy(ImVec2(0, 0.5f));

auto specular_texture = standard_material->GetSpecularMap();
auto specular_tint_color = ZEngine::Maths::Vector4{1, 1, 1, 1};
Helpers::DrawTextureColorControl("Specular Map", reinterpret_cast<ImTextureID>(specular_texture->GetIdentifier()), specular_tint_color);
ImGui::Dummy(ImVec2(0, 0.5f));
}

ImGui::TreePop();
}
ImGui::Dummy(ImVec2(0, 5));
Expand Down
86 changes: 74 additions & 12 deletions Tetragrama/src/Helpers/UIComponentDrawerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Tetragrama::Helpers {

void DrawVec4Control(
std::string_view label, ZEngine::Maths::Vector4& values, const std::function<void(ZEngine::Maths::Vector4&)>& callback, float default_value, float column_width) {
ImGui::PushID(label.data());
ImGui::PushID(label.data(), (label.data() + label.size()));

ImGui::Columns(2);

Expand Down Expand Up @@ -108,7 +108,7 @@ namespace Tetragrama::Helpers {

void DrawVec3Control(
std::string_view label, ZEngine::Maths::Vector3& values, const std::function<void(ZEngine::Maths::Vector3&)>& callback, float default_value, float column_width) {
ImGui::PushID(label.data());
ImGui::PushID(label.data(), (label.data() + label.size()));

ImGui::Columns(2);

Expand Down Expand Up @@ -192,7 +192,7 @@ namespace Tetragrama::Helpers {

void DrawVec2Control(
std::string_view label, ZEngine::Maths::Vector2& values, const std::function<void(ZEngine::Maths::Vector2&)>& callback, float default_value, float column_width) {
ImGui::PushID(label.data());
ImGui::PushID(label.data(), (label.data() + label.size()));

ImGui::Columns(2);

Expand Down Expand Up @@ -252,7 +252,7 @@ namespace Tetragrama::Helpers {


void DrawInputTextControl(std::string_view label, std::string_view content, const std::function<void(std::string_view)>& callback, bool read_only_mode, float column_width) {
ImGui::PushID(label.data());
ImGui::PushID(label.data(), (label.data() + label.size()));
ImGui::Columns(2);

ImGui::SetColumnWidth(0, column_width);
Expand All @@ -262,9 +262,6 @@ namespace Tetragrama::Helpers {
ImGui::PushMultiItemsWidths(1, ImGui::CalcItemWidth() + 60.f);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{0.5f, 0});

float line_height = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f;
ImVec2 input_control_size = {line_height + 3.0f, line_height};

char buffer[1024];
memset(buffer, 0, sizeof(buffer));
auto raw_entity_name = content.data();
Expand All @@ -288,7 +285,7 @@ namespace Tetragrama::Helpers {

void DrawDragFloatControl(std::string_view label, float value, float increment_speed, float min_value, float max_value, std::string_view fmt,
const std::function<void(float)>& callback, float column_width) {
ImGui::PushID(label.data());
ImGui::PushID(label.data(), (label.data() + label.size()));
ImGui::Columns(2);

ImGui::SetColumnWidth(0, column_width);
Expand All @@ -298,9 +295,6 @@ namespace Tetragrama::Helpers {
ImGui::PushMultiItemsWidths(1, ImGui::CalcItemWidth() + 60.f);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{0.5f, 0});

float line_height = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f;
ImVec2 input_control_size = {line_height + 3.0f, line_height};

if (ImGui::DragFloat("##DragFloat", &value, increment_speed, min_value, max_value, fmt.data())) {
if (callback) {
callback(value);
Expand All @@ -314,7 +308,7 @@ namespace Tetragrama::Helpers {

void DrawCenteredButtonControl(std::string_view label, const std::function<void(void)>& callback) {

ImGui::PushID(label.data());
ImGui::PushID(label.data(), (label.data() + label.size()));

ImGui::BeginTable("##table", 3);

Expand All @@ -335,4 +329,72 @@ namespace Tetragrama::Helpers {
ImGui::EndTable();
ImGui::PopID();
}

void DrawColorEdit4Control(
std::string_view label, ZEngine::Maths::Vector4& values, const std::function<void(ZEngine::Maths::Vector4&)>& callback, float default_value, float column_width) {
ImGui::PushID(label.data(), (label.data() + label.size()));

ImGui::Columns(2);

ImGui::SetColumnWidth(0, column_width);
ImGui::Text(label.data());
ImGui::NextColumn();

ImGui::PushMultiItemsWidths(1, ImGui::CalcItemWidth() + 60.f);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{0.5f, 0});

if (ImGui::ColorEdit4("##TintColor", ZEngine::Maths::value_ptr(values))) {
if (callback) {
callback(values);
}
}

ImGui::PopItemWidth();
ImGui::PopStyleVar();
ImGui::Columns(1);
ImGui::PopID();
}

void DrawTextureColorControl(std::string_view label, ImTextureID texture_id, ZEngine::Maths::Vector4& tint_color, bool enable_zoom,
const std::function<void(void)>& image_click_callback, const std::function<void(ZEngine::Maths::Vector4&)>& tint_color_change_callback, float column_width) {
ImGui::PushID(label.data(), (label.data() + label.size()));
ImGui::Columns(2);

ImGui::SetColumnWidth(0, column_width);
ImGui::Text(label.data());
ImGui::NextColumn();

ImGui::PushMultiItemsWidths(1, ImGui::CalcItemWidth() + 60.f);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{0.5f, 0});

float line_height = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f;
ImVec2 button_size = {line_height + 3.0f, line_height};

if (ImGui::ImageButton(texture_id, button_size, ImVec2(0, 0), ImVec2(1, 1), 1, ImVec4(0, 0, 0, 0), ImVec4{tint_color.x, tint_color.y, tint_color.z, tint_color.w})) {
if (image_click_callback) {
image_click_callback();
}
}
if (enable_zoom) {
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Image(texture_id, ImVec2(200, 200), {0, 0}, {1, 1}, ImVec4{tint_color.x, tint_color.y, tint_color.z, tint_color.w});
ImGui::EndTooltip();
}
}
ImGui::PopItemWidth();

ImGui::SameLine();
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(1, 4));
if (ImGui::ColorEdit4("##TintColor", ZEngine::Maths::value_ptr(tint_color))) {
if (tint_color_change_callback) {
tint_color_change_callback(tint_color);
}
}
ImGui::PopItemWidth();

ImGui::PopStyleVar(2);
ImGui::Columns(1);
ImGui::PopID();
}
} // namespace Tetragrama::Helpers
7 changes: 7 additions & 0 deletions Tetragrama/src/Helpers/UIComponentDrawerHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ namespace Tetragrama::Helpers {
const std::function<void(float)>& callback = nullptr, float column_width = 100.0f);

void DrawCenteredButtonControl(std::string_view label, const std::function<void(void)>& callback = nullptr);

void DrawColorEdit4Control(std::string_view label, ZEngine::Maths::Vector4& values, const std::function<void(ZEngine::Maths::Vector4&)>& callback = nullptr,
float default_value = 0.0f, float column_width = 100.0f);

void DrawTextureColorControl(std::string_view label, ImTextureID texture_id, ZEngine::Maths::Vector4& texture_tint_color, bool enable_zoom = true,
const std::function<void(void)>& image_click_callback = nullptr, const std::function<void(ZEngine::Maths::Vector4&)>& tint_color_change_callback = nullptr,
float column_width = 100.0f);
} // namespace Tetragrama::Helpers
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ namespace ZEngine::Rendering::Materials {
void SetTexture(Textures::Texture* const texture) override;
void SetTexture(const Ref<Textures::Texture>& texture) override;

float GetTileFactor() const;
float GetShininess() const;
const Maths::Vector4& GetTintColor() const;

Ref<Textures::Texture> GetSpecularMap() const;
Ref<Textures::Texture> GetDiffuseMap() const;

private:
float m_shininess;
float m_tile_factor;
Expand Down
12 changes: 12 additions & 0 deletions ZEngine/include/ZEngine/Rendering/Textures/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ namespace ZEngine::Rendering::Textures {
return m_texture_id;
}

unsigned int GetWidth() const {
return m_width;
}

unsigned int GetHeight() const {
return m_height;
}

std::string_view GetFilePath() {
return m_path;
}

protected:
std::string m_path;
GLuint m_texture_id{0};
Expand Down
20 changes: 20 additions & 0 deletions ZEngine/src/StandardMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ namespace ZEngine::Rendering::Materials {
SetDiffuseMap(texture);
}

float StandardMaterial::GetTileFactor() const {
return m_tile_factor;
}

float StandardMaterial::GetShininess() const {
return m_shininess;
}

const Maths::Vector4& StandardMaterial::GetTintColor() const {
return m_tint_color;
}

Ref<Textures::Texture> StandardMaterial::GetSpecularMap() const {
return m_specular_map;
}

Ref<Textures::Texture> StandardMaterial::GetDiffuseMap() const {
return m_texture;
}

void StandardMaterial::SetTexture(Textures::Texture* const texture) {
SetDiffuseMap(texture);
}
Expand Down