add Console panel; fix the problem when cs set Rotation the direction not update; fix some little bug; add simple texture material Edit system;some treaks
This commit is contained in:
@ -19,6 +19,7 @@
|
||||
#include "Prism/Physics/Physics3D.h"
|
||||
#include "Prism/Renderer/Renderer2D.h"
|
||||
#include "Prism/Script/ScriptEngine.h"
|
||||
#include "Prism/Script/ScriptWrappers.h"
|
||||
|
||||
namespace Prism
|
||||
{
|
||||
@ -56,6 +57,12 @@ namespace Prism
|
||||
AssetEditorPanel::RegisterDefaultEditors();
|
||||
FileSystem::StartWatching();
|
||||
|
||||
m_ConsolePanel = CreateScope<ConsolePanel>();
|
||||
Script::SetLogCallback([this](const std::string& message)
|
||||
{
|
||||
if (m_ConsolePanel)
|
||||
m_ConsolePanel->AddMessage(message, ImVec4(1,1,1,1));
|
||||
});
|
||||
}
|
||||
|
||||
void EditorLayer::OnDetach()
|
||||
@ -147,6 +154,18 @@ namespace Prism
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (m_SceneState == SceneState::Play)
|
||||
{
|
||||
if (Input::GetCursorMode() != CursorMode::Normal)
|
||||
{
|
||||
if (Input::IsKeyPressed(KeyCode::LEFT_CONTROL) && Input::IsKeyPressed(KeyCode::LEFT_ALT) && Input::IsKeyPressed(KeyCode::GRAVE_ACCENT))
|
||||
{
|
||||
Input::SetCursorMode(CursorMode::Normal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorLayer::OnImGuiRender()
|
||||
@ -278,8 +297,9 @@ namespace Prism
|
||||
Entity selectedEntity = m_SelectionContext.front().Entity;
|
||||
if (selectedEntity.HasComponent<MeshComponent>())
|
||||
{
|
||||
Ref<Mesh> mesh = selectedEntity.GetComponent<MeshComponent>().Mesh;
|
||||
if (mesh)
|
||||
auto& meshComponent = selectedEntity.GetComponent<MeshComponent>();
|
||||
|
||||
if (Ref<Mesh> mesh = meshComponent.Mesh)
|
||||
{
|
||||
auto& materials = mesh->GetMaterials();
|
||||
static uint32_t selectedMaterialIndex = 0;
|
||||
@ -307,27 +327,13 @@ namespace Prism
|
||||
}
|
||||
ImGui::EndChild();
|
||||
}
|
||||
/*
|
||||
for (uint32_t i = 0; i < materials.size(); i++)
|
||||
{
|
||||
const auto& materialInstance = materials[i];
|
||||
|
||||
ImGuiTreeNodeFlags node_flags = (selectedMaterialIndex == i ? ImGuiTreeNodeFlags_Selected : 0) | ImGuiTreeNodeFlags_Leaf;
|
||||
bool opened = ImGui::TreeNodeEx((void*)(&materialInstance), node_flags, "%s", materialInstance->GetName().c_str());
|
||||
if (ImGui::IsItemClicked())
|
||||
{
|
||||
selectedMaterialIndex = i;
|
||||
}
|
||||
if (opened)
|
||||
ImGui::TreePop();
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
if (selectedMaterialIndex < materials.size())
|
||||
{
|
||||
bool shouldUpdate = false;
|
||||
|
||||
auto& materialInstance = materials[selectedMaterialIndex];
|
||||
ImGui::Text("Shader: %s", materialInstance->GetShader()->GetName().c_str());
|
||||
// Textures ------------------------------------------------------------------------------
|
||||
@ -342,6 +348,21 @@ namespace Prism
|
||||
Ref<Texture2D> albedoMap = materialInstance->TryGetResource<Texture2D>("u_AlbedoTexture");
|
||||
|
||||
ImGui::Image(albedoMap ? (ImTextureRef)albedoMap->GetRendererID() : (ImTextureRef)m_CheckerboardTex->GetRendererID(), ImVec2(64, 64));
|
||||
|
||||
if (ImGui::BeginDragDropTarget())
|
||||
{
|
||||
if (const auto data = ImGui::AcceptDragDropPayload("asset_payload"))
|
||||
{
|
||||
AssetHandle assetHandle = *(AssetHandle*)data->Data;
|
||||
if (AssetsManager::IsAssetType(assetHandle, AssetType::Texture))
|
||||
{
|
||||
albedoMap = AssetsManager::GetAsset<Texture2D>(assetHandle);
|
||||
shouldUpdate = true;
|
||||
}
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
@ -354,28 +375,23 @@ namespace Prism
|
||||
ImGui::Image((ImTextureRef)albedoMap->GetRendererID(), ImVec2(384, 384));
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
if (ImGui::IsItemClicked())
|
||||
{
|
||||
if (std::string filename = FileSystem::OpenFileSelector("*.png;*.tga;*.jpg;*.jpeg"); !filename.empty())
|
||||
{
|
||||
albedoMap = Texture2D::Create(filename, true/*m_AlbedoInput.SRGB*/);
|
||||
materialInstance->Set("u_AlbedoTexture", albedoMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginGroup();
|
||||
if (ImGui::Checkbox("Use##AlbedoMap", &useAlbedoMap))
|
||||
materialInstance->Set<float>("u_AlbedoTexToggle", useAlbedoMap ? 1.0f : 0.0f);
|
||||
|
||||
/*if (ImGui::Checkbox("sRGB##AlbedoMap", &m_AlbedoInput.SRGB))
|
||||
{
|
||||
if (m_AlbedoInput.TextureMap)
|
||||
m_AlbedoInput.TextureMap = Texture2D::Create(m_AlbedoInput.TextureMap->GetPath(), m_AlbedoInput.SRGB);
|
||||
}*/
|
||||
materialInstance->Set<float>("u_AlbedoTexToggle", useAlbedoMap ? 1.0f : 0.0f);
|
||||
shouldUpdate = true;
|
||||
}
|
||||
|
||||
|
||||
ImGui::EndGroup();
|
||||
ImGui::SameLine();
|
||||
ImGui::ColorEdit3("Color##Albedo", glm::value_ptr(albedoColor), ImGuiColorEditFlags_NoInputs);
|
||||
if (ImGui::ColorEdit3("Color##Albedo", glm::value_ptr(albedoColor), ImGuiColorEditFlags_NoInputs))
|
||||
{
|
||||
meshComponent.UpdateMaterials(selectedMaterialIndex);
|
||||
shouldUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
@ -388,6 +404,21 @@ namespace Prism
|
||||
Ref<Texture2D> normalMap = materialInstance->TryGetResource<Texture2D>("u_NormalTexture");
|
||||
|
||||
ImGui::Image(normalMap ? (ImTextureRef)normalMap->GetRendererID() : (ImTextureRef)m_CheckerboardTex->GetRendererID(), ImVec2(64, 64));
|
||||
|
||||
if (ImGui::BeginDragDropTarget())
|
||||
{
|
||||
if (const auto data = ImGui::AcceptDragDropPayload("asset_payload"))
|
||||
{
|
||||
AssetHandle assetHandle = *(AssetHandle*)data->Data;
|
||||
if (AssetsManager::IsAssetType(assetHandle, AssetType::Texture))
|
||||
{
|
||||
normalMap = AssetsManager::GetAsset<Texture2D>(assetHandle);
|
||||
shouldUpdate = true;
|
||||
}
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
@ -406,12 +437,16 @@ namespace Prism
|
||||
{
|
||||
normalMap = Texture2D::Create(filename);
|
||||
materialInstance->Set("u_NormalTexture", normalMap);
|
||||
shouldUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Checkbox("Use##NormalMap", &useNormalMap))
|
||||
{
|
||||
materialInstance->Set<float>("u_NormalTexToggle", useNormalMap ? 1.0f : 0.0f);
|
||||
shouldUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
@ -425,6 +460,21 @@ namespace Prism
|
||||
Ref<Texture2D> metalnessMap = materialInstance->TryGetResource<Texture2D>("u_MetalnessTexture");
|
||||
|
||||
ImGui::Image(metalnessMap ? (ImTextureRef)metalnessMap->GetRendererID() : (ImTextureRef)m_CheckerboardTex->GetRendererID(), ImVec2(64, 64));
|
||||
|
||||
if (ImGui::BeginDragDropTarget())
|
||||
{
|
||||
if (const auto data = ImGui::AcceptDragDropPayload("asset_payload"))
|
||||
{
|
||||
AssetHandle assetHandle = *(AssetHandle*)data->Data;
|
||||
if (AssetsManager::IsAssetType(assetHandle, AssetType::Texture))
|
||||
{
|
||||
metalnessMap = AssetsManager::GetAsset<Texture2D>(assetHandle);
|
||||
shouldUpdate = true;
|
||||
}
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
@ -437,20 +487,18 @@ namespace Prism
|
||||
ImGui::Image((ImTextureRef)metalnessMap->GetRendererID(), ImVec2(384, 384));
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
if (ImGui::IsItemClicked())
|
||||
{
|
||||
if (std::string filename = FileSystem::OpenFileSelector("*.png;*.tga;*.jpg;*.jpeg"); !filename.empty())
|
||||
{
|
||||
metalnessMap = Texture2D::Create(filename);
|
||||
materialInstance->Set("u_MetalnessTexture", metalnessMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Checkbox("Use##MetalnessMap", &useMetalnessMap))
|
||||
{
|
||||
materialInstance->Set<float>("u_MetalnessTexToggle", useMetalnessMap ? 1.0f : 0.0f);
|
||||
shouldUpdate = true;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::SliderFloat("Value##MetalnessInput", &metalnessValue, 0.0f, 1.0f);
|
||||
if (ImGui::SliderFloat("Value##MetalnessInput", &metalnessValue, 0.0f, 1.0f))
|
||||
{
|
||||
shouldUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
@ -463,6 +511,20 @@ namespace Prism
|
||||
Ref<Texture2D> roughnessMap = materialInstance->TryGetResource<Texture2D>("u_RoughnessTexture");
|
||||
|
||||
ImGui::Image(roughnessMap ? (ImTextureRef)roughnessMap->GetRendererID() : (ImTextureRef)m_CheckerboardTex->GetRendererID(), ImVec2(64, 64));
|
||||
if (ImGui::BeginDragDropTarget())
|
||||
{
|
||||
if (const auto data = ImGui::AcceptDragDropPayload("asset_payload"))
|
||||
{
|
||||
AssetHandle assetHandle = *(AssetHandle*)data->Data;
|
||||
if (AssetsManager::IsAssetType(assetHandle, AssetType::Texture))
|
||||
{
|
||||
roughnessMap = AssetsManager::GetAsset<Texture2D>(assetHandle);
|
||||
shouldUpdate = true;
|
||||
}
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
@ -475,22 +537,21 @@ namespace Prism
|
||||
ImGui::Image((ImTextureRef)roughnessMap->GetRendererID(), ImVec2(384, 384));
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
if (ImGui::IsItemClicked())
|
||||
{
|
||||
if (std::string filename = FileSystem::OpenFileSelector("*.png;*.tga;*.jpg;*.jpeg"); !filename.empty())
|
||||
{
|
||||
roughnessMap = Texture2D::Create(filename);
|
||||
materialInstance->Set("u_RoughnessTexture", roughnessMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Checkbox("Use##RoughnessMap", &useRoughnessMap))
|
||||
{
|
||||
materialInstance->Set<float>("u_RoughnessTexToggle", useRoughnessMap ? 1.0f : 0.0f);
|
||||
shouldUpdate = true;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::SliderFloat("Value##RoughnessInput", &roughnessValue, 0.0f, 1.0f);
|
||||
if (ImGui::SliderFloat("Value##RoughnessInput", &roughnessValue, 0.0f, 1.0f))
|
||||
{
|
||||
shouldUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (shouldUpdate) meshComponent.UpdateMaterials(selectedMaterialIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -508,7 +569,8 @@ namespace Prism
|
||||
m_ObjectsPanel->OnImGuiRender();
|
||||
|
||||
m_SceneHierarchyPanel->OnImGuiRender();
|
||||
m_EditorCamera.OnImGuiRender();
|
||||
// m_EditorCamera.OnImGuiRender();
|
||||
m_ConsolePanel->OnImGuiRender();
|
||||
|
||||
// Editor Panel ------------------------------------------------------------------------------
|
||||
ImGui::Begin("Environment");
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#ifndef EDITORLAYER_H
|
||||
#define EDITORLAYER_H
|
||||
|
||||
#include "Panels/ConsolePanel.h"
|
||||
#include "Prism.h"
|
||||
#include "Prism/Editor/ContentBrowserPanel.h"
|
||||
#include "Prism/Editor/ObjectsPanel.h"
|
||||
@ -150,6 +151,9 @@ namespace Prism
|
||||
Edit = 0, Play = 1, Pause = 2
|
||||
};
|
||||
SceneState m_SceneState = SceneState::Edit;
|
||||
|
||||
private:
|
||||
Scope<ConsolePanel> m_ConsolePanel;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
66
Editor/Editor/Panels/ConsolePanel.cpp
Normal file
66
Editor/Editor/Panels/ConsolePanel.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
//
|
||||
// Created by Atdunbg on 2026/3/26.
|
||||
//
|
||||
|
||||
#include "ConsolePanel.h"
|
||||
|
||||
namespace Prism
|
||||
{
|
||||
ConsolePanel::ConsolePanel()
|
||||
{
|
||||
// 预留一些空间
|
||||
m_Messages.reserve(1000);
|
||||
}
|
||||
|
||||
void ConsolePanel::OnImGuiRender()
|
||||
{
|
||||
ImGui::Begin("Console");
|
||||
|
||||
// 工具栏
|
||||
if (ImGui::Button("Clear"))
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_Mutex);
|
||||
m_Messages.clear();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Auto-scroll", &m_AutoScroll);
|
||||
ImGui::SameLine();
|
||||
m_Filter.Draw("Filter", 200);
|
||||
|
||||
// 消息列表区域
|
||||
ImGui::BeginChild("ScrollingRegion", ImVec2(0, 0), ImGuiChildFlags_Borders, ImGuiWindowFlags_HorizontalScrollbar);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_Mutex);
|
||||
for (const auto& [msg, color] : m_Messages)
|
||||
{
|
||||
if (m_Filter.PassFilter(msg.c_str()))
|
||||
{
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, color);
|
||||
ImGui::TextUnformatted(msg.c_str());
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_ScrollToBottom)
|
||||
{
|
||||
ImGui::SetScrollHereY(1.0f);
|
||||
m_ScrollToBottom = false;
|
||||
}
|
||||
}
|
||||
ImGui::EndChild();
|
||||
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void ConsolePanel::AddMessage(const std::string& message, ImVec4 color)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_Mutex);
|
||||
m_Messages.emplace_back(message, color);
|
||||
while (m_Messages.size() > 5000)
|
||||
m_Messages.erase(m_Messages.begin());
|
||||
|
||||
if (m_AutoScroll && !m_ScrollToBottom)
|
||||
m_ScrollToBottom = true;
|
||||
}
|
||||
}
|
||||
31
Editor/Editor/Panels/ConsolePanel.h
Normal file
31
Editor/Editor/Panels/ConsolePanel.h
Normal file
@ -0,0 +1,31 @@
|
||||
//
|
||||
// Created by Atdunbg on 2026/3/26.
|
||||
//
|
||||
|
||||
#ifndef PRISM_CONSOLEPANEL_H
|
||||
#define PRISM_CONSOLEPANEL_H
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
namespace Prism
|
||||
{
|
||||
class ConsolePanel
|
||||
{
|
||||
public:
|
||||
ConsolePanel();
|
||||
void OnImGuiRender();
|
||||
|
||||
void AddMessage(const std::string& message, ImVec4 color = ImVec4(1,1,1,1));
|
||||
|
||||
private:
|
||||
std::vector<std::pair<std::string, ImVec4>> m_Messages;
|
||||
ImGuiTextFilter m_Filter;
|
||||
bool m_AutoScroll = true;
|
||||
bool m_ScrollToBottom = false;
|
||||
std::mutex m_Mutex;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //PRISM_CONSOLEPANEL_H
|
||||
@ -1,6 +1,6 @@
|
||||
[Window][DockSpace Demo]
|
||||
Pos=0,0
|
||||
Size=2560,1566
|
||||
Size=1920,1080
|
||||
Collapsed=0
|
||||
|
||||
[Window][Debug##Default]
|
||||
@ -9,32 +9,32 @@ Size=400,400
|
||||
Collapsed=0
|
||||
|
||||
[Window][Scene Hierarchy]
|
||||
Pos=2089,24
|
||||
Size=471,563
|
||||
Pos=1449,24
|
||||
Size=471,385
|
||||
Collapsed=0
|
||||
DockId=0x00000009,0
|
||||
|
||||
[Window][Properties]
|
||||
Pos=2089,589
|
||||
Size=471,977
|
||||
Pos=1449,411
|
||||
Size=471,669
|
||||
Collapsed=0
|
||||
DockId=0x0000000A,0
|
||||
|
||||
[Window][Scene Renderer]
|
||||
Pos=0,843
|
||||
Size=481,723
|
||||
Pos=0,585
|
||||
Size=481,495
|
||||
Collapsed=0
|
||||
DockId=0x00000006,0
|
||||
|
||||
[Window][Materials]
|
||||
Pos=0,24
|
||||
Size=481,817
|
||||
Size=481,559
|
||||
Collapsed=0
|
||||
DockId=0x00000005,0
|
||||
|
||||
[Window][Script Engine Debug]
|
||||
Pos=2089,589
|
||||
Size=471,977
|
||||
Pos=1449,411
|
||||
Size=471,669
|
||||
Collapsed=0
|
||||
DockId=0x0000000A,2
|
||||
|
||||
@ -52,25 +52,25 @@ DockId=0x00000001,0
|
||||
|
||||
[Window][Viewport]
|
||||
Pos=483,58
|
||||
Size=1604,955
|
||||
Size=964,647
|
||||
Collapsed=0
|
||||
DockId=0x0000000B,0
|
||||
|
||||
[Window][Environment]
|
||||
Pos=2089,589
|
||||
Size=471,977
|
||||
Pos=1449,411
|
||||
Size=471,669
|
||||
Collapsed=0
|
||||
DockId=0x0000000A,1
|
||||
|
||||
[Window][Project]
|
||||
Pos=483,1015
|
||||
Size=1604,551
|
||||
Pos=483,707
|
||||
Size=964,373
|
||||
Collapsed=0
|
||||
DockId=0x0000000C,0
|
||||
|
||||
[Window][Objects]
|
||||
Pos=483,1015
|
||||
Size=1604,551
|
||||
Pos=483,707
|
||||
Size=964,373
|
||||
Collapsed=0
|
||||
DockId=0x0000000C,1
|
||||
|
||||
@ -81,12 +81,18 @@ Collapsed=0
|
||||
|
||||
[Window][##tool_bar]
|
||||
Pos=483,24
|
||||
Size=1604,32
|
||||
Size=964,32
|
||||
Collapsed=0
|
||||
DockId=0x00000001,0
|
||||
|
||||
[Window][Console]
|
||||
Pos=483,707
|
||||
Size=964,373
|
||||
Collapsed=0
|
||||
DockId=0x0000000C,2
|
||||
|
||||
[Docking][Data]
|
||||
DockSpace ID=0xC0DFADC4 Window=0xD0388BC8 Pos=0,58 Size=2560,1542 Split=X Selected=0x0C01D6D5
|
||||
DockSpace ID=0xC0DFADC4 Window=0xD0388BC8 Pos=268,189 Size=1920,1056 Split=X Selected=0x0C01D6D5
|
||||
DockNode ID=0x00000007 Parent=0xC0DFADC4 SizeRef=1557,1542 Split=X
|
||||
DockNode ID=0x00000003 Parent=0x00000007 SizeRef=481,1542 Split=Y Selected=0x5D711C2C
|
||||
DockNode ID=0x00000005 Parent=0x00000003 SizeRef=481,817 Selected=0x5D711C2C
|
||||
|
||||
Reference in New Issue
Block a user