Skip to content

Commit

Permalink
Prefabs, DebugText, Vulkan labels
Browse files Browse the repository at this point in the history
  • Loading branch information
jmorton06 committed Aug 3, 2023
1 parent ed6671a commit affcf81
Show file tree
Hide file tree
Showing 86 changed files with 6,841 additions and 429 deletions.
2 changes: 1 addition & 1 deletion Editor/Source/ApplicationInfoPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace Lumos
// if (frame > (int)(ImGui::GetIO().Framerate / 60))
{
rdata.AddPoint(t, ImGui::GetIO().Framerate);
rdata1.AddPoint(t, Lumos::Engine::GetTimeStep().GetMillis()); // 1000.0f / ImGui::GetIO().Framerate);
rdata1.AddPoint(t, (float)Lumos::Engine::GetTimeStep().GetMillis()); // 1000.0f / ImGui::GetIO().Framerate);
}

static ImPlotAxisFlags rt_axis = ImPlotAxisFlags_NoTickLabels;
Expand Down
43 changes: 36 additions & 7 deletions Editor/Source/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,17 @@ namespace Lumos
return false;
}

bool IsPrefab(const std::string& filePath)
{
LUMOS_PROFILE_FUNCTION();
std::string extension = StringUtilities::GetFilePathExtension(filePath);
extension = StringUtilities::ToLower(extension);
if(extension == "lprefab")
return true;

return false;
}

void Editor::OnImGui()
{
LUMOS_PROFILE_FUNCTION();
Expand Down Expand Up @@ -808,9 +819,12 @@ namespace Lumos
ImGui::Separator();

ImGui::TextUnformatted("Third-Party");
ImGui::Text("ImGui - Version : %s, Revision - %d", IMGUI_VERSION, IMGUI_VERSION_NUM);
ImGui::Text("Entt - Version %s", ENTT_VERSION);
ImGui::Text("Cereal - Version %d.&d.%d", CEREAL_VERSION_MAJOR, CEREAL_VERSION_MINOR, CEREAL_VERSION_PATCH);
if(ImGui::MenuItem(fmt::format("ImGui - Version : {0}, Revision - {1}", IMGUI_VERSION, IMGUI_VERSION_NUM).c_str()))
Lumos::OS::Instance()->OpenURL("https://github.com/ocornut/imgui");
if(ImGui::MenuItem(fmt::format("Entt - Version : {0}", ENTT_VERSION).c_str()))
Lumos::OS::Instance()->OpenURL("https://github.com/skypjack/entt");
if(ImGui::MenuItem(fmt::format("Cereal - Version : {0}.{1}.{2}", CEREAL_VERSION_MAJOR, CEREAL_VERSION_MINOR, CEREAL_VERSION_PATCH).c_str()))
Lumos::OS::Instance()->OpenURL("https://github.com/USCiLab/cereal");

ImGui::EndMenu();
}
Expand Down Expand Up @@ -1357,8 +1371,6 @@ namespace Lumos

glm::mat4 medianPointMatrix = glm::translate(glm::mat4(1.0f), medianPointLocation) * glm::scale(glm::mat4(1.0f), medianPointScale);

glm::mat4 projectionMatrix, viewMatrix;

ImGuizmo::SetDrawlist();
ImGuizmo::SetOrthographic(m_CurrentCamera->IsOrthographic());

Expand Down Expand Up @@ -1811,7 +1823,7 @@ namespace Lumos
autoSaveTimer = 0;
}

autoSaveTimer += ts.GetMillis();
autoSaveTimer += (float)ts.GetMillis();
}

if(m_EditorState == EditorState::Play)
Expand Down Expand Up @@ -1853,7 +1865,7 @@ namespace Lumos
m_EditorCameraController.HandleKeyboard(m_EditorCameraTransform, (float)ts.GetSeconds());
m_EditorCameraTransform.SetWorldMatrix(glm::mat4(1.0f));

if(Input::Get().GetKeyPressed(InputCode::Key::F))
if(!m_SelectedEntities.empty() && Input::Get().GetKeyPressed(InputCode::Key::F))
{
if(registry.valid(m_SelectedEntities.front()))
{
Expand Down Expand Up @@ -2076,6 +2088,19 @@ namespace Lumos
}
}

if(m_Settings.m_DebugDrawFlags & EditorDebugFlags::EntityNames)
{
auto transform = registry.view<Maths::Transform>();

for(auto entity : transform)
{
Entity e = { entity, GetCurrentScene() };
{
DebugRenderer::DrawTextWsNDT(e.GetTransform().GetWorldPosition(), 20.0f, glm::vec4(1.0f), e.GetName());
}
}
}

for(auto m_SelectedEntity : m_SelectedEntities)
if(registry.valid(m_SelectedEntity)) // && Application::Get().GetEditorState() == EditorState::Preview)
{
Expand Down Expand Up @@ -2487,6 +2512,10 @@ namespace Lumos
SharedPtr<Graphics::Texture2D> texture = SharedPtr<Graphics::Texture2D>(Graphics::Texture2D::CreateFromFile(path, path));
sprite.SetTexture(texture);
}
else if(IsPrefab(path))
{
m_SceneManager->GetCurrentScene()->InstantiatePrefab(path);
}
}

void Editor::FileEmbedCallback(const std::string& filePath)
Expand Down
2 changes: 2 additions & 0 deletions Editor/Source/Editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ namespace Lumos
CameraFrustum = 8,
MeshBoundingBoxes = 16,
SpriteBoxes = 32,
EntityNames = 64,

};

class Editor : public Application
Expand Down
4 changes: 4 additions & 0 deletions Editor/Source/GameViewPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace Lumos

m_RenderPasses = CreateUniquePtr<Graphics::RenderPasses>(m_Width, m_Height);
m_RenderPasses->GetSettings().DebugPass = false;
m_RenderPasses->m_DebugRenderEnabled = false;
}

static std::string AspectToString(float aspect)
Expand Down Expand Up @@ -172,6 +173,9 @@ namespace Lumos
sceneViewSize.x -= static_cast<int>(sceneViewSize.x) % 2 != 0 ? 1.0f : 0.0f;
sceneViewSize.y -= static_cast<int>(sceneViewSize.y) % 2 != 0 ? 1.0f : 0.0f;

sceneViewSize.x = Maths::Max(sceneViewSize.x, 2);
sceneViewSize.y = Maths::Max(sceneViewSize.y, 2);

Resize(static_cast<uint32_t>(sceneViewSize.x), static_cast<uint32_t>(sceneViewSize.y));

if(m_Editor->GetSettings().m_HalfRes)
Expand Down
55 changes: 42 additions & 13 deletions Editor/Source/HierarchyPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ namespace Lumos
if(!registry.valid(node))
return;

Entity nodeEntity = { node, Application::Get().GetSceneManager()->GetCurrentScene() };

static const char* defaultName = "Entity";
const NameComponent* nameComponent = registry.try_get<NameComponent>(node);
const char* name = nameComponent ? nameComponent->name.c_str() : defaultName; // StringUtilities::ToString(entt::to_integral(node));
Expand Down Expand Up @@ -156,7 +158,33 @@ namespace Lumos
ImGui::PopStyleColor();
ImGui::SameLine();
if(!doubleClicked)
{
bool isPrefab = false;
if(registry.any_of<PrefabComponent>(node))
isPrefab = true;
else
{
auto Parent = nodeEntity.GetParent();
while(Parent && Parent.Valid())
{
if(Parent.HasComponent<PrefabComponent>())
{
isPrefab = true;
Parent = {};
}
else
{
Parent = Parent.GetParent();
}
}
}

if(isPrefab)
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_CheckMark));
ImGui::TextUnformatted(name);
if(isPrefab)
ImGui::PopStyleColor();
}
// ImGui::EndGroup();

if(doubleClicked)
Expand Down Expand Up @@ -328,7 +356,7 @@ namespace Lumos

if(m_SelectUp)
{
if(m_Editor->GetSelected().front() == node && registry.valid(m_CurrentPrevious))
if(!m_Editor->GetSelected().empty() && m_Editor->GetSelected().front() == node && registry.valid(m_CurrentPrevious))
{
m_SelectUp = false;
m_Editor->SetSelected(m_CurrentPrevious);
Expand All @@ -337,7 +365,7 @@ namespace Lumos

if(m_SelectDown)
{
if(registry.valid(m_CurrentPrevious) && m_CurrentPrevious == m_Editor->GetSelected().front())
if(!m_Editor->GetSelected().empty() && registry.valid(m_CurrentPrevious) && m_CurrentPrevious == m_Editor->GetSelected().front())
{
m_SelectDown = false;
m_Editor->SetSelected(node);
Expand Down Expand Up @@ -377,7 +405,7 @@ namespace Lumos
entt::entity child = hierarchyComponent->First();
while(child != entt::null && registry.valid(child))
{
float HorizontalTreeLineSize = 16.0f * Application::Get().GetWindowDPI(); // chosen arbitrarily
float HorizontalTreeLineSize = 20.0f * Application::Get().GetWindowDPI(); // chosen arbitrarily
auto currentPos = ImGui::GetCursorScreenPos();
ImGui::Indent(10.0f);

Expand All @@ -388,7 +416,7 @@ namespace Lumos
entt::entity firstChild = childHerarchyComponent->First();
if(firstChild != entt::null && registry.valid(firstChild))
{
HorizontalTreeLineSize *= 0.5f;
HorizontalTreeLineSize *= 0.1f;
}
}
DrawNode(child, registry);
Expand Down Expand Up @@ -627,15 +655,16 @@ namespace Lumos

// ImGuiUtilities::AlternatingRowsBackground(ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.y);

registry.each([&](auto entity)
{
if(registry.valid(entity))
{
auto hierarchyComponent = registry.try_get<Hierarchy>(entity);

if(!hierarchyComponent || hierarchyComponent->Parent() == entt::null)
DrawNode(entity, registry);
} });
for(auto [entity] : registry.storage<entt::entity>().each())
{
if(registry.valid(entity))
{
auto hierarchyComponent = registry.try_get<Hierarchy>(entity);

if(!hierarchyComponent || hierarchyComponent->Parent() == entt::null)
DrawNode(entity, registry);
}
}

// Only supports one scene
ImVec2 min_space = ImGui::GetWindowContentRegionMin();
Expand Down
90 changes: 86 additions & 4 deletions Editor/Source/InspectorPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#include <imgui/imgui_internal.h>
#include <glm/gtx/matrix_decompose.hpp>

#include <cereal/types/polymorphic.hpp>
#include <cereal/archives/binary.hpp>
#include <cereal/archives/json.hpp>

// #include <sol/sol.hpp>
#include <inttypes.h>

Expand Down Expand Up @@ -1954,6 +1958,21 @@ end
{
using namespace Lumos;
ImGui::Indent();
if(ImGui::Button("Save to file"))
{
std::string filePath = "//Meshes"; // Materials/" + matName + ".lmat";
std::string physicalPath;
if(VFS::Get().ResolvePhysicalPath(filePath, physicalPath))
{
physicalPath += "/Materials/" + matName + ".lmat";
std::stringstream storage;

cereal::JSONOutputArchive output { storage };
material->save(output);

FileSystem::WriteTextFile(physicalPath, storage.str());
}
}
bool flipImage = Graphics::Renderer::GetGraphicsContext()->FlipImGUITexture();

bool twoSided = material->GetFlag(Lumos::Graphics::Material::RenderFlags::TWOSIDED);
Expand Down Expand Up @@ -2326,15 +2345,17 @@ namespace Lumos
{
ImGuiUtilities::PushID();

if(!Application::Get().GetSceneManager()->GetCurrentScene())
Scene* currentScene = Application::Get().GetSceneManager()->GetCurrentScene();

if(!currentScene)
{
m_Editor->SetSelected(entt::null);
ImGuiUtilities::PopID();
ImGui::End();
return;
}

auto& registry = Application::Get().GetSceneManager()->GetCurrentScene()->GetRegistry();
auto& registry = currentScene->GetRegistry();
if(selectedEntities.size() != 1 || !registry.valid(selectedEntities.front()))
{
m_Editor->SetSelected(entt::null);
Expand All @@ -2343,7 +2364,8 @@ namespace Lumos
return;
}

auto selected = selectedEntities.front();
auto selected = selectedEntities.front();
Entity SelectedEntity = { selected, currentScene };

// active checkbox
auto activeComponent = registry.try_get<ActiveComponent>(selected);
Expand Down Expand Up @@ -2379,7 +2401,7 @@ namespace Lumos
}

ImGui::SameLine();
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGui::GetFontSize() * 2.0f);
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGui::GetFontSize() * 4.0f);
{
ImGuiUtilities::ScopedFont boldFont(ImGui::GetIO().Fonts->Fonts[1]);
if(ImGuiUtilities::InputText(name))
Expand All @@ -2389,19 +2411,70 @@ namespace Lumos

ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.7f, 0.7f, 0.7f, 0.0f));

if(ImGui::Button(ICON_MDI_FLOPPY))
ImGui::OpenPopup("SavePrefab");

ImGuiUtilities::Tooltip("Save Entity As Prefab");

ImGui::SameLine();
if(ImGui::Button(ICON_MDI_TUNE))
ImGui::OpenPopup("SetDebugMode");
ImGui::PopStyleColor();

if(ImGui::BeginPopup("SetDebugMode", 3))
{
if(SelectedEntity.HasComponent<PrefabComponent>() && ImGui::Button("Revert To Prefab"))
{
auto path = SelectedEntity.GetComponent<PrefabComponent>().Path;
m_Editor->UnSelect(selected);
SelectedEntity.Destroy();

SelectedEntity = Application::Get().GetSceneManager()->GetCurrentScene()->InstantiatePrefab(path);
selected = SelectedEntity.GetHandle();
m_Editor->SetSelected(selected);
}

if(ImGui::Selectable("Debug Mode", m_DebugMode))
{
m_DebugMode = !m_DebugMode;
}
ImGui::EndPopup();
}

if(ImGui::BeginPopupModal("SavePrefab", NULL, ImGuiWindowFlags_AlwaysAutoResize))
{
ImGui::Text("Save Current Entity as a Prefab?\n\n");
ImGui::Separator();

static std::string prefabName = SelectedEntity.GetName();
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted("Name : ");
ImGui::SameLine();
ImGuiUtilities::InputText(prefabName);

static std::string prefabNamePath = "//Assets/Prefabs/";
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted("Path : ");
ImGui::SameLine();
ImGuiUtilities::InputText(prefabNamePath);

if(ImGui::Button("OK", ImVec2(120, 0)))
{
std::string physicalPath;
VFS::Get().ResolvePhysicalPath(prefabNamePath, physicalPath, true);
std::string FullPath = physicalPath + prefabName + std::string(".lprefab");
Application::Get().GetSceneManager()->GetCurrentScene()->SavePrefab({ selected, Application::Get().GetSceneManager()->GetCurrentScene() }, FullPath);
ImGui::CloseCurrentPopup();
}
ImGui::SetItemDefaultFocus();
ImGui::SameLine();
if(ImGui::Button("Cancel", ImVec2(120, 0)))
{
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}

ImGui::Separator();

if(m_DebugMode)
Expand Down Expand Up @@ -2447,6 +2520,15 @@ namespace Lumos
ImGui::Separator();
}

if(registry.try_get<PrefabComponent>(selected))
{
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_CheckMark));
ImGui::Separator();
ImGui::Text("Prefab %s", registry.get<PrefabComponent>(selected).Path.c_str());
ImGui::Separator();
ImGui::PopStyleColor();
}

ImGui::BeginChild("Components", ImVec2(0.0f, 0.0f), false, ImGuiWindowFlags_None);
m_EnttEditor.RenderImGui(registry, selected);
ImGui::EndChild();
Expand Down
Loading

0 comments on commit affcf81

Please sign in to comment.