Editing the modelimporter to allow to create scene graphs

This commit is contained in:
2022-07-08 21:35:14 +02:00
parent 85f9c78adf
commit b7e3465406
19 changed files with 241 additions and 256 deletions

View File

@ -10,17 +10,20 @@
#include <assimp/postprocess.h>
#include <string>
void ProcessVertices(aiMesh* mesh, std::vector<BarinkEngine::Vertex>& out_vertices);
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices);
class ModelImporter {
private:
void ImportFBX(std::string path);
void ImportBlend(std::string path);
void ImportGLTF(std::string path);
void ImportOBJ(std::string path);
static BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene);
static std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene);
public:
void Import(std::string path);
std::vector<BarinkEngine::Mesh> Import(const std::string path);
private:
static BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene);
static std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene);
static std::vector<BarinkEngine::Mesh> Test();
};

View File

@ -1,6 +1,6 @@
#pragma once
#include <glad/glad.h>
class Buffer {
class GpuBuffer {
private:
unsigned int id;
public:

View File

@ -1,10 +1,11 @@
#pragma once
#include <vector>
#include <glm/glm.hpp>
#include "VertexArray.h"
#include "Buffer.h"
namespace BarinkEngine{
struct Vertex {
glm::vec3 vertices;
glm::vec2 uv;
@ -13,8 +14,13 @@ namespace BarinkEngine{
class Mesh {
public:
std::vector<Vertex> vertices;
std::vector<unsigned int > elements;
std::vector<unsigned int> elements;
private:
GpuBuffer vertexBuffer;
GpuBuffer elementBuffer;
VertexArray VAO;
unsigned int UV_id;
};
}

View File

@ -20,8 +20,8 @@ private:
std::vector<unsigned int > indices;
Buffer vertexBuffer;
Buffer elementBuffer;
GpuBuffer vertexBuffer;
GpuBuffer elementBuffer;
VertexArray VAO;

View File

@ -1,37 +1,23 @@
#pragma once
#include <vector>
#include "Mesh.h"
#include "Buffer.h"
#include "Material.h"
#include "Texture.h"
#include "VertexArray.h"
#include "Scene.h"
namespace BarinkEngine {
class Renderable : public SceneNode {
public:
/*
* NOTE: Should combine into a Mesh!!
*/
Buffer vertexBuffer;
Buffer elementBuffer;
//Buffer uv;
VertexArray VAO;
class Renderable {
public:
Mesh mesh;
Material* material;
Texture* texture;
Shader* shader;
GLuint UV_id;
Material* material;
Texture* texture;
Shader* shader;
~Renderable();
static Renderable* Load();
void Draw();
private:
std::vector<BarinkEngine::Mesh> meshes;
Renderable();
};
Renderable();
~Renderable();
};
}

View File

@ -0,0 +1,11 @@
#pragma once
#include <glm/glm.hpp>
struct Transform {
glm::vec3 Position;
glm::vec3 Rotation;
glm::vec3 Scale;
glm::mat4 ModelMatrix;
};

View File

@ -2,46 +2,22 @@
#include <string>
#include <vector>
#include "glm/glm.hpp"
#include "Graphics/Transform.h"
#include "Scene/Node.h"
/*
* Scene should be a description of a game world
*/
struct Transform {
glm::vec3 Position;
glm::vec3 Rotation;
glm::vec3 Scale;
glm::mat4 ModelMatrix;
};
class SceneNode {
public:
std::string name;
Transform transform;
SceneNode* parent;
std::vector<SceneNode*> children;
void addChild(SceneNode& node);
};
class Scene {
public:
SceneNode& GetSceneNode(std::string);
SceneNode& GetRoot();
Node& GetSceneNode(std::string);
Node& GetRoot();
Scene(std::string SceneName = "Default Scene");
~Scene();
private:
SceneNode* root;
Node* root;
};

View File

@ -0,0 +1,21 @@
#pragma once
#include <string>
#include <vector>
#include "Graphics/Transform.h"
class Node {
public:
std::string& name;
Node* parent;
std::vector<Node*> children;
void addChild(Node& node);
};
class Group : Node {
Transform& transform;
};

View File

@ -0,0 +1,14 @@
#pragma once
#include "Graphics/Renderable.h"
#include "Scene/SceneNodeTypes.h"
#include <glm/glm.hpp>
/*
* Define a helper class to more easily build a proper scene
*/
static class SceneBuilder {
static Group* AddGroup(std::string name);
static SceneObject* AddVisual(std::string name, Renderable& object, glm::vec3 position );
};

View File

@ -0,0 +1,15 @@
#pragma once
#include <string>
#include <map>
#include "Scene.h"
static class SceneManager {
public:
static Scene* CreateScene();
static Scene& GetScene(std::string name);
private:
static std::map<std::string , Scene*>
};

View File

@ -0,0 +1,21 @@
#pragma once
#include "Graphics/Camera.h"
#include "Graphics/Renderable.h"
#include "Scene/Node.h"
class SceneCamera : Group
{
Camera& camera;
};
class SceneObject : Group
{
Renderable& renderable;
};