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");
|
||||
|
||||
Reference in New Issue
Block a user