improved model loading and added model component
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
#ifndef EDITOR_HPP
|
||||
#define EDITOR_HPP
|
||||
|
||||
#include <X11/X.h>
|
||||
#include <open_engine.hpp>
|
||||
|
||||
#include "open_engine/fastgltf.hpp"
|
||||
#include "open_engine/logging.hpp"
|
||||
#include "open_engine/ref_scope.hpp"
|
||||
#include "open_engine/renderer/model3d.hpp"
|
||||
#include "open_engine/renderer/renderer3d.hpp"
|
||||
#include "open_engine/scene/components.hpp"
|
||||
#include "panels/content_browser.hpp"
|
||||
@@ -135,11 +135,16 @@ namespace OpenEngine {
|
||||
// ============================================================
|
||||
|
||||
Entity cube3 = scene->CreateEntity("glb");
|
||||
Entity cube4 = scene->CreateEntity("glb2");
|
||||
cube3.AddComponent<TransformComponent>();
|
||||
cube4.AddComponent<TransformComponent>();
|
||||
|
||||
Ref<Mesh> test = TestGLTF();
|
||||
Ref<Model3D> model = Model3D::Create("./assets/models/cubes.glb");
|
||||
Ref<Model3D> model2 = Model3D::Create("./assets/models/cube_legs.glb");
|
||||
Ref<Model3D> monkey = Model3D::Create("./assets/models/monkey.glb");
|
||||
|
||||
cube3.AddComponent<MeshComponent>(CreateMesh(test->vertices, test->indices, (uint32_t)cube3));
|
||||
cube3.AddComponent<ModelComponent>(model);
|
||||
cube4.AddComponent<ModelComponent>(monkey);
|
||||
|
||||
/*
|
||||
auto view = scene->GetRegistry().view<TagComponent>();
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace OpenEngine {
|
||||
void SphereShapeOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||
void BoxShapeOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||
void PlaneShapeOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||
void ModelOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||
}
|
||||
|
||||
#endif // EDITOR_COMPONENT_HPP
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "open_engine/renderer/renderer3d.hpp"
|
||||
#include "open_engine/scene/components.hpp"
|
||||
#include <Jolt/Physics/Body/MotionType.h>
|
||||
#include <cstdint>
|
||||
#include <editor_component.hpp>
|
||||
#include <entt/entity/fwd.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
@@ -295,4 +296,33 @@ namespace OpenEngine {
|
||||
"%.2f",
|
||||
ImGuiSliderFlags_AlwaysClamp);
|
||||
}
|
||||
|
||||
void ModelOnImGuiRender(entt::registry& registry, entt::entity entity)
|
||||
{
|
||||
auto& model_comp = registry.get<ModelComponent>(entity);
|
||||
|
||||
bool opened = ImGui::TreeNodeEx(
|
||||
(void*)(intptr_t)entity,
|
||||
ImGuiTreeNodeFlags_None,
|
||||
"Meshes",
|
||||
nullptr
|
||||
);
|
||||
|
||||
if (opened) {
|
||||
unsigned int i = 0;
|
||||
for (auto& mesh : model_comp.model->GetMeshes())
|
||||
ImGui::Text("Mesh: %i", i++);
|
||||
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, {1, 1, 1, 1});
|
||||
if (ImGui::BeginChild("Material list")) {
|
||||
for (auto& mesh : model_comp.model->GetMeshes())
|
||||
ImGui::Text("Material: %s", mesh.material.name.c_str());
|
||||
ImGui::EndChild();
|
||||
}
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace OpenEngine {
|
||||
RegisterDrawer<SphereShapeComponent>("Sphere Shape", &SphereShapeOnImGuiRender);
|
||||
RegisterDrawer<BoxShapeComponent>("Box Shape", &BoxShapeOnImGuiRender);
|
||||
RegisterDrawer<PlaneShapeComponent>("Plane Shape", &PlaneShapeOnImGuiRender);
|
||||
RegisterDrawer<ModelComponent>("Model", &ModelOnImGuiRender);
|
||||
|
||||
scene = context;
|
||||
selected_context = {};
|
||||
@@ -81,6 +82,11 @@ namespace OpenEngine {
|
||||
selected_context.AddComponent<PlaneShapeComponent>();
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
if (!selected_context.HasComponent<ModelComponent>())
|
||||
if (ImGui::MenuItem("Model")) {
|
||||
selected_context.AddComponent<ModelComponent>();
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
}
|
||||
|
||||
void EntityPopup(Ref<Scene>& scene)
|
||||
|
||||
Reference in New Issue
Block a user