Fixed math problem and display submeshes in editor panel

This commit is contained in:
a.pilote
2022-07-16 21:49:17 -04:00
parent 7d9e5b07b5
commit dbec248d8a
8 changed files with 78 additions and 20 deletions

View File

@@ -1,5 +1,8 @@
#pragma once
#include <src/Core/Core.h>
#include "ComponentPanel.h"
#include "ModelResourceInspector.h"
#include <src/Scene/Entities/ImGuiHelper.h>
#include <src/Scene/Components/MeshComponent.h>
@@ -7,9 +10,14 @@
#include <src/Core/String.h>
class MeshPanel : ComponentPanel {
private:
Scope<ModelResourceInspector> _modelInspector;
bool _expanded = false;
public:
MeshPanel() {}
MeshPanel()
{
CreateScope<ModelResourceInspector>();
}
void Draw(Nuake::Entity entity) override
{
@@ -23,7 +31,20 @@ public:
ImGui::TableNextColumn();
std::string label = std::to_string(component.ModelResource->ID);
ImGui::Button(label.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0));
if (ImGui::Button(label.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0)))
{
if (!_expanded)
{
_modelInspector = CreateScope<ModelResourceInspector>(component.ModelResource);
}
_expanded = !_expanded;
}
if (_expanded)
{
_modelInspector->Draw();
}
if (ImGui::BeginDragDropTarget())
{

View File

@@ -0,0 +1,23 @@
#include "ModelResourceInspector.h"
#include <imgui/imgui.h>
ModelResourceInspector::ModelResourceInspector(Ref<Nuake::Model> model)
{
_model = model;
}
void ModelResourceInspector::Draw()
{
ImGui::BeginChild("modelInspector",ImVec2(0,0), true);
{
for (uint32_t i = 0; i < std::size(_model->GetMeshes()); i++)
{
std::string headerLabel = "Mesh " + std::to_string(i);
if (ImGui::CollapsingHeader(headerLabel.c_str()))
{
}
}
}
ImGui::EndChild();
}

View File

@@ -0,0 +1,16 @@
#pragma once
#include <src/Core/Core.h>
#include <src/Resource/Model.h>
class ModelResourceInspector
{
private:
Ref<Nuake::Model> _model;
public:
ModelResourceInspector(Ref<Nuake::Model> model);
ModelResourceInspector() = default;
~ModelResourceInspector() = default;
void Draw();
};

View File

@@ -2,7 +2,7 @@
#include "ComponentPanel.h"
#include <src/Scene/Entities/ImGuiHelper.h>
#include <src/Scene/Components/TransformComponent.h>
#include <src/Core/Maths.h>
class TransformPanel : ComponentPanel {
public:
@@ -44,7 +44,7 @@ public:
if (eulerLocal != eulerAngles)
{
Quat rotation = QuatFromEuler(eulerAngles.x, eulerAngles.y, eulerAngles.z);
//component.SetLocalRotation(rotation);
component.SetLocalRotation(rotation);
}
ImGui::TableNextColumn();

View File

@@ -1,13 +0,0 @@
#include "src/Core/Maths.h"
namespace Nuake
{
Quat QuatFromEuler(float x, float y, float z)
{
// Taken from: https://gamedev.stackexchange.com/questions/13436/glm-euler-angles-to-quaternion
Quat QuatAroundX = Quat(x, Vector3(1.0, 0.0, 0.0));
Quat QuatAroundY = Quat(y, Vector3(0.0, 1.0, 0.0));
Quat QuatAroundZ = Quat(z, Vector3(0.0, 0.0, 1.0));
return QuatAroundX * QuatAroundY * QuatAroundZ;
}
}

View File

@@ -202,7 +202,5 @@ namespace Nuake
}
}
}
}
}

12
Nuake/src/Core/Maths.cpp Normal file
View File

@@ -0,0 +1,12 @@
#include "src/Core/Maths.h"
using namespace Nuake;
Quat Nuake::QuatFromEuler(float x, float y, float z)
{
// Taken from: https://gamedev.stackexchange.com/questions/13436/glm-euler-angles-to-quaternion
Quat QuatAroundX = Quat(x, Vector3(1.0, 0.0, 0.0));
Quat QuatAroundY = Quat(y, Vector3(0.0, 1.0, 0.0));
Quat QuatAroundZ = Quat(z, Vector3(0.0, 0.0, 1.0));
return QuatAroundX * QuatAroundY * QuatAroundZ;
}

View File

@@ -6,6 +6,7 @@
#include <src/Vendors/glm/ext/vector_float2.hpp>
#include <src/Vendors/glm/ext/matrix_float4x4.hpp>
#include <glm/gtx/quaternion.hpp>
namespace Nuake
{
// Type definitions