Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions EclipseEngine/EclipseEditor/EditorRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ void EditorRenderer::Render(Scene* scene, Camera* editorCamera, std::shared_ptr<
{
if (!scene) return;

// Normal object rendering
glStencilFunc(GL_ALWAYS, 1, 0xFF); // Write 1 to the stencil buffer for all objects
glStencilMask(0xFF); // Enable writing to the stencil buffer

for (auto& object : scene->GetObjects())
{
// Normal object rendering
glStencilFunc(GL_ALWAYS, 1, 0xFF); // Write 1 to the stencil buffer for all objects
glStencilMask(0xFF); // Enable writing to the stencil buffer

glm::mat4 identity = object->transform.GetMatrix();
object->UpdateAABB(glm::mat4(1.0f));
if (glfwGetKey(core->window->GetWindow(), GLFW_KEY_P) == GLFW_PRESS)
{
optionShader = posShader;
Expand All @@ -77,30 +78,30 @@ void EditorRenderer::Render(Scene* scene, Camera* editorCamera, std::shared_ptr<
optionShader = normalShader;
}
object->Draw(*optionShader, *editorCamera, identity);
RenderAABB(object->GetAABB(), *aabbShader);
for (auto& child : object->GetChildren())
{
RenderAABB(child->GetAABB(), *aabbShader);
}
}

if (selectedObject != nullptr)
{
glm::mat4 objectModel = selectedObject->CalculateWorldTransform(selectedObject->transform.GetMatrix());

// Outlining: Second pass (draw outline)
glStencilFunc(GL_NOTEQUAL, 1, 0xFF); // Only draw where stencil buffer is not 1
glStencilMask(0x00); // Disable writing to the stencil buffer
glDisable(GL_DEPTH_TEST); // Disable depth testing for stencil write
if (selectedObject != nullptr)
{
// Calculate the world transform for the selected object
glm::mat4 worldTransform = glm::mat4(1.0f);

selectedObject->Draw(*outliningShader, *editorCamera, identity); // Draw outline
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // Reset to fill mode
}
// Outlining: Second pass (draw outline)
glStencilFunc(GL_NOTEQUAL, 1, 0xFF); // Only draw where stencil buffer is not 1
glStencilMask(0x00); // Disable writing to the stencil buffer
glDisable(GL_DEPTH_TEST); // Disable depth testing for stencil write

glStencilMask(0xFF); // Re-enable writing to stencil buffer for next frame
glStencilFunc(GL_ALWAYS, 1, 0xFF); // Reset stencil function
glEnable(GL_DEPTH_TEST); // Re-enable depth testing
selectedObject->Draw(*outliningShader, *editorCamera, selectedObject->transform.GetMatrix()); // Draw outline
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // Reset to fill mode
}

glStencilMask(0xFF); // Re-enable writing to stencil buffer for next frame
glStencilFunc(GL_ALWAYS, 1, 0xFF); // Reset stencil function
glEnable(GL_DEPTH_TEST); // Re-enable depth testing

RenderGrid(grid, editorCamera);
RenderGuizmo();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
Expand Down
53 changes: 30 additions & 23 deletions EclipseEngine/EclipseEditor/HierarchyPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,35 @@ void HierarchyPanel::Render()
m_RootObjects = core->scene->GetObjects();
}

if(ImGui::Button("Add Object"))
{
const char* filterPatterns[1] = { "*.fbx" };
const char* filePath = tinyfd_openFileDialog("Select Object", "", 1, filterPatterns, NULL, 0);
if (filePath) {
std::filesystem::path path(filePath);
ModelLoader modelLoader;
auto gameObject = modelLoader.LoadModel(filePath);
gameObject->name = path.stem().string();
core->scene->AddGameObject(gameObject);
if (ImGui::IsKeyPressed(ImGuiKey_MouseRight)
&& ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup))
{
ImGui::OpenPopup("AddObject");
}

if (ImGui::BeginPopup("AddObject"))
{
if (ImGui::MenuItem("Add Object"))
{
const char* filterPatterns[1] = { "*.fbx" };
const char* filePath = tinyfd_openFileDialog("Select Object", "", 1, filterPatterns, NULL, 0);
if (filePath) {
std::filesystem::path path(filePath);
ModelLoader modelLoader;
auto gameObject = modelLoader.LoadModel(filePath);
gameObject->name = path.stem().string();
core->scene->AddGameObject(gameObject);
}
}
if (ImGui::MenuItem("Add Empty GameObject"))
{
core->scene->AddEmptyGameObject();
}
if (ImGui::MenuItem("Add Cube"))
{
core->scene->AddCube();
}
ImGui::EndPopup();
}

for (const auto& rootObject : m_RootObjects) {
Expand All @@ -46,15 +64,6 @@ void HierarchyPanel::Render()
ImGui::End();
}

void HierarchyPanel::RemoveObject(std::shared_ptr<GameObject> rootObject)
{
// TODO: delete method
}

void HierarchyPanel::AddRootObject(std::shared_ptr<GameObject> rootObject) {
m_RootObjects.emplace_back(rootObject);
}

void HierarchyPanel::RenderGameObjectTree(const std::shared_ptr<GameObject>& gameObject) {

// Check if this GameObject is the selected one
Expand All @@ -72,12 +81,10 @@ void HierarchyPanel::RenderGameObjectTree(const std::shared_ptr<GameObject>& gam
m_SelectedObject = gameObject;
Logger::Log("Selected object: " + gameObject->GetName());

if (m_InspectorPanel != nullptr)
{
if (m_InspectorPanel != nullptr) {
m_InspectorPanel->SetSelectedObject(m_SelectedObject);
}
if (m_ViewportPanel != nullptr)
{
if (m_ViewportPanel != nullptr) {
m_ViewportPanel->SetSelectedObject(m_SelectedObject);
}
}
Expand Down
2 changes: 0 additions & 2 deletions EclipseEngine/EclipseEditor/HierarchyPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class HierarchyPanel : public Panel
HierarchyPanel(const std::string& name, bool isVisible = false);

void Render() override;
void RemoveObject(std::shared_ptr<GameObject> rootObject);
void AddRootObject(std::shared_ptr<GameObject> rootObject);
std::shared_ptr<GameObject> GetSelectedObject() const { return m_SelectedObject; }
void SetInspectorPanel(InspectorPanel* inspectorPanel) { m_InspectorPanel = inspectorPanel; }
void SetViewportPanel(ViewportPanel* viewportPanel) { m_ViewportPanel = viewportPanel; }
Expand Down
120 changes: 87 additions & 33 deletions EclipseEngine/EclipseEditor/InspectorPanel.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "imgui.h"
#include "glm/glm.hpp"
#include "App.h"
#include "InspectorPanel.h"
#include "tinyfiledialogs.h"

Expand All @@ -17,7 +18,7 @@ void InspectorPanel::Render()

if(ImGui::BeginTabBar("##tabs", ImGuiTabBarFlags_None))
{
if (m_SelectedObject)
if (m_SelectedObject != nullptr)
{
// Display the name of the selected object
ImGui::Text("Selected Object: %s", m_SelectedObject->GetName().c_str());
Expand All @@ -27,8 +28,7 @@ void InspectorPanel::Render()
// Render Transform controls (you already have this implemented)
if (ImGui::BeginTabBar("##tabs", ImGuiTabBarFlags_None))
{
ImGui::Text("Transform");
ImGui::Separator();
ImGui::Text("TRANSFORM");

// Position
glm::vec3 position = m_SelectedObject->transform.position;
Expand All @@ -53,43 +53,97 @@ void InspectorPanel::Render()
m_SelectedObject->transform.SetRotation(rotationQuat);
}

// Add Component button with selection menu
if (ImGui::Button("Add Component"))
{
ImGui::OpenPopup("AddComponentPopup");
}

ImGui::Separator();
(ImGui::Text("Mesh"));
ImGui::Separator();
bool temp = false;
ImGui::Checkbox("Active", &temp);
ImGui::SameLine();
ImGui::Text("File: ");
ImGui::Separator();
ImGui::Text("Draw:");
// Display the texture
GLuint textureID = m_SelectedObject.get()->GetTextureID();
if (textureID) {
ImGui::Image((void*)(intptr_t)textureID, ImVec2(128, 128)); // Adjust size as needed
if (ImGui::BeginPopup("AddComponentPopup"))
{
if (ImGui::MenuItem("Mesh"))
{
//m_SelectedObject->AddComponent<Mesh>();
}
if (ImGui::MenuItem("Material"))
{
//m_SelectedObject->AddComponent<Material>();
}
if (ImGui::MenuItem("Camera"))
{
m_SelectedObject->AddComponent<Camera>(1500, 844, m_SelectedObject->transform.position);
}
ImGui::EndPopup();
}
//ImGui::Checkbox("Vertex Normals", &temp);
//ImGui::Checkbox("Face Normals", &temp);
//ImGui::SameLine();
//ImGui::Separator();
//ImGui::Text("Indexes: ");
//ImGui::Text("Normals: ");
//ImGui::Text("Vertexs: ");
//ImGui::Text("Faces: ");
//ImGui::Text("Tex coords: ");
//ImGui::Separator();
//ImGui::SliderFloat("Normals length", nullptr, 0.000f, 1.000f);
ImGui::Separator();

ImGui::SameLine(0.0f, 1.0f);
if (m_SelectedObject->components.size() > 0)
{
// Remove Component button with selection menu
if (ImGui::Button("Remove Component"))
{
ImGui::OpenPopup("RemoveComponentPopup");
}
}

if (ImGui::BeginPopup("RemoveComponentPopup"))
{
if (m_SelectedObject->GetComponent<Mesh>() && ImGui::MenuItem("Mesh"))
{
m_SelectedObject->RemoveComponent<Mesh>();
}
if (m_SelectedObject->GetComponent<Material>() && ImGui::MenuItem("Material"))
{
m_SelectedObject->RemoveComponent<Material>();
}
if (m_SelectedObject->GetComponent<Camera>() && ImGui::MenuItem("Camera"))
{
m_SelectedObject->RemoveComponent<Camera>();
}
ImGui::EndPopup();
}

if (m_SelectedObject->GetComponent<Mesh>()) {
ImGui::Separator();
(ImGui::Text("MESH"));
bool temp = true;
ImGui::Checkbox("Active", &temp);
ImGui::Text("Vertices: %d", m_SelectedObject->GetComponent<Mesh>()->vertices.size());
ImGui::SameLine(0, 20);
ImGui::Text("Indices: %d", m_SelectedObject->GetComponent<Mesh>()->indices.size());
}

if (m_SelectedObject->GetComponent<Material>()) {
ImGui::Separator();
(ImGui::Text("MATERIAL"));

(ImGui::Text("Texture Preview:"));
// Display the texture
GLuint textureID = m_SelectedObject.get()->GetTextureID();
if (textureID) {
ImGui::Image((void*)(intptr_t)textureID, ImVec2(256, 256));
}
}

if (m_SelectedObject->GetComponent<Camera>()) {
if (ImGui::Checkbox("Active", &m_SelectedObject->GetComponent<Camera>()->mainCamera)) {
core->scene->SetActiveCamera(m_SelectedObject->GetComponent<Camera>());
}
if (ImGui::SliderFloat("FOV", &m_SelectedObject->GetComponent<Camera>()->FOVdeg, 1.0f, 179.0f))
{
//m_SelectedObject->GetComponent<Camera>()->UpdateProjectionMatrix();
}
if (ImGui::SliderFloat("Near Plane", &m_SelectedObject->GetComponent<Camera>()->nearPlane, 0.1f, 100.0f));
if (ImGui::SliderFloat("Far Plane", &m_SelectedObject->GetComponent<Camera>()->farPlane, 0.1f, 100.0f));
}
ImGui::Separator();
(ImGui::Text("Material"));
ImGui::Separator();
bool temp1;
ImGui::Checkbox("Active", &temp1);
if (ImGui::Button("Delete Object")) {
core->scene->DeleteGameObject(m_SelectedObject);
m_SelectedObject = nullptr;
}

ImGui::EndTabBar();
}

}
else
{
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion EclipseEngine/EclipseEditor/ViewportPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ void ViewportPanel::Render()
Logger::Log("Texture file dropped to selected object: " + std::string(filePath));
std::vector<Texture> textures{ Texture(filePath, "diffuse", 0, GL_RGBA, GL_UNSIGNED_BYTE) };

m_SelectedObject->RemoveComponent<Material>();
m_SelectedObject->AddComponent<Material>(textures);
// Display the texture
GLuint textureID = m_SelectedObject.get()->GetTextureID();
if (textureID) {
ImGui::Image((void*)(intptr_t)textureID, ImVec2(128, 128)); // Adjust size as needed
}

// Handle texture file loading
}
else
{
Expand Down
Loading