diff --git a/Source/Core/VideoCommon/GraphicsModEditor/Controls/MeshControl.cpp b/Source/Core/VideoCommon/GraphicsModEditor/Controls/MeshControl.cpp new file mode 100644 index 0000000000..4a0dec8e2a --- /dev/null +++ b/Source/Core/VideoCommon/GraphicsModEditor/Controls/MeshControl.cpp @@ -0,0 +1,71 @@ +// Copyright 2023 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "VideoCommon/GraphicsModEditor/Controls/MeshControl.h" + +#include + +#include + +#include "Common/StringUtil.h" +#include "VideoCommon/Assets/TextureAsset.h" +#include "VideoCommon/GraphicsModEditor/Controls/AssetDisplay.h" +#include "VideoCommon/GraphicsModEditor/EditorEvents.h" + +namespace GraphicsModEditor::Controls +{ +MeshControl::MeshControl(EditorState& state) : m_state(state) +{ +} +void MeshControl::DrawImGui(const VideoCommon::CustomAssetLibrary::AssetID& asset_id, + VideoCommon::MeshData* mesh_data, const std::filesystem::path& path, + VideoCommon::CustomAsset::TimeType* last_data_write, + AbstractTexture* mesh_preview) +{ + if (ImGui::BeginTable("MeshForm", 2)) + { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Text("ID"); + ImGui::TableNextColumn(); + ImGui::Text("%s", asset_id.c_str()); + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Text("Name"); + ImGui::TableNextColumn(); + ImGui::TextWrapped("%s", PathToString(path.stem()).c_str()); + ImGui::EndTable(); + } + + if (ImGui::CollapsingHeader("Materials", ImGuiTreeNodeFlags_DefaultOpen)) + { + if (ImGui::BeginTable("MeshMaterialsForm", 2)) + { + for (auto& [mesh_material, material_asset_id] : + mesh_data->m_mesh_material_to_material_asset_id) + { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Text("%s", mesh_material.c_str()); + ImGui::TableNextColumn(); + + if (AssetDisplay(mesh_material, &m_state, &material_asset_id, + AssetDataType::RasterMaterial)) + { + *last_data_write = VideoCommon::CustomAsset::ClockType::now(); + GraphicsModEditor::EditorEvents::AssetReloadEvent::Trigger(material_asset_id); + } + } + ImGui::EndTable(); + } + } + + if (mesh_preview) + { + const auto ratio = mesh_preview->GetWidth() / mesh_preview->GetHeight(); + ImGui::Image(*mesh_preview, ImVec2{ImGui::GetContentRegionAvail().x, + ImGui::GetContentRegionAvail().x * ratio}); + } +} +} // namespace GraphicsModEditor::Controls diff --git a/Source/Core/VideoCommon/GraphicsModEditor/Controls/MeshControl.h b/Source/Core/VideoCommon/GraphicsModEditor/Controls/MeshControl.h new file mode 100644 index 0000000000..f442480362 --- /dev/null +++ b/Source/Core/VideoCommon/GraphicsModEditor/Controls/MeshControl.h @@ -0,0 +1,31 @@ +// Copyright 2023 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include + +#include "VideoCommon/Assets/CustomAsset.h" +#include "VideoCommon/GraphicsModEditor/EditorState.h" + +namespace VideoCommon +{ +class AbstractTexture; +struct MeshData; +} // namespace VideoCommon + +namespace GraphicsModEditor::Controls +{ +class MeshControl +{ +public: + explicit MeshControl(EditorState& state); + void DrawImGui(const VideoCommon::CustomAssetLibrary::AssetID& asset_id, + VideoCommon::MeshData* mesh_data, const std::filesystem::path& path, + VideoCommon::CustomAsset::TimeType* last_data_write, + AbstractTexture* texture_preview); + +private: + EditorState& m_state; +}; +} // namespace GraphicsModEditor::Controls