Compare commits
2 Commits
fastgltf
...
7da00008e0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7da00008e0 | ||
|
|
f26ee2bca8 |
@@ -2,8 +2,10 @@
|
|||||||
#version 450 core
|
#version 450 core
|
||||||
|
|
||||||
layout(location = 0) in vec3 a_Position;
|
layout(location = 0) in vec3 a_Position;
|
||||||
layout(location = 1) in vec3 a_Normal;
|
layout(location = 1) in vec4 a_Color;
|
||||||
layout(location = 2) in vec2 a_TexCoord;
|
layout(location = 2) in vec3 a_Normal;
|
||||||
|
layout(location = 3) in vec2 a_TexCoord;
|
||||||
|
layout(location = 4) in int a_EntityID;
|
||||||
|
|
||||||
layout(std140, binding = 0) uniform Camera
|
layout(std140, binding = 0) uniform Camera
|
||||||
{
|
{
|
||||||
@@ -18,20 +20,25 @@ layout(std140, binding = 1) uniform Transform
|
|||||||
|
|
||||||
struct VertexOutput
|
struct VertexOutput
|
||||||
{
|
{
|
||||||
|
vec4 Color;
|
||||||
vec2 TexCoord;
|
vec2 TexCoord;
|
||||||
vec3 Normal;
|
vec3 Normal;
|
||||||
vec3 ViewPos;
|
vec3 ViewPos;
|
||||||
};
|
};
|
||||||
|
|
||||||
layout (location = 0) out VertexOutput Output;
|
layout (location = 0) out VertexOutput Output;
|
||||||
|
layout (location = 4) out flat int v_EntityID;
|
||||||
layout (location = 5) out vec4 v_Pos;
|
layout (location = 5) out vec4 v_Pos;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
Output.Color = a_Color;
|
||||||
Output.TexCoord = a_TexCoord;
|
Output.TexCoord = a_TexCoord;
|
||||||
Output.Normal = mat3(transpose(inverse(u_Transform))) * a_Normal;
|
Output.Normal = mat3(transpose(inverse(u_Transform))) * a_Normal;
|
||||||
Output.ViewPos = u_ViewPosition;
|
Output.ViewPos = u_ViewPosition;
|
||||||
|
|
||||||
|
v_EntityID = a_EntityID;
|
||||||
|
|
||||||
v_Pos = u_Transform * vec4(a_Position, 1.0);
|
v_Pos = u_Transform * vec4(a_Position, 1.0);
|
||||||
gl_Position = u_ViewProjection * v_Pos;
|
gl_Position = u_ViewProjection * v_Pos;
|
||||||
}
|
}
|
||||||
@@ -42,22 +49,9 @@ void main()
|
|||||||
layout (location = 0) out vec4 color;
|
layout (location = 0) out vec4 color;
|
||||||
layout (location = 1) out int color2;
|
layout (location = 1) out int color2;
|
||||||
|
|
||||||
layout (std140, binding = 2) uniform Material
|
|
||||||
{
|
|
||||||
vec4 u_Albedo;
|
|
||||||
float u_Roughness;
|
|
||||||
float u_Metallic;
|
|
||||||
float u_AmbientStrength;
|
|
||||||
float u_SpecularStrength;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(std140, binding = 3) uniform EditorID
|
|
||||||
{
|
|
||||||
int u_EntityID;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct VertexOutput
|
struct VertexOutput
|
||||||
{
|
{
|
||||||
|
vec4 Color;
|
||||||
vec2 TexCoord;
|
vec2 TexCoord;
|
||||||
vec3 Normal;
|
vec3 Normal;
|
||||||
vec3 ViewPos;
|
vec3 ViewPos;
|
||||||
@@ -73,7 +67,8 @@ void main()
|
|||||||
vec3 lightColor = vec3(1.0f, 1.0f, 1.0f);
|
vec3 lightColor = vec3(1.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
// Ambiant lighting
|
// Ambiant lighting
|
||||||
vec3 ambient = lightColor * u_AmbientStrength;
|
float ambientStrength = 0.8;
|
||||||
|
vec3 ambient = ambientStrength * lightColor;
|
||||||
|
|
||||||
// Diffuse lighting
|
// Diffuse lighting
|
||||||
vec3 norm = normalize(Input.Normal);
|
vec3 norm = normalize(Input.Normal);
|
||||||
@@ -83,19 +78,16 @@ void main()
|
|||||||
vec3 diffuse = diff * lightColor;
|
vec3 diffuse = diff * lightColor;
|
||||||
|
|
||||||
// Specular highlight
|
// Specular highlight
|
||||||
|
float specularStrength = 0.5;
|
||||||
vec3 viewDir = normalize(Input.ViewPos - v_Pos.xyz); // .xyz here too
|
vec3 viewDir = normalize(Input.ViewPos - v_Pos.xyz); // .xyz here too
|
||||||
vec3 reflectDir = reflect(-lightDir, norm);
|
vec3 reflectDir = reflect(-lightDir, norm);
|
||||||
|
|
||||||
float shininess = mix(2.0, 256.0, 1.0 - u_Roughness);
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
|
||||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), shininess);
|
vec3 specular = specularStrength * spec * lightColor;
|
||||||
vec3 specularColor = mix(vec3(1.0), u_Albedo.rgb, u_Metallic);
|
|
||||||
vec3 specular = u_SpecularStrength * spec * lightColor * specularColor;
|
|
||||||
|
|
||||||
// Total
|
vec3 result = (ambient + diffuse + specular) * Input.Color.rgb; // objectColor → Input.Color.rgb
|
||||||
//vec3 result = (ambient + diffuse + specular) * Input.Color.rgb; // objectColor → Input.Color.rgb
|
|
||||||
vec3 result = (ambient + diffuse + specular) * u_Albedo.rgb; // objectColor → Input.Color.rgb
|
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
color = vec4(result, u_Albedo.w); // vec3 → vec4
|
color = vec4(result, 1.0); // vec3 → vec4
|
||||||
color2 = u_EntityID;
|
color2 = v_EntityID;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ spdlog/1.16.0
|
|||||||
entt/3.16.0
|
entt/3.16.0
|
||||||
yaml-cpp/0.8.0
|
yaml-cpp/0.8.0
|
||||||
joltphysics/5.2.0
|
joltphysics/5.2.0
|
||||||
fastgltf/0.9.0
|
|
||||||
|
|
||||||
[generators]
|
[generators]
|
||||||
CMakeDeps
|
CMakeDeps
|
||||||
|
|||||||
@@ -1,21 +1,15 @@
|
|||||||
#ifndef EDITOR_HPP
|
#ifndef EDITOR_HPP
|
||||||
#define EDITOR_HPP
|
#define EDITOR_HPP
|
||||||
|
|
||||||
|
#include <X11/X.h>
|
||||||
#include <open_engine.hpp>
|
#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/renderer/renderer3d.hpp"
|
||||||
#include "open_engine/scene/components.hpp"
|
#include "open_engine/scene/components.hpp"
|
||||||
|
#include "open_engine/scene/scene_serializer.hpp"
|
||||||
#include "panels/content_browser.hpp"
|
#include "panels/content_browser.hpp"
|
||||||
#include "panels/scene_hierarchy.hpp"
|
#include "panels/scene_hierarchy.hpp"
|
||||||
|
|
||||||
#include <Jolt/Physics/Collision/Shape/Shape.h>
|
|
||||||
#include <Jolt/Math/Real.h>
|
|
||||||
#include <Jolt/Math/Vec3.h>
|
|
||||||
#include <Jolt/Physics/Body/BodyCreationSettings.h>
|
|
||||||
#include <glm/ext/matrix_transform.hpp>
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
#include <glm/matrix.hpp>
|
#include <glm/matrix.hpp>
|
||||||
@@ -98,53 +92,33 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
editor_camera = EditorCamera(30.0f, 1920.0f/1080.0f, 0.1f, 1000.0f);
|
editor_camera = EditorCamera(30.0f, 1920.0f/1080.0f, 0.1f, 1000.0f);
|
||||||
|
|
||||||
// TODO: Add license
|
|
||||||
icons["play"] = Texture2D::Create("resources/textures/icons/play.png");
|
icons["play"] = Texture2D::Create("resources/textures/icons/play.png");
|
||||||
icons["stop"] = Texture2D::Create("resources/textures/icons/stop.png");
|
icons["stop"] = Texture2D::Create("resources/textures/icons/stop.png");
|
||||||
|
|
||||||
// =============================================
|
|
||||||
Entity cube = scene->CreateEntity("cube");
|
Entity cube = scene->CreateEntity("cube");
|
||||||
|
|
||||||
auto& tc = cube.AddComponent<TransformComponent>();
|
|
||||||
|
cube.AddComponent<TransformComponent>();
|
||||||
|
|
||||||
Ref<Mesh> mesh = CreateCube(cube);
|
Ref<Mesh> mesh = CreateCube(cube);
|
||||||
|
|
||||||
auto& mc = cube.AddComponent<MeshComponent>(mesh);
|
cube.AddComponent<MeshComponent>(mesh);
|
||||||
mc.primitive_type = PrimitiveType::Cube;
|
|
||||||
|
|
||||||
// =============================================
|
|
||||||
Entity quad = scene->CreateEntity("quad");
|
Entity quad = scene->CreateEntity("quad");
|
||||||
quad.AddComponent<TransformComponent>();
|
quad.AddComponent<TransformComponent>();
|
||||||
quad.GetComponents<TransformComponent>().translation = {0, 0, 0};
|
quad.GetComponents<TransformComponent>().translation = {0, 0, 0};
|
||||||
|
|
||||||
Ref<Mesh> quad_mesh = CreateQuad(quad, true);
|
Ref<Mesh> quad_mesh = CreateQuad(quad, true);
|
||||||
|
|
||||||
auto& mc3 = quad.AddComponent<MeshComponent>(quad_mesh);
|
quad.AddComponent<MeshComponent>(quad_mesh);
|
||||||
mc3.primitive_type = PrimitiveType::Quad;
|
|
||||||
|
|
||||||
// =============================================
|
|
||||||
Entity cube2 = scene->CreateEntity("cube2");
|
Entity cube2 = scene->CreateEntity("cube2");
|
||||||
cube2.AddComponent<TransformComponent>();
|
cube2.AddComponent<TransformComponent>();
|
||||||
cube2.GetComponents<TransformComponent>().translation = {2, 0, 0};
|
cube2.GetComponents<TransformComponent>().translation = {2, 0, 0};
|
||||||
|
|
||||||
Ref<Mesh> mesh2 = CreateCube(cube2);
|
Ref<Mesh> mesh2 = CreateCube(cube2);
|
||||||
|
|
||||||
auto& mc2 = cube2.AddComponent<MeshComponent>(mesh2);
|
cube2.AddComponent<MeshComponent>(mesh2);
|
||||||
mc2.primitive_type = PrimitiveType::Cube;
|
|
||||||
|
|
||||||
// ============================================================
|
|
||||||
|
|
||||||
Entity cube3 = scene->CreateEntity("glb");
|
|
||||||
Entity cube4 = scene->CreateEntity("glb2");
|
|
||||||
cube3.AddComponent<TransformComponent>();
|
|
||||||
cube4.AddComponent<TransformComponent>();
|
|
||||||
|
|
||||||
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<ModelComponent>(model);
|
|
||||||
cube4.AddComponent<ModelComponent>(monkey);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
auto view = scene->GetRegistry().view<TagComponent>();
|
auto view = scene->GetRegistry().view<TagComponent>();
|
||||||
@@ -155,6 +129,7 @@ namespace OpenEngine {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// TODO: Add file texture. Get free icons and add license
|
||||||
//icons["folder"] = Texture2D::Create("resources/textures/icons/folder.png");
|
//icons["folder"] = Texture2D::Create("resources/textures/icons/folder.png");
|
||||||
/*
|
/*
|
||||||
for (float i = 0; i < 200; i++) {
|
for (float i = 0; i < 200; i++) {
|
||||||
@@ -204,6 +179,7 @@ namespace OpenEngine {
|
|||||||
RenderCommand::Clear();
|
RenderCommand::Clear();
|
||||||
framebuffer->ClearBufferI(1, -1);
|
framebuffer->ClearBufferI(1, -1);
|
||||||
|
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case PlayState::Play: {
|
case PlayState::Play: {
|
||||||
scene->OnUpdateRuntime();
|
scene->OnUpdateRuntime();
|
||||||
@@ -230,7 +206,6 @@ namespace OpenEngine {
|
|||||||
static bool clicked = false;
|
static bool clicked = false;
|
||||||
// Mouse Picking
|
// Mouse Picking
|
||||||
if (Input::IsMouseButtonPressed(MouseCode::ButtonLeft)
|
if (Input::IsMouseButtonPressed(MouseCode::ButtonLeft)
|
||||||
&& !Application::Get().GetImGuiLayer()->GetBlockEvents()
|
|
||||||
&& mouse_x >= 0 && mouse_y >= 0
|
&& mouse_x >= 0 && mouse_y >= 0
|
||||||
&& mouse_x < (int)viewport_size.x
|
&& mouse_x < (int)viewport_size.x
|
||||||
&& mouse_y < (int)viewport_size.y
|
&& mouse_y < (int)viewport_size.y
|
||||||
@@ -303,10 +278,6 @@ namespace OpenEngine {
|
|||||||
guizmo_operation = ImGuizmo::OPERATION::SCALE;
|
guizmo_operation = ImGuizmo::OPERATION::SCALE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case KeyCode::T: {
|
|
||||||
guizmo_operation = ImGuizmo::OPERATION::UNIVERSAL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case KeyCode::Delete: {
|
case KeyCode::Delete: {
|
||||||
scene->MarkEntityForDeletion(selected_entity);
|
scene->MarkEntityForDeletion(selected_entity);
|
||||||
scene_hierarchy.ClearSelection();
|
scene_hierarchy.ClearSelection();
|
||||||
@@ -381,7 +352,7 @@ namespace OpenEngine {
|
|||||||
bool was_focused = viewport_focused;
|
bool was_focused = viewport_focused;
|
||||||
viewport_focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_RootWindow);
|
viewport_focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_RootWindow);
|
||||||
viewport_hovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_RootWindow);
|
viewport_hovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_RootWindow);
|
||||||
Application::Get().GetImGuiLayer()->SetBlockEvents(ImGui::IsAnyItemActive());
|
Application::Get().GetImGuiLayer()->SetBlockEvents((!viewport_focused && !viewport_hovered) || ImGui::IsAnyItemActive());
|
||||||
|
|
||||||
if (viewport_focused && !was_focused)
|
if (viewport_focused && !was_focused)
|
||||||
editor_camera.ResetMousePosition();
|
editor_camera.ResetMousePosition();
|
||||||
@@ -592,12 +563,10 @@ namespace OpenEngine {
|
|||||||
void OnScenePlay()
|
void OnScenePlay()
|
||||||
{
|
{
|
||||||
state = PlayState::Play;
|
state = PlayState::Play;
|
||||||
scene->OnRuntimeStart();
|
|
||||||
}
|
}
|
||||||
void OnSceneStop()
|
void OnSceneStop()
|
||||||
{
|
{
|
||||||
state = PlayState::Edit;
|
state = PlayState::Edit;
|
||||||
scene->OnRuntimeStop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -17,12 +17,6 @@ namespace OpenEngine {
|
|||||||
void SpriteOnImGuiRender(entt::registry& registry, entt::entity entity);
|
void SpriteOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||||
void CameraOnImGuiRender(entt::registry& registry, entt::entity entity);
|
void CameraOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||||
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 BodyOnImGuiRender(entt::registry& registry, entt::entity entity);
|
|
||||||
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
|
#endif // EDITOR_COMPONENT_HPP
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ namespace OpenEngine {
|
|||||||
private:
|
private:
|
||||||
std::filesystem::path current_directory;
|
std::filesystem::path current_directory;
|
||||||
Ref<Texture2D> folder_icon;
|
Ref<Texture2D> folder_icon;
|
||||||
Ref<Texture2D> file_icon;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#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 <editor_component.hpp>
|
||||||
#include <entt/entity/fwd.hpp>
|
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
|
||||||
#include <open_engine.hpp>
|
#include <open_engine.hpp>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
@@ -97,7 +91,6 @@ namespace OpenEngine {
|
|||||||
if (ImGui::InputText("##tagEditor", buffer, sizeof(buffer), ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)
|
if (ImGui::InputText("##tagEditor", buffer, sizeof(buffer), ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)
|
||||||
|| (!ImGui::IsItemActive() && ImGui::IsMouseClicked(0)))
|
|| (!ImGui::IsItemActive() && ImGui::IsMouseClicked(0)))
|
||||||
tag = buffer;
|
tag = buffer;
|
||||||
ImGui::Spacing();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void TransformOnImGuiRender(entt::registry& registry, entt::entity entity)
|
void TransformOnImGuiRender(entt::registry& registry, entt::entity entity)
|
||||||
@@ -108,7 +101,6 @@ namespace OpenEngine {
|
|||||||
DrawVec3Control("Rotation", rotation_comp);
|
DrawVec3Control("Rotation", rotation_comp);
|
||||||
transform.rotation = glm::radians(rotation_comp);
|
transform.rotation = glm::radians(rotation_comp);
|
||||||
DrawVec3Control("Scale", transform.scale);
|
DrawVec3Control("Scale", transform.scale);
|
||||||
ImGui::Spacing();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void SpriteOnImGuiRender(entt::registry& registry, entt::entity entity)
|
void SpriteOnImGuiRender(entt::registry& registry, entt::entity entity)
|
||||||
@@ -181,148 +173,6 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void MeshOnImGuiRender(entt::registry®istry, entt::entity entity)
|
void MeshOnImGuiRender(entt::registry®istry, entt::entity entity)
|
||||||
{
|
{
|
||||||
auto& mesh_component = registry.get<MeshComponent>(entity);
|
|
||||||
|
|
||||||
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 < 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((int)mesh_component.primitive_type == (item_selected_idx))
|
|
||||||
return;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MaterialOnImGuiRender(entt::registry& registry, entt::entity entity)
|
|
||||||
{
|
|
||||||
auto& material = registry.get<MaterialComponent>(entity).material;
|
|
||||||
|
|
||||||
ImGui::SliderFloat4("Albedo", glm::value_ptr(material.albedo), 0, 1);
|
|
||||||
ImGui::SliderFloat("Roughness", &material.roughness, 0, 1);
|
|
||||||
ImGui::SliderFloat("Metallic", &material.metallic, 0, 1);
|
|
||||||
ImGui::SliderFloat("Ambient strength", &material.ambient_strength, 0, 1);
|
|
||||||
ImGui::SliderFloat("Specular strength", &material.specular_strength, 0, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BodyOnImGuiRender(entt::registry ®istry, entt::entity 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("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 SphereShapeOnImGuiRender(entt::registry ®istry, entt::entity entity)
|
|
||||||
{
|
|
||||||
auto& sphere_comp = registry.get<SphereShapeComponent>(entity);
|
|
||||||
|
|
||||||
ImGui::DragFloat("Radius",
|
|
||||||
&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);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlaneShapeOnImGuiRender(entt::registry& registry, entt::entity entity)
|
|
||||||
{
|
|
||||||
auto& planed_comp = registry.get<PlaneShapeComponent>(entity);
|
|
||||||
|
|
||||||
ImGui::DragFloat("Size",
|
|
||||||
&planed_comp.extent,
|
|
||||||
0.1f,
|
|
||||||
0.01f, FLT_MAX,
|
|
||||||
"%.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
editor/src/panels/content_browser.cpp
Executable file → Normal file
28
editor/src/panels/content_browser.cpp
Executable file → Normal file
@@ -15,9 +15,8 @@ namespace OpenEngine {
|
|||||||
ContentBrowserPanel::ContentBrowserPanel()
|
ContentBrowserPanel::ContentBrowserPanel()
|
||||||
: current_directory(assets_directory)
|
: current_directory(assets_directory)
|
||||||
{
|
{
|
||||||
// TODO: Add license
|
// TODO: Add file texture. Get free icons and add license
|
||||||
folder_icon = Texture2D::Create("resources/textures/icons/folder2.png");
|
folder_icon = Texture2D::Create("resources/textures/icons/folder.png");
|
||||||
file_icon = Texture2D::Create("resources/textures/icons/file.png");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentBrowserPanel::OnImGuiRender()
|
void ContentBrowserPanel::OnImGuiRender()
|
||||||
@@ -31,16 +30,6 @@ namespace OpenEngine {
|
|||||||
current_directory = current_directory.parent_path();
|
current_directory = current_directory.parent_path();
|
||||||
|
|
||||||
auto directory_it = std::filesystem::directory_iterator(current_directory);
|
auto directory_it = std::filesystem::directory_iterator(current_directory);
|
||||||
std::vector<std::filesystem::directory_entry> entries;
|
|
||||||
|
|
||||||
for (auto entry : directory_it)
|
|
||||||
entries.emplace_back(entry);
|
|
||||||
|
|
||||||
std::sort(entries.begin(), entries.end(),
|
|
||||||
[](const std::filesystem::directory_entry& a,
|
|
||||||
const std::filesystem::directory_entry& b) {
|
|
||||||
return (a.is_directory() && !b.is_directory());
|
|
||||||
});
|
|
||||||
|
|
||||||
ImVec2 button_size = { 100, 100 };
|
ImVec2 button_size = { 100, 100 };
|
||||||
auto panel_width = ImGui::GetContentRegionAvail().x;
|
auto panel_width = ImGui::GetContentRegionAvail().x;
|
||||||
@@ -53,12 +42,9 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, padding);
|
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, padding);
|
||||||
|
|
||||||
float margin = 20.0f;
|
|
||||||
ImGui::Indent(margin);
|
|
||||||
|
|
||||||
if (ImGui::BeginTable("table1", table_columns, ImGuiTableFlags_SizingFixedSame))
|
if (ImGui::BeginTable("table1", table_columns, ImGuiTableFlags_SizingFixedSame))
|
||||||
{
|
{
|
||||||
for (auto& entry : entries) {
|
for (auto& entry : directory_it) {
|
||||||
auto file_name = entry.path().filename().string();
|
auto file_name = entry.path().filename().string();
|
||||||
|
|
||||||
ImGui::PushID(file_name.c_str());
|
ImGui::PushID(file_name.c_str());
|
||||||
@@ -70,14 +56,17 @@ namespace OpenEngine {
|
|||||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, { 0.270f, 0.278f, 0.352f, 1.0f });
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, { 0.270f, 0.278f, 0.352f, 1.0f });
|
||||||
|
|
||||||
ImGui::BeginGroup();
|
ImGui::BeginGroup();
|
||||||
Ref<Texture2D> icon = entry.is_directory() ? folder_icon : file_icon;
|
ImGui::ImageButton("##X", (ImTextureID)folder_icon->GetID(), button_size, { 0, 1 }, { 1, 0 });
|
||||||
ImGui::ImageButton("##X", (ImTextureID)icon->GetID(), button_size, { 0, 1 }, { 1, 0 });
|
|
||||||
if (entry.is_regular_file() && ImGui::BeginDragDropSource()) {
|
if (entry.is_regular_file() && ImGui::BeginDragDropSource()) {
|
||||||
const char* source = entry.path().c_str();
|
const char* source = entry.path().c_str();
|
||||||
ImGui::SetDragDropPayload("CONTENT_BROWSER_PAYLOAD", source, (strlen(source) + 1) * sizeof(char), ImGuiCond_Once);
|
ImGui::SetDragDropPayload("CONTENT_BROWSER_PAYLOAD", source, (strlen(source) + 1) * sizeof(char), ImGuiCond_Once);
|
||||||
|
|
||||||
ImGui::EndDragDropSource();
|
ImGui::EndDragDropSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float columnWidth = ImGui::GetColumnWidth();
|
||||||
|
float textWidth = ImGui::CalcTextSize(file_name.c_str()).x;
|
||||||
|
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (columnWidth - textWidth) * 0.5f);
|
||||||
ImGui::TextWrapped("%s", file_name.c_str());
|
ImGui::TextWrapped("%s", file_name.c_str());
|
||||||
|
|
||||||
ImGui::EndGroup();
|
ImGui::EndGroup();
|
||||||
@@ -92,7 +81,6 @@ namespace OpenEngine {
|
|||||||
}
|
}
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
ImGui::Unindent();
|
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|||||||
@@ -23,12 +23,6 @@ namespace OpenEngine {
|
|||||||
RegisterDrawer<SpriteRendererComponent>("Sprite Renderer", &SpriteOnImGuiRender);
|
RegisterDrawer<SpriteRendererComponent>("Sprite Renderer", &SpriteOnImGuiRender);
|
||||||
RegisterDrawer<CameraComponent>("Camera", &CameraOnImGuiRender);
|
RegisterDrawer<CameraComponent>("Camera", &CameraOnImGuiRender);
|
||||||
RegisterDrawer<MeshComponent>("Mesh", &MeshOnImGuiRender);
|
RegisterDrawer<MeshComponent>("Mesh", &MeshOnImGuiRender);
|
||||||
RegisterDrawer<MaterialComponent>("Material", &MaterialOnImGuiRender);
|
|
||||||
RegisterDrawer<PhysicsBodyComponent>("Physics Body", &BodyOnImGuiRender);
|
|
||||||
RegisterDrawer<SphereShapeComponent>("Sphere Shape", &SphereShapeOnImGuiRender);
|
|
||||||
RegisterDrawer<BoxShapeComponent>("Box Shape", &BoxShapeOnImGuiRender);
|
|
||||||
RegisterDrawer<PlaneShapeComponent>("Plane Shape", &PlaneShapeOnImGuiRender);
|
|
||||||
RegisterDrawer<ModelComponent>("Model", &ModelOnImGuiRender);
|
|
||||||
|
|
||||||
scene = context;
|
scene = context;
|
||||||
selected_context = {};
|
selected_context = {};
|
||||||
@@ -57,36 +51,6 @@ namespace OpenEngine {
|
|||||||
selected_context.AddComponent<MeshComponent>();
|
selected_context.AddComponent<MeshComponent>();
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
}
|
}
|
||||||
if (!selected_context.HasComponent<MaterialComponent>())
|
|
||||||
if (ImGui::MenuItem("Material")) {
|
|
||||||
selected_context.AddComponent<MaterialComponent>();
|
|
||||||
ImGui::CloseCurrentPopup();
|
|
||||||
}
|
|
||||||
if (!selected_context.HasComponent<PhysicsBodyComponent>())
|
|
||||||
if (ImGui::MenuItem("Physics body")) {
|
|
||||||
selected_context.AddComponent<PhysicsBodyComponent>();
|
|
||||||
ImGui::CloseCurrentPopup();
|
|
||||||
}
|
|
||||||
if (!selected_context.HasComponent<SphereShapeComponent>())
|
|
||||||
if (ImGui::MenuItem("Sphere shape")) {
|
|
||||||
selected_context.AddComponent<SphereShapeComponent>();
|
|
||||||
ImGui::CloseCurrentPopup();
|
|
||||||
}
|
|
||||||
if (!selected_context.HasComponent<BoxShapeComponent>())
|
|
||||||
if (ImGui::MenuItem("Box shape")) {
|
|
||||||
selected_context.AddComponent<BoxShapeComponent>();
|
|
||||||
ImGui::CloseCurrentPopup();
|
|
||||||
}
|
|
||||||
if (!selected_context.HasComponent<PlaneShapeComponent>())
|
|
||||||
if (ImGui::MenuItem("Plane shape")) {
|
|
||||||
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)
|
void EntityPopup(Ref<Scene>& scene)
|
||||||
@@ -231,17 +195,16 @@ namespace OpenEngine {
|
|||||||
void SceneHierarchy::DrawComponents(Entity& entity)
|
void SceneHierarchy::DrawComponents(Entity& entity)
|
||||||
{
|
{
|
||||||
auto& reg = scene->GetRegistry();
|
auto& reg = scene->GetRegistry();
|
||||||
entt::entity handle = entity;
|
entt::entity handle = selected_context;
|
||||||
|
|
||||||
if (!entity)
|
if (!selected_context || !entity)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
entity.GetComponents<TagComponent>();
|
entity.GetComponents<TagComponent>();
|
||||||
TagOnImGuiRender(reg, entity);
|
TagOnImGuiRender(reg, entity);
|
||||||
|
|
||||||
// TODO: Defer deletion like the entities?
|
|
||||||
std::vector<entt::id_type> pending_deletion; // 0 is null/invalid in entt usually
|
|
||||||
|
|
||||||
|
std::vector<entt::id_type> component_to_delete; // 0 is null/invalid in entt usually
|
||||||
// Iterate through every component type entt knows about
|
// Iterate through every component type entt knows about
|
||||||
for (auto [id, storage] : reg.storage()) {
|
for (auto [id, storage] : reg.storage()) {
|
||||||
if (storage.contains(handle)) {
|
if (storage.contains(handle)) {
|
||||||
@@ -265,24 +228,20 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
if (ImGui::BeginPopup("component_settings")) {
|
if (ImGui::BeginPopup("component_settings")) {
|
||||||
if (ImGui::MenuItem("Remove component"))
|
if (ImGui::MenuItem("Remove component"))
|
||||||
pending_deletion.emplace_back(id);
|
component_to_delete.emplace_back(id);
|
||||||
|
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opened) {
|
if (opened) {
|
||||||
ImGui::Spacing();
|
|
||||||
drawers[id].draw_func(reg, handle);
|
drawers[id].draw_func(reg, handle);
|
||||||
ImGui::Spacing();
|
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& id : pending_deletion) {
|
for (auto& id : component_to_delete)
|
||||||
drawers[id].remove_func(reg, entity);
|
drawers[id].remove_func(reg, entity);
|
||||||
pending_deletion.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
26
imgui.ini
26
imgui.ini
@@ -10,7 +10,7 @@ Collapsed=0
|
|||||||
|
|
||||||
[Window][Statistics]
|
[Window][Statistics]
|
||||||
Pos=0,24
|
Pos=0,24
|
||||||
Size=409,437
|
Size=224,437
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000003,0
|
DockId=0x00000003,0
|
||||||
|
|
||||||
@@ -21,8 +21,8 @@ Collapsed=0
|
|||||||
DockId=0x00000007,0
|
DockId=0x00000007,0
|
||||||
|
|
||||||
[Window][Viewport]
|
[Window][Viewport]
|
||||||
Pos=411,61
|
Pos=226,61
|
||||||
Size=409,956
|
Size=594,956
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000012,0
|
DockId=0x00000012,0
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ DockId=0x00000008,0
|
|||||||
|
|
||||||
[Window][Scene]
|
[Window][Scene]
|
||||||
Pos=0,463
|
Pos=0,463
|
||||||
Size=409,924
|
Size=224,924
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000004,0
|
DockId=0x00000004,0
|
||||||
|
|
||||||
@@ -143,8 +143,8 @@ Collapsed=0
|
|||||||
DockId=0x00000012,1
|
DockId=0x00000012,1
|
||||||
|
|
||||||
[Window][Assets]
|
[Window][Assets]
|
||||||
Pos=411,1019
|
Pos=226,1019
|
||||||
Size=409,368
|
Size=594,368
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x0000000C,0
|
DockId=0x0000000C,0
|
||||||
|
|
||||||
@@ -155,29 +155,29 @@ Collapsed=0
|
|||||||
DockId=0x0000000F,0
|
DockId=0x0000000F,0
|
||||||
|
|
||||||
[Window][##play_state_bar]
|
[Window][##play_state_bar]
|
||||||
Pos=411,24
|
Pos=226,24
|
||||||
Size=409,35
|
Size=594,35
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000011,0
|
DockId=0x00000011,0
|
||||||
|
|
||||||
[Docking][Data]
|
[Docking][Data]
|
||||||
DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=0,24 Size=1272,1363 Split=X
|
DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=0,24 Size=1272,1363 Split=X
|
||||||
DockNode ID=0x00000005 Parent=0x08BD597D SizeRef=820,1386 Split=X
|
DockNode ID=0x00000005 Parent=0x08BD597D SizeRef=820,1386 Split=X
|
||||||
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=409,1386 Split=Y Selected=0xE601B12F
|
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=224,1386 Split=Y Selected=0xE601B12F
|
||||||
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=255,417 Selected=0x553E127E
|
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=255,417 Selected=0x553E127E
|
||||||
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=255,883 Selected=0xE601B12F
|
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=255,883 Selected=0xE601B12F
|
||||||
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=409,1386 Split=Y Selected=0xC450F867
|
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=594,1386 Split=Y Selected=0xC450F867
|
||||||
DockNode ID=0x00000009 Parent=0x00000002 SizeRef=483,784 Split=Y Selected=0xC450F867
|
DockNode ID=0x00000009 Parent=0x00000002 SizeRef=483,784 Split=Y Selected=0xC450F867
|
||||||
DockNode ID=0x0000000B Parent=0x00000009 SizeRef=409,932 Split=X Selected=0xC450F867
|
DockNode ID=0x0000000B Parent=0x00000009 SizeRef=409,932 Split=X Selected=0xC450F867
|
||||||
DockNode ID=0x0000000D Parent=0x0000000B SizeRef=1080,993 Split=Y Selected=0xC450F867
|
DockNode ID=0x0000000D Parent=0x0000000B SizeRef=1080,993 Split=Y Selected=0xC450F867
|
||||||
DockNode ID=0x0000000F Parent=0x0000000D SizeRef=594,60 Selected=0x8325EBDA
|
DockNode ID=0x0000000F Parent=0x0000000D SizeRef=594,60 Selected=0x8325EBDA
|
||||||
DockNode ID=0x00000010 Parent=0x0000000D SizeRef=594,931 Split=Y Selected=0xC450F867
|
DockNode ID=0x00000010 Parent=0x0000000D SizeRef=594,931 Split=Y Selected=0xC450F867
|
||||||
DockNode ID=0x00000011 Parent=0x00000010 SizeRef=594,35 HiddenTabBar=1 Selected=0xAB37695D
|
DockNode ID=0x00000011 Parent=0x00000010 SizeRef=594,35 HiddenTabBar=1 Selected=0xAB37695D
|
||||||
DockNode ID=0x00000012 Parent=0x00000010 SizeRef=594,964 CentralNode=1 Selected=0xC450F867
|
DockNode ID=0x00000012 Parent=0x00000010 SizeRef=594,956 CentralNode=1 Selected=0xC450F867
|
||||||
DockNode ID=0x0000000E Parent=0x0000000B SizeRef=800,993 Selected=0x3EEA4247
|
DockNode ID=0x0000000E Parent=0x0000000B SizeRef=800,993 Selected=0x3EEA4247
|
||||||
DockNode ID=0x0000000C Parent=0x00000009 SizeRef=409,368 Selected=0x42C24103
|
DockNode ID=0x0000000C Parent=0x00000009 SizeRef=409,368 Selected=0x42C24103
|
||||||
DockNode ID=0x0000000A Parent=0x00000002 SizeRef=483,600 Selected=0x1BCA3180
|
DockNode ID=0x0000000A Parent=0x00000002 SizeRef=483,600 Selected=0x1BCA3180
|
||||||
DockNode ID=0x00000006 Parent=0x08BD597D SizeRef=450,1386 Split=Y Selected=0x8C72BEA8
|
DockNode ID=0x00000006 Parent=0x08BD597D SizeRef=450,1386 Split=Y Selected=0x8C72BEA8
|
||||||
DockNode ID=0x00000007 Parent=0x00000006 SizeRef=444,805 Selected=0x8C72BEA8
|
DockNode ID=0x00000007 Parent=0x00000006 SizeRef=444,769 Selected=0x8C72BEA8
|
||||||
DockNode ID=0x00000008 Parent=0x00000006 SizeRef=444,556 Selected=0x5E5F7166
|
DockNode ID=0x00000008 Parent=0x00000006 SizeRef=444,531 Selected=0x5E5F7166
|
||||||
|
|
||||||
|
|||||||
@@ -74,5 +74,3 @@ add_subdirectory(vendor/glad
|
|||||||
)
|
)
|
||||||
|
|
||||||
add_subdirectory("vendor/nativefiledialog-extended")
|
add_subdirectory("vendor/nativefiledialog-extended")
|
||||||
|
|
||||||
target_compile_options(open_engine PRIVATE -msse4.1 -msse4.2 -mavx -mavx2)
|
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
#ifndef UUID_HPP
|
|
||||||
#define UUID_HPP
|
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
|
||||||
|
|
||||||
class UUID
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
UUID();
|
|
||||||
UUID(uint64_t uuid);
|
|
||||||
UUID(const UUID&) = default;
|
|
||||||
|
|
||||||
operator uint64_t() const { return uuid; };
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint64_t uuid;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace std {
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct hash<OpenEngine::UUID>
|
|
||||||
{
|
|
||||||
std::size_t operator()(const OpenEngine::UUID& uuid) const
|
|
||||||
{
|
|
||||||
return hash<uint64_t>()((uint64_t)uuid);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // UUID_HPP
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#ifndef FASTGLTF_HPP
|
|
||||||
#define FASTGLTF_HPP
|
|
||||||
|
|
||||||
#include "renderer/renderer3d.hpp"
|
|
||||||
#include "open_engine/ref_scope.hpp"
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
|
||||||
|
|
||||||
Ref<Mesh> TestGLTF();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // FASTGLTF_HPP
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
#ifndef GLTF_MODEL3D_HPP
|
|
||||||
#define GLTF_MODEL3D_HPP
|
|
||||||
|
|
||||||
#include "open_engine/renderer/model3d.hpp"
|
|
||||||
|
|
||||||
#include <fastgltf/types.hpp>
|
|
||||||
#include <vector>
|
|
||||||
#include <cstddef>
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
|
||||||
|
|
||||||
class GLTFModel3D : public Model3D
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GLTFModel3D(const char* path);
|
|
||||||
|
|
||||||
void loadPrimitive(fastgltf::Asset& asset,
|
|
||||||
fastgltf::Primitive& primitive,
|
|
||||||
Mesh& out);
|
|
||||||
virtual const Mesh& GetMesh(int index) const override;
|
|
||||||
virtual const std::vector<Mesh>& GetMeshes() const override;
|
|
||||||
|
|
||||||
virtual size_t GetMeshCount() const override { return meshes.size(); };
|
|
||||||
|
|
||||||
virtual std::vector<Mesh>::iterator begin() override { return meshes.begin(); };
|
|
||||||
virtual std::vector<Mesh>::iterator end() override { return meshes.end(); };
|
|
||||||
|
|
||||||
virtual std::vector<Mesh>::const_iterator begin() const override { return meshes.cbegin(); };
|
|
||||||
virtual std::vector<Mesh>::const_iterator end() const override { return meshes.end(); };
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string name;
|
|
||||||
std::vector<Mesh> meshes;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // GLTF_MODEL3D_HPP
|
|
||||||
@@ -19,7 +19,6 @@ namespace OpenEngine {
|
|||||||
bool CloseWindow(OpenEngine::KeyPressedEvent& event);
|
bool CloseWindow(OpenEngine::KeyPressedEvent& event);
|
||||||
|
|
||||||
void SetBlockEvents(bool block) { block_events = block; };
|
void SetBlockEvents(bool block) { block_events = block; };
|
||||||
bool GetBlockEvents() { return block_events; };
|
|
||||||
|
|
||||||
void Begin();
|
void Begin();
|
||||||
void End();
|
void End();
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define INPUT_HPP
|
#define INPUT_HPP
|
||||||
|
|
||||||
#include "open_engine/input/mouse_codes.hpp"
|
#include "open_engine/input/mouse_codes.hpp"
|
||||||
|
#include "open_engine/ref_scope.hpp"
|
||||||
#include "open_engine/input/keycodes.hpp"
|
#include "open_engine/input/keycodes.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|||||||
@@ -1,191 +0,0 @@
|
|||||||
#ifndef PHYSICS_HPP
|
|
||||||
#define PHYSICS_HPP
|
|
||||||
|
|
||||||
#include "logging.hpp"
|
|
||||||
|
|
||||||
#include <Jolt/Jolt.h>
|
|
||||||
#include <Jolt/Physics/Body/BodyInterface.h>
|
|
||||||
#include <Jolt/RegisterTypes.h>
|
|
||||||
#include <Jolt/Core/Factory.h>
|
|
||||||
#include <Jolt/Core/TempAllocator.h>
|
|
||||||
#include <Jolt/Core/JobSystemThreadPool.h>
|
|
||||||
#include <Jolt/Physics/PhysicsSettings.h>
|
|
||||||
#include <Jolt/Physics/PhysicsSystem.h>
|
|
||||||
#include <Jolt/Physics/Collision/Shape/BoxShape.h>
|
|
||||||
#include <Jolt/Physics/Collision/Shape/SphereShape.h>
|
|
||||||
#include <Jolt/Physics/Body/BodyCreationSettings.h>
|
|
||||||
#include <Jolt/Physics/Body/BodyActivationListener.h>
|
|
||||||
|
|
||||||
#include <cstdarg>
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
using namespace JPH;
|
|
||||||
using namespace JPH::literals;
|
|
||||||
|
|
||||||
// Callback for traces, connect this to your own trace function if you have one
|
|
||||||
static void TraceImpl(const char *in_fmt, ...)
|
|
||||||
{
|
|
||||||
// Format the message
|
|
||||||
va_list list;
|
|
||||||
va_start(list, in_fmt);
|
|
||||||
char buffer[1024];
|
|
||||||
vsnprintf(buffer, sizeof(buffer), in_fmt, list);
|
|
||||||
va_end(list);
|
|
||||||
|
|
||||||
OE_CORE_TRACE("Jolt: {}", buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef JPH_ENABLE_ASSERTS
|
|
||||||
// Callback for asserts, connect this to your own assert handler if you have one
|
|
||||||
static bool AssertFailedImpl(const char *in_expression, const char *in_message, const char *in_file, uint in_line)
|
|
||||||
{
|
|
||||||
OE_CORE_ERROR("Jolt: Assert in file: {}:{} :({}) {}", in_file, in_line, in_expression, (in_message != nullptr? in_message : ""));
|
|
||||||
|
|
||||||
// Breakpoint
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
#endif // JPH_ENABLE_ASSERTS
|
|
||||||
|
|
||||||
// Layer that objects can be in, determines which other objects it can collide with
|
|
||||||
// Typically you at least want to have 1 layer for moving bodies and 1 layer for static bodies, but you can have more
|
|
||||||
// layers if you want. E.g. you could have a layer for high detail collision (which is not used by the physics simulation
|
|
||||||
// but only if you do collision testing).
|
|
||||||
namespace Layers {
|
|
||||||
static constexpr ObjectLayer NON_MOVING = 0;
|
|
||||||
static constexpr ObjectLayer MOVING = 1;
|
|
||||||
static constexpr ObjectLayer NUM_LAYERS = 2;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ObjectLayerPairFilterImpl : public ObjectLayerPairFilter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual bool ShouldCollide(ObjectLayer object1, ObjectLayer object2) const override;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Each broadphase layer results in a separate bounding volume tree in the broad phase. You at least want to have
|
|
||||||
// a layer for non-moving and moving objects to avoid having to update a tree full of static objects every frame.
|
|
||||||
// You can have a 1-on-1 mapping between object layers and broadphase layers (like in this case) but if you have
|
|
||||||
// many object layers you'll be creating many broad phase trees, which is not efficient. If you want to fine tune
|
|
||||||
// your broadphase layers define JPH_TRACK_BROADPHASE_STATS and look at the stats reported on the TTY.
|
|
||||||
namespace BroadPhaseLayers
|
|
||||||
{
|
|
||||||
static constexpr BroadPhaseLayer NON_MOVING(0);
|
|
||||||
static constexpr BroadPhaseLayer MOVING(1);
|
|
||||||
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
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
BPLayerInterfaceImpl()
|
|
||||||
{
|
|
||||||
object_to_broad_phase[Layers::NON_MOVING] = BroadPhaseLayers::NON_MOVING;
|
|
||||||
object_to_broad_phase[Layers::MOVING] = BroadPhaseLayers::MOVING;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual uint GetNumBroadPhaseLayers() const override { return BroadPhaseLayers::NUM_LAYERS; };
|
|
||||||
|
|
||||||
virtual BroadPhaseLayer GetBroadPhaseLayer(ObjectLayer layer) const override
|
|
||||||
{
|
|
||||||
JPH_ASSERT(layer < Layers::NUM_LAYERS);
|
|
||||||
return object_to_broad_phase[layer];
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
BroadPhaseLayer object_to_broad_phase[Layers::NUM_LAYERS];
|
|
||||||
};
|
|
||||||
|
|
||||||
class ObjectVsBroadPhaseLayerFilterImpl : public ObjectVsBroadPhaseLayerFilter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual bool ShouldCollide(ObjectLayer layer1, BroadPhaseLayer layer2) const override
|
|
||||||
{
|
|
||||||
switch (layer1)
|
|
||||||
{
|
|
||||||
case Layers::NON_MOVING:
|
|
||||||
return layer2 == BroadPhaseLayers::MOVING;
|
|
||||||
case Layers::MOVING:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
JPH_ASSERT(false);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// An example contact listener
|
|
||||||
class MyContactListener : public ContactListener
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// See: ContactListener
|
|
||||||
virtual ValidateResult OnContactValidate(const Body &inBody1, const Body &inBody2, RVec3Arg inBaseOffset, const CollideShapeResult &inCollisionResult) override
|
|
||||||
{
|
|
||||||
OE_CORE_TRACE("Jolt: Contact validate callback");
|
|
||||||
|
|
||||||
// Allows you to ignore a contact before it is created (using layers to not make objects collide is cheaper!)
|
|
||||||
return ValidateResult::AcceptAllContactsForThisBodyPair;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void OnContactAdded(const Body &inBody1, const Body &inBody2, const ContactManifold &inManifold, ContactSettings &ioSettings) override
|
|
||||||
{
|
|
||||||
OE_CORE_TRACE("Jolt: A contact was added");
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void OnContactPersisted(const Body &inBody1, const Body &inBody2, const ContactManifold &inManifold, ContactSettings &ioSettings) override
|
|
||||||
{
|
|
||||||
OE_CORE_TRACE("Jolt: A contact was persisted");
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void OnContactRemoved(const SubShapeIDPair &inSubShapePair) override
|
|
||||||
{
|
|
||||||
OE_CORE_TRACE("Jolt: A contact was removed");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// An example activation listener
|
|
||||||
class MyBodyActivationListener : public BodyActivationListener
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual void OnBodyActivated(const BodyID &inBodyID, uint64 inBodyUserData) override
|
|
||||||
{
|
|
||||||
OE_CORE_TRACE("Jolt: A body got activated");
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void OnBodyDeactivated(const BodyID &inBodyID, uint64 inBodyUserData) override
|
|
||||||
{
|
|
||||||
OE_CORE_TRACE("Jolt: A body went to sleep");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
|
||||||
|
|
||||||
// Consider making this static like the renderer
|
|
||||||
class PhysicsEngine
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PhysicsEngine();
|
|
||||||
~PhysicsEngine();
|
|
||||||
|
|
||||||
// TODO: Temp, make abstract function to create a body
|
|
||||||
BodyInterface& GetBodyInterface() { return physics_system.GetBodyInterface(); };
|
|
||||||
void Update( float delta_time, int collision_steps);
|
|
||||||
|
|
||||||
private:
|
|
||||||
PhysicsSystem physics_system;
|
|
||||||
|
|
||||||
Ref<TempAllocatorImpl> tmp_allocator;
|
|
||||||
Ref<JobSystemThreadPool> job_system;
|
|
||||||
|
|
||||||
MyBodyActivationListener body_activation_listener;
|
|
||||||
MyContactListener contact_listener;
|
|
||||||
|
|
||||||
BPLayerInterfaceImpl broad_phase_layer_interface;
|
|
||||||
ObjectVsBroadPhaseLayerFilterImpl object_vs_broadphase_layer_filter;
|
|
||||||
ObjectLayerPairFilterImpl object_vs_object_layer_filter;
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // PHYSICS_HPP
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
#ifndef MODEL3D_HPP
|
|
||||||
#define MODEL3D_HPP
|
|
||||||
|
|
||||||
#include "open_engine/core/uuid.hpp"
|
|
||||||
#include "open_engine/renderer/vertex_array.hpp"
|
|
||||||
#include <cstddef>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
|
||||||
|
|
||||||
struct Material
|
|
||||||
{
|
|
||||||
glm::vec4 albedo = { 1.0f, 0.0f, 0.8f, 1.0f };
|
|
||||||
float roughness = 1.0f;
|
|
||||||
float metallic = 1.0f;
|
|
||||||
float ambient_strength = 1.0f;
|
|
||||||
float specular_strength = 1.0f;
|
|
||||||
std::string name = "un-named material";
|
|
||||||
};
|
|
||||||
|
|
||||||
struct MeshVertex
|
|
||||||
{
|
|
||||||
glm::vec3 position;
|
|
||||||
glm::vec3 normal;
|
|
||||||
glm::vec2 text_coords;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Mesh
|
|
||||||
{
|
|
||||||
UUID uuid;
|
|
||||||
|
|
||||||
Material material;
|
|
||||||
|
|
||||||
Ref<VertexArray> vertex_array;
|
|
||||||
Ref<VertexBuffer> vertex_buffer;
|
|
||||||
Ref<IndexBuffer> index_buffer;
|
|
||||||
|
|
||||||
// TODO: Make them a ptr or something
|
|
||||||
std::vector<MeshVertex> vertices;
|
|
||||||
std::vector<uint32_t> indices;
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: Model3D.Instanciate();
|
|
||||||
// Or Model3D.GetVertices() {return iterateaccessorwithindex bla bla bla}
|
|
||||||
// What data should Model3D hold in the end if it is not a renderable object?
|
|
||||||
class Model3D
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~Model3D() = default;
|
|
||||||
|
|
||||||
static Ref<Model3D> Create(const char* path);
|
|
||||||
|
|
||||||
virtual const Mesh& GetMesh(int index) const = 0;
|
|
||||||
virtual const std::vector<Mesh>& GetMeshes() const = 0;
|
|
||||||
|
|
||||||
virtual size_t GetMeshCount() const = 0;
|
|
||||||
|
|
||||||
virtual std::vector<Mesh>::iterator begin() = 0;
|
|
||||||
virtual std::vector<Mesh>::iterator end() = 0;
|
|
||||||
|
|
||||||
virtual std::vector<Mesh>::const_iterator begin() const = 0;
|
|
||||||
virtual std::vector<Mesh>::const_iterator end() const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // MODEL3D_HPP
|
|
||||||
@@ -2,27 +2,38 @@
|
|||||||
#define RENDERER3D_HPP
|
#define RENDERER3D_HPP
|
||||||
|
|
||||||
#include "open_engine/renderer/editor_camera.hpp"
|
#include "open_engine/renderer/editor_camera.hpp"
|
||||||
|
#include "open_engine/renderer/vertex_array.hpp"
|
||||||
|
#include "open_engine/renderer/buffer.hpp"
|
||||||
#include "open_engine/scene/scene_camera.hpp"
|
#include "open_engine/scene/scene_camera.hpp"
|
||||||
#include "open_engine/renderer/model3d.hpp"
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
|
|
||||||
// SHOULD BE MOVED ==================================
|
// SHOULD BE MOVED ==================================
|
||||||
|
struct MeshVertex
|
||||||
enum class PrimitiveType
|
|
||||||
{
|
{
|
||||||
None = 0,
|
glm::vec3 position;
|
||||||
Quad,
|
glm::vec4 color;
|
||||||
Cube
|
glm::vec3 normal;
|
||||||
|
glm::vec2 text_coords;
|
||||||
|
uint32_t id = -1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Mesh
|
||||||
|
{
|
||||||
|
Ref<VertexArray> vertex_array;
|
||||||
|
Ref<VertexBuffer> vertex_buffer;
|
||||||
|
Ref<IndexBuffer> index_buffer;
|
||||||
|
|
||||||
|
// TODO: Make them a ptr or something
|
||||||
|
std::vector<MeshVertex> vertices;
|
||||||
|
std::vector<uint32_t> indices;
|
||||||
};
|
};
|
||||||
|
|
||||||
Ref<Mesh> CreateMesh(const std::vector<MeshVertex>& vertices,
|
Ref<Mesh> CreateMesh(const std::vector<MeshVertex>& vertices,
|
||||||
const std::vector<uint32_t>& indices);
|
const std::vector<uint32_t>& indices);
|
||||||
void PopulateMesh(Mesh& mesh);
|
|
||||||
Ref<Mesh> CreateCube(uint32_t id = -1);
|
Ref<Mesh> CreateCube(uint32_t id = -1);
|
||||||
Ref<Mesh> CreateQuad(uint32_t id = -1, bool back_face = false);
|
Ref<Mesh> CreateQuad(uint32_t id = -1, bool back_face = false);
|
||||||
|
|
||||||
// ==================================================
|
// ==================================================
|
||||||
|
|
||||||
class Renderer3D
|
class Renderer3D
|
||||||
@@ -35,14 +46,7 @@ namespace OpenEngine {
|
|||||||
static void BeginScene(const EditorCamera& camera);
|
static void BeginScene(const EditorCamera& camera);
|
||||||
static void EndScene();
|
static void EndScene();
|
||||||
|
|
||||||
static void DrawMesh(const Ref<Mesh>& mesh, Material& material,
|
static void DrawMesh(const Ref<Mesh>& mesh, const glm::mat4& transform);
|
||||||
const glm::mat4& transform);
|
|
||||||
static void DrawMesh(const Ref<Mesh>& mesh, Material& material,
|
|
||||||
const glm::mat4& transform,
|
|
||||||
uint32_t entity_id);
|
|
||||||
static void DrawModel(const Ref<Model3D>& model,
|
|
||||||
const glm::mat4& transform,
|
|
||||||
uint32_t entity_id);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace OpenEngine {
|
|||||||
class UniformBuffer
|
class UniformBuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~UniformBuffer() = default;
|
virtual ~UniformBuffer() {}
|
||||||
virtual void SetData(const void* data, uint32_t size,
|
virtual void SetData(const void* data, uint32_t size,
|
||||||
uint32_t offset = 0) = 0;
|
uint32_t offset = 0) = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,12 @@
|
|||||||
#ifndef COMPONENTS_HPP
|
#ifndef COMPONENTS_HPP
|
||||||
#define COMPONENTS_HPP
|
#define COMPONENTS_HPP
|
||||||
|
|
||||||
|
#include "open_engine/scene/native_scriptable_entity.hpp"
|
||||||
#include "open_engine/renderer/renderer3d.hpp"
|
#include "open_engine/renderer/renderer3d.hpp"
|
||||||
#include "open_engine/scene/scene_camera.hpp"
|
#include "open_engine/scene/scene_camera.hpp"
|
||||||
#include "open_engine/renderer/texture.hpp"
|
#include "open_engine/renderer/texture.hpp"
|
||||||
#include "open_engine/renderer/renderer3d.hpp"
|
#include "open_engine/renderer/renderer3d.hpp"
|
||||||
#include "open_engine/physics.hpp"
|
|
||||||
#include "open_engine/core/uuid.hpp"
|
|
||||||
#include "open_engine/ref_scope.hpp"
|
|
||||||
#include "open_engine/renderer/model3d.hpp"
|
|
||||||
|
|
||||||
#include <Jolt/Physics/Body/BodyCreationSettings.h>
|
|
||||||
#include <Jolt/Physics/Body/BodyInterface.h>
|
|
||||||
#include <Jolt/Physics/Body/MotionType.h>
|
|
||||||
#include <Jolt/Physics/Collision/ObjectLayer.h>
|
|
||||||
#include <Jolt/Physics/Collision/Shape/Shape.h>
|
|
||||||
#include <Jolt/Physics/EActivation.h>
|
|
||||||
#include <glm/ext/matrix_transform.hpp>
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
#include <glm/fwd.hpp>
|
#include <glm/fwd.hpp>
|
||||||
@@ -30,15 +21,6 @@
|
|||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
|
|
||||||
struct IDComponent
|
|
||||||
{
|
|
||||||
UUID id;
|
|
||||||
|
|
||||||
IDComponent() = default;
|
|
||||||
IDComponent(const IDComponent&) = default;
|
|
||||||
IDComponent(const UUID& uuid) : id(uuid) {};
|
|
||||||
};
|
|
||||||
|
|
||||||
struct TagComponent
|
struct TagComponent
|
||||||
{
|
{
|
||||||
std::string tag;
|
std::string tag;
|
||||||
@@ -85,8 +67,6 @@ namespace OpenEngine {
|
|||||||
CameraComponent(const CameraComponent&) = default;
|
CameraComponent(const CameraComponent&) = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
class NativeScriptableEntity;
|
|
||||||
|
|
||||||
struct NativeScriptComponent
|
struct NativeScriptComponent
|
||||||
{
|
{
|
||||||
NativeScriptableEntity* instance = nullptr;
|
NativeScriptableEntity* instance = nullptr;
|
||||||
@@ -94,6 +74,9 @@ namespace OpenEngine {
|
|||||||
NativeScriptableEntity* (*InstanciateScript)();
|
NativeScriptableEntity* (*InstanciateScript)();
|
||||||
void (*DestroyInstanceScript)(NativeScriptComponent*);
|
void (*DestroyInstanceScript)(NativeScriptComponent*);
|
||||||
|
|
||||||
|
void OnImGuiRender(Entity& entity)
|
||||||
|
{};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void Bind()
|
void Bind()
|
||||||
{
|
{
|
||||||
@@ -103,83 +86,19 @@ namespace OpenEngine {
|
|||||||
(delete nsc->instance);
|
(delete nsc->instance);
|
||||||
nsc->instance = nullptr;
|
nsc->instance = nullptr;
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MeshComponent
|
struct MeshComponent
|
||||||
{
|
{
|
||||||
Ref<Mesh> mesh;
|
Ref<Mesh> mesh;
|
||||||
PrimitiveType primitive_type = PrimitiveType::None;
|
|
||||||
|
|
||||||
MeshComponent() = default;
|
MeshComponent() = default;
|
||||||
MeshComponent(const MeshComponent&) = default;
|
MeshComponent(const MeshComponent&) = default;
|
||||||
MeshComponent(const Ref<Mesh>& mesh)
|
MeshComponent(const Ref<Mesh>& mesh)
|
||||||
: mesh(mesh) {};
|
: mesh(mesh) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MaterialComponent
|
|
||||||
{
|
|
||||||
Material material;
|
|
||||||
|
|
||||||
MaterialComponent() = default;
|
|
||||||
MaterialComponent(const MaterialComponent&) = default;
|
|
||||||
MaterialComponent(const Material& material)
|
|
||||||
: material(material) {};
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PhysicsBodyComponent
|
|
||||||
{
|
|
||||||
BodyID body;
|
|
||||||
|
|
||||||
float linear_damping = 0.05f;
|
|
||||||
float angular_damping = 0.05f;
|
|
||||||
float gravity_factor = 1.0f;
|
|
||||||
float restitution = 0.8f;
|
|
||||||
float friction = 0.5f;
|
|
||||||
|
|
||||||
int type = (int)EMotionType::Static;
|
|
||||||
int initial_activation_state = (int)EActivation::Activate;
|
|
||||||
int layer = (int)Layers::MOVING;
|
|
||||||
|
|
||||||
PhysicsBodyComponent() = default;
|
|
||||||
PhysicsBodyComponent(const PhysicsBodyComponent&) = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: Let's add more shapes
|
|
||||||
struct BoxShapeComponent
|
|
||||||
{
|
|
||||||
glm::vec3 size = { 1.0f, 1.0f, 1.0f };
|
|
||||||
|
|
||||||
BoxShapeComponent() = default;
|
|
||||||
BoxShapeComponent(const BoxShapeComponent&) = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SphereShapeComponent
|
|
||||||
{
|
|
||||||
float radius = 1.0f;
|
|
||||||
|
|
||||||
SphereShapeComponent() = default;
|
|
||||||
SphereShapeComponent(const SphereShapeComponent&) = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PlaneShapeComponent
|
|
||||||
{
|
|
||||||
float extent = 1.0f;
|
|
||||||
|
|
||||||
PlaneShapeComponent() = default;
|
|
||||||
PlaneShapeComponent(const PlaneShapeComponent&) = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ModelComponent
|
|
||||||
{
|
|
||||||
Ref<Model3D> model;
|
|
||||||
|
|
||||||
ModelComponent() = default;
|
|
||||||
ModelComponent(const ModelComponent&) = default;
|
|
||||||
ModelComponent(Ref<Model3D>& model)
|
|
||||||
: model(model)
|
|
||||||
{}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // COMPONENTS_HPP
|
#endif // COMPONENTS_HPP
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
#include "open_engine/core.hpp"
|
#include "open_engine/core.hpp"
|
||||||
|
|
||||||
#include "open_engine/core/uuid.hpp"
|
|
||||||
#include "open_engine/scene/components.hpp"
|
|
||||||
#include "open_engine/scene/scene.hpp"
|
#include "open_engine/scene/scene.hpp"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@@ -50,8 +48,6 @@ namespace OpenEngine {
|
|||||||
return scene->registry.all_of<T>(handle);
|
return scene->registry.all_of<T>(handle);
|
||||||
};
|
};
|
||||||
|
|
||||||
UUID GetUUID() { return GetComponents<IDComponent>().id; };
|
|
||||||
|
|
||||||
operator bool() const { return handle != entt::null; };
|
operator bool() const { return handle != entt::null; };
|
||||||
operator entt::entity() const { return handle; };
|
operator entt::entity() const { return handle; };
|
||||||
operator uint32_t() const { return (uint32_t)handle; };
|
operator uint32_t() const { return (uint32_t)handle; };
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#ifndef NATIVE_SCRIPTABLE_ENTITY_HPP
|
#ifndef NATIVE_SCRIPTABLE_ENTITY_HPP
|
||||||
#define NATIVE_SCRIPTABLE_ENTITY_HPP
|
#define NATIVE_SCRIPTABLE_ENTITY_HPP
|
||||||
|
|
||||||
#include "open_engine/scene/native_scriptable_entity.hpp"
|
|
||||||
#include "open_engine/scene/entity.hpp"
|
#include "open_engine/scene/entity.hpp"
|
||||||
|
|
||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
#ifndef SCENE_HPP
|
#ifndef SCENE_HPP
|
||||||
#define SCENE_HPP
|
#define SCENE_HPP
|
||||||
|
|
||||||
#include "open_engine/core/uuid.hpp"
|
|
||||||
#include "open_engine/renderer/editor_camera.hpp"
|
#include "open_engine/renderer/editor_camera.hpp"
|
||||||
#include "open_engine/physics.hpp"
|
|
||||||
|
|
||||||
#include <Jolt/Physics/Body/BodyInterface.h>
|
|
||||||
#include <entt/entity/fwd.hpp>
|
#include <entt/entity/fwd.hpp>
|
||||||
#include <entt/entt.hpp>
|
#include <entt/entt.hpp>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@@ -19,13 +16,8 @@ namespace OpenEngine {
|
|||||||
public:
|
public:
|
||||||
Scene() = default;
|
Scene() = default;
|
||||||
~Scene() = default;
|
~Scene() = default;
|
||||||
Scene(Scene& other) {};
|
|
||||||
|
|
||||||
void OnRuntimeStart();
|
|
||||||
void OnRuntimeStop();
|
|
||||||
|
|
||||||
Entity CreateEntity(const std::string& name = std::string());
|
Entity CreateEntity(const std::string& name = std::string());
|
||||||
Entity CreateEntityWithUUID(UUID uuid, const std::string& name = std::string());
|
|
||||||
void DeleteEntity(entt::entity entity);
|
void DeleteEntity(entt::entity entity);
|
||||||
void MarkEntityForDeletion(Entity entity);
|
void MarkEntityForDeletion(Entity entity);
|
||||||
|
|
||||||
@@ -36,24 +28,19 @@ namespace OpenEngine {
|
|||||||
void OnViewportResize(uint32_t width, uint32_t height);
|
void OnViewportResize(uint32_t width, uint32_t height);
|
||||||
|
|
||||||
entt::registry& GetRegistry() { return registry; };
|
entt::registry& GetRegistry() { return registry; };
|
||||||
PhysicsEngine& GetPhysicsEngine() { return physics_engine; };
|
|
||||||
Entity GetPrimaryCamera();
|
Entity GetPrimaryCamera();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnUpdatePhysics();
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void OnComponentAdded(Entity entity, T& component);
|
void OnComponentAdded(Entity entity, T& component);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
entt::registry registry;
|
entt::registry registry;
|
||||||
PhysicsEngine physics_engine;
|
|
||||||
|
|
||||||
BodyInterface* body_interface;
|
|
||||||
|
|
||||||
uint32_t viewport_width = 0, viewport_height = 0;
|
uint32_t viewport_width = 0, viewport_height = 0;
|
||||||
|
|
||||||
std::vector<entt::entity> pending_deletion;
|
std::vector<entt::entity> entities_to_be_deleted;
|
||||||
|
|
||||||
friend class SceneSerializer;
|
friend class SceneSerializer;
|
||||||
friend class Entity;
|
friend class Entity;
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
#include <cstdint>
|
|
||||||
#include <pch.hpp>
|
|
||||||
|
|
||||||
#include <core/uuid.hpp>
|
|
||||||
|
|
||||||
#include <random>
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
|
||||||
|
|
||||||
static std::random_device s_random_device;
|
|
||||||
static std::mt19937_64 s_engine(s_random_device());
|
|
||||||
static std::uniform_int_distribution<uint64_t> s_uniform_distribution;
|
|
||||||
|
|
||||||
UUID::UUID()
|
|
||||||
: uuid(s_uniform_distribution(s_engine))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
UUID::UUID(uint64_t uuid)
|
|
||||||
: uuid(uuid)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
#include <pch.hpp>
|
|
||||||
|
|
||||||
#include "logging.hpp"
|
|
||||||
#include <fastgltf.hpp>
|
|
||||||
#include "ref_scope.hpp"
|
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <glm/fwd.hpp>
|
|
||||||
#include <fastgltf/core.hpp>
|
|
||||||
#include <fastgltf/types.hpp>
|
|
||||||
#include <fastgltf/tools.hpp>
|
|
||||||
#include <fastgltf/glm_element_traits.hpp>
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
|
||||||
|
|
||||||
void loadPrimitive(fastgltf::Asset& asset,
|
|
||||||
fastgltf::Primitive& primitive,
|
|
||||||
Mesh& out)
|
|
||||||
{
|
|
||||||
if (primitive.indicesAccessor.has_value()) {
|
|
||||||
auto& accessor = asset.accessors[primitive.indicesAccessor.value()];
|
|
||||||
out.indices.resize(accessor.count);
|
|
||||||
|
|
||||||
fastgltf::iterateAccessorWithIndex<uint32_t>(asset, accessor,
|
|
||||||
[&](uint32_t index, size_t i) {
|
|
||||||
out.indices[i] = index;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto* position_iterator = primitive.findAttribute("POSITION");
|
|
||||||
auto& accessor = asset.accessors[position_iterator->accessorIndex];
|
|
||||||
out.vertices.resize(accessor.count);
|
|
||||||
|
|
||||||
fastgltf::iterateAccessorWithIndex<glm::vec3>(asset, accessor,
|
|
||||||
[&](glm::vec3 pos, size_t i) {
|
|
||||||
out.vertices[i].position = pos;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auto* normal_iterator = primitive.findAttribute("NORMAL");
|
|
||||||
normal_iterator != primitive.attributes.end()) {
|
|
||||||
auto& accessor = asset.accessors[normal_iterator->accessorIndex];
|
|
||||||
|
|
||||||
fastgltf::iterateAccessorWithIndex<glm::vec3>(asset, accessor,
|
|
||||||
[&](glm::vec3 norm, size_t i) {
|
|
||||||
out.vertices[i].normal = norm;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
if (primitive.materialIndex.has_value()) {
|
|
||||||
auto& material = asset.materials[primitive.materialIndex.value()];
|
|
||||||
auto& pbr = material.pbrData;
|
|
||||||
|
|
||||||
auto& c = pbr.baseColorFactor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref<Mesh> TestGLTF()
|
|
||||||
{
|
|
||||||
fastgltf::Parser parser;
|
|
||||||
Ref<Mesh> new_mesh = CreateRef<Mesh>();
|
|
||||||
|
|
||||||
auto data = fastgltf::GltfDataBuffer::FromPath("assets/models/cube.glb");
|
|
||||||
if (data.error() != fastgltf::Error::None)
|
|
||||||
OE_CORE_ERROR("Could not parse model");
|
|
||||||
|
|
||||||
auto asset = parser.loadGltfBinary(data.get(), ".",
|
|
||||||
fastgltf::Options::LoadExternalBuffers
|
|
||||||
);
|
|
||||||
if (asset.error() != fastgltf::Error::None)
|
|
||||||
OE_CORE_ERROR("Could not optain asset");
|
|
||||||
|
|
||||||
for (auto& mesh : asset->meshes)
|
|
||||||
for (auto& primitive : mesh.primitives)
|
|
||||||
loadPrimitive(asset.get(), primitive, *new_mesh);
|
|
||||||
|
|
||||||
return new_mesh;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,137 +0,0 @@
|
|||||||
#include "logging.hpp"
|
|
||||||
#include <pch.hpp>
|
|
||||||
|
|
||||||
#include <gltf/gltf_model3d.hpp>
|
|
||||||
|
|
||||||
#include <fastgltf/core.hpp>
|
|
||||||
#include <fastgltf/types.hpp>
|
|
||||||
#include <fastgltf/tools.hpp>
|
|
||||||
#include <fastgltf/glm_element_traits.hpp>
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
|
||||||
|
|
||||||
void PopulateMesh(Mesh& mesh)
|
|
||||||
{
|
|
||||||
mesh.vertex_array = VertexArray::Create();
|
|
||||||
|
|
||||||
mesh.vertex_buffer = VertexBuffer::Create(mesh.vertices.size() * sizeof(MeshVertex));
|
|
||||||
mesh.vertex_buffer->SetData(mesh.vertices.data(), mesh.vertices.size() * sizeof(MeshVertex));
|
|
||||||
|
|
||||||
BufferLayout layout = {
|
|
||||||
{ ShaderDataType::Float3, "a_Position" },
|
|
||||||
{ ShaderDataType::Float3, "a_Normal" },
|
|
||||||
{ ShaderDataType::Float2, "a_TexCoord" }
|
|
||||||
};
|
|
||||||
|
|
||||||
mesh.vertex_buffer->SetLayout(layout);
|
|
||||||
mesh.vertex_array->AddVertexBuffer(mesh.vertex_buffer);
|
|
||||||
|
|
||||||
mesh.index_buffer = IndexBuffer::Create(mesh.indices.data(), mesh.indices.size());
|
|
||||||
mesh.vertex_array->SetIndexBuffer(mesh.index_buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref<Mesh> CreateMesh(const std::vector<MeshVertex>& vertices,
|
|
||||||
const std::vector<uint32_t>& indices)
|
|
||||||
{
|
|
||||||
Ref<Mesh> mesh = CreateRef<Mesh>();
|
|
||||||
|
|
||||||
mesh->vertices = vertices;
|
|
||||||
mesh->indices = indices;
|
|
||||||
|
|
||||||
PopulateMesh(*mesh);
|
|
||||||
|
|
||||||
return mesh;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GLTFModel3D::loadPrimitive(fastgltf::Asset& asset,
|
|
||||||
fastgltf::Primitive& primitive,
|
|
||||||
Mesh& out)
|
|
||||||
{
|
|
||||||
if (primitive.indicesAccessor.has_value()) {
|
|
||||||
auto& accessor = asset.accessors[primitive.indicesAccessor.value()];
|
|
||||||
out.indices.resize(accessor.count);
|
|
||||||
|
|
||||||
fastgltf::iterateAccessorWithIndex<uint32_t>(asset, accessor,
|
|
||||||
[&](uint32_t index, size_t i) {
|
|
||||||
out.indices[i] = index;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto* position_iterator = primitive.findAttribute("POSITION");
|
|
||||||
auto& accessor = asset.accessors[position_iterator->accessorIndex];
|
|
||||||
out.vertices.resize(accessor.count);
|
|
||||||
|
|
||||||
fastgltf::iterateAccessorWithIndex<glm::vec3>(asset, accessor,
|
|
||||||
[&](glm::vec3 pos, size_t i) {
|
|
||||||
out.vertices[i].position = pos;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auto* normal_iterator = primitive.findAttribute("NORMAL");
|
|
||||||
normal_iterator != primitive.attributes.end()) {
|
|
||||||
auto& accessor = asset.accessors[normal_iterator->accessorIndex];
|
|
||||||
|
|
||||||
fastgltf::iterateAccessorWithIndex<glm::vec3>(asset, accessor,
|
|
||||||
[&](glm::vec3 norm, size_t i) {
|
|
||||||
out.vertices[i].normal = norm;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
if (primitive.materialIndex.has_value()) {
|
|
||||||
auto& material = asset.materials[primitive.materialIndex.value()];
|
|
||||||
auto& pbr = material.pbrData;
|
|
||||||
|
|
||||||
auto& color = pbr.baseColorFactor;
|
|
||||||
auto& roughness = pbr.roughnessFactor;
|
|
||||||
auto& metallic = pbr.metallicFactor;
|
|
||||||
|
|
||||||
out.material.name = material.name;
|
|
||||||
out.material.albedo = glm::vec4(color[0], color[1], color[2], color[3]);
|
|
||||||
out.material.roughness = roughness;
|
|
||||||
out.material.metallic = metallic;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GLTFModel3D::GLTFModel3D(const char* path)
|
|
||||||
{
|
|
||||||
fastgltf::Parser parser;
|
|
||||||
|
|
||||||
auto data = fastgltf::GltfDataBuffer::FromPath(path);
|
|
||||||
if (data.error() != fastgltf::Error::None)
|
|
||||||
OE_CORE_ERROR("Could not parse model");
|
|
||||||
|
|
||||||
auto asset = parser.loadGltfBinary(data.get(), ".",
|
|
||||||
fastgltf::Options::LoadExternalBuffers
|
|
||||||
);
|
|
||||||
if (asset.error() != fastgltf::Error::None)
|
|
||||||
OE_CORE_ERROR("Could not optain asset");
|
|
||||||
|
|
||||||
|
|
||||||
for (auto& mesh : asset->meshes) {
|
|
||||||
name = mesh.name;
|
|
||||||
|
|
||||||
for (auto& primitive : mesh.primitives) {
|
|
||||||
Mesh prim_mesh;
|
|
||||||
|
|
||||||
loadPrimitive(asset.get(), primitive, prim_mesh);
|
|
||||||
PopulateMesh(prim_mesh);
|
|
||||||
|
|
||||||
meshes.emplace_back(prim_mesh);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const Mesh& GLTFModel3D::GetMesh(int index) const
|
|
||||||
{
|
|
||||||
return meshes[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<Mesh>& GLTFModel3D::GetMeshes() const
|
|
||||||
{
|
|
||||||
return meshes;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
#include <pch.hpp>
|
|
||||||
|
|
||||||
#include <ref_scope.hpp>
|
|
||||||
#include <physics.hpp>
|
|
||||||
|
|
||||||
#include <Jolt/Physics/Body/BodyInterface.h>
|
|
||||||
#include <Jolt/Core/JobSystemThreadPool.h>
|
|
||||||
#include <Jolt/Core/Memory.h>
|
|
||||||
#include <Jolt/Physics/PhysicsSystem.h>
|
|
||||||
#include <Jolt/Physics/PhysicsUpdateContext.h>
|
|
||||||
|
|
||||||
bool ObjectLayerPairFilterImpl::ShouldCollide(ObjectLayer object1, ObjectLayer object2) const
|
|
||||||
{
|
|
||||||
switch (object1)
|
|
||||||
{
|
|
||||||
case Layers::NON_MOVING:
|
|
||||||
return object2 == Layers::MOVING; // Non moving only collides with moving
|
|
||||||
case Layers::MOVING:
|
|
||||||
return true; // Moving collides with everything
|
|
||||||
default:
|
|
||||||
JPH_ASSERT(false);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
|
||||||
|
|
||||||
PhysicsEngine::PhysicsEngine()
|
|
||||||
{
|
|
||||||
RegisterDefaultAllocator();
|
|
||||||
|
|
||||||
Trace = TraceImpl;
|
|
||||||
JPH_IF_ENABLE_ASSERTS(AssertFailed = AssertFailedImpl);
|
|
||||||
|
|
||||||
Factory::sInstance = new Factory();
|
|
||||||
|
|
||||||
RegisterTypes();
|
|
||||||
|
|
||||||
tmp_allocator = CreateRef<TempAllocatorImpl>(10 * 1024 * 1024);
|
|
||||||
|
|
||||||
job_system = CreateRef<JobSystemThreadPool>(cMaxPhysicsJobs,
|
|
||||||
cMaxPhysicsBarriers,
|
|
||||||
thread::hardware_concurrency() - 1);
|
|
||||||
|
|
||||||
physics_system.Init(
|
|
||||||
1024,
|
|
||||||
0,
|
|
||||||
1024,
|
|
||||||
1024,
|
|
||||||
broad_phase_layer_interface,
|
|
||||||
object_vs_broadphase_layer_filter,
|
|
||||||
object_vs_object_layer_filter);
|
|
||||||
|
|
||||||
//physics_system.SetBodyActivationListener(&body_activation_listener);
|
|
||||||
//physics_system.SetContactListener(&contact_listener);
|
|
||||||
|
|
||||||
// TODO: Check the comment on Jolt's example
|
|
||||||
physics_system.OptimizeBroadPhase();
|
|
||||||
}
|
|
||||||
|
|
||||||
PhysicsEngine::~PhysicsEngine() {
|
|
||||||
UnregisterTypes();
|
|
||||||
|
|
||||||
// Destroy the factory
|
|
||||||
delete Factory::sInstance;
|
|
||||||
Factory::sInstance = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
void PhysicsEngine::Update(float delta_time, int collision_steps)
|
|
||||||
{
|
|
||||||
physics_system.Update(delta_time, collision_steps, &*tmp_allocator, &*job_system);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#include <pch.hpp>
|
|
||||||
|
|
||||||
#include <renderer/model3d.hpp>
|
|
||||||
|
|
||||||
#include <gltf/gltf_model3d.hpp>
|
|
||||||
#include <instrumentor.hpp>
|
|
||||||
#include <ref_scope.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace OpenEngine {
|
|
||||||
|
|
||||||
Ref<Model3D> Model3D::Create(const char* path)
|
|
||||||
{
|
|
||||||
OE_PROFILE_FUNCTION();
|
|
||||||
|
|
||||||
return CreateRef<GLTFModel3D>(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -23,6 +23,33 @@
|
|||||||
namespace OpenEngine {
|
namespace OpenEngine {
|
||||||
|
|
||||||
// SHOULD BE MOVED ==================================
|
// SHOULD BE MOVED ==================================
|
||||||
|
Ref<Mesh> CreateMesh(const std::vector<MeshVertex>& vertices,
|
||||||
|
const std::vector<uint32_t>& indices)
|
||||||
|
{
|
||||||
|
Ref<Mesh> mesh = CreateRef<Mesh>();
|
||||||
|
mesh->vertices = vertices;
|
||||||
|
mesh->indices = indices;
|
||||||
|
|
||||||
|
mesh->vertex_array = VertexArray::Create();
|
||||||
|
|
||||||
|
mesh->vertex_buffer = VertexBuffer::Create(vertices.size() * sizeof(MeshVertex));
|
||||||
|
mesh->vertex_buffer->SetData(vertices.data(), vertices.size() * sizeof(MeshVertex));
|
||||||
|
|
||||||
|
BufferLayout layout = {
|
||||||
|
{ ShaderDataType::Float3, "a_Position" },
|
||||||
|
{ ShaderDataType::Float4, "a_Color" },
|
||||||
|
{ ShaderDataType::Float3, "a_Normal" },
|
||||||
|
{ ShaderDataType::Float2, "a_TexCoord" },
|
||||||
|
{ ShaderDataType::Int, "a_EntityID"}
|
||||||
|
};
|
||||||
|
mesh->vertex_buffer->SetLayout(layout);
|
||||||
|
mesh->vertex_array->AddVertexBuffer(mesh->vertex_buffer);
|
||||||
|
|
||||||
|
mesh->index_buffer = IndexBuffer::Create(indices.data(), indices.size());
|
||||||
|
mesh->vertex_array->SetIndexBuffer(mesh->index_buffer);
|
||||||
|
|
||||||
|
return mesh;
|
||||||
|
}
|
||||||
|
|
||||||
Ref<Mesh> CreateQuad(uint32_t id, bool back_face)
|
Ref<Mesh> CreateQuad(uint32_t id, bool back_face)
|
||||||
{
|
{
|
||||||
@@ -34,16 +61,16 @@ namespace OpenEngine {
|
|||||||
if (back_face) {
|
if (back_face) {
|
||||||
vertices = {
|
vertices = {
|
||||||
// Front face (normal 0, 0, 1)
|
// Front face (normal 0, 0, 1)
|
||||||
{{-0.5f, -0.5f, 0.0f}, {0,0,1}, {0,0}},
|
{{-0.5f, -0.5f, 0.0f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,1}, {0,0}, id},
|
||||||
{{-0.5f, 0.5f, 0.0f}, {0,0,1}, {0,1}},
|
{{-0.5f, 0.5f, 0.0f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,1}, {0,1}, id},
|
||||||
{{ 0.5f, 0.5f, 0.0f}, {0,0,1}, {1,1}},
|
{{ 0.5f, 0.5f, 0.0f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,1}, {1,1}, id},
|
||||||
{{ 0.5f, -0.5f, 0.0f}, {0,0,1}, {1,0}},
|
{{ 0.5f, -0.5f, 0.0f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,1}, {1,0}, id},
|
||||||
|
|
||||||
// Back face (normal 0, 0, -1)
|
// Back face (normal 0, 0, -1)
|
||||||
{{-0.5f, -0.5f, -0.0f}, {0,0,-1}, {0,0}},
|
{{-0.5f, -0.5f, -0.0f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,-1}, {0,0}, id},
|
||||||
{{-0.5f, 0.5f, -0.0f}, {0,0,-1}, {0,1}},
|
{{-0.5f, 0.5f, -0.0f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,-1}, {0,1}, id},
|
||||||
{{ 0.5f, 0.5f, -0.0f}, {0,0,-1}, {1,1}},
|
{{ 0.5f, 0.5f, -0.0f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,-1}, {1,1}, id},
|
||||||
{{ 0.5f, -0.5f, -0.0f}, {0,0,-1}, {1,0}}
|
{{ 0.5f, -0.5f, -0.0f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,-1}, {1,0}, id}
|
||||||
};
|
};
|
||||||
|
|
||||||
indices = {
|
indices = {
|
||||||
@@ -55,10 +82,10 @@ namespace OpenEngine {
|
|||||||
} else {
|
} else {
|
||||||
vertices = {
|
vertices = {
|
||||||
// Front face (normal 0, 0, 1)
|
// Front face (normal 0, 0, 1)
|
||||||
{{-0.5f, -0.5f, 0.0f}, {0,0,1}, {0,0}},
|
{{-0.5f, -0.5f, 0.0f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,1}, {0,0}, id},
|
||||||
{{-0.5f, 0.5f, 0.0f}, {0,0,1}, {0,1}},
|
{{-0.5f, 0.5f, 0.0f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,1}, {0,1}, id},
|
||||||
{{ 0.5f, 0.5f, 0.0f}, {0,0,1}, {1,1}},
|
{{ 0.5f, 0.5f, 0.0f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,1}, {1,1}, id},
|
||||||
{{ 0.5f, -0.5f, 0.0f}, {0,0,1}, {1,0}}
|
{{ 0.5f, -0.5f, 0.0f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,1}, {1,0}, id}
|
||||||
};
|
};
|
||||||
|
|
||||||
indices = {
|
indices = {
|
||||||
@@ -76,40 +103,40 @@ namespace OpenEngine {
|
|||||||
OE_CORE_DEBUG("Creating cube with id {}.", id);
|
OE_CORE_DEBUG("Creating cube with id {}.", id);
|
||||||
std::vector<MeshVertex> vertices = {
|
std::vector<MeshVertex> vertices = {
|
||||||
// Front face (normal 0, 0, 1)
|
// Front face (normal 0, 0, 1)
|
||||||
{{-0.5f, -0.5f, 0.5f}, {0,0,1}, {0,0}},
|
{{-0.5f, -0.5f, 0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,1}, {0,0}, id},
|
||||||
{{-0.5f, 0.5f, 0.5f}, {0,0,1}, {0,1}},
|
{{-0.5f, 0.5f, 0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,1}, {0,1}, id},
|
||||||
{{ 0.5f, 0.5f, 0.5f}, {0,0,1}, {1,1}},
|
{{ 0.5f, 0.5f, 0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,1}, {1,1}, id},
|
||||||
{{ 0.5f, -0.5f, 0.5f}, {0,0,1}, {1,0}},
|
{{ 0.5f, -0.5f, 0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,1}, {1,0}, id},
|
||||||
|
|
||||||
// Back face (normal 0, 0, -1)
|
// Back face (normal 0, 0, -1)
|
||||||
{{-0.5f, -0.5f, -0.5f}, {0,0,-1}, {0,0}},
|
{{-0.5f, -0.5f, -0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,-1}, {0,0}, id},
|
||||||
{{-0.5f, 0.5f, -0.5f}, {0,0,-1}, {0,1}},
|
{{-0.5f, 0.5f, -0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,-1}, {0,1}, id},
|
||||||
{{ 0.5f, 0.5f, -0.5f}, {0,0,-1}, {1,1}},
|
{{ 0.5f, 0.5f, -0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,-1}, {1,1}, id},
|
||||||
{{ 0.5f, -0.5f, -0.5f}, {0,0,-1}, {1,0}},
|
{{ 0.5f, -0.5f, -0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,0,-1}, {1,0}, id},
|
||||||
|
|
||||||
// Left face (normal -1, 0, 0)
|
// Left face (normal -1, 0, 0)
|
||||||
{{-0.5f, -0.5f, -0.5f}, {-1,0,0}, {0,0}},
|
{{-0.5f, -0.5f, -0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {-1,0,0}, {0,0}, id},
|
||||||
{{-0.5f, 0.5f, -0.5f}, {-1,0,0}, {0,1}},
|
{{-0.5f, 0.5f, -0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {-1,0,0}, {0,1}, id},
|
||||||
{{-0.5f, 0.5f, 0.5f}, {-1,0,0}, {1,1}},
|
{{-0.5f, 0.5f, 0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {-1,0,0}, {1,1}, id},
|
||||||
{{-0.5f, -0.5f, 0.5f}, {-1,0,0}, {1,0}},
|
{{-0.5f, -0.5f, 0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {-1,0,0}, {1,0}, id},
|
||||||
|
|
||||||
// Right face (normal 1, 0, 0)
|
// Right face (normal 1, 0, 0)
|
||||||
{{ 0.5f, -0.5f, -0.5f}, {1,0,0}, {0,0}},
|
{{ 0.5f, -0.5f, -0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {1,0,0}, {0,0}, id},
|
||||||
{{ 0.5f, 0.5f, -0.5f}, {1,0,0}, {0,1}},
|
{{ 0.5f, 0.5f, -0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {1,0,0}, {0,1}, id},
|
||||||
{{ 0.5f, 0.5f, 0.5f}, {1,0,0}, {1,1}},
|
{{ 0.5f, 0.5f, 0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {1,0,0}, {1,1}, id},
|
||||||
{{ 0.5f, -0.5f, 0.5f}, {1,0,0}, {1,0}},
|
{{ 0.5f, -0.5f, 0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {1,0,0}, {1,0}, id},
|
||||||
|
|
||||||
// Top face (normal 0, 1, 0)
|
// Top face (normal 0, 1, 0)
|
||||||
{{-0.5f, 0.5f, -0.5f}, {0,1,0}, {0,0}},
|
{{-0.5f, 0.5f, -0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,1,0}, {0,0}, id},
|
||||||
{{-0.5f, 0.5f, 0.5f}, {0,1,0}, {0,1}},
|
{{-0.5f, 0.5f, 0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,1,0}, {0,1}, id},
|
||||||
{{ 0.5f, 0.5f, 0.5f}, {0,1,0}, {1,1}},
|
{{ 0.5f, 0.5f, 0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,1,0}, {1,1}, id},
|
||||||
{{ 0.5f, 0.5f, -0.5f}, {0,1,0}, {1,0}},
|
{{ 0.5f, 0.5f, -0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,1,0}, {1,0}, id},
|
||||||
|
|
||||||
// Bottom face (normal 0, -1, 0)
|
// Bottom face (normal 0, -1, 0)
|
||||||
{{-0.5f, -0.5f, -0.5f}, {0,-1,0}, {0,0}},
|
{{-0.5f, -0.5f, -0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,-1,0}, {0,0}, id},
|
||||||
{{-0.5f, -0.5f, 0.5f}, {0,-1,0}, {0,1}},
|
{{-0.5f, -0.5f, 0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,-1,0}, {0,1}, id},
|
||||||
{{ 0.5f, -0.5f, 0.5f}, {0,-1,0}, {1,1}},
|
{{ 0.5f, -0.5f, 0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,-1,0}, {1,1}, id},
|
||||||
{{ 0.5f, -0.5f, -0.5f}, {0,-1,0}, {1,0}},
|
{{ 0.5f, -0.5f, -0.5f}, { 0.5f, 0.5f, 0.5f, 1 }, {0,-1,0}, {1,0}, id},
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<uint32_t> indices = {
|
std::vector<uint32_t> indices = {
|
||||||
@@ -149,11 +176,6 @@ namespace OpenEngine {
|
|||||||
};
|
};
|
||||||
TransformData transform_buffer;
|
TransformData transform_buffer;
|
||||||
Ref<UniformBuffer> transform_uniform_buffer;
|
Ref<UniformBuffer> transform_uniform_buffer;
|
||||||
|
|
||||||
Material material_buffer;
|
|
||||||
Ref<UniformBuffer> material_uniform_buffer;
|
|
||||||
|
|
||||||
Ref<UniformBuffer> id_uniform_buffer;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static Renderer3DData renderer_data;
|
static Renderer3DData renderer_data;
|
||||||
@@ -168,8 +190,6 @@ namespace OpenEngine {
|
|||||||
renderer_data.color_shader_3d = Shader::Create("assets/shaders/color3d.glsl");
|
renderer_data.color_shader_3d = Shader::Create("assets/shaders/color3d.glsl");
|
||||||
renderer_data.camera_uniform_buffer = UniformBuffer::Create(sizeof(Renderer3DData::CameraData), 0);
|
renderer_data.camera_uniform_buffer = UniformBuffer::Create(sizeof(Renderer3DData::CameraData), 0);
|
||||||
renderer_data.transform_uniform_buffer = UniformBuffer::Create(sizeof(Renderer3DData::TransformData), 1);
|
renderer_data.transform_uniform_buffer = UniformBuffer::Create(sizeof(Renderer3DData::TransformData), 1);
|
||||||
renderer_data.material_uniform_buffer = UniformBuffer::Create(sizeof(Material), 2);
|
|
||||||
renderer_data.id_uniform_buffer = UniformBuffer::Create(sizeof(uint32_t), 3);
|
|
||||||
|
|
||||||
glEnable(GL_DEBUG_OUTPUT);
|
glEnable(GL_DEBUG_OUTPUT);
|
||||||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
||||||
@@ -181,11 +201,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void Renderer3D::Shutdown()
|
void Renderer3D::Shutdown()
|
||||||
{
|
{
|
||||||
renderer_data.color_shader_3d.reset();
|
|
||||||
renderer_data.camera_uniform_buffer.reset();
|
renderer_data.camera_uniform_buffer.reset();
|
||||||
renderer_data.transform_uniform_buffer.reset();
|
renderer_data.color_shader_3d.reset();
|
||||||
renderer_data.material_uniform_buffer.reset();
|
|
||||||
renderer_data.id_uniform_buffer.reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer3D::BeginScene(const SceneCamera& camera, const glm::mat4& transform)
|
void Renderer3D::BeginScene(const SceneCamera& camera, const glm::mat4& transform)
|
||||||
@@ -213,8 +230,7 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer3D::DrawMesh(const Ref<Mesh>& mesh, Material& material,
|
void Renderer3D::DrawMesh(const Ref<Mesh>& mesh, const glm::mat4& transform)
|
||||||
const glm::mat4& transform)
|
|
||||||
{
|
{
|
||||||
OE_PROFILE_FUNCTION();
|
OE_PROFILE_FUNCTION();
|
||||||
|
|
||||||
@@ -223,55 +239,8 @@ namespace OpenEngine {
|
|||||||
renderer_data.transform_buffer.transform = transform;
|
renderer_data.transform_buffer.transform = transform;
|
||||||
renderer_data.transform_uniform_buffer->SetData(&renderer_data.transform_buffer, sizeof(Renderer3DData::TransformData));
|
renderer_data.transform_uniform_buffer->SetData(&renderer_data.transform_buffer, sizeof(Renderer3DData::TransformData));
|
||||||
|
|
||||||
renderer_data.material_buffer = material;
|
|
||||||
renderer_data.material_uniform_buffer->SetData(&renderer_data.material_buffer, sizeof(Material));
|
|
||||||
|
|
||||||
mesh->vertex_array->Bind();
|
mesh->vertex_array->Bind();
|
||||||
|
|
||||||
RenderCommand::DrawIndexed(mesh->vertex_array, mesh->indices.size());
|
RenderCommand::DrawIndexed(mesh->vertex_array, mesh->indices.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer3D::DrawMesh(const Ref<Mesh>& mesh, Material& material,
|
|
||||||
const glm::mat4& transform,
|
|
||||||
uint32_t entity_id)
|
|
||||||
{
|
|
||||||
OE_PROFILE_FUNCTION();
|
|
||||||
|
|
||||||
renderer_data.color_shader_3d->Bind();
|
|
||||||
|
|
||||||
renderer_data.transform_buffer.transform = transform;
|
|
||||||
renderer_data.transform_uniform_buffer->SetData(&renderer_data.transform_buffer, sizeof(Renderer3DData::TransformData));
|
|
||||||
|
|
||||||
renderer_data.material_buffer = material;
|
|
||||||
renderer_data.material_uniform_buffer->SetData(&renderer_data.material_buffer, sizeof(Material));
|
|
||||||
|
|
||||||
renderer_data.id_uniform_buffer->SetData(&entity_id, sizeof(uint32_t));
|
|
||||||
|
|
||||||
mesh->vertex_array->Bind();
|
|
||||||
|
|
||||||
RenderCommand::DrawIndexed(mesh->vertex_array, mesh->indices.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer3D::DrawModel(const Ref<Model3D>& model,
|
|
||||||
const glm::mat4& transform,
|
|
||||||
uint32_t entity_id)
|
|
||||||
{
|
|
||||||
OE_PROFILE_FUNCTION();
|
|
||||||
|
|
||||||
renderer_data.color_shader_3d->Bind();
|
|
||||||
|
|
||||||
renderer_data.transform_buffer.transform = transform;
|
|
||||||
renderer_data.transform_uniform_buffer->SetData(&renderer_data.transform_buffer, sizeof(Renderer3DData::TransformData));
|
|
||||||
|
|
||||||
for (auto& mesh : *model) {
|
|
||||||
renderer_data.material_buffer = mesh.material;
|
|
||||||
renderer_data.material_uniform_buffer->SetData(&renderer_data.material_buffer, sizeof(Material));
|
|
||||||
|
|
||||||
renderer_data.id_uniform_buffer->SetData(&entity_id, sizeof(uint32_t));
|
|
||||||
|
|
||||||
mesh.vertex_array->Bind();
|
|
||||||
|
|
||||||
RenderCommand::DrawIndexed(mesh.vertex_array, mesh.indices.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
227
open_engine/src/open_engine/scene/scene.cpp
Executable file → Normal file
227
open_engine/src/open_engine/scene/scene.cpp
Executable file → Normal file
@@ -1,120 +1,18 @@
|
|||||||
#include "logging.hpp"
|
#include <cstdint>
|
||||||
#include "physics.hpp"
|
#include <entt/entity/fwd.hpp>
|
||||||
#include "ref_scope.hpp"
|
|
||||||
#include "renderer/model3d.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>
|
||||||
#include <scene/components.hpp>
|
#include <scene/components.hpp>
|
||||||
#include <open_engine/scene/native_scriptable_entity.hpp>
|
|
||||||
#include <scene/entity.hpp>
|
#include <scene/entity.hpp>
|
||||||
#include <scene/scene.hpp>
|
#include <scene/scene.hpp>
|
||||||
#include <core/time.hpp>
|
|
||||||
|
|
||||||
#include <Jolt/Physics/Collision/Shape/Shape.h>
|
|
||||||
#include <Jolt/Physics/Collision/Shape/PlaneShape.h>
|
|
||||||
#include <Jolt/Physics/Collision/Shape/BoxShape.h>
|
|
||||||
#include <Jolt/Physics/Collision/Shape/SphereShape.h>
|
|
||||||
#include <Jolt/Physics/EActivation.h>
|
|
||||||
#include <Jolt/Math/Real.h>
|
|
||||||
#include <Jolt/Math/Quat.h>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <entt/entity/fwd.hpp>
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
if (reg.any_of<PlaneShapeComponent>(e)) {
|
|
||||||
auto& c = reg.get<PlaneShapeComponent>(e);
|
|
||||||
const Plane plane({ 0.0f, 1.0f, 0.0f }, 0);
|
|
||||||
return CreateRef<PlaneShapeSettings>(plane, nullptr, c.extent);
|
|
||||||
}
|
|
||||||
|
|
||||||
OE_CORE_ERROR("Entity {} has no shape component!", reg.get<TagComponent>(e).tag);
|
|
||||||
return nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
void Scene::OnRuntimeStart()
|
|
||||||
{
|
|
||||||
body_interface = &physics_engine.GetBodyInterface();
|
|
||||||
// TODO: Cleanup components aquisition
|
|
||||||
auto view = registry.view<TransformComponent, PhysicsBodyComponent>();
|
|
||||||
for (auto e : view) {
|
|
||||||
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& tc = entity.GetComponents<TransformComponent>();
|
|
||||||
|
|
||||||
glm::vec3& pos = tc.translation;
|
|
||||||
glm::vec3& scale = tc.scale;
|
|
||||||
glm::vec3& rot = tc.rotation;
|
|
||||||
|
|
||||||
Quat quat = Quat::sEulerAngles(Vec3(rot.x, rot.y, rot.z));
|
|
||||||
BodyCreationSettings settings(
|
|
||||||
shape,
|
|
||||||
//new BoxShape(Vec3(scale.x * 0.5, scale.y * 0.5f, scale.z * 0.5f)),
|
|
||||||
Vec3(pos.x, pos.y, pos.z),
|
|
||||||
quat,
|
|
||||||
(EMotionType)pbc.type,
|
|
||||||
pbc.layer);
|
|
||||||
|
|
||||||
settings.mLinearDamping = pbc.linear_damping;
|
|
||||||
settings.mAngularDamping = pbc.angular_damping;
|
|
||||||
settings.mGravityFactor = pbc.gravity_factor;
|
|
||||||
settings.mRestitution = pbc.restitution;
|
|
||||||
settings.mFriction = pbc.friction;
|
|
||||||
settings.mObjectLayer = (ObjectLayer)pbc.layer;
|
|
||||||
|
|
||||||
pbc.body = body_interface->CreateAndAddBody(settings, (EActivation)pbc.initial_activation_state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Scene::OnRuntimeStop()
|
|
||||||
{
|
|
||||||
auto view = registry.view<PhysicsBodyComponent>();
|
|
||||||
for (auto e : view) {
|
|
||||||
Entity entity = { e, this };
|
|
||||||
|
|
||||||
auto& pbc = entity.GetComponents<PhysicsBodyComponent>();
|
|
||||||
|
|
||||||
body_interface->RemoveBody(pbc.body);
|
|
||||||
body_interface->DestroyBody(pbc.body);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity Scene::CreateEntity(const std::string& name)
|
Entity Scene::CreateEntity(const std::string& name)
|
||||||
{
|
|
||||||
return CreateEntityWithUUID(UUID(), name);
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity Scene::CreateEntityWithUUID(UUID uuid, const std::string& name)
|
|
||||||
{
|
{
|
||||||
Entity entity = { registry.create(), this };
|
Entity entity = { registry.create(), this };
|
||||||
|
|
||||||
entity.AddComponent<IDComponent>(uuid);
|
|
||||||
auto& tag = entity.AddComponent<TagComponent>();
|
auto& tag = entity.AddComponent<TagComponent>();
|
||||||
tag.tag = name.empty() ? "Entity" : name;
|
tag.tag = name.empty() ? "Entity" : name;
|
||||||
|
|
||||||
@@ -128,31 +26,15 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
void Scene::MarkEntityForDeletion(Entity entity)
|
void Scene::MarkEntityForDeletion(Entity entity)
|
||||||
{
|
{
|
||||||
pending_deletion.emplace_back(entity);
|
entities_to_be_deleted.emplace_back(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::UpdateEntities()
|
void Scene::UpdateEntities()
|
||||||
{
|
{
|
||||||
for (auto& entity : pending_deletion)
|
for (auto& entity : entities_to_be_deleted)
|
||||||
DeleteEntity(entity);
|
DeleteEntity(entity);
|
||||||
|
|
||||||
pending_deletion.clear();
|
entities_to_be_deleted.clear();
|
||||||
}
|
|
||||||
|
|
||||||
void Scene::OnUpdatePhysics()
|
|
||||||
{
|
|
||||||
static int step = 0;
|
|
||||||
static float accumulator = 0.0f;
|
|
||||||
static const float fixedDT = 1.0f / 60.0f;
|
|
||||||
|
|
||||||
float real_delta_time = Time::DeltaTime(); // e.g. from a timer
|
|
||||||
accumulator += real_delta_time;
|
|
||||||
|
|
||||||
if (accumulator >= fixedDT) {
|
|
||||||
step++;
|
|
||||||
physics_engine.Update(fixedDT, 1);
|
|
||||||
accumulator -= fixedDT;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::OnUpdateRuntime()
|
void Scene::OnUpdateRuntime()
|
||||||
@@ -172,40 +54,6 @@ namespace OpenEngine {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
auto view = registry.view<TransformComponent, PhysicsBodyComponent>();
|
|
||||||
for (auto e : view) {
|
|
||||||
Entity entity = { e, this };
|
|
||||||
|
|
||||||
auto& pos = entity.GetComponents<TransformComponent>().translation;
|
|
||||||
auto& body = entity.GetComponents<PhysicsBodyComponent>();
|
|
||||||
|
|
||||||
body_interface->SetPosition(body.body, { pos.x, pos.y, pos.z }, EActivation::Activate);
|
|
||||||
|
|
||||||
body_interface->SetRestitution(body.body, body.restitution);
|
|
||||||
body_interface->SetFriction(body.body, body.friction);
|
|
||||||
}
|
|
||||||
|
|
||||||
OnUpdatePhysics();
|
|
||||||
|
|
||||||
for (auto e : view) {
|
|
||||||
Entity entity = { e, this };
|
|
||||||
|
|
||||||
auto& transform = entity.GetComponents<TransformComponent>();
|
|
||||||
auto& body = entity.GetComponents<PhysicsBodyComponent>();
|
|
||||||
|
|
||||||
auto position = body_interface->GetPosition(body.body);
|
|
||||||
auto rotation = body_interface->GetRotation(body.body).GetEulerAngles();
|
|
||||||
transform.translation.x = position.GetX();
|
|
||||||
transform.translation.y = position.GetY();
|
|
||||||
transform.translation.z = position.GetZ();
|
|
||||||
|
|
||||||
transform.rotation.x = rotation.GetX();
|
|
||||||
transform.rotation.y = rotation.GetY();
|
|
||||||
transform.rotation.z = rotation.GetZ();
|
|
||||||
|
|
||||||
body_interface->SetGravityFactor(body.body, body.gravity_factor);
|
|
||||||
}
|
|
||||||
|
|
||||||
SceneCamera* main_camera = nullptr;
|
SceneCamera* main_camera = nullptr;
|
||||||
glm::mat4 main_transform{ 1.0f };
|
glm::mat4 main_transform{ 1.0f };
|
||||||
{
|
{
|
||||||
@@ -225,15 +73,10 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
auto view = registry.view<TransformComponent, MeshComponent>();
|
auto view = registry.view<TransformComponent, MeshComponent>();
|
||||||
|
|
||||||
for (const auto& e : view) {
|
for (const auto& entity : view) {
|
||||||
auto [transform, mesh] = view.get<TransformComponent, MeshComponent>(e);
|
auto [transform, mesh] = view.get<TransformComponent, MeshComponent>(entity);
|
||||||
Entity entity(e, this);
|
|
||||||
|
|
||||||
Material material;
|
Renderer3D::DrawMesh(mesh.mesh, GetTransformFromComp(transform));
|
||||||
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),
|
||||||
@@ -258,24 +101,7 @@ namespace OpenEngine {
|
|||||||
for (const auto& entity : view) {
|
for (const auto& entity : view) {
|
||||||
auto [transform, mesh] = view.get<TransformComponent, MeshComponent>(entity);
|
auto [transform, mesh] = view.get<TransformComponent, MeshComponent>(entity);
|
||||||
|
|
||||||
Material material;
|
Renderer3D::DrawMesh(mesh.mesh, GetTransformFromComp(transform));
|
||||||
|
|
||||||
Entity _entity(entity, this);
|
|
||||||
if (_entity.HasComponent<MaterialComponent>())
|
|
||||||
material = _entity.GetComponents<MaterialComponent>().material;
|
|
||||||
|
|
||||||
if (mesh.mesh)
|
|
||||||
Renderer3D::DrawMesh(mesh.mesh, material, GetTransformFromComp(transform), (uint32_t)_entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto model_view = registry.view<TransformComponent, ModelComponent>();
|
|
||||||
|
|
||||||
for (const auto& entity : model_view) {
|
|
||||||
auto [transform, model_comp] = model_view.get<TransformComponent, ModelComponent>(entity);
|
|
||||||
|
|
||||||
Entity _entity(entity, this);
|
|
||||||
|
|
||||||
Renderer3D::DrawModel(model_comp.model, GetTransformFromComp(transform), (uint32_t)_entity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer3D::EndScene();
|
Renderer3D::EndScene();
|
||||||
@@ -344,39 +170,4 @@ namespace OpenEngine {
|
|||||||
void Scene::OnComponentAdded<MeshComponent>(Entity entity, MeshComponent& component)
|
void Scene::OnComponentAdded<MeshComponent>(Entity entity, MeshComponent& component)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
|
||||||
void Scene::OnComponentAdded<MaterialComponent>(Entity entity, MaterialComponent& component)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
void Scene::OnComponentAdded<PhysicsBodyComponent>(Entity entity, PhysicsBodyComponent& component)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
void Scene::OnComponentAdded<SphereShapeComponent>(Entity entity, SphereShapeComponent& component)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
void Scene::OnComponentAdded<BoxShapeComponent>(Entity entity, BoxShapeComponent& component)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
void Scene::OnComponentAdded<IDComponent>(Entity entity, IDComponent& component)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
void Scene::OnComponentAdded<PlaneShapeComponent>(Entity entity, PlaneShapeComponent& component)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
void Scene::OnComponentAdded<ModelComponent>(Entity entity, ModelComponent& component)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
#include <cstdint>
|
|
||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
|
|
||||||
#include "core.hpp"
|
#include "core.hpp"
|
||||||
#include <scene/scene_serializer.hpp>
|
#include <scene/scene_serializer.hpp>
|
||||||
#include "renderer/renderer3d.hpp"
|
|
||||||
#include "scene/components.hpp"
|
#include "scene/components.hpp"
|
||||||
#include "scene/entity.hpp"
|
#include "scene/entity.hpp"
|
||||||
|
|
||||||
@@ -88,12 +86,11 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
static void SerializeEntity(YAML::Emitter& out, Entity entity)
|
static void SerializeEntity(YAML::Emitter& out, Entity entity)
|
||||||
{
|
{
|
||||||
OE_CORE_ASSERT(entity.HasComponent<IDComponent>(), "Entity is missing UUID.");
|
|
||||||
|
|
||||||
out << YAML::BeginMap;
|
out << YAML::BeginMap;
|
||||||
out << YAML::Key << "Entity" << YAML::Value << entity.GetUUID(); // Needs random
|
out << YAML::Key << "Entity" << YAML::Value << "412741205"; // Needs random
|
||||||
|
|
||||||
if (entity.HasComponent<TagComponent>()) {
|
if (entity.HasComponent<TagComponent>())
|
||||||
|
{
|
||||||
out << YAML::Key << "TagComponent";
|
out << YAML::Key << "TagComponent";
|
||||||
out << YAML::BeginMap; // TagComponent
|
out << YAML::BeginMap; // TagComponent
|
||||||
|
|
||||||
@@ -103,7 +100,8 @@ namespace OpenEngine {
|
|||||||
out << YAML::EndMap; // TagComponent
|
out << YAML::EndMap; // TagComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity.HasComponent<TransformComponent>()) {
|
if (entity.HasComponent<TransformComponent>())
|
||||||
|
{
|
||||||
out << YAML::Key << "TransformComponent";
|
out << YAML::Key << "TransformComponent";
|
||||||
out << YAML::BeginMap; // TransformComponent
|
out << YAML::BeginMap; // TransformComponent
|
||||||
|
|
||||||
@@ -115,7 +113,8 @@ 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
|
||||||
|
|
||||||
@@ -139,7 +138,8 @@ namespace OpenEngine {
|
|||||||
out << YAML::EndMap; // CameraComponent
|
out << YAML::EndMap; // CameraComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity.HasComponent<SpriteRendererComponent>()) {
|
if (entity.HasComponent<SpriteRendererComponent>())
|
||||||
|
{
|
||||||
out << YAML::Key << "SpriteRendererComponent";
|
out << YAML::Key << "SpriteRendererComponent";
|
||||||
out << YAML::BeginMap; // SpriteRendererComponent
|
out << YAML::BeginMap; // SpriteRendererComponent
|
||||||
|
|
||||||
@@ -149,78 +149,6 @@ namespace OpenEngine {
|
|||||||
out << YAML::EndMap; // SpriteRendererComponent
|
out << YAML::EndMap; // SpriteRendererComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity.HasComponent<MeshComponent>()) {
|
|
||||||
out << YAML::Key << "MeshComponent";
|
|
||||||
out << YAML::BeginMap; // MeshComponent
|
|
||||||
|
|
||||||
auto& mesh_component = entity.GetComponents<MeshComponent>();
|
|
||||||
out << YAML::Key << "MeshType" << YAML::Value << (int)mesh_component.primitive_type;
|
|
||||||
|
|
||||||
out << YAML::EndMap; // MeshComponent
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity.HasComponent<MaterialComponent>()) {
|
|
||||||
out << YAML::Key << "MaterialComponent";
|
|
||||||
out << YAML::BeginMap; // MaterialComponent
|
|
||||||
|
|
||||||
auto& material = entity.GetComponents<MaterialComponent>().material;
|
|
||||||
out << YAML::Key << "Albedo" << YAML::Value << material.albedo;
|
|
||||||
out << YAML::Key << "Roughness" << YAML::Value << material.roughness;
|
|
||||||
out << YAML::Key << "Metalic" << YAML::Value << material.metallic;
|
|
||||||
out << YAML::Key << "AmbiantStrength" << YAML::Value << material.ambient_strength;
|
|
||||||
out << YAML::Key << "SpecularStrength" << YAML::Value << material.specular_strength;
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity.HasComponent<PlaneShapeComponent>()) {
|
|
||||||
out << YAML::Key << "PlaneShapeComponent";
|
|
||||||
out << YAML::BeginMap; //PlaneShapeComponent
|
|
||||||
|
|
||||||
auto& psc = entity.GetComponents<PlaneShapeComponent>();
|
|
||||||
out << YAML::Key << "Extent" << YAML::Value << psc.extent;
|
|
||||||
|
|
||||||
out << YAML::EndMap; //PlaneShapeComponent
|
|
||||||
}
|
|
||||||
|
|
||||||
out << YAML::EndMap;
|
out << YAML::EndMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,10 +191,11 @@ namespace OpenEngine {
|
|||||||
OE_CORE_TRACE("Deserializing scene '{0}'", sceneName);
|
OE_CORE_TRACE("Deserializing scene '{0}'", sceneName);
|
||||||
|
|
||||||
auto entities = data["Entities"];
|
auto entities = data["Entities"];
|
||||||
if (entities) {
|
if (entities)
|
||||||
|
{
|
||||||
for (auto entity : entities)
|
for (auto entity : entities)
|
||||||
{
|
{
|
||||||
uint64_t uuid = entity["Entity"].as<uint64_t>();
|
uint64_t uuid = entity["Entity"].as<uint64_t>(); // TODO
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
auto tagComponent = entity["TagComponent"];
|
auto tagComponent = entity["TagComponent"];
|
||||||
@@ -275,10 +204,11 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
OE_CORE_TRACE("Deserialized entity with ID = {0}, name = {1}", uuid, name);
|
OE_CORE_TRACE("Deserialized entity with ID = {0}, name = {1}", uuid, name);
|
||||||
|
|
||||||
Entity deserializedEntity = context->CreateEntityWithUUID(uuid, name);
|
Entity deserializedEntity = context->CreateEntity(name);
|
||||||
|
|
||||||
auto transformComponent = entity["TransformComponent"];
|
auto transformComponent = entity["TransformComponent"];
|
||||||
if (transformComponent) {
|
if (transformComponent)
|
||||||
|
{
|
||||||
auto& tc = deserializedEntity.AddComponent<TransformComponent>();
|
auto& tc = deserializedEntity.AddComponent<TransformComponent>();
|
||||||
tc.translation = transformComponent["Translation"].as<glm::vec3>();
|
tc.translation = transformComponent["Translation"].as<glm::vec3>();
|
||||||
tc.rotation = transformComponent["Rotation"].as<glm::vec3>();
|
tc.rotation = transformComponent["Rotation"].as<glm::vec3>();
|
||||||
@@ -286,7 +216,8 @@ namespace OpenEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto cameraComponent = entity["CameraComponent"];
|
auto cameraComponent = entity["CameraComponent"];
|
||||||
if (cameraComponent) {
|
if (cameraComponent)
|
||||||
|
{
|
||||||
auto& cc = deserializedEntity.AddComponent<CameraComponent>();
|
auto& cc = deserializedEntity.AddComponent<CameraComponent>();
|
||||||
|
|
||||||
auto camera_props = cameraComponent["Camera"];
|
auto camera_props = cameraComponent["Camera"];
|
||||||
@@ -305,82 +236,16 @@ namespace OpenEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto spriteRendererComponent = entity["SpriteRendererComponent"];
|
auto spriteRendererComponent = entity["SpriteRendererComponent"];
|
||||||
if (spriteRendererComponent) {
|
if (spriteRendererComponent)
|
||||||
|
{
|
||||||
auto& src = deserializedEntity.AddComponent<SpriteRendererComponent>();
|
auto& src = deserializedEntity.AddComponent<SpriteRendererComponent>();
|
||||||
src.color = spriteRendererComponent["Color"].as<glm::vec4>();
|
src.color = spriteRendererComponent["Color"].as<glm::vec4>();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto mesh_component = entity["MeshComponent"];
|
|
||||||
if (mesh_component) {
|
|
||||||
auto& mesh = deserializedEntity.AddComponent<MeshComponent>();
|
|
||||||
mesh.primitive_type = (PrimitiveType)mesh_component["MeshType"].as<int>();
|
|
||||||
switch (mesh.primitive_type) {
|
|
||||||
case OpenEngine::PrimitiveType::Quad: {
|
|
||||||
mesh.mesh = CreateQuad((uint32_t)deserializedEntity);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case OpenEngine::PrimitiveType::Cube: {
|
|
||||||
mesh.mesh = CreateCube((uint32_t)deserializedEntity);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
OE_CORE_ASSERT(false, "No mesh");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto material_component = entity["MaterialComponent"];
|
|
||||||
if (material_component) {
|
|
||||||
auto& material = deserializedEntity.AddComponent<MaterialComponent>();
|
|
||||||
material.material.albedo = material_component["Albedo"].as<glm::vec4>();
|
|
||||||
material.material.roughness = material_component["Roughness"].as<float>();
|
|
||||||
material.material.metallic = material_component["Metalic"].as<float>();
|
|
||||||
material.material.ambient_strength = material_component["AmbiantStrength"].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>();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto plane_shape_component = entity["PlaneShapeComponent"];
|
|
||||||
if (sphere_shape_component) {
|
|
||||||
auto& psc = deserializedEntity.AddComponent<PlaneShapeComponent>();
|
|
||||||
|
|
||||||
psc.extent = plane_shape_component["Extent"].as<float>();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SceneSerializer::DeserializeRuntime(const std::string& file_path)
|
bool SceneSerializer::DeserializeRuntime(const std::string& file_path)
|
||||||
{
|
{
|
||||||
OE_CORE_ASSERT(false, "Not implemented yet");
|
OE_CORE_ASSERT(false, "Not implemented yet");
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.1 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 320 B |
Binary file not shown.
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 156 B |
47
untitled_persp.oes
Normal file
47
untitled_persp.oes
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
Scene: N/A
|
||||||
|
Entities:
|
||||||
|
- Entity: 412741205
|
||||||
|
TagComponent:
|
||||||
|
Tag: square 3
|
||||||
|
TransformComponent:
|
||||||
|
Translation: [-1.49011612e-08, 0.299999774, -0.499999911]
|
||||||
|
Rotation: [-1.57079685, 0, 0]
|
||||||
|
Scale: [0.605000019, 0.60496217, 0.60496217]
|
||||||
|
SpriteRendererComponent:
|
||||||
|
Color: [1, 1, 1, 1]
|
||||||
|
- Entity: 412741205
|
||||||
|
TagComponent:
|
||||||
|
Tag: "square 2 "
|
||||||
|
TransformComponent:
|
||||||
|
Translation: [0, 0, -0.200000003]
|
||||||
|
Rotation: [0, 0, 0]
|
||||||
|
Scale: [0.600000024, 0.600000083, 0.600000024]
|
||||||
|
SpriteRendererComponent:
|
||||||
|
Color: [0.882352948, 0.745098054, 0.376470596, 1]
|
||||||
|
- Entity: 412741205
|
||||||
|
TagComponent:
|
||||||
|
Tag: square
|
||||||
|
TransformComponent:
|
||||||
|
Translation: [0.299827427, -9.68575478e-08, -0.499896437]
|
||||||
|
Rotation: [0, 1.57079637, 0]
|
||||||
|
Scale: [0.6049999, 0.604999959, 0.6049999]
|
||||||
|
SpriteRendererComponent:
|
||||||
|
Color: [0.517647088, 0.0901960805, 1, 1]
|
||||||
|
- Entity: 412741205
|
||||||
|
TagComponent:
|
||||||
|
Tag: camera
|
||||||
|
TransformComponent:
|
||||||
|
Translation: [0, 0, 20.8999996]
|
||||||
|
Rotation: [0, 0, 0]
|
||||||
|
Scale: [1, 1, 1]
|
||||||
|
CameraComponent:
|
||||||
|
Camera:
|
||||||
|
ProjectionType: 0
|
||||||
|
PerspectiveFOV: 45
|
||||||
|
PerspectiveNear: 0.00999999978
|
||||||
|
PerspectiveFar: 1000
|
||||||
|
OrthographicSize: 10
|
||||||
|
OrthographicNear: -1
|
||||||
|
OrthographicFar: 1
|
||||||
|
Primary: true
|
||||||
|
FixedAspectRatio: false
|
||||||
Reference in New Issue
Block a user