Working on semi proper API to build a scene
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
#define TINYGLTF_IMPLEMENTATION
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
|
||||
#define TINYGLTF_IMPLEMENTATION
|
||||
#define TINYGLTF_NO_EXTERNAL_IMAGE
|
||||
|
||||
#include "Graphics/Mesh.h"
|
||||
@ -9,6 +10,7 @@
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
#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);
|
||||
@ -17,7 +19,9 @@ void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices);
|
||||
class ModelImporter {
|
||||
|
||||
public:
|
||||
std::vector<BarinkEngine::Mesh> Import(const std::string path);
|
||||
|
||||
SceneObject* Import(const std::string path);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
class Node {
|
||||
public:
|
||||
Node(std::string& name);
|
||||
std::string& name;
|
||||
Node* parent;
|
||||
std::vector<Node*> children;
|
||||
@ -15,7 +16,9 @@ class Node {
|
||||
|
||||
|
||||
|
||||
class Group : Node {
|
||||
class Group : public Node {
|
||||
public:
|
||||
Group(std::string& name);
|
||||
Transform& transform;
|
||||
|
||||
};
|
||||
|
@ -5,11 +5,14 @@
|
||||
static class SceneManager {
|
||||
|
||||
public:
|
||||
static Scene* CreateScene();
|
||||
static Scene& GetScene(std::string name);
|
||||
static Scene* CreateScene(const std::string& name );
|
||||
static Scene& GetScene(const std::string& name);
|
||||
|
||||
static void LoadScene(Scene& scene);
|
||||
|
||||
private:
|
||||
static std::map<std::string , Scene*>
|
||||
static Scene* CurrentScene;
|
||||
|
||||
static std::map<std::string, Scene*> Scenes;
|
||||
|
||||
};
|
@ -3,18 +3,19 @@
|
||||
#include "Graphics/Renderable.h"
|
||||
#include "Scene/Node.h"
|
||||
|
||||
class SceneCamera : Group
|
||||
class SceneCamera : public Group
|
||||
{
|
||||
public:
|
||||
Camera& camera;
|
||||
|
||||
|
||||
SceneCamera();
|
||||
};
|
||||
|
||||
|
||||
class SceneObject : Group
|
||||
class SceneObject : public Group
|
||||
{
|
||||
public:
|
||||
Renderable& renderable;
|
||||
|
||||
SceneObject();
|
||||
|
||||
|
||||
};
|
||||
|
@ -1,10 +1,11 @@
|
||||
#include "Scene.h"
|
||||
#include "Scene/Node.h"
|
||||
void DeleteSubGraph(Node* tree);
|
||||
|
||||
Scene::Scene(std::string sceneName)
|
||||
{
|
||||
// Create a root node
|
||||
root = new Node();
|
||||
root = new Group(sceneName);
|
||||
root->name = sceneName;
|
||||
|
||||
}
|
||||
@ -42,6 +43,8 @@ Node& Scene::GetRoot()
|
||||
return *root;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Node::addChild(Node& node)
|
||||
{
|
||||
children.push_back(&node);
|
||||
|
7
BarinkEngine/Scene/Node.cpp
Normal file
7
BarinkEngine/Scene/Node.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
#include "Scene/Node.h"
|
||||
|
||||
Node::Node(std::string& name)
|
||||
: name(name), parent(nullptr), children(std::vector<Node*>()) {}
|
||||
|
||||
Group::Group(std::string& name )
|
||||
: Node(name), transform(Transform()) {}
|
18
BarinkEngine/Scene/SceneManager.cpp
Normal file
18
BarinkEngine/Scene/SceneManager.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include "Scene/SceneManager.h"
|
||||
|
||||
Scene* SceneManager::CreateScene(const std::string& name)
|
||||
{
|
||||
SceneManager::Scenes[name] = new Scene(name);
|
||||
|
||||
return &SceneManager::GetScene(name);
|
||||
}
|
||||
|
||||
Scene& SceneManager::GetScene(const std::string& name)
|
||||
{
|
||||
return *SceneManager::Scenes[name];
|
||||
}
|
||||
|
||||
void SceneManager::LoadScene( Scene& scene)
|
||||
{
|
||||
CurrentScene = &scene;
|
||||
}
|
@ -1,14 +1,20 @@
|
||||
#include "AssetManager/ModelImporter.h"
|
||||
|
||||
|
||||
std::vector<BarinkEngine::Mesh> ModelImporter::Import(const std::string path)
|
||||
SceneObject* ModelImporter::Import(const std::string path)
|
||||
{
|
||||
SceneObject* root = new SceneObject();
|
||||
|
||||
|
||||
Assimp::Importer importer;
|
||||
const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);
|
||||
|
||||
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)
|
||||
|
Reference in New Issue
Block a user