various bug fix, serialization, adding shapes
This commit is contained in:
@@ -19,7 +19,8 @@ namespace OpenEngine {
|
|||||||
void MeshOnImGuiRender(entt::registry®istry, entt::entity entity);
|
void MeshOnImGuiRender(entt::registry®istry, entt::entity entity);
|
||||||
void MaterialOnImGuiRender(entt::registry& registry, entt::entity entity);
|
void MaterialOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||||
void BodyOnImGuiRender(entt::registry& registry, entt::entity entity);
|
void BodyOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||||
void ShapeOnImGuiRender(entt::registry& registry, entt::entity entity);
|
void SphereShapeOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||||
|
void BoxShapeOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // EDITOR_COMPONENT_HPP
|
#endif // EDITOR_COMPONENT_HPP
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "open_engine/renderer/renderer3d.hpp"
|
#include "open_engine/renderer/renderer3d.hpp"
|
||||||
#include "open_engine/scene/components.hpp"
|
#include "open_engine/scene/components.hpp"
|
||||||
|
#include <Jolt/Physics/Body/MotionType.h>
|
||||||
#include <editor_component.hpp>
|
#include <editor_component.hpp>
|
||||||
#include <entt/entity/fwd.hpp>
|
#include <entt/entity/fwd.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
@@ -181,12 +182,11 @@ namespace OpenEngine {
|
|||||||
{
|
{
|
||||||
auto& mesh_component = registry.get<MeshComponent>(entity);
|
auto& mesh_component = registry.get<MeshComponent>(entity);
|
||||||
|
|
||||||
const char* items[] = { "Quad", "Cube" };
|
const char* items[] = { "None", "Quad", "Cube" };
|
||||||
static int item_selected_idx = 0;
|
|
||||||
|
|
||||||
|
int item_selected_idx = (int)mesh_component.primitive_type;
|
||||||
if (ImGui::BeginCombo("Mesh", items[item_selected_idx])) {
|
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);
|
const bool is_selected = (item_selected_idx == n);
|
||||||
if (ImGui::Selectable(items[n], is_selected))
|
if (ImGui::Selectable(items[n], is_selected))
|
||||||
item_selected_idx = n;
|
item_selected_idx = n;
|
||||||
@@ -196,11 +196,12 @@ namespace OpenEngine {
|
|||||||
ImGui::SetItemDefaultFocus();
|
ImGui::SetItemDefaultFocus();
|
||||||
}
|
}
|
||||||
ImGui::EndCombo();
|
ImGui::EndCombo();
|
||||||
|
}
|
||||||
|
|
||||||
if ((int)mesh_component.primitive_type == (item_selected_idx + 1))
|
if ((int)mesh_component.primitive_type == (item_selected_idx))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mesh_component.primitive_type = (PrimitiveType)(item_selected_idx + 1);
|
mesh_component.primitive_type = (PrimitiveType)(item_selected_idx);
|
||||||
switch (mesh_component.primitive_type) {
|
switch (mesh_component.primitive_type) {
|
||||||
case OpenEngine::PrimitiveType::Quad:
|
case OpenEngine::PrimitiveType::Quad:
|
||||||
{
|
{
|
||||||
@@ -213,10 +214,10 @@ namespace OpenEngine {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
mesh_component.mesh = nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void MaterialOnImGuiRender(entt::registry& registry, entt::entity entity)
|
void MaterialOnImGuiRender(entt::registry& registry, entt::entity entity)
|
||||||
{
|
{
|
||||||
@@ -233,16 +234,53 @@ namespace OpenEngine {
|
|||||||
{
|
{
|
||||||
auto& body_comp = registry.get<PhysicsBodyComponent>(entity);
|
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("Linear damping", &body_comp.linear_damping, 0, 1);
|
||||||
ImGui::SliderFloat("Angular damping", &body_comp.angular_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("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::SliderFloat("Bounciness", &shape_comp.restitution, 0, 1);
|
ImGui::DragFloat("Radius",
|
||||||
ImGui::SliderFloat("Friction", &shape_comp.friction, 0, 1);
|
&sphere_comp.radius,
|
||||||
|
0.1f,
|
||||||
|
0.11f, FLT_MAX,
|
||||||
|
"%.2f",
|
||||||
|
ImGuiSliderFlags_AlwaysClamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ namespace OpenEngine {
|
|||||||
RegisterDrawer<MeshComponent>("Mesh", &MeshOnImGuiRender);
|
RegisterDrawer<MeshComponent>("Mesh", &MeshOnImGuiRender);
|
||||||
RegisterDrawer<MaterialComponent>("Material", &MaterialOnImGuiRender);
|
RegisterDrawer<MaterialComponent>("Material", &MaterialOnImGuiRender);
|
||||||
RegisterDrawer<PhysicsBodyComponent>("Physics Body", &BodyOnImGuiRender);
|
RegisterDrawer<PhysicsBodyComponent>("Physics Body", &BodyOnImGuiRender);
|
||||||
RegisterDrawer<PhysicsShapeComponent>("Physics Shape", &ShapeOnImGuiRender);
|
RegisterDrawer<SphereShapeComponent>("Sphere Shape", &SphereShapeOnImGuiRender);
|
||||||
|
RegisterDrawer<BoxShapeComponent>("Box Shape", &BoxShapeOnImGuiRender);
|
||||||
|
|
||||||
scene = context;
|
scene = context;
|
||||||
selected_context = {};
|
selected_context = {};
|
||||||
@@ -64,9 +65,14 @@ namespace OpenEngine {
|
|||||||
selected_context.AddComponent<PhysicsBodyComponent>();
|
selected_context.AddComponent<PhysicsBodyComponent>();
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
}
|
}
|
||||||
if (!selected_context.HasComponent<PhysicsShapeComponent>())
|
if (!selected_context.HasComponent<SphereShapeComponent>())
|
||||||
if (ImGui::MenuItem("Physics shape")) {
|
if (ImGui::MenuItem("Sphere shape")) {
|
||||||
selected_context.AddComponent<PhysicsShapeComponent>();
|
selected_context.AddComponent<SphereShapeComponent>();
|
||||||
|
ImGui::CloseCurrentPopup();
|
||||||
|
}
|
||||||
|
if (!selected_context.HasComponent<BoxShapeComponent>())
|
||||||
|
if (ImGui::MenuItem("Box shape")) {
|
||||||
|
selected_context.AddComponent<BoxShapeComponent>();
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <Jolt/Physics/Body/BodyActivationListener.h>
|
#include <Jolt/Physics/Body/BodyActivationListener.h>
|
||||||
|
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
using namespace JPH;
|
using namespace JPH;
|
||||||
using namespace JPH::literals;
|
using namespace JPH::literals;
|
||||||
@@ -73,6 +74,8 @@ namespace BroadPhaseLayers
|
|||||||
static constexpr uint NUM_LAYERS(2);
|
static constexpr uint NUM_LAYERS(2);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline JPH::Vec3 ToJolt(const glm::vec3& v) { return JPH::Vec3(v.x, v.y, v.z); };
|
||||||
|
|
||||||
class BPLayerInterfaceImpl final : public BroadPhaseLayerInterface
|
class BPLayerInterfaceImpl final : public BroadPhaseLayerInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -124,23 +124,27 @@ namespace OpenEngine {
|
|||||||
float linear_damping = 0.05f;
|
float linear_damping = 0.05f;
|
||||||
float angular_damping = 0.05f;
|
float angular_damping = 0.05f;
|
||||||
float gravity_factor = 1.0f;
|
float gravity_factor = 1.0f;
|
||||||
|
float restitution = 0.8f;
|
||||||
|
float friction = 0.5f;
|
||||||
|
|
||||||
EMotionType type = EMotionType::Dynamic;
|
int type = (int)EMotionType::Static;
|
||||||
EActivation initial_activation_state = EActivation::Activate;
|
int initial_activation_state = (int)EActivation::Activate;
|
||||||
ObjectLayer layer = Layers::MOVING;
|
int layer = (int)Layers::MOVING;
|
||||||
|
|
||||||
PhysicsBodyComponent() = default;
|
PhysicsBodyComponent() = default;
|
||||||
PhysicsBodyComponent(const PhysicsBodyComponent&) = default;
|
PhysicsBodyComponent(const PhysicsBodyComponent&) = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PhysicsShapeComponent
|
// TODO: Let's add more shapes
|
||||||
|
struct BoxShapeComponent
|
||||||
{
|
{
|
||||||
ShapeRefC shape;
|
glm::vec3 size = { 1.0f, 1.0f, 1.0f };
|
||||||
|
|
||||||
float restitution = 0.8f;
|
|
||||||
float friction = 0.5f;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SphereShapeComponent
|
||||||
|
{
|
||||||
|
float radius = 1.0f;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // COMPONENTS_HPP
|
#endif // COMPONENTS_HPP
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ namespace OpenEngine {
|
|||||||
public:
|
public:
|
||||||
Scene() = default;
|
Scene() = default;
|
||||||
~Scene() = default;
|
~Scene() = default;
|
||||||
|
Scene(Scene& other) {};
|
||||||
|
|
||||||
void OnRuntimeStart();
|
void OnRuntimeStart();
|
||||||
void OnRuntimeStop();
|
void OnRuntimeStop();
|
||||||
@@ -52,8 +53,6 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
std::vector<entt::entity> pending_deletion;
|
std::vector<entt::entity> pending_deletion;
|
||||||
|
|
||||||
//BodyID sphere_id;
|
|
||||||
|
|
||||||
friend class SceneSerializer;
|
friend class SceneSerializer;
|
||||||
friend class Entity;
|
friend class Entity;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
#include "logging.hpp"
|
#include "logging.hpp"
|
||||||
|
#include "physics.hpp"
|
||||||
|
#include "ref_scope.hpp"
|
||||||
|
#include <Jolt/Physics/Body/MotionType.h>
|
||||||
|
#include <Jolt/Physics/Collision/ObjectLayer.h>
|
||||||
|
#include <Jolt/Physics/Collision/Shape/ConvexShape.h>
|
||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
|
|
||||||
#include <renderer/renderer3d.hpp>
|
#include <renderer/renderer3d.hpp>
|
||||||
@@ -8,6 +13,7 @@
|
|||||||
#include <core/time.hpp>
|
#include <core/time.hpp>
|
||||||
|
|
||||||
#include <Jolt/Physics/Collision/Shape/Shape.h>
|
#include <Jolt/Physics/Collision/Shape/Shape.h>
|
||||||
|
#include <Jolt/Physics/Collision/Shape/BoxShape.h>
|
||||||
#include <Jolt/Physics/Collision/Shape/SphereShape.h>
|
#include <Jolt/Physics/Collision/Shape/SphereShape.h>
|
||||||
#include <Jolt/Physics/EActivation.h>
|
#include <Jolt/Physics/EActivation.h>
|
||||||
#include <Jolt/Math/Real.h>
|
#include <Jolt/Math/Real.h>
|
||||||
@@ -17,60 +23,64 @@
|
|||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
|
|
||||||
|
static Ref<ShapeSettings> CreateShape(entt::registry& reg, entt::entity e)
|
||||||
|
{
|
||||||
|
if (reg.any_of<BoxShapeComponent>(e)) {
|
||||||
|
auto& c = reg.get<BoxShapeComponent>(e);
|
||||||
|
return CreateRef<BoxShapeSettings>(ToJolt(c.size * 0.5f));
|
||||||
|
}
|
||||||
|
if (reg.any_of<SphereShapeComponent>(e)) {
|
||||||
|
auto& c = reg.get<SphereShapeComponent>(e);
|
||||||
|
return CreateRef<SphereShapeSettings>(c.radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
OE_CORE_ERROR("Entity has no shape component!");
|
||||||
|
return nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
void Scene::OnRuntimeStart()
|
void Scene::OnRuntimeStart()
|
||||||
{
|
{
|
||||||
body_interface = &physics_engine.GetBodyInterface();
|
body_interface = &physics_engine.GetBodyInterface();
|
||||||
|
|
||||||
BoxShapeSettings floor_shape_settings(Vec3(100.0f, 1.0f, 100.0f));
|
|
||||||
floor_shape_settings.SetEmbedded(); // A ref counted object on the stack (base class RefTarget) should be marked as such to prevent it from being freed when its reference count goes to 0.
|
|
||||||
|
|
||||||
// Create the shape
|
|
||||||
ShapeSettings::ShapeResult floor_shape_result = floor_shape_settings.Create();
|
|
||||||
ShapeRefC floor_shape = floor_shape_result.Get(); // We don't expect an error here, but you can check floor_shape_result for HasError() / GetError()
|
|
||||||
|
|
||||||
// Create the settings for the body itself. Note that here you can also set other properties like the restitution / friction.
|
|
||||||
BodyCreationSettings floor_settings(floor_shape, RVec3(0.0_r, -1.0_r, 0.0_r), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING);
|
|
||||||
|
|
||||||
// Create the actual rigid body
|
|
||||||
Body *floor = body_interface->CreateBody(floor_settings); // Note that if we run out of bodies this can return nullptr
|
|
||||||
|
|
||||||
// Add it to the world
|
|
||||||
body_interface->AddBody(floor->GetID(), EActivation::DontActivate);
|
|
||||||
|
|
||||||
// TODO: Cleanup components aquisition
|
// TODO: Cleanup components aquisition
|
||||||
auto view = registry.view<TransformComponent, PhysicsBodyComponent>();
|
auto view = registry.view<TransformComponent, PhysicsBodyComponent>();
|
||||||
for (auto e : view) {
|
for (auto e : view) {
|
||||||
Entity entity = { e, this };
|
Entity entity = { e, this };
|
||||||
|
|
||||||
|
auto shape_settings = CreateShape(registry, e);
|
||||||
|
if (!shape_settings)
|
||||||
|
shape_settings = CreateRef<BoxShapeSettings>(Vec3(0.5f, 0.5f, 0.5f));
|
||||||
|
|
||||||
|
auto shape_result = shape_settings->Create();
|
||||||
|
if (shape_result.HasError()) {
|
||||||
|
OE_CORE_ERROR("Shape creation failed: {}", shape_result.GetError().c_str());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ShapeRefC shape = shape_result.Get();
|
||||||
|
|
||||||
auto& pbc = entity.GetComponents<PhysicsBodyComponent>();
|
auto& pbc = entity.GetComponents<PhysicsBodyComponent>();
|
||||||
auto& tc = entity.GetComponents<TransformComponent>();
|
auto& tc = entity.GetComponents<TransformComponent>();
|
||||||
|
|
||||||
PhysicsShapeComponent* psc = nullptr;
|
|
||||||
if (entity.HasComponent<PhysicsShapeComponent>())
|
|
||||||
psc = &entity.GetComponents<PhysicsShapeComponent>();
|
|
||||||
|
|
||||||
glm::vec3& pos = tc.translation;
|
glm::vec3& pos = tc.translation;
|
||||||
glm::vec3& scale = tc.scale;
|
glm::vec3& scale = tc.scale;
|
||||||
glm::vec3& rot = tc.rotation;
|
glm::vec3& rot = tc.rotation;
|
||||||
|
|
||||||
Quat quat = Quat::sEulerAngles(Vec3(rot.x, rot.y, rot.z));
|
Quat quat = Quat::sEulerAngles(Vec3(rot.x, rot.y, rot.z));
|
||||||
BodyCreationSettings settings(
|
BodyCreationSettings settings(
|
||||||
new BoxShape(Vec3(scale.x * 0.5, scale.y * 0.5f, scale.z * 0.5f)),
|
shape,
|
||||||
|
//new BoxShape(Vec3(scale.x * 0.5, scale.y * 0.5f, scale.z * 0.5f)),
|
||||||
Vec3(pos.x, pos.y, pos.z),
|
Vec3(pos.x, pos.y, pos.z),
|
||||||
quat,
|
quat,
|
||||||
pbc.type,
|
(EMotionType)pbc.type,
|
||||||
pbc.layer);
|
pbc.layer);
|
||||||
|
|
||||||
settings.mLinearDamping = pbc.linear_damping;
|
settings.mLinearDamping = pbc.linear_damping;
|
||||||
settings.mAngularDamping = pbc.angular_damping;
|
settings.mAngularDamping = pbc.angular_damping;
|
||||||
settings.mGravityFactor = pbc.gravity_factor;
|
settings.mGravityFactor = pbc.gravity_factor;
|
||||||
|
settings.mRestitution = pbc.restitution;
|
||||||
|
settings.mFriction = pbc.friction;
|
||||||
|
settings.mObjectLayer = (ObjectLayer)pbc.layer;
|
||||||
|
|
||||||
if (psc != nullptr) {
|
pbc.body = body_interface->CreateAndAddBody(settings, (EActivation)pbc.initial_activation_state);
|
||||||
settings.mRestitution = psc->restitution;
|
|
||||||
settings.mFriction = psc->friction;
|
|
||||||
}
|
|
||||||
|
|
||||||
pbc.body = body_interface->CreateAndAddBody(settings, pbc.initial_activation_state);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,14 +167,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
body_interface->SetPosition(body.body, { pos.x, pos.y, pos.z }, EActivation::Activate);
|
body_interface->SetPosition(body.body, { pos.x, pos.y, pos.z }, EActivation::Activate);
|
||||||
|
|
||||||
PhysicsShapeComponent* shape;
|
body_interface->SetRestitution(body.body, body.restitution);
|
||||||
if (entity.HasComponent<PhysicsShapeComponent>()) {
|
body_interface->SetFriction(body.body, body.friction);
|
||||||
shape = &entity.GetComponents<PhysicsShapeComponent>();
|
|
||||||
|
|
||||||
body_interface->SetRestitution(body.body, shape->restitution);
|
|
||||||
body_interface->SetFriction(body.body, shape->friction);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OnUpdatePhysics();
|
OnUpdatePhysics();
|
||||||
@@ -209,14 +213,13 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
for (const auto& e : view) {
|
for (const auto& e : view) {
|
||||||
auto [transform, mesh] = view.get<TransformComponent, MeshComponent>(e);
|
auto [transform, mesh] = view.get<TransformComponent, MeshComponent>(e);
|
||||||
|
|
||||||
Material* material;
|
|
||||||
|
|
||||||
Entity entity(e, this);
|
Entity entity(e, this);
|
||||||
if (entity.HasComponent<MaterialComponent>())
|
|
||||||
material = &entity.GetComponents<MaterialComponent>().material;
|
|
||||||
|
|
||||||
Renderer3D::DrawMesh(mesh.mesh, *material, GetTransformFromComp(transform));
|
Material material;
|
||||||
|
if (entity.HasComponent<MaterialComponent>())
|
||||||
|
material = entity.GetComponents<MaterialComponent>().material;
|
||||||
|
|
||||||
|
Renderer3D::DrawMesh(mesh.mesh, material, GetTransformFromComp(transform));
|
||||||
/*
|
/*
|
||||||
if (sprite.texture)
|
if (sprite.texture)
|
||||||
Renderer2D::DrawQuad(GetTransformFromComp(transform),
|
Renderer2D::DrawQuad(GetTransformFromComp(transform),
|
||||||
@@ -247,6 +250,7 @@ namespace OpenEngine {
|
|||||||
if (_entity.HasComponent<MaterialComponent>())
|
if (_entity.HasComponent<MaterialComponent>())
|
||||||
material = _entity.GetComponents<MaterialComponent>().material;
|
material = _entity.GetComponents<MaterialComponent>().material;
|
||||||
|
|
||||||
|
if (mesh.mesh)
|
||||||
Renderer3D::DrawMesh(mesh.mesh, material, GetTransformFromComp(transform));
|
Renderer3D::DrawMesh(mesh.mesh, material, GetTransformFromComp(transform));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,7 +332,12 @@ namespace OpenEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
void Scene::OnComponentAdded<PhysicsShapeComponent>(Entity entity, PhysicsShapeComponent& component)
|
void Scene::OnComponentAdded<SphereShapeComponent>(Entity entity, SphereShapeComponent& component)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
void Scene::OnComponentAdded<BoxShapeComponent>(Entity entity, BoxShapeComponent& component)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,8 +115,7 @@ namespace OpenEngine {
|
|||||||
out << YAML::EndMap; // TransformComponent
|
out << YAML::EndMap; // TransformComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity.HasComponent<CameraComponent>())
|
if (entity.HasComponent<CameraComponent>()) {
|
||||||
{
|
|
||||||
out << YAML::Key << "CameraComponent";
|
out << YAML::Key << "CameraComponent";
|
||||||
out << YAML::BeginMap; // CameraComponent
|
out << YAML::BeginMap; // CameraComponent
|
||||||
|
|
||||||
@@ -151,8 +150,7 @@ namespace OpenEngine {
|
|||||||
out << YAML::EndMap; // SpriteRendererComponent
|
out << YAML::EndMap; // SpriteRendererComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity.HasComponent<MeshComponent>())
|
if (entity.HasComponent<MeshComponent>()) {
|
||||||
{
|
|
||||||
out << YAML::Key << "MeshComponent";
|
out << YAML::Key << "MeshComponent";
|
||||||
out << YAML::BeginMap; // MeshComponent
|
out << YAML::BeginMap; // MeshComponent
|
||||||
|
|
||||||
@@ -162,8 +160,7 @@ namespace OpenEngine {
|
|||||||
out << YAML::EndMap; // MeshComponent
|
out << YAML::EndMap; // MeshComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity.HasComponent<MaterialComponent>())
|
if (entity.HasComponent<MaterialComponent>()) {
|
||||||
{
|
|
||||||
out << YAML::Key << "MaterialComponent";
|
out << YAML::Key << "MaterialComponent";
|
||||||
out << YAML::BeginMap; // MaterialComponent
|
out << YAML::BeginMap; // MaterialComponent
|
||||||
|
|
||||||
@@ -177,6 +174,44 @@ namespace OpenEngine {
|
|||||||
out << YAML::EndMap; // MaterialComponent
|
out << YAML::EndMap; // MaterialComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (entity.HasComponent<PhysicsBodyComponent>()) {
|
||||||
|
out << YAML::Key << "PhysicsBodyComponent";
|
||||||
|
out << YAML::BeginMap; // PhysicsBodyComponent
|
||||||
|
|
||||||
|
auto& pbc = entity.GetComponents<PhysicsBodyComponent>();
|
||||||
|
out << YAML::Key << "LinearDamping" << YAML::Value << pbc.linear_damping;
|
||||||
|
out << YAML::Key << "AngularDamping" << YAML::Value << pbc.angular_damping;
|
||||||
|
out << YAML::Key << "GravityFactor" << YAML::Value << pbc.gravity_factor;
|
||||||
|
out << YAML::Key << "Restitution" << YAML::Value << pbc.restitution;
|
||||||
|
out << YAML::Key << "Friction" << YAML::Value << pbc.friction;
|
||||||
|
|
||||||
|
out << YAML::Key << "Type" << YAML::Value << pbc.type;
|
||||||
|
out << YAML::Key << "ActivationState" << YAML::Value << pbc.initial_activation_state;
|
||||||
|
out << YAML::Key << "Layer" << YAML::Value << pbc.layer;
|
||||||
|
|
||||||
|
out << YAML::EndMap; // PhysicsBodyComponent
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.HasComponent<BoxShapeComponent>()) {
|
||||||
|
out << YAML::Key << "BoxShapeComponent";
|
||||||
|
out << YAML::BeginMap; //BoxShapeComponent
|
||||||
|
|
||||||
|
auto& bsc = entity.GetComponents<BoxShapeComponent>();
|
||||||
|
out << YAML::Key << "Size" << YAML::Value << bsc.size;
|
||||||
|
|
||||||
|
out << YAML::EndMap; //BoxShapeComponent
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.HasComponent<SphereShapeComponent>()) {
|
||||||
|
out << YAML::Key << "SphereShapeComponent";
|
||||||
|
out << YAML::BeginMap; //SphereShapeComponent
|
||||||
|
|
||||||
|
auto& ssc = entity.GetComponents<SphereShapeComponent>();
|
||||||
|
out << YAML::Key << "Radius" << YAML::Value << ssc.radius;
|
||||||
|
|
||||||
|
out << YAML::EndMap; //SphereShapeComponent
|
||||||
|
}
|
||||||
|
|
||||||
out << YAML::EndMap;
|
out << YAML::EndMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,8 +327,7 @@ namespace OpenEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto material_component = entity["MaterialComponent"];
|
auto material_component = entity["MaterialComponent"];
|
||||||
if (material_component)
|
if (material_component) {
|
||||||
{
|
|
||||||
auto& material = deserializedEntity.AddComponent<MaterialComponent>();
|
auto& material = deserializedEntity.AddComponent<MaterialComponent>();
|
||||||
material.material.albedo = material_component["Albedo"].as<glm::vec4>();
|
material.material.albedo = material_component["Albedo"].as<glm::vec4>();
|
||||||
material.material.roughness = material_component["Roughness"].as<float>();
|
material.material.roughness = material_component["Roughness"].as<float>();
|
||||||
@@ -301,6 +335,35 @@ namespace OpenEngine {
|
|||||||
material.material.ambient_strength = material_component["AmbiantStrength"].as<float>();
|
material.material.ambient_strength = material_component["AmbiantStrength"].as<float>();
|
||||||
material.material.specular_strength = material_component["SpecularStrength"].as<float>();
|
material.material.specular_strength = material_component["SpecularStrength"].as<float>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto physics_body_component = entity["PhysicsBodyComponent"];
|
||||||
|
if (physics_body_component) {
|
||||||
|
auto& pbc = deserializedEntity.AddComponent<PhysicsBodyComponent>();
|
||||||
|
|
||||||
|
pbc.linear_damping = physics_body_component["LinearDamping"].as<float>();
|
||||||
|
pbc.angular_damping = physics_body_component["AngularDamping"].as<float>();
|
||||||
|
pbc.gravity_factor = physics_body_component["GravityFactor"].as<float>();
|
||||||
|
pbc.restitution = physics_body_component["Restitution"].as<float>();
|
||||||
|
pbc.friction = physics_body_component["Friction"].as<float>();
|
||||||
|
|
||||||
|
pbc.type = physics_body_component["Type"].as<int>();
|
||||||
|
pbc.initial_activation_state = physics_body_component["ActivationState"].as<int>();
|
||||||
|
pbc.layer = physics_body_component["Layer"].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto box_shape_component = entity["BoxShapeComponent"];
|
||||||
|
if (box_shape_component) {
|
||||||
|
auto& bsc = deserializedEntity.AddComponent<BoxShapeComponent>();
|
||||||
|
|
||||||
|
bsc.size = box_shape_component["Size"].as<glm::vec3>();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto sphere_shape_component = entity["SphereShapeComponent"];
|
||||||
|
if (sphere_shape_component) {
|
||||||
|
auto& ssc = deserializedEntity.AddComponent<SphereShapeComponent>();
|
||||||
|
|
||||||
|
ssc.radius = sphere_shape_component["Radius"].as<float>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user