Basic Scene creation

This commit is contained in:
Nigel Barink 2022-07-09 22:21:56 +02:00
parent f8b390923e
commit 6a2e8d3b2f
13 changed files with 80 additions and 108 deletions

View File

@ -15,19 +15,20 @@
void ProcessVertices(aiMesh* mesh, std::vector<BarinkEngine::Vertex>& out_vertices); void ProcessVertices(aiMesh* mesh, std::vector<BarinkEngine::Vertex>& out_vertices);
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices); void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices);
namespace BarinkEngine {
class ModelImporter {
class ModelImporter { public:
public: SceneObject* Import(const std::string path);
SceneObject* Import(const std::string path);
private: private:
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);
}; };
}

View File

@ -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;

View File

@ -13,7 +13,7 @@ public:
Node& GetSceneNode(std::string); Node& GetSceneNode(std::string);
Node& GetRoot(); Node& GetRoot();
Scene(std::string SceneName = "Default Scene"); Scene(const std::string& sceneName = "Default Scene");
~Scene(); ~Scene();
private: private:

View File

@ -5,8 +5,8 @@
class Node { class Node {
public: public:
Node(std::string& name); Node(const std::string& name);
std::string& name; const std::string& name;
Node* parent; Node* parent;
std::vector<Node*> children; std::vector<Node*> children;
@ -18,7 +18,7 @@ class Node {
class Group : public Node { class Group : public Node {
public: public:
Group(std::string& name); Group(const std::string& name);
Transform& transform; Transform& transform;
}; };

View File

@ -2,7 +2,7 @@
#include <string> #include <string>
#include <map> #include <map>
#include "Scene.h" #include "Scene.h"
static class SceneManager { class SceneManager {
public: public:
static Scene* CreateScene(const std::string& name ); static Scene* CreateScene(const std::string& name );
@ -12,7 +12,6 @@ public:
private: private:
static Scene* CurrentScene; static Scene* CurrentScene;
static std::map<std::string, Scene*> Scenes; static std::map<std::string, Scene*> Scenes;
}; };

View File

@ -3,20 +3,20 @@
#include "Graphics/Renderable.h" #include "Graphics/Renderable.h"
#include "Scene/Node.h" #include "Scene/Node.h"
class SceneCamera : public Group namespace BarinkEngine {
{ class SceneCamera : public Group
public: {
Camera& camera; public:
SceneCamera(); Camera& camera;
}; SceneCamera();
};
class SceneObject : public Group class SceneObject : public Group
{ {
public: public:
Renderable& renderable; SceneObject(std::string name, Renderable* visual);
SceneObject(); ~SceneObject();
Renderable* renderable;
};
}; }

View File

@ -1,13 +1,12 @@
#include "Scene.h" #include "Scene.h"
#include "Scene.h"
#include "Scene/Node.h" #include "Scene/Node.h"
void DeleteSubGraph(Node* tree); void DeleteSubGraph(Node* tree);
Scene::Scene(std::string sceneName) Scene::Scene(const std::string& sceneName)
{ {
// Create a root node // Create a root node
root = new Group(sceneName); root = new Group(sceneName);
root->name = sceneName;
} }
Scene::~Scene() Scene::~Scene()
@ -18,7 +17,7 @@ Scene::~Scene()
} }
Node* SearchInChildren(Node* root, std::string name ) { Node* SearchInChildren(Node* root, const std::string name ) {
if (root->name == name) if (root->name == name)
return root; return root;

View File

@ -1,7 +1,7 @@
#include "Scene/Node.h" #include "Scene/Node.h"
Node::Node(std::string& name) Node::Node(const std::string& name)
: name(name), parent(nullptr), children(std::vector<Node*>()) {} : name(name), parent(nullptr), children(std::vector<Node*>()) {}
Group::Group(std::string& name ) Group::Group(const std::string& name )
: Node(name), transform(Transform()) {} : Node(name), transform(Transform()) {}

View File

@ -2,17 +2,21 @@
Scene* SceneManager::CreateScene(const std::string& name) Scene* SceneManager::CreateScene(const std::string& name)
{ {
/*
Scenes = std::map<std::string, Scene*>();
SceneManager::Scenes[name] = new Scene(name); SceneManager::Scenes[name] = new Scene(name);
*/
return &SceneManager::GetScene(name); return new Scene(name);
} }
Scene& SceneManager::GetScene(const std::string& name) Scene& SceneManager::GetScene(const std::string& name)
{ {
return *SceneManager::Scenes[name]; return Scene();
//return *SceneManager::Scenes[name];
} }
void SceneManager::LoadScene( Scene& scene) void SceneManager::LoadScene( Scene& scene)
{ {
CurrentScene = &scene; //SceneManager::CurrentScene = &scene;
} }

View 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()
{}

View File

@ -1,10 +1,10 @@
#include "AssetManager/ModelImporter.h" #include "AssetManager/ModelImporter.h"
SceneObject* ModelImporter::Import(const std::string path) BarinkEngine::SceneObject* BarinkEngine::ModelImporter::Import(const std::string path)
{ {
SceneObject* root = new SceneObject();
SceneObject* root = new SceneObject(std::string(path), nullptr);
Assimp::Importer importer; Assimp::Importer importer;
const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs); const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);
@ -17,7 +17,7 @@ SceneObject* ModelImporter::Import(const std::string path)
} }
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;
@ -38,7 +38,7 @@ 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;

View File

@ -14,7 +14,7 @@ void BarinkEngine::Renderer::Render()
{ {
for (auto model : models) { for (auto model : models) {
model->Draw(); //model->Draw();
} }
} }

View File

@ -11,27 +11,14 @@
* Define globals * Define globals
*/ */
Camera* cam; Camera* cam;
Shader* shader; Shader* shader;
//BarinkEngine::Renderable* Cube;
//Material* matCube;
//Texture* textureCube;
//BarinkEngine::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();
ModelImporter* MI = new ModelImporter();
/* /*
* Runs once at startup * Runs once at startup
@ -40,13 +27,19 @@ ModelImporter* MI = new ModelImporter();
void Start() { void Start() {
// Create a level and load it as the current level // Create a level and load it as the current level
auto Level1 = SceneManager::CreateScene("TestLevel"); std::string levelName("TestLevel");
auto Level1 = SceneManager::CreateScene(levelName);
SceneManager::LoadScene(*Level1); SceneManager::LoadScene(*Level1);
// Create a cube node // Create a cube node
Level1->GetRoot().addChild(*(MI->Import("build/SandboxApplication/Debug/Models"))); // Load a model
// *(MI->Import("build/SandboxApplication/Debug/Models/Cube.obj"))
//
std::string groupName("Nested-Group");
auto testGroup = new Group(groupName);
Level1->GetRoot().addChild( *testGroup);
// Build a basic test scene // Build a basic test scene
// NOTE: This will later be done through an editor // NOTE: This will later be done through an editor
@ -56,30 +49,6 @@ void Start() {
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 =
//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);
@ -153,18 +122,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;
} }