Added skeleton creation

This commit is contained in:
Antoine Pilote
2023-09-05 20:28:33 -04:00
parent 33e04e9216
commit e125bf5fdb
6 changed files with 125 additions and 6 deletions

View File

@@ -0,0 +1,36 @@
#pragma once
#include "ComponentPanel.h"
#include <src/Core/FileSystem.h>
#include <src/Core/Maths.h>
#include <src/Scene/Components/BoneComponent.h>
#include <src/Scene/Entities/ImGuiHelper.h>
class BonePanel : ComponentPanel
{
public:
BonePanel() {}
void Draw(Nuake::Entity entity) override
{
using namespace Nuake;
if (!entity.HasComponent<BoneComponent>())
return;
auto& component = entity.GetComponent<BoneComponent>();
BeginComponentTable(BONE, BoneComponent);
{
{
ImGui::Text("Name");
ImGui::TableNextColumn();
ImGui::InputText("##BoneName", &component.Name);
ImGui::TableNextColumn();
ComponentTableReset(component.Name, "");
}
}
EndComponentTable();
}
};

View File

@@ -12,8 +12,9 @@
class SkinnedModelPanel : ComponentPanel
{
private:
Scope<ModelResourceInspector> _modelInspector;
bool _expanded = false;
Scope<ModelResourceInspector> m_ModelInspector;
bool m_Expanded = false;
std::string m_QueuedModelPath;
public:
SkinnedModelPanel()
@@ -45,9 +46,9 @@ public:
{
}
if (_expanded)
if (m_Expanded)
{
_modelInspector->Draw();
m_ModelInspector->Draw();
}
if (ImGui::BeginDragDropTarget())
@@ -64,13 +65,41 @@ public:
}
else
{
component.ModelPath = fullPath;
component.LoadModel();
m_QueuedModelPath = fullPath;
ImGui::OpenPopup("Create Skeleton");
}
}
ImGui::EndDragDropTarget();
}
if (ImGui::BeginPopupModal("Create Skeleton", NULL, ImGuiWindowFlags_AlwaysAutoResize))
{
ImGui::SetItemDefaultFocus();
ImGui::Text("Would you like to create the skeleton structure in the scene tree?");
ImGui::Separator();
if (ImGui::Button("OK", ImVec2(120, 0)))
{
component.ModelPath = m_QueuedModelPath;
component.LoadModel();
Scene* scene = entity.GetScene();
scene->CreateSkeleton(entity);
ImGui::CloseCurrentPopup();
}
ImGui::SetItemDefaultFocus();
ImGui::SameLine();
if (ImGui::Button("Cancel", ImVec2(120, 0)))
{
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
ImGui::TableNextColumn();
ComponentTableReset(component.ModelPath, "");
}

View File

@@ -0,0 +1,8 @@
#include "src/Core/Core.h"
#include "BoneComponent.h"
namespace Nuake
{
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include "src/Core/Core.h"
namespace Nuake
{
class BoneComponent
{
public:
BoneComponent() = default;
~BoneComponent() = default;
std::string Name;
};
}

View File

@@ -24,6 +24,7 @@
#include "src/Scene/Components/WrenScriptComponent.h"
#include "src/Scene/Components/BSPBrushComponent.h"
#include "src/Scene/Components/InterfaceComponent.h"
#include "src/Scene/Components/SkinnedModelComponent.h"
#include <fstream>
#include <future>
@@ -448,4 +449,31 @@ namespace Nuake
return true;
}
void Scene::CreateSkeleton(Entity& entity)
{
// We cannot create a component if the entity doesn't have a skinned model
if (!entity.HasComponent<SkinnedModelComponent>())
{
const std::string msg = "Cannot create a skeleton on entity: " + std::to_string(entity.GetID());
Logger::Log(msg);
return;
}
SkinnedModelComponent& component = entity.GetComponent<SkinnedModelComponent>();
for (Ref<SkinnedMesh>& model : component.ModelResource->GetMeshes())
{
auto& bones = model->GetBones();
if (bones.size() > 0)
{
for (auto& bone : bones)
{
auto& parentComponent = entity.GetComponent<ParentComponent>();
Entity boneEntity = CreateEntity(bone.Name);
entity.AddChild(boneEntity);
}
}
}
}
}

View File

@@ -89,5 +89,8 @@ namespace Nuake
json Serialize() override;
bool Deserialize(const json& j) override;
// Component specific utilies
void CreateSkeleton(Entity& entity);
};
}