adding materials, adding serialization for meshes and materials, random fixes
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#ifndef EDITOR_HPP
|
||||
#define EDITOR_HPP
|
||||
|
||||
#include <X11/X.h>
|
||||
#include <open_engine.hpp>
|
||||
|
||||
#include "open_engine/renderer/renderer3d.hpp"
|
||||
@@ -92,9 +91,11 @@ namespace OpenEngine {
|
||||
|
||||
editor_camera = EditorCamera(30.0f, 1920.0f/1080.0f, 0.1f, 1000.0f);
|
||||
|
||||
// TODO: Add license
|
||||
icons["play"] = Texture2D::Create("resources/textures/icons/play.png");
|
||||
icons["stop"] = Texture2D::Create("resources/textures/icons/stop.png");
|
||||
|
||||
// =============================================
|
||||
Entity cube = scene->CreateEntity("cube");
|
||||
|
||||
|
||||
@@ -104,6 +105,7 @@ namespace OpenEngine {
|
||||
|
||||
cube.AddComponent<MeshComponent>(mesh);
|
||||
|
||||
// =============================================
|
||||
Entity quad = scene->CreateEntity("quad");
|
||||
quad.AddComponent<TransformComponent>();
|
||||
quad.GetComponents<TransformComponent>().translation = {0, 0, 0};
|
||||
@@ -112,6 +114,7 @@ namespace OpenEngine {
|
||||
|
||||
quad.AddComponent<MeshComponent>(quad_mesh);
|
||||
|
||||
// =============================================
|
||||
Entity cube2 = scene->CreateEntity("cube2");
|
||||
cube2.AddComponent<TransformComponent>();
|
||||
cube2.GetComponents<TransformComponent>().translation = {2, 0, 0};
|
||||
@@ -129,7 +132,6 @@ namespace OpenEngine {
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO: Add file texture. Get free icons and add license
|
||||
//icons["folder"] = Texture2D::Create("resources/textures/icons/folder.png");
|
||||
/*
|
||||
for (float i = 0; i < 200; i++) {
|
||||
@@ -352,7 +354,7 @@ namespace OpenEngine {
|
||||
bool was_focused = viewport_focused;
|
||||
viewport_focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_RootWindow);
|
||||
viewport_hovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_RootWindow);
|
||||
Application::Get().GetImGuiLayer()->SetBlockEvents((!viewport_focused && !viewport_hovered) || ImGui::IsAnyItemActive());
|
||||
Application::Get().GetImGuiLayer()->SetBlockEvents(ImGui::IsAnyItemActive());
|
||||
|
||||
if (viewport_focused && !was_focused)
|
||||
editor_camera.ResetMousePosition();
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace OpenEngine {
|
||||
void SpriteOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||
void CameraOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||
void MeshOnImGuiRender(entt::registry®istry, entt::entity entity);
|
||||
void MaterialOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||
}
|
||||
|
||||
#endif // EDITOR_COMPONENT_HPP
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace OpenEngine {
|
||||
private:
|
||||
std::filesystem::path current_directory;
|
||||
Ref<Texture2D> folder_icon;
|
||||
Ref<Texture2D> file_icon;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#include "imgui.h"
|
||||
#include "open_engine/renderer/renderer3d.hpp"
|
||||
#include "open_engine/scene/components.hpp"
|
||||
#include <editor_component.hpp>
|
||||
#include <entt/entity/fwd.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <open_engine.hpp>
|
||||
|
||||
namespace OpenEngine {
|
||||
@@ -101,6 +105,7 @@ namespace OpenEngine {
|
||||
DrawVec3Control("Rotation", rotation_comp);
|
||||
transform.rotation = glm::radians(rotation_comp);
|
||||
DrawVec3Control("Scale", transform.scale);
|
||||
ImGui::Spacing();
|
||||
};
|
||||
|
||||
void SpriteOnImGuiRender(entt::registry& registry, entt::entity entity)
|
||||
@@ -171,8 +176,66 @@ namespace OpenEngine {
|
||||
|
||||
};
|
||||
|
||||
void MeshOnImGuiRender(entt::registry®istry, entt::entity entity)
|
||||
void MeshOnImGuiRender(entt::registry& registry, entt::entity entity)
|
||||
{
|
||||
auto& mesh_component = registry.get<MeshComponent>(entity);
|
||||
|
||||
const char* items[] = { "Quad", "Cube" };
|
||||
static int item_selected_idx = 0;
|
||||
|
||||
if (ImGui::BeginCombo("Mesh", items[item_selected_idx])) {
|
||||
for (int n = 0; n < 2; n++)
|
||||
{
|
||||
const bool is_selected = (item_selected_idx == n);
|
||||
if (ImGui::Selectable(items[n], is_selected))
|
||||
item_selected_idx = n;
|
||||
|
||||
// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
|
||||
if (is_selected)
|
||||
ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
|
||||
if ((int)mesh_component.primitive_type == (item_selected_idx + 1))
|
||||
return;
|
||||
|
||||
mesh_component.primitive_type = (PrimitiveType)(item_selected_idx + 1);
|
||||
switch (mesh_component.primitive_type) {
|
||||
case OpenEngine::PrimitiveType::Quad:
|
||||
{
|
||||
mesh_component.mesh = CreateQuad((uint32_t)entity);
|
||||
break;
|
||||
}
|
||||
case OpenEngine::PrimitiveType::Cube:
|
||||
{
|
||||
mesh_component.mesh = CreateCube((uint32_t)entity);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialOnImGuiRender(entt::registry& registry, entt::entity entity)
|
||||
{
|
||||
auto& material = registry.get<MaterialComponent>(entity).material;
|
||||
|
||||
auto& albedo = material.albedo;
|
||||
auto& roughness = material.roughness;
|
||||
auto& metallic = material.metallic;
|
||||
auto& ambient = material.ambient_strength;
|
||||
auto& specular = material.specular_strength;
|
||||
|
||||
if (ImGui::SliderFloat4("Albedo", glm::value_ptr(albedo), 0, 1))
|
||||
material.albedo = albedo;
|
||||
if (ImGui::SliderFloat("Roughness", &roughness, 0, 1))
|
||||
material.roughness = roughness;
|
||||
if (ImGui::SliderFloat("Metallic", &metallic, 0, 1))
|
||||
material.metallic = metallic;
|
||||
if (ImGui::SliderFloat("Ambient strength", &ambient, 0, 1))
|
||||
material.ambient_strength = ambient;
|
||||
if (ImGui::SliderFloat("Specular strength", &specular, 0, 10))
|
||||
material.specular_strength = specular;
|
||||
}
|
||||
}
|
||||
|
||||
28
editor/src/panels/content_browser.cpp
Normal file → Executable file
28
editor/src/panels/content_browser.cpp
Normal file → Executable file
@@ -15,8 +15,9 @@ namespace OpenEngine {
|
||||
ContentBrowserPanel::ContentBrowserPanel()
|
||||
: current_directory(assets_directory)
|
||||
{
|
||||
// TODO: Add file texture. Get free icons and add license
|
||||
folder_icon = Texture2D::Create("resources/textures/icons/folder.png");
|
||||
// TODO: Add license
|
||||
folder_icon = Texture2D::Create("resources/textures/icons/folder2.png");
|
||||
file_icon = Texture2D::Create("resources/textures/icons/file.png");
|
||||
}
|
||||
|
||||
void ContentBrowserPanel::OnImGuiRender()
|
||||
@@ -30,6 +31,16 @@ namespace OpenEngine {
|
||||
current_directory = current_directory.parent_path();
|
||||
|
||||
auto directory_it = std::filesystem::directory_iterator(current_directory);
|
||||
std::vector<std::filesystem::directory_entry> entries;
|
||||
|
||||
for (auto entry : directory_it)
|
||||
entries.emplace_back(entry);
|
||||
|
||||
std::sort(entries.begin(), entries.end(),
|
||||
[](const std::filesystem::directory_entry& a,
|
||||
const std::filesystem::directory_entry& b) {
|
||||
return (a.is_directory() && !b.is_directory());
|
||||
});
|
||||
|
||||
ImVec2 button_size = { 100, 100 };
|
||||
auto panel_width = ImGui::GetContentRegionAvail().x;
|
||||
@@ -42,9 +53,12 @@ namespace OpenEngine {
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, padding);
|
||||
|
||||
float margin = 20.0f;
|
||||
ImGui::Indent(margin);
|
||||
|
||||
if (ImGui::BeginTable("table1", table_columns, ImGuiTableFlags_SizingFixedSame))
|
||||
{
|
||||
for (auto& entry : directory_it) {
|
||||
for (auto& entry : entries) {
|
||||
auto file_name = entry.path().filename().string();
|
||||
|
||||
ImGui::PushID(file_name.c_str());
|
||||
@@ -56,17 +70,14 @@ namespace OpenEngine {
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, { 0.270f, 0.278f, 0.352f, 1.0f });
|
||||
|
||||
ImGui::BeginGroup();
|
||||
ImGui::ImageButton("##X", (ImTextureID)folder_icon->GetID(), button_size, { 0, 1 }, { 1, 0 });
|
||||
Ref<Texture2D> icon = entry.is_directory() ? folder_icon : file_icon;
|
||||
ImGui::ImageButton("##X", (ImTextureID)icon->GetID(), button_size, { 0, 1 }, { 1, 0 });
|
||||
if (entry.is_regular_file() && ImGui::BeginDragDropSource()) {
|
||||
const char* source = entry.path().c_str();
|
||||
ImGui::SetDragDropPayload("CONTENT_BROWSER_PAYLOAD", source, (strlen(source) + 1) * sizeof(char), ImGuiCond_Once);
|
||||
|
||||
ImGui::EndDragDropSource();
|
||||
}
|
||||
|
||||
float columnWidth = ImGui::GetColumnWidth();
|
||||
float textWidth = ImGui::CalcTextSize(file_name.c_str()).x;
|
||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (columnWidth - textWidth) * 0.5f);
|
||||
ImGui::TextWrapped("%s", file_name.c_str());
|
||||
|
||||
ImGui::EndGroup();
|
||||
@@ -81,6 +92,7 @@ namespace OpenEngine {
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::Unindent();
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::End();
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace OpenEngine {
|
||||
RegisterDrawer<SpriteRendererComponent>("Sprite Renderer", &SpriteOnImGuiRender);
|
||||
RegisterDrawer<CameraComponent>("Camera", &CameraOnImGuiRender);
|
||||
RegisterDrawer<MeshComponent>("Mesh", &MeshOnImGuiRender);
|
||||
RegisterDrawer<MaterialComponent>("Material", &MaterialOnImGuiRender);
|
||||
|
||||
scene = context;
|
||||
selected_context = {};
|
||||
@@ -51,6 +52,11 @@ namespace OpenEngine {
|
||||
selected_context.AddComponent<MeshComponent>();
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
if (!selected_context.HasComponent<MaterialComponent>())
|
||||
if (ImGui::MenuItem("Material")) {
|
||||
selected_context.AddComponent<MaterialComponent>();
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
}
|
||||
|
||||
void EntityPopup(Ref<Scene>& scene)
|
||||
|
||||
Reference in New Issue
Block a user