various bug fix, serialization, adding shapes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "imgui.h"
|
||||
#include "open_engine/renderer/renderer3d.hpp"
|
||||
#include "open_engine/scene/components.hpp"
|
||||
#include <Jolt/Physics/Body/MotionType.h>
|
||||
#include <editor_component.hpp>
|
||||
#include <entt/entity/fwd.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
@@ -181,12 +182,11 @@ namespace OpenEngine {
|
||||
{
|
||||
auto& mesh_component = registry.get<MeshComponent>(entity);
|
||||
|
||||
const char* items[] = { "Quad", "Cube" };
|
||||
static int item_selected_idx = 0;
|
||||
const char* items[] = { "None", "Quad", "Cube" };
|
||||
|
||||
int item_selected_idx = (int)mesh_component.primitive_type;
|
||||
if (ImGui::BeginCombo("Mesh", items[item_selected_idx])) {
|
||||
for (int n = 0; n < 2; n++)
|
||||
{
|
||||
for (int n = 0; n < 3; n++) {
|
||||
const bool is_selected = (item_selected_idx == n);
|
||||
if (ImGui::Selectable(items[n], is_selected))
|
||||
item_selected_idx = n;
|
||||
@@ -196,25 +196,26 @@ namespace OpenEngine {
|
||||
ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
if ((int)mesh_component.primitive_type == (item_selected_idx + 1))
|
||||
return;
|
||||
if ((int)mesh_component.primitive_type == (item_selected_idx))
|
||||
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:
|
||||
mesh_component.primitive_type = (PrimitiveType)(item_selected_idx);
|
||||
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:
|
||||
mesh_component.mesh = nullptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,16 +234,53 @@ namespace OpenEngine {
|
||||
{
|
||||
auto& body_comp = registry.get<PhysicsBodyComponent>(entity);
|
||||
|
||||
const char* items[] = { "Static", "Kinematic", "Dynamic" };
|
||||
int item_selected_idx = body_comp.type;
|
||||
|
||||
if (ImGui::BeginCombo("Body type", items[item_selected_idx])) {
|
||||
for (int n = 0; n < 3; 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();
|
||||
}
|
||||
|
||||
body_comp.type = item_selected_idx;
|
||||
|
||||
ImGui::SliderFloat("Linear damping", &body_comp.linear_damping, 0, 1);
|
||||
ImGui::SliderFloat("Angular damping", &body_comp.angular_damping, 0, 1);
|
||||
ImGui::SliderFloat("Gravity factor", &body_comp.gravity_factor, 0, 1);
|
||||
ImGui::SliderFloat("Bounciness", &body_comp.restitution, 0, 1);
|
||||
ImGui::SliderFloat("Friction", &body_comp.friction, 0, 1);
|
||||
}
|
||||
|
||||
void ShapeOnImGuiRender(entt::registry ®istry, entt::entity entity)
|
||||
void SphereShapeOnImGuiRender(entt::registry ®istry, entt::entity entity)
|
||||
{
|
||||
auto& shape_comp = registry.get<PhysicsShapeComponent>(entity);
|
||||
auto& sphere_comp = registry.get<SphereShapeComponent>(entity);
|
||||
|
||||
ImGui::DragFloat("Radius",
|
||||
&sphere_comp.radius,
|
||||
0.1f,
|
||||
0.11f, FLT_MAX,
|
||||
"%.2f",
|
||||
ImGuiSliderFlags_AlwaysClamp);
|
||||
}
|
||||
|
||||
ImGui::SliderFloat("Bounciness", &shape_comp.restitution, 0, 1);
|
||||
ImGui::SliderFloat("Friction", &shape_comp.friction, 0, 1);
|
||||
void BoxShapeOnImGuiRender(entt::registry ®istry, entt::entity entity)
|
||||
{
|
||||
auto& box_comp = registry.get<BoxShapeComponent>(entity);
|
||||
|
||||
ImGui::DragFloat3("Size",
|
||||
glm::value_ptr(box_comp.size),
|
||||
0.1f,
|
||||
0.11f, FLT_MAX,
|
||||
"%.2f",
|
||||
ImGuiSliderFlags_AlwaysClamp);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user