Trenchbroom parser work with entities

Fixed lighting
Fixed global position system
Fixed child deletion system.
editor work for custom entities registration
This commit is contained in:
Antoine Pilote
2021-06-23 17:37:54 -04:00
parent 1740a5707f
commit c7dc3cc476
35 changed files with 753 additions and 486 deletions

View File

@@ -22,6 +22,7 @@
#include <src/Scene/Components/WrenScriptComponent.h>
#include <src/Rendering/MSAAFramebuffer.h>
#include "ProjectInterface.h"
#include <src/Scene/Systems/QuakeMapBuilder.h>
Ref<UI::UserInterface> userInterface;
ImFont* normalFont;
ImFont* EditorInterface::bigIconFont;
@@ -161,6 +162,7 @@ void EditorInterface::DrawViewport()
if (m_IsEntitySelected && !Engine::IsPlayMode)
{
TransformComponent& tc = m_SelectedEntity.GetComponent<TransformComponent>();
ParentComponent& parent = m_SelectedEntity.GetComponent<ParentComponent>();
glm::mat4 oldTransform = tc.GetTransform();
ImGuizmo::Manipulate(
glm::value_ptr(Engine::GetCurrentScene()->GetCurrentCamera()->GetTransform()),
@@ -180,6 +182,20 @@ void EditorInterface::DrawViewport()
scale = glm::vec3(0, 0, 0);
rotation = glm::conjugate(rotation);
glm::vec3 euler = glm::eulerAngles(rotation);
Vector3 globalPos = Vector3();
Entity currentParent = m_SelectedEntity;
if (parent.HasParent)
{
while (currentParent.GetComponent<ParentComponent>().HasParent) {
currentParent = currentParent.GetComponent<ParentComponent>().Parent;
globalPos -= currentParent.GetComponent<TransformComponent>().Translation;
}
translation = globalPos - translation;
}
tc.Translation = translation;
tc.Rotation = glm::vec3(glm::degrees(euler.x), glm::degrees(euler.y), glm::degrees(euler.z));
tc.Scale = scale;
@@ -188,6 +204,10 @@ void EditorInterface::DrawViewport()
}
else
{
ImGui::PopStyleVar();
}
ImGui::End();
@@ -590,7 +610,11 @@ void EditorInterface::DrawEntityPropreties()
ImGui::Checkbox("Build collisions?", &component.HasCollisions);
if (ImGui::Button("Build"))
component.Build();
{
QuakeMapBuilder mapBuilder;
mapBuilder.BuildQuakeMap(m_SelectedEntity);
}
ImGui::Separator();
}
}
@@ -888,9 +912,9 @@ void EditorInterface::DrawRessourceWindow()
std::string texture = FileDialog::OpenFile("*.png | *.jpg");
}
ImGui::SameLine();
ImGui::Checkbox("Use##1", &m_SelectedMaterial->UseAlbedo);
//ImGui::Checkbox("Use##1", &(bool)(m_SelectedMaterial->data.u_HasAlbedo));
ImGui::SameLine();
ImGui::ColorPicker4("Color", &m_SelectedMaterial->m_AlbedoColor.r);
ImGui::ColorPicker3("Color", &m_SelectedMaterial->data.m_AlbedoColor.r);
}
if (ImGui::CollapsingHeader("AO", ImGuiTreeNodeFlags_DefaultOpen))
{
@@ -906,9 +930,9 @@ void EditorInterface::DrawRessourceWindow()
}
}
ImGui::SameLine();
ImGui::Checkbox("Use##2", &m_SelectedMaterial->UseAO);
//ImGui::Checkbox("Use##2", &m_SelectedMaterial->data.u_HasAO);
ImGui::SameLine();
ImGui::DragFloat("Value##2", &m_SelectedMaterial->m_AOValue, 0.01f, 0.0f, 1.0f);
ImGui::DragFloat("Value##2", &m_SelectedMaterial->data.u_AOValue, 0.01f, 0.0f, 1.0f);
}
if (ImGui::CollapsingHeader("Normal", ImGuiTreeNodeFlags_DefaultOpen))
{
@@ -923,8 +947,8 @@ void EditorInterface::DrawRessourceWindow()
m_SelectedMaterial->SetNormal(TextureManager::Get()->GetTexture(texture));
}
}
ImGui::SameLine();
ImGui::Checkbox("Use##3", &m_SelectedMaterial->UseNormal);
//ImGui::SameLine();
//ImGui::Checkbox("Use##3", &m_SelectedMaterial->data.u_HasNormal);
}
if (ImGui::CollapsingHeader("Metalness", ImGuiTreeNodeFlags_DefaultOpen))
{
@@ -936,9 +960,9 @@ void EditorInterface::DrawRessourceWindow()
std::string texture = FileDialog::OpenFile("*.png | *.jpg");
}
ImGui::SameLine();
ImGui::Checkbox("Use##4", &m_SelectedMaterial->UseMetalness);
//ImGui::Checkbox("Use##4", &m_SelectedMaterial->data.u_HasMetalness);
ImGui::SameLine();
ImGui::DragFloat("Value##4", &m_SelectedMaterial->m_MetalnessValue, 0.01f, 0.0f, 1.0f);
ImGui::DragFloat("Value##4", &m_SelectedMaterial->data.u_MetalnessValue, 0.01f, 0.0f, 1.0f);
}
if (ImGui::CollapsingHeader("Roughness", ImGuiTreeNodeFlags_DefaultOpen))
{
@@ -950,9 +974,9 @@ void EditorInterface::DrawRessourceWindow()
std::string texture = FileDialog::OpenFile("*.png | *.jpg");
}
ImGui::SameLine();
ImGui::Checkbox("Use##5", &m_SelectedMaterial->UseRoughness);
//ImGui::Checkbox("Use##5", &m_SelectedMaterial->data.u_HasRoughness);
ImGui::SameLine();
ImGui::DragFloat("Value##5", &m_SelectedMaterial->m_RoughnessValue, 0.01f, 0.0f, 1.0f);
ImGui::DragFloat("Value##5", &m_SelectedMaterial->data.u_RoughnessValue, 0.01f, 0.0f, 1.0f);
}
}
else

View File

@@ -0,0 +1,28 @@
#pragma once
#include <vcruntime_string.h>
#include <string>
#include <src/Vendors/imgui/imgui.h>
void ImGuiTextSTD(const std::string& label, std::string& value)
{
char buffer[256];
memset(buffer, 0, sizeof(buffer));
std::strncpy(buffer, value.c_str(), sizeof(buffer));
if (ImGui::InputText(label.c_str(), buffer, sizeof(buffer)))
{
value = std::string(buffer);
}
}
void ImGuiTextMultiline(const std::string& label, std::string& value)
{
char buffer[256];
memset(buffer, 0, sizeof(buffer));
std::strncpy(buffer, value.c_str(), sizeof(buffer));
if (ImGui::InputTextMultiline(label.c_str(), buffer, sizeof(buffer)))
{
value = std::string(buffer);
}
}

View File

@@ -1,6 +1,7 @@
#include "ProjectInterface.h"
#include <src/Vendors/imgui/imgui.h>
#include "Engine.h"
#include "ImGuiTextHelper.h"
void ProjectInterface::DrawProjectSettings()
{
@@ -20,6 +21,7 @@ void ProjectInterface::DrawProjectSettings()
void ProjectInterface::DrawCreatePointEntity()
{
char buffer[256];
memset(buffer, 0, sizeof(buffer));
std::strncpy(buffer, Engine::GetProject()->Name.c_str(), sizeof(buffer));
@@ -30,32 +32,81 @@ void ProjectInterface::DrawCreatePointEntity()
}
FGDPointEntity newEntity;
const char* items[] = { "String", "Integer", "Float", "Boolean"};
void ProjectInterface::DrawEntitySettings()
{
if (ImGui::Begin("Entity definitions"))
{
ImGui::Text("This is the entity definition used by trenchbroom. This files allows you to see your entities inside Trenchbroom");
ImGui::Text("Trenchbroom path:");
// path here...
Ref<FGDFile> file = Engine::GetProject()->EntityDefinitionsFile;
auto flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize;
auto flags = ImGuiWindowFlags_NoTitleBar;
if (ImGui::BeginPopupModal("Create new point entity", NULL, flags))
{
ImGuiTextSTD("Name", newEntity.Name);
ImGuiTextMultiline("Description", newEntity.Description);
if (ImGui::BeginTable("DictCreate", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable))
{
ImGui::TableSetupColumn("Name");
ImGui::TableSetupColumn("Type");
ImGui::TableHeadersRow();
ImGui::TableNextColumn();
int idx = 0;
for (auto& p : newEntity.Properties)
{
ImGuiTextSTD("Name", p.name);
ImGui::TableNextColumn();
std::string current_item = NULL;
if(ImGui::BeginCombo(("TypeSelection" + std::to_string(idx)).c_str(), current_item.c_str()))
{
for (int n = 0; n < IM_ARRAYSIZE(items); n++)
{
bool is_selected = (p.type == (ClassPropertyType)n); // You can store your selection however you want, outside or inside your objects
if (ImGui::Selectable(items[n], is_selected))
if (is_selected)
{
p.type = (ClassPropertyType)n;
ImGui::SetItemDefaultFocus();
}
}
ImGui::EndCombo();
}
idx++;
ImGui::TableNextColumn();
}
if (ImGui::Button("Add new property")) {
newEntity.Properties.push_back(ClassProperty());
}
ImGui::EndTable();
}
ImGui::Button("Create");
ImGui::SameLine();
ImGui::Button("Cancel");
if (ImGui::Button("Cancel"))
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0, 100));
if (ImGui::BeginTabBar("##Tabs", ImGuiTabBarFlags_None))
{
if (ImGui::BeginTabItem("Point entities"))
{
ImVec2 avail = ImGui::GetContentRegionAvail();
avail.y *= .8;
ImGui::BeginChild("table_child", avail, false);
if (ImGui::BeginTable("nested1", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable))
{
ImGui::TableSetupColumn("Name");
@@ -78,10 +129,10 @@ void ProjectInterface::DrawEntitySettings()
ImGui::Button("Browse");
}
ImGui::EndTable();
}
ImGui::EndChild();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Brush entities"))
@@ -91,9 +142,11 @@ void ProjectInterface::DrawEntitySettings()
}
ImGui::EndTabBar();
}
ImGui::PopStyleVar();
if (ImGui::Button("Add new"))
ImGui::OpenPopup("Create new point entity");
}
ImGui::End();
}