138 lines
3.8 KiB
C++
Executable file
138 lines
3.8 KiB
C++
Executable file
#include "materialeditor.hpp"
|
|
|
|
#include <imgui.h>
|
|
#include <imgui_stdlib.h>
|
|
#include <imgui_internal.h>
|
|
|
|
#include "engine.hpp"
|
|
|
|
bool MaterialEditor::has_menubar() const {
|
|
return true;
|
|
}
|
|
|
|
std::string MaterialEditor::get_title() const {
|
|
return path.empty() ? "New Material" : get_filename(path);
|
|
}
|
|
|
|
Scene* MaterialEditor::get_scene() const {
|
|
return scene;
|
|
}
|
|
|
|
void MaterialEditor::setup_windows(ImGuiID dockspace) {
|
|
ImGuiID dock_main_id = dockspace;
|
|
|
|
ImGuiID dock_id_left, dock_id_right;
|
|
ImGui::DockBuilderSplitNode(dock_main_id, ImGuiDir_Left, 0.40f, &dock_id_left, &dock_id_right);
|
|
|
|
ImGui::DockBuilderDockWindow(get_window_name("Viewport").c_str(), dock_id_left);
|
|
ImGui::DockBuilderDockWindow(get_window_name("Node Editor").c_str(), dock_id_right);
|
|
}
|
|
|
|
void MaterialEditor::setup_material() {
|
|
renderable->materials.push_back(material);
|
|
}
|
|
|
|
void recompile(Material* material) {
|
|
material->static_pipeline = nullptr;
|
|
material->skinned_pipeline = nullptr;
|
|
}
|
|
|
|
void MaterialEditor::draw(CommonEditor* editor) {
|
|
if(!material)
|
|
return;
|
|
|
|
if (ImGui::BeginMenuBar()) {
|
|
if (ImGui::BeginMenu("File")) {
|
|
if(ImGui::MenuItem("Save", "CTRL+S")) {
|
|
if (path.empty()) {
|
|
engine->get_imgui().save_dialog([this](std::string path) {
|
|
this->path = path;
|
|
|
|
save_material(*material, path);
|
|
});
|
|
} else {
|
|
save_material(*material, prism::get_file_path(path));
|
|
}
|
|
}
|
|
|
|
if (ImGui::MenuItem("Save as...", "CTRL+S")) {
|
|
engine->get_imgui().save_dialog([this](std::string path) {
|
|
this->path = path;
|
|
|
|
save_material(*material, path);
|
|
});
|
|
}
|
|
|
|
ImGui::Separator();
|
|
|
|
if(ImGui::MenuItem("Close"))
|
|
wants_to_close = true;
|
|
|
|
ImGui::EndMenu();
|
|
}
|
|
|
|
if(ImGui::MenuItem("Compile"))
|
|
recompile(*material);
|
|
|
|
ImGui::EndMenuBar();
|
|
}
|
|
|
|
auto viewport_scene = engine->get_scene();
|
|
|
|
if(viewport_scene != nullptr) {
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
|
if(begin("Viewport"))
|
|
editor->drawViewport(viewport_scene);
|
|
|
|
ImGui::End();
|
|
|
|
ImGui::PopStyleVar();
|
|
}
|
|
|
|
if(begin("Node Editor")) {
|
|
const auto draw_list = ImGui::GetWindowDrawList();
|
|
const auto window_pos = ImGui::GetCursorScreenPos();
|
|
|
|
bool changed = false;
|
|
|
|
auto& property = material->colorProperty;
|
|
|
|
ImGui::PushID(property.name.c_str());
|
|
|
|
if(ImGui::BeginCombo("Type", "test")) {
|
|
if(ImGui::Selectable("Vector3"))
|
|
property.type = DataType::Vector3;
|
|
|
|
if(ImGui::Selectable("Texture"))
|
|
property.type = DataType::AssetTexture;
|
|
|
|
if(ImGui::Selectable("Float"))
|
|
property.type = DataType::Float;
|
|
|
|
ImGui::EndCombo();
|
|
}
|
|
|
|
ImGui::TextDisabled("%s", property.name.c_str());
|
|
|
|
switch(property.type) {
|
|
case DataType::Vector3:
|
|
changed |= ImGui::ColorEdit3("", property.value.ptr());
|
|
break;
|
|
case DataType::Float:
|
|
changed |= ImGui::DragFloat("", &property.float_value);
|
|
break;
|
|
case DataType::AssetTexture:
|
|
changed |= editor->edit_asset("", property.value_tex);
|
|
break;
|
|
}
|
|
|
|
ImGui::PopID();
|
|
|
|
if(changed)
|
|
recompile(*material);
|
|
|
|
}
|
|
|
|
|
|
ImGui::End();
|
|
}
|