Compare commits
4 Commits
Feature/Ba
...
e31fd036ea
Author | SHA1 | Date | |
---|---|---|---|
e31fd036ea | |||
6a2e8d3b2f | |||
f8b390923e | |||
b7e3465406 |
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"cmake.configureOnOpen": true,
|
|
||||||
"files.associations": {
|
|
||||||
"iosfwd": "cpp"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#define TINYGLTF_IMPLEMENTATION
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
|
|
||||||
|
#define TINYGLTF_IMPLEMENTATION
|
||||||
#define TINYGLTF_NO_EXTERNAL_IMAGE
|
#define TINYGLTF_NO_EXTERNAL_IMAGE
|
||||||
|
|
||||||
#include "Graphics/Mesh.h"
|
#include "Graphics/Mesh.h"
|
||||||
@ -9,18 +10,25 @@
|
|||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
#include <assimp/postprocess.h>
|
#include <assimp/postprocess.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "Scene/SceneNodeTypes.h"
|
||||||
|
|
||||||
|
void ProcessVertices(aiMesh* mesh, std::vector<BarinkEngine::Vertex>& out_vertices);
|
||||||
|
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices);
|
||||||
|
|
||||||
|
namespace BarinkEngine {
|
||||||
|
class ModelImporter {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
SceneObject* Import(const std::string path);
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
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 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> ModelImporter::processNode(aiNode* node, const aiScene* scene);
|
||||||
|
|
||||||
public:
|
|
||||||
void Import(std::string path);
|
|
||||||
|
|
||||||
static std::vector<BarinkEngine::Mesh> Test();
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
class Buffer {
|
class GpuBuffer {
|
||||||
private:
|
private:
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
public:
|
public:
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
#include "VertexArray.h"
|
||||||
|
#include "Buffer.h"
|
||||||
|
|
||||||
namespace BarinkEngine{
|
namespace BarinkEngine{
|
||||||
|
|
||||||
|
|
||||||
struct Vertex {
|
struct Vertex {
|
||||||
glm::vec3 vertices;
|
glm::vec3 vertices;
|
||||||
glm::vec2 uv;
|
glm::vec2 uv;
|
||||||
@ -13,8 +14,13 @@ namespace BarinkEngine{
|
|||||||
class Mesh {
|
class Mesh {
|
||||||
public:
|
public:
|
||||||
std::vector<Vertex> vertices;
|
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;
|
std::vector<unsigned int > indices;
|
||||||
|
|
||||||
|
|
||||||
Buffer vertexBuffer;
|
GpuBuffer vertexBuffer;
|
||||||
Buffer elementBuffer;
|
GpuBuffer elementBuffer;
|
||||||
|
|
||||||
VertexArray VAO;
|
VertexArray VAO;
|
||||||
|
|
||||||
|
@ -1,37 +1,23 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Mesh.h"
|
#include "Mesh.h"
|
||||||
#include "Buffer.h"
|
|
||||||
#include "Material.h"
|
#include "Material.h"
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
#include "VertexArray.h"
|
|
||||||
#include "Scene.h"
|
#include "Scene.h"
|
||||||
|
|
||||||
|
namespace BarinkEngine {
|
||||||
|
|
||||||
class Renderable : public SceneNode {
|
class Renderable {
|
||||||
public:
|
public:
|
||||||
/*
|
Mesh mesh;
|
||||||
* NOTE: Should combine into a Mesh!!
|
|
||||||
*/
|
|
||||||
Buffer vertexBuffer;
|
|
||||||
Buffer elementBuffer;
|
|
||||||
//Buffer uv;
|
|
||||||
VertexArray VAO;
|
|
||||||
|
|
||||||
|
|
||||||
GLuint UV_id;
|
|
||||||
Material* material;
|
Material* material;
|
||||||
Texture* texture;
|
Texture* texture;
|
||||||
|
|
||||||
|
|
||||||
Shader* shader;
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
@ -3,13 +3,13 @@
|
|||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
|
||||||
struct EngineStatistics {
|
struct EngineStatistics {
|
||||||
uint32_t lastSampleTime;
|
long long lastSampleTime;
|
||||||
float frameTime;
|
float frameTime;
|
||||||
uint32_t verts;
|
uint32_t verts;
|
||||||
uint32_t DC;
|
uint32_t DC;
|
||||||
|
|
||||||
uint64_t frames;
|
long long frames;
|
||||||
uint64_t FPS;
|
long long FPS;
|
||||||
};
|
};
|
||||||
extern EngineStatistics* ES;
|
extern EngineStatistics* ES;
|
||||||
|
|
||||||
@ -25,8 +25,8 @@ inline void SamplePerformance(void) {
|
|||||||
ES->frames++;
|
ES->frames++;
|
||||||
ES->DC = 0;
|
ES->DC = 0;
|
||||||
ES->verts = 0;
|
ES->verts = 0;
|
||||||
unsigned int now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
unsigned long long now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||||
unsigned int MilliSecondsPast = now - ES->lastSampleTime;
|
unsigned long long MilliSecondsPast = now - ES->lastSampleTime;
|
||||||
if (MilliSecondsPast >= 1000) {
|
if (MilliSecondsPast >= 1000) {
|
||||||
|
|
||||||
ES->frameTime = (float)1000 / ES->frames;
|
ES->frameTime = (float)1000 / ES->frames;
|
||||||
|
@ -2,46 +2,22 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "glm/glm.hpp"
|
#include "Graphics/Transform.h"
|
||||||
|
#include "Scene/Node.h"
|
||||||
/*
|
/*
|
||||||
* Scene should be a description of a game world
|
* 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 {
|
class Scene {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SceneNode& GetSceneNode(std::string);
|
Node& GetSceneNode(std::string);
|
||||||
SceneNode& GetRoot();
|
Node& GetRoot();
|
||||||
|
|
||||||
Scene(std::string SceneName = "Default Scene");
|
Scene(const std::string& sceneName = "Default Scene");
|
||||||
~Scene();
|
~Scene();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SceneNode* root;
|
Node* root;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
24
BarinkEngine/Include/Scene/Node.h
Normal file
24
BarinkEngine/Include/Scene/Node.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include "Graphics/Transform.h"
|
||||||
|
|
||||||
|
class Node {
|
||||||
|
public:
|
||||||
|
Node(const std::string& name);
|
||||||
|
std::string name;
|
||||||
|
Node* parent;
|
||||||
|
std::vector<Node*> children;
|
||||||
|
|
||||||
|
void addChild(Node& node);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Group : public Node {
|
||||||
|
public:
|
||||||
|
Group(const std::string& name);
|
||||||
|
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 );
|
||||||
|
|
||||||
|
};
|
17
BarinkEngine/Include/Scene/SceneManager.h
Normal file
17
BarinkEngine/Include/Scene/SceneManager.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
#include "Scene.h"
|
||||||
|
class SceneManager {
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Scene* CreateScene(const std::string& name );
|
||||||
|
static Scene& GetScene(const std::string& name);
|
||||||
|
|
||||||
|
static void LoadScene(Scene& scene);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static Scene* CurrentScene;
|
||||||
|
static std::map<std::string, Scene*> Scenes;
|
||||||
|
|
||||||
|
};
|
22
BarinkEngine/Include/Scene/SceneNodeTypes.h
Normal file
22
BarinkEngine/Include/Scene/SceneNodeTypes.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Graphics/Camera.h"
|
||||||
|
#include "Graphics/Renderable.h"
|
||||||
|
#include "Scene/Node.h"
|
||||||
|
|
||||||
|
namespace BarinkEngine {
|
||||||
|
class SceneCamera : public Group
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Camera& camera;
|
||||||
|
SceneCamera();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class SceneObject : public Group
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SceneObject(std::string name, Renderable* visual);
|
||||||
|
~SceneObject();
|
||||||
|
Renderable* renderable;
|
||||||
|
};
|
||||||
|
}
|
@ -1,12 +1,28 @@
|
|||||||
#include "Scene.h"
|
#include "Scene.h"
|
||||||
|
#include "Scene.h"
|
||||||
|
#include "Scene/Node.h"
|
||||||
|
void DeleteSubGraph(Node* tree);
|
||||||
|
|
||||||
|
Scene::Scene(const std::string& sceneName)
|
||||||
|
{
|
||||||
|
// Create a root node
|
||||||
|
root = new Group(sceneName);
|
||||||
|
}
|
||||||
|
|
||||||
|
Scene::~Scene()
|
||||||
|
{
|
||||||
|
// Delete all nodes in the graph.
|
||||||
|
DeleteSubGraph(root);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SceneNode* SearchInChildren(SceneNode* root, std::string name ) {
|
Node* SearchInChildren(Node* root, const std::string name ) {
|
||||||
|
|
||||||
if (root->name == name)
|
if (root->name == name)
|
||||||
return root;
|
return root;
|
||||||
|
|
||||||
SceneNode* found = nullptr;
|
Node* found = nullptr;
|
||||||
for (auto child : root->children) {
|
for (auto child : root->children) {
|
||||||
found = SearchInChildren(child, name);
|
found = SearchInChildren(child, name);
|
||||||
}
|
}
|
||||||
@ -14,39 +30,37 @@ SceneNode* SearchInChildren(SceneNode* root, std::string name ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SceneNode& Scene::GetSceneNode(std::string name)
|
Node& Scene::GetSceneNode(std::string name)
|
||||||
{
|
{
|
||||||
return *SearchInChildren(root, name);
|
return *SearchInChildren(root, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SceneNode& Scene::GetRoot()
|
Node& Scene::GetRoot()
|
||||||
{
|
{
|
||||||
return *root;
|
return *root;
|
||||||
}
|
}
|
||||||
|
|
||||||
Scene::Scene(std::string sceneName)
|
|
||||||
{
|
|
||||||
// Create a root node
|
|
||||||
root = new SceneNode();
|
|
||||||
root->name = sceneName;
|
|
||||||
root->transform = Transform();
|
|
||||||
|
|
||||||
root->transform.Position = glm::vec3(0);
|
|
||||||
root->transform.Rotation = glm::vec3(0);
|
|
||||||
root->transform.Scale = glm::vec3(0);
|
|
||||||
|
|
||||||
root->transform.ModelMatrix = glm::mat4(0);
|
void Node::addChild(Node& node)
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Scene::~Scene()
|
|
||||||
{
|
|
||||||
// Destruct scene!
|
|
||||||
}
|
|
||||||
|
|
||||||
void SceneNode::addChild(SceneNode& node)
|
|
||||||
{
|
{
|
||||||
children.push_back(&node);
|
children.push_back(&node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DeleteSubGraph(Node* tree)
|
||||||
|
{
|
||||||
|
if (tree->children.size() == 0) {
|
||||||
|
delete tree;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto child : tree->children) {
|
||||||
|
if (child->children.size() > 0) {
|
||||||
|
DeleteSubGraph(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
7
BarinkEngine/Scene/Node.cpp
Normal file
7
BarinkEngine/Scene/Node.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "Scene/Node.h"
|
||||||
|
|
||||||
|
Node::Node(const std::string& name)
|
||||||
|
: name(name), parent(nullptr), children(std::vector<Node*>()) {}
|
||||||
|
|
||||||
|
Group::Group(const std::string& name )
|
||||||
|
: Node(name), transform(Transform()) {}
|
22
BarinkEngine/Scene/SceneManager.cpp
Normal file
22
BarinkEngine/Scene/SceneManager.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include "Scene/SceneManager.h"
|
||||||
|
|
||||||
|
Scene* SceneManager::CreateScene(const std::string& name)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Scenes = std::map<std::string, Scene*>();
|
||||||
|
SceneManager::Scenes[name] = new Scene(name);
|
||||||
|
*/
|
||||||
|
|
||||||
|
return new Scene(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
Scene& SceneManager::GetScene(const std::string& name)
|
||||||
|
{
|
||||||
|
return Scene();
|
||||||
|
//return *SceneManager::Scenes[name];
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneManager::LoadScene( Scene& scene)
|
||||||
|
{
|
||||||
|
//SceneManager::CurrentScene = &scene;
|
||||||
|
}
|
12
BarinkEngine/Scene/SceneNodeTypes.cpp
Normal file
12
BarinkEngine/Scene/SceneNodeTypes.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include "Scene/SceneNodeTypes.h"
|
||||||
|
|
||||||
|
BarinkEngine::SceneCamera::SceneCamera()
|
||||||
|
: Group(std::string("Camera")), camera(Camera(glm::vec3(0.0f), glm::vec3(0.0f), 0))
|
||||||
|
{}
|
||||||
|
|
||||||
|
BarinkEngine::SceneObject::SceneObject(std::string name, Renderable* visual)
|
||||||
|
: Group(name), renderable(visual)
|
||||||
|
{}
|
||||||
|
|
||||||
|
BarinkEngine::SceneObject::~SceneObject()
|
||||||
|
{}
|
@ -1,15 +1,15 @@
|
|||||||
#include "Graphics/Buffer.h"
|
#include "Graphics/Buffer.h"
|
||||||
|
|
||||||
|
|
||||||
int Buffer::getBufferID() {
|
int GpuBuffer::getBufferID() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::createBuffer() {
|
void GpuBuffer::createBuffer() {
|
||||||
glGenBuffers(1, (GLuint*) &id);
|
glGenBuffers(1, (GLuint*) &id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = false ) {
|
void GpuBuffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = false ) {
|
||||||
|
|
||||||
if (elementBuffer) {
|
if (elementBuffer) {
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
|
||||||
@ -21,7 +21,7 @@ void Buffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = fal
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::Bind(bool elementBuffer = false ) {
|
void GpuBuffer::Bind(bool elementBuffer = false ) {
|
||||||
if (elementBuffer) {
|
if (elementBuffer) {
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ void Buffer::Bind(bool elementBuffer = false ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::Unbind(bool elementBuffer = false) {
|
void GpuBuffer::Unbind(bool elementBuffer = false) {
|
||||||
if (elementBuffer) {
|
if (elementBuffer) {
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
@ -42,6 +42,6 @@ void Buffer::Unbind(bool elementBuffer = false) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::Delete() {
|
void GpuBuffer::Delete() {
|
||||||
glDeleteBuffers(1, (GLuint*) &id);
|
glDeleteBuffers(1, (GLuint*) &id);
|
||||||
}
|
}
|
@ -1,70 +1,27 @@
|
|||||||
#include "AssetManager/ModelImporter.h"
|
#include "AssetManager/ModelImporter.h"
|
||||||
|
|
||||||
|
|
||||||
void ModelImporter::ImportFBX(std::string path)
|
BarinkEngine::SceneObject* BarinkEngine::ModelImporter::Import(const std::string path)
|
||||||
{
|
{
|
||||||
//spdlog::warn("ImportFBX not implemented!");
|
|
||||||
}
|
|
||||||
|
|
||||||
void ModelImporter::ImportBlend(std::string path)
|
SceneObject* root = new SceneObject(std::string(path), nullptr);
|
||||||
{
|
|
||||||
//spdlog::warn("ImportBlend not implemented!");
|
|
||||||
}
|
|
||||||
|
|
||||||
void ModelImporter::ImportGLTF(std::string path)
|
|
||||||
{
|
|
||||||
//spdlog::warn("ImportGLTF not implemented!");
|
|
||||||
}
|
|
||||||
|
|
||||||
void ModelImporter::ImportOBJ(std::string path)
|
|
||||||
{
|
|
||||||
//spdlog::warn("ImportOBJ not implemented!");
|
|
||||||
}
|
|
||||||
|
|
||||||
void ModelImporter::Import(std::string path)
|
|
||||||
{
|
|
||||||
//spdlog::warn("Import not implemented!");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<BarinkEngine::Mesh> ModelImporter::Test() {
|
|
||||||
|
|
||||||
/*
|
|
||||||
spdlog::info("====== Tiny GLTF ======");
|
|
||||||
tinygltf::Model loadedModel;
|
|
||||||
tinygltf::TinyGLTF loader;
|
|
||||||
std::string error;
|
|
||||||
std::string warn;
|
|
||||||
bool ret = loader.LoadASCIIFromFile(&loadedModel, &error, &warn, "./Build/SandboxApplication/Debug/sponza.gltf");
|
|
||||||
|
|
||||||
if (!warn.empty())
|
|
||||||
spdlog::warn("TinyGLTF Warning: {}", warn);
|
|
||||||
if (!error.empty())
|
|
||||||
spdlog::error("TinyGLTF Error: {}", error);
|
|
||||||
if (!ret) {
|
|
||||||
spdlog::error("TinyGLTF Error: Failed to parse glTF");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
spdlog::info("Meshes in model: {}", loadedModel.meshes.size());
|
|
||||||
spdlog::info("Primitives in mesh: {}", loadedModel.meshes[0].primitives.size());
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
//spdlog::info("======= Assimp ======");
|
|
||||||
|
|
||||||
Assimp::Importer importer;
|
Assimp::Importer importer;
|
||||||
const aiScene* scene = importer.ReadFile("build/SandboxApplication/Debug/Models/Cube.obj", aiProcess_Triangulate | aiProcess_FlipUVs);
|
const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);
|
||||||
|
|
||||||
aiNode* currentNode = scene->mRootNode;
|
aiNode* currentNode = scene->mRootNode;
|
||||||
|
|
||||||
return processNode(currentNode, scene);
|
std::vector<BarinkEngine::Mesh> meshes = processNode(currentNode, scene);
|
||||||
|
|
||||||
|
return root;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene) {
|
std::vector<BarinkEngine::Mesh> BarinkEngine::ModelImporter::processNode(aiNode* node, const aiScene* scene)
|
||||||
|
{
|
||||||
|
|
||||||
std::vector<BarinkEngine::Mesh> meshes;
|
std::vector<BarinkEngine::Mesh> meshes;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < node->mNumMeshes; i++) {
|
for (unsigned int i = 0; i < node->mNumMeshes; i++) {
|
||||||
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
||||||
meshes.push_back(processMesh(mesh, scene));
|
meshes.push_back(processMesh(mesh, scene));
|
||||||
@ -81,10 +38,24 @@ std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const a
|
|||||||
return meshes;
|
return meshes;
|
||||||
}
|
}
|
||||||
|
|
||||||
BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) {
|
BarinkEngine::Mesh BarinkEngine::ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) {
|
||||||
std::vector<unsigned int> indices;
|
std::vector<unsigned int> indices;
|
||||||
std::vector<BarinkEngine::Vertex> vertices;
|
std::vector<BarinkEngine::Vertex> vertices;
|
||||||
|
|
||||||
|
ProcessVertices(mesh, vertices);
|
||||||
|
|
||||||
|
ProcessIndices(mesh, indices);
|
||||||
|
|
||||||
|
BarinkEngine::Mesh result;
|
||||||
|
result.vertices = vertices;
|
||||||
|
result.elements = indices;
|
||||||
|
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProcessVertices(aiMesh* mesh, std::vector<BarinkEngine::Vertex>& out_vertices) {
|
||||||
// Process vertices
|
// Process vertices
|
||||||
for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
|
for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
|
||||||
BarinkEngine::Vertex v{};
|
BarinkEngine::Vertex v{};
|
||||||
@ -106,28 +77,18 @@ BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vertices.push_back(v);
|
out_vertices.push_back(v);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices) {
|
||||||
// Process Indices
|
// Process Indices
|
||||||
for (unsigned int i = 0; i < mesh->mNumFaces; i++) {
|
for (unsigned int i = 0; i < mesh->mNumFaces; i++) {
|
||||||
aiFace face = mesh->mFaces[i];
|
aiFace face = mesh->mFaces[i];
|
||||||
if (face.mNumIndices < 3)
|
if (face.mNumIndices < 3)
|
||||||
continue;
|
continue;
|
||||||
for (unsigned int j = 0; j < face.mNumIndices; j++) {
|
for (unsigned int j = 0; j < face.mNumIndices; j++) {
|
||||||
indices.push_back(face.mIndices[j]);
|
out_indices.push_back(face.mIndices[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BarinkEngine::Mesh result;
|
|
||||||
|
|
||||||
|
|
||||||
result.vertices = vertices;
|
|
||||||
result.elements = indices;
|
|
||||||
|
|
||||||
|
|
||||||
return result;
|
|
||||||
|
|
||||||
}
|
}
|
@ -3,18 +3,9 @@
|
|||||||
#include "PerfCounter.h"
|
#include "PerfCounter.h"
|
||||||
|
|
||||||
|
|
||||||
Renderable* Renderable::Load()
|
BarinkEngine::Renderable::Renderable()
|
||||||
{
|
{
|
||||||
return new Renderable();
|
/*
|
||||||
}
|
|
||||||
|
|
||||||
Renderable::Renderable()
|
|
||||||
{
|
|
||||||
meshes = ModelImporter::Test();
|
|
||||||
|
|
||||||
transform.Scale = glm::vec3(1.0f);
|
|
||||||
transform.Rotation = glm::vec3(0.0f, 0.0f, 0.0f);
|
|
||||||
transform.Position = glm::vec3(0.0f, 0.0f, 0.0f);
|
|
||||||
|
|
||||||
VAO.Create();
|
VAO.Create();
|
||||||
VAO.Bind();
|
VAO.Bind();
|
||||||
@ -33,20 +24,20 @@ Renderable::Renderable()
|
|||||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex),(void* )offsetof(BarinkEngine::Vertex, vertices));
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex),(void* )offsetof(BarinkEngine::Vertex, vertices));
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
|
|
||||||
vertexBuffer.Unbind(false);
|
//vertexBuffer.Unbind(false);
|
||||||
|
|
||||||
VAO.Unbind();
|
VAO.Unbind();
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderable::~Renderable()
|
BarinkEngine::Renderable::~Renderable()
|
||||||
{
|
{
|
||||||
glDeleteBuffers(1, &UV_id);
|
// glDeleteBuffers(1, &UV_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderable::Draw()
|
// Draw call Example !!
|
||||||
{
|
/*
|
||||||
VAO.Bind();
|
VAO.Bind();
|
||||||
elementBuffer.Bind(true);
|
elementBuffer.Bind(true);
|
||||||
|
|
||||||
@ -58,5 +49,5 @@ void Renderable::Draw()
|
|||||||
ES->DC++;
|
ES->DC++;
|
||||||
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(meshes[0].elements.size()), GL_UNSIGNED_INT, NULL);
|
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(meshes[0].elements.size()), GL_UNSIGNED_INT, NULL);
|
||||||
VAO.Unbind();
|
VAO.Unbind();
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -14,7 +14,7 @@ void BarinkEngine::Renderer::Render()
|
|||||||
{
|
{
|
||||||
|
|
||||||
for (auto model : models) {
|
for (auto model : models) {
|
||||||
model->Draw();
|
//model->Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,32 @@
|
|||||||
#include "GUI.h"
|
#include "GUI.h"
|
||||||
|
|
||||||
|
void SceneExplorer(Scene& scene, std::string PanelName) {
|
||||||
|
ImGui::Begin(PanelName.c_str());
|
||||||
|
|
||||||
|
ImGui::ListBoxHeader("##ObjectList");
|
||||||
|
|
||||||
|
Node& current = scene.GetRoot();
|
||||||
|
|
||||||
|
Node* next = ¤t;
|
||||||
|
|
||||||
|
// Show first node
|
||||||
|
ImGui::Selectable(next->name.c_str(), true);
|
||||||
|
|
||||||
|
ImGui::Indent();
|
||||||
|
|
||||||
|
if (next->children.size() != 0) {
|
||||||
|
for (auto child : next->children)
|
||||||
|
{
|
||||||
|
std::string& name = child->name;
|
||||||
|
ImGui::Selectable(name.c_str(), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::ListBoxFooter();
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
void CameraTool(Camera* cam) {
|
void CameraTool(Camera* cam) {
|
||||||
|
|
||||||
ImGui::Begin("Camera");
|
ImGui::Begin("Camera");
|
||||||
|
@ -6,3 +6,4 @@ void CameraTool(Camera* camera);
|
|||||||
void ScriptingTool(char* code);
|
void ScriptingTool(char* code);
|
||||||
void transformWindow(Transform& transform, std::string PanelName);
|
void transformWindow(Transform& transform, std::string PanelName);
|
||||||
void materialWindow(Material& material, std::string PanelName);
|
void materialWindow(Material& material, std::string PanelName);
|
||||||
|
void SceneExplorer(Scene& scene, std::string PanelName);
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
#include "BarinkEngine.h"
|
#include "BarinkEngine.h"
|
||||||
|
#include "Scene\SceneManager.h"
|
||||||
|
#include "Scene\SceneNodeTypes.h"
|
||||||
|
#include "AssetManager/ModelImporter.h"
|
||||||
|
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "GUI.h"
|
#include "GUI.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
@ -7,86 +11,50 @@
|
|||||||
* Define globals
|
* Define globals
|
||||||
*/
|
*/
|
||||||
Camera* cam;
|
Camera* cam;
|
||||||
|
|
||||||
|
|
||||||
Shader* shader;
|
Shader* shader;
|
||||||
|
|
||||||
Renderable* Cube;
|
|
||||||
Material* matCube;
|
|
||||||
Texture* textureCube;
|
|
||||||
|
|
||||||
Renderable* Cube2;
|
|
||||||
Material* matCube2;
|
|
||||||
|
|
||||||
char* code = new char[254];
|
char* code = new char[254];
|
||||||
|
|
||||||
|
|
||||||
const std::string vertexShaderSource = "build/SandboxApplication/Debug/test.vs";
|
const std::string vertexShaderSource = "build/SandboxApplication/Debug/test.vs";
|
||||||
const std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs";
|
const std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs";
|
||||||
|
|
||||||
|
BarinkEngine::ModelImporter* MI = new BarinkEngine::ModelImporter();
|
||||||
|
|
||||||
|
Scene* Level1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Runs once at startup
|
* Runs once at startup
|
||||||
* - USe to initialize the game/sandbox/demo
|
* - USe to initialize the game/sandbox/demo
|
||||||
*/
|
*/
|
||||||
void Start() {
|
void Start() {
|
||||||
|
// Build a basic test scene
|
||||||
|
// NOTE: This will later be done through an editor
|
||||||
|
|
||||||
/*
|
// Create a level and load it as the current level
|
||||||
Building a very basic scene graph
|
std::string levelName("Test Level");
|
||||||
*/
|
Level1 = SceneManager::CreateScene(levelName);
|
||||||
SceneNode MyCube = SceneNode();
|
SceneManager::LoadScene(*Level1);
|
||||||
MyCube.name = "MyCube";
|
|
||||||
|
|
||||||
SceneNode MyBaby = SceneNode();
|
// Create a cube node
|
||||||
MyBaby.name = "Baby";
|
|
||||||
|
|
||||||
SceneNode MySecondCube = SceneNode();
|
// Load a model
|
||||||
MySecondCube.name = "MySecondCube";
|
// *(MI->Import("build/SandboxApplication/Debug/Models/Cube.obj"))
|
||||||
|
|
||||||
|
std::string groupName("Nested-Group");
|
||||||
|
auto testGroup = new Group(groupName);
|
||||||
|
Level1->GetRoot().addChild( *testGroup);
|
||||||
|
|
||||||
MyCube.addChild(MyBaby);
|
std::string group2Name("Nested-Group2");
|
||||||
|
auto testGroup2 = new Group(group2Name);
|
||||||
|
Level1->GetRoot().addChild(*testGroup2);
|
||||||
Scene scene = Scene("My awesome Game Scene");
|
|
||||||
scene.GetRoot().addChild(MyCube);
|
|
||||||
scene.GetRoot().addChild(MySecondCube);
|
|
||||||
|
|
||||||
|
|
||||||
// Walk scene graph
|
// Walk scene graph
|
||||||
PrintSceneTree(scene.GetRoot(),0);
|
PrintSceneTree(Level1->GetRoot(),0);
|
||||||
|
|
||||||
shader = new Shader(vertexShaderSource, fragmentShaderSource);
|
shader = new Shader(vertexShaderSource, fragmentShaderSource);
|
||||||
|
|
||||||
textureCube = new Texture("build/SandboxApplication/Debug/Textures/wall.jpg");
|
|
||||||
|
|
||||||
matCube = new Material(*shader);
|
|
||||||
matCube->Color = glm::vec3(1.0, 0.0, 0.0);
|
|
||||||
|
|
||||||
matCube2 = new Material(*shader);
|
|
||||||
matCube2->Color = glm::vec3(0.0, 1.0f, 0.0);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* load meshes
|
|
||||||
*/
|
|
||||||
Cube = Renderable::Load();
|
|
||||||
Cube2 = Renderable::Load();
|
|
||||||
Cube->addChild(*Cube2);
|
|
||||||
|
|
||||||
Cube->shader = shader;
|
|
||||||
Cube2->shader = shader;
|
|
||||||
|
|
||||||
Cube->texture = textureCube;
|
|
||||||
Cube2->texture = textureCube;
|
|
||||||
|
|
||||||
Cube2->transform.Position = glm::vec3(-9.0f, 0.0f, 0.0f);
|
|
||||||
|
|
||||||
Cube->transform.Position = glm::vec3(-8.0f, 0.0f, -2.0f);
|
|
||||||
|
|
||||||
cam = new Camera(glm::vec3(0.0f, 1.5f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
|
cam = new Camera(glm::vec3(0.0f, 1.5f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
|
||||||
|
|
||||||
memset(code, '\0', 254);
|
memset(code, '\0', 254);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -101,24 +69,14 @@ void ImmediateGraphicsDraw() {
|
|||||||
// at possible GUI elements to use
|
// at possible GUI elements to use
|
||||||
ImGui::ShowDemoWindow();
|
ImGui::ShowDemoWindow();
|
||||||
|
|
||||||
|
|
||||||
// Show internal BarinkEngine stats
|
// Show internal BarinkEngine stats
|
||||||
ShowStats();
|
ShowStats();
|
||||||
|
|
||||||
|
|
||||||
// Show different tooling for this specific sandbox
|
// Show different tooling for this specific sandbox
|
||||||
CameraTool(cam);
|
CameraTool(cam);
|
||||||
ScriptingTool(code);
|
ScriptingTool(code);
|
||||||
|
|
||||||
transformWindow(Cube->transform, "Transform (Cube)");
|
SceneExplorer(*Level1, "Scene Explorer");
|
||||||
|
|
||||||
transformWindow(Cube2->transform, "Transform (Cube2)");
|
|
||||||
|
|
||||||
materialWindow(*matCube, "Material Cube");
|
|
||||||
materialWindow(*matCube2, "Material Cube2");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -127,8 +85,6 @@ void ImmediateGraphicsDraw() {
|
|||||||
*/
|
*/
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NOTE: this needs to move to the renderer
|
* NOTE: this needs to move to the renderer
|
||||||
* Render code should not appear in the sandbox file
|
* Render code should not appear in the sandbox file
|
||||||
@ -139,16 +95,16 @@ void Update()
|
|||||||
|
|
||||||
shader->Use();
|
shader->Use();
|
||||||
shader->setUniformMat4("P", projection);
|
shader->setUniformMat4("P", projection);
|
||||||
shader->setUniformMat4("M", CalculateModelMat(Cube->transform));
|
//shader->setUniformMat4("M", CalculateModelMat(Cube->transform));
|
||||||
shader->setUniformMat4("V", cam->GetViewMatrix());
|
shader->setUniformMat4("V", cam->GetViewMatrix());
|
||||||
matCube->Apply();
|
//matCube->Apply();
|
||||||
|
|
||||||
Cube->Draw();
|
//Cube->Draw();
|
||||||
|
|
||||||
shader->setUniformMat4("M", CalculateModelMat(Cube2->transform));
|
//shader->setUniformMat4("M", CalculateModelMat(Cube2->transform));
|
||||||
matCube2->Apply();
|
// matCube2->Apply();
|
||||||
|
|
||||||
Cube2->Draw();
|
//Cube2->Draw();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,18 +113,6 @@ void Update()
|
|||||||
* - Meant for cleanup
|
* - Meant for cleanup
|
||||||
*/
|
*/
|
||||||
void Stop() {
|
void Stop() {
|
||||||
// Cleanup
|
delete MI;
|
||||||
Cube->VAO.Delete();
|
|
||||||
Cube->elementBuffer.Delete();
|
|
||||||
|
|
||||||
Cube2->VAO.Delete();
|
|
||||||
Cube2->elementBuffer.Delete();
|
|
||||||
|
|
||||||
delete Cube2;
|
|
||||||
delete Cube;
|
|
||||||
|
|
||||||
delete matCube;
|
|
||||||
delete matCube2;
|
|
||||||
|
|
||||||
delete shader;
|
delete shader;
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
void PrintSceneTree(SceneNode& node, int depth) {
|
void PrintSceneTree(Node& node, int depth) {
|
||||||
// Indent name based on depth
|
// Indent name based on depth
|
||||||
std::cout << " ";
|
std::cout << " ";
|
||||||
for (int i = 0; i < depth; i++) {
|
for (int i = 0; i < depth; i++) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "BarinkEngine.h"
|
#include "BarinkEngine.h"
|
||||||
|
|
||||||
void PrintSceneTree(SceneNode& node, int depth);
|
void PrintSceneTree(Node& node, int depth);
|
||||||
|
|
||||||
glm::mat4 CalculateModelMat(Transform& transform);
|
glm::mat4 CalculateModelMat(Transform& transform);
|
Reference in New Issue
Block a user