improved model loading and added model component
This commit is contained in:
38
open_engine/include/open_engine/gltf/gltf_model3d.hpp
Normal file
38
open_engine/include/open_engine/gltf/gltf_model3d.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#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
|
||||
69
open_engine/include/open_engine/renderer/model3d.hpp
Normal file
69
open_engine/include/open_engine/renderer/model3d.hpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#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,9 +2,8 @@
|
||||
#define RENDERER3D_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/renderer/model3d.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
namespace OpenEngine {
|
||||
@@ -18,40 +17,12 @@ namespace OpenEngine {
|
||||
Cube
|
||||
};
|
||||
|
||||
struct MeshVertex
|
||||
{
|
||||
glm::vec3 position;
|
||||
glm::vec4 color;
|
||||
glm::vec3 normal;
|
||||
glm::vec2 text_coords;
|
||||
uint32_t id = -1;
|
||||
};
|
||||
|
||||
struct Material
|
||||
{
|
||||
glm::vec4 albedo = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
float roughness = 1.0f;
|
||||
float metallic = 1.0f;
|
||||
float ambient_strength = 1.0f;
|
||||
float specular_strength = 1.0f;
|
||||
};
|
||||
|
||||
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,
|
||||
const std::vector<uint32_t>& indices,
|
||||
uint32_t id);
|
||||
const std::vector<uint32_t>& indices);
|
||||
void PopulateMesh(Mesh& mesh);
|
||||
Ref<Mesh> CreateCube(uint32_t id = -1);
|
||||
Ref<Mesh> CreateQuad(uint32_t id = -1, bool back_face = false);
|
||||
|
||||
// ==================================================
|
||||
|
||||
class Renderer3D
|
||||
@@ -66,6 +37,12 @@ namespace OpenEngine {
|
||||
|
||||
static void DrawMesh(const Ref<Mesh>& mesh, Material& material,
|
||||
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);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#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>
|
||||
@@ -147,16 +149,36 @@ namespace OpenEngine {
|
||||
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)
|
||||
{}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user