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 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 std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, 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);
};
};
}

View File

@ -3,13 +3,13 @@
#include <imgui.h>
struct EngineStatistics {
uint32_t lastSampleTime;
long long lastSampleTime;
float frameTime;
uint32_t verts;
uint32_t DC;
uint64_t frames;
uint64_t FPS;
long long frames;
long long FPS;
};
extern EngineStatistics* ES;
@ -25,8 +25,8 @@ inline void SamplePerformance(void) {
ES->frames++;
ES->DC = 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 int MilliSecondsPast = now - ES->lastSampleTime;
unsigned long long now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
unsigned long long MilliSecondsPast = now - ES->lastSampleTime;
if (MilliSecondsPast >= 1000) {
ES->frameTime = (float)1000 / ES->frames;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,17 +2,21 @@
Scene* SceneManager::CreateScene(const std::string& name)
{
/*
Scenes = std::map<std::string, Scene*>();
SceneManager::Scenes[name] = new Scene(name);
*/
return &SceneManager::GetScene(name);
return new Scene(name);
}
Scene& SceneManager::GetScene(const std::string& name)
{
return *SceneManager::Scenes[name];
return Scene();
//return *SceneManager::Scenes[name];
}
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"
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;
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;
@ -38,7 +38,7 @@ std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const a
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<BarinkEngine::Vertex> vertices;

View File

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

View File

@ -11,27 +11,14 @@
* Define globals
*/
Camera* cam;
Shader* shader;
//BarinkEngine::Renderable* Cube;
//Material* matCube;
//Texture* textureCube;
//BarinkEngine::Renderable* Cube2;
//Material* matCube2;
char* code = new char[254];
const std::string vertexShaderSource = "build/SandboxApplication/Debug/test.vs";
const std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs";
ModelImporter* MI = new ModelImporter();
BarinkEngine::ModelImporter* MI = new BarinkEngine::ModelImporter();
/*
* Runs once at startup
@ -40,13 +27,19 @@ ModelImporter* MI = new ModelImporter();
void Start() {
// 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);
// 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
// NOTE: This will later be done through an editor
@ -56,30 +49,6 @@ void Start() {
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);
@ -153,18 +122,6 @@ void Update()
* - Meant for cleanup
*/
void Stop() {
// Cleanup
//Cube->VAO.Delete();
//Cube->elementBuffer.Delete();
//Cube2->VAO.Delete();
//Cube2->elementBuffer.Delete();
//delete Cube2;
//delete Cube;
//delete matCube;
//delete matCube2;
delete MI;
delete shader;
}