Editing the modelimporter to allow to create scene graphs
This commit is contained in:
@ -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();
|
||||
};
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <glad/glad.h>
|
||||
class Buffer {
|
||||
class GpuBuffer {
|
||||
private:
|
||||
unsigned int id;
|
||||
public:
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
@ -20,8 +20,8 @@ private:
|
||||
std::vector<unsigned int > indices;
|
||||
|
||||
|
||||
Buffer vertexBuffer;
|
||||
Buffer elementBuffer;
|
||||
GpuBuffer vertexBuffer;
|
||||
GpuBuffer elementBuffer;
|
||||
|
||||
VertexArray VAO;
|
||||
|
||||
|
@ -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();
|
||||
};
|
||||
}
|
11
BarinkEngine/Include/Graphics/Transform.h
Normal file
11
BarinkEngine/Include/Graphics/Transform.h
Normal 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;
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
21
BarinkEngine/Include/Scene/Node.h
Normal file
21
BarinkEngine/Include/Scene/Node.h
Normal 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;
|
||||
|
||||
};
|
14
BarinkEngine/Include/Scene/SceneBuilder.h
Normal file
14
BarinkEngine/Include/Scene/SceneBuilder.h
Normal 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 );
|
||||
|
||||
};
|
15
BarinkEngine/Include/Scene/SceneManager.h
Normal file
15
BarinkEngine/Include/Scene/SceneManager.h
Normal 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*>
|
||||
|
||||
};
|
21
BarinkEngine/Include/Scene/SceneNodeTypes.h
Normal file
21
BarinkEngine/Include/Scene/SceneNodeTypes.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user