Skip to content

Commit

Permalink
This commit explodes the code. I'm just saving progress in case apoca…
Browse files Browse the repository at this point in the history
…lypsis come, my PC dies, but gitHub severs don't. Unlikely, but I'm prepared for anything. Don't have 68 bunkers spread all around the world for nothing I tell you. I was going to make nuclear weaponry jokes, then kind of thought what about I don't, then remembered dinner is on the table, so yeah... Committing...
  • Loading branch information
HoduRe committed Oct 19, 2020
1 parent 1e48425 commit 53f4ec3
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 6 deletions.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions NotThatGameEngine/NotThatGameEngine/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Application::Application() : userDt(false), msVecCounter(0), framerateVecCounter
imGui = new ModuleImGui(this);
eventManager = new ModuleEventManager(this);
primitives = new ModulePrimitives(this);
fileLoad = new ModuleFileLoad(this);
modelManager = new ModelManager(this);

// The order of calls is very important!
// Modules will Init() Start() and Update in this order
Expand All @@ -23,12 +25,14 @@ Application::Application() : userDt(false), msVecCounter(0), framerateVecCounter
AddModule(reset);
AddModule(eventManager);
AddModule(window);
AddModule(fileLoad);
AddModule(camera);
AddModule(input);
AddModule(audio);
AddModule(physics);
AddModule(scene_intro);
AddModule(player);
AddModule(modelManager);

// Renderer last!
AddModule(renderer3D);
Expand Down
6 changes: 4 additions & 2 deletions NotThatGameEngine/NotThatGameEngine/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#include "ModuleImGui.h"
#include "ModuleEventManager.h"
#include "ModulePrimitives.h"

#include "ModuleFileLoad.h"
#include "ModelManager.h"

#define LOG(format, ...) App->log(__FILE__, __LINE__, format, __VA_ARGS__);


class Application
{
public:
Expand All @@ -36,6 +36,8 @@ class Application
ModuleImGui* imGui;
ModuleEventManager* eventManager;
ModulePrimitives* primitives;
ModuleFileLoad* fileLoad;
ModelManager* modelManager;

Timer ms_timer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
return AI_FAILURE;
}

iNum = std::min((size_t)iNum,prop->mDataLength / sizeof(Type));
iNum = min((size_t)iNum,prop->mDataLength / sizeof(Type));
::memcpy(pOut,prop->mData,iNum * sizeof(Type));
if (pMax) {
*pMax = iNum;
Expand Down
Binary file not shown.
149 changes: 149 additions & 0 deletions NotThatGameEngine/NotThatGameEngine/ModelManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#include "Application.h"
#include "ModelManager.h"

#pragma comment( lib, "Assimp/libx86/assimp.lib" )


ModelManager::ModelManager(Application* app, bool start_enabled) : Module(app, start_enabled) {}


ModelManager::~ModelManager() {}


bool ModelManager::Init() {

bool ret = true;

stream = aiGetPredefinedLogStream(aiDefaultLogStream_DEBUGGER, nullptr);
aiAttachLogStream(&stream);

LoadModel("/Library/Meshes/warrior/warrior.FBX");

return ret;
}


bool ModelManager::CleanUp() {

aiDetachAllLogStreams();

return true;
}


update_status ModelManager::PreUpdate(float dt) {

return update_status::UPDATE_CONTINUE;
}


update_status ModelManager::Update(float dt) {

CheckListener(this);

return update_status::UPDATE_CONTINUE;
}


update_status ModelManager::PostUpdate(float dt) {

CheckListener(this);

return update_status::UPDATE_CONTINUE;
}


void ModelManager::ExecuteEvent(EVENT_ENUM eventId) {


}


void ModelManager::LoadModel(std::string path) {

const aiScene* scene = aiImportFile(path.c_str(), aiProcessPreset_TargetRealtime_MaxQuality);
if (scene != nullptr && scene->HasMeshes()) { aiReleaseImport(scene); }
else { LOG("Error loading scene % s", path); }

Assimp::Importer importer;

scene = importer.ReadFile(path.c_str(), aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_JoinIdenticalVertices);

//
testMesh.subMeshes.resize(scene->mNumMeshes);
//m_Textures.resize(pScene->mNumMaterials);

for (unsigned int i = 0; i < testMesh.subMeshes.size(); i++) {
const aiMesh* paiMesh = scene->mMeshes[i];
testMesh.subMeshes[i].MaterialIndex = paiMesh->mMaterialIndex;

std::vector<float> vertices;
std::vector<uint> indices;
const aiVector3D Zero3D(0.0f, 0.0f, 0.0f);

for (unsigned int i = 0; i < paiMesh->mNumVertices; i++) { // Vertices
const aiVector3D* pPos = &(paiMesh->mVertices[i]);
const aiVector3D* pNormal = &(paiMesh->mNormals[i]) : &Zero3D;
const aiVector3D* pTexCoord = paiMesh->HasTextureCoords(0) ? &(paiMesh->mTextureCoords[0][i]) : &Zero3D;

vertices.push_back(pPos->x);
vertices.push_back(pPos->y);
vertices.push_back(pPos->z);
vertices.push_back(pTexCoord->x);
vertices.push_back(pTexCoord->y);
vertices.push_back(pNormal->x);
vertices.push_back(pNormal->y);
vertices.push_back(pNormal->z);
}

for (unsigned int i = 0; i < paiMesh->mNumFaces; i++) { // Indices
const aiFace& Face = paiMesh->mFaces[i];
assert(Face.mNumIndices == 3);
indices.push_back(Face.mIndices[0]);
indices.push_back(Face.mIndices[1]);
indices.push_back(Face.mIndices[2]);
}

// TODO: have an openGL module / functionality (maybe just do a sepparate OpenGLInitialization file to do ALL OpenGl shit there) that intitalizes a buffer with vertices and index.
glGenBuffers(1, (GLuint*)&testMesh.subMeshes[i].vertexBufferId);
glBindBuffer(GL_ARRAY_BUFFER, testMesh.subMeshes[i].vertexBufferId);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vertices.size(), vertices.data(), GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);

glGenBuffers(1, (GLuint*)&testMesh.subMeshes[i].indexBufferId);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, testMesh.subMeshes[i].indexBufferId);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(uint) * indices.size(), indices.data(), GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}

// Init materials
for (unsigned int i = 0; i < scene->mNumMaterials; i++) {
const aiMaterial* pMaterial = scene->mMaterials[i];
textures[i] = NULL;
if (pMaterial->GetTextureCount(aiTextureType_DIFFUSE) > 0) {
aiString Path;

if (pMaterial->GetTexture(aiTextureType_DIFFUSE, 0, &Path, NULL, NULL, NULL, NULL, NULL) == AI_SUCCESS) {
std::string FullPath = Dir + "/" + Path.data;
textures[i] = new Texture(GL_TEXTURE_2D, FullPath.c_str());

if (!m_Textures[i]->Load()) {
printf("Error loading texture '%s'\n", FullPath.c_str());
delete m_Textures[i];
m_Textures[i] = NULL;
}
}
}
if (!textures[i]) {
textures[i] = new Texture(GL_TEXTURE_2D, "../Content/white.png");
textures[i]->Load();
}
}

//
testMesh.numVertices = mesh.mNumVertices;
testMesh.vertices = new float[testMesh.numVertices * 3];
memcpy(testMesh.vertices, aiMesh->mVertices, sizeof(float) * testMesh.numVertices * 3);

LOG("New mesh with %d vertices", testMesh.numVertices);
}
126 changes: 126 additions & 0 deletions NotThatGameEngine/NotThatGameEngine/ModelManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#ifndef __MODELMANAGER_H__
#define __MODELMANAGER_H__

#include "Module.h"
#include "Globals.h"
#include "Primitives.h"

#include "Assimp/include/cimport.h"
#include "Assimp/include/scene.h"
#include "Assimp/include/Importer.hpp"
#include "Assimp/include/postprocess.h"

/*
#ifndef TEXTURE_H
#define TEXTURE_H
#include <string>
#include <GL/glew.h>
#include <ImageMagick-6/Magick++.h>
class Texture
{
public:
Texture(GLenum TextureTarget, const std::string& FileName);
bool Load();
void Bind(GLenum TextureUnit);
private:
std::string m_fileName;
GLenum m_textureTarget;
GLuint m_textureObj;
Magick::Image m_image;
Magick::Blob m_blob;
};
#endif // TEXTURE_H
Texture::Texture(GLenum TextureTarget, const std::string& FileName)
{
m_textureTarget = TextureTarget;
m_fileName = FileName;
}
bool Texture::Load()
{
try {
m_image.read(m_fileName);
m_image.write(&m_blob, "RGBA");
}
catch (Magick::Error& Error) {
std::cout << "Error loading texture '" << m_fileName << "': " << Error.what() << std::endl;
return false;
}
glGenTextures(1, &m_textureObj);
glBindTexture(m_textureTarget, m_textureObj);
glTexImage2D(m_textureTarget, 0, GL_RGBA, m_image.columns(), m_image.rows(), 0, GL_RGBA, GL_UNSIGNED_BYTE, m_blob.data());
glTexParameterf(m_textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(m_textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(m_textureTarget, 0);
return true;
}
void Texture::Bind(GLenum TextureUnit)
{
glActiveTexture(TextureUnit);
glBindTexture(m_textureTarget, m_textureObj);
}
*/

struct Mesh {

struct SubMeshes {
GLuint vertexBufferId;
GLuint indexBufferId;
unsigned int NumIndices;
unsigned int MaterialIndex;
};

uint vramIndexId = 0;
uint numIndex = 0;
uint* index = nullptr;

uint vramUniqueVertices = 0;
uint numVertices = 0;
float* vertices = nullptr;

std::vector<SubMeshes> subMeshes;
std::vector textures;

};

class ModelManager : public Module
{

public:

ModelManager(Application* app, bool start_enabled = true);
~ModelManager();

bool Init();
update_status PreUpdate(float dt);
update_status Update(float dt);
update_status PostUpdate(float dt);
bool CleanUp();

void LoadModel(std::string path);

public:

private:

void ExecuteEvent(EVENT_ENUM eventId);

private:
aiLogStream stream;
Mesh testMesh;
};

#endif
4 changes: 1 addition & 3 deletions NotThatGameEngine/NotThatGameEngine/ModuleFileLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
#include <fstream>
#include <filesystem>

#include "Assimp/include/cfileio.h"
#include "Assimp/include/types.h"

#pragma comment( lib, "PhysFS/libx86/physfs.lib" )


ModuleFileLoad::ModuleFileLoad(Application* app, bool start_enabled) : Module(app, start_enabled) {
// needs to be created before Init so other modules can use it
char* base_path = SDL_GetBasePath();
Expand Down
2 changes: 2 additions & 0 deletions NotThatGameEngine/NotThatGameEngine/NotThatGameEngine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
<ClCompile Include="imgui_widgets.cpp" />
<ClCompile Include="Light.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="ModelManager.cpp" />
<ClCompile Include="Module.cpp" />
<ClCompile Include="ModuleAudio.cpp" />
<ClCompile Include="ModuleCamera3D.cpp" />
Expand Down Expand Up @@ -188,6 +189,7 @@
<ClInclude Include="imstb_truetype.h" />
<ClInclude Include="Light.h" />
<ClInclude Include="MemLeaks.h" />
<ClInclude Include="ModelManager.h" />
<ClInclude Include="Module.h" />
<ClInclude Include="ModuleAudio.h" />
<ClInclude Include="ModuleCamera3D.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
<ClCompile Include="ModuleFileLoad.cpp">
<Filter>Archivos de recursos</Filter>
</ClCompile>
<ClCompile Include="ModelManager.cpp">
<Filter>Archivos de recursos</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ModuleAudio.h">
Expand Down Expand Up @@ -197,5 +200,8 @@
<ClInclude Include="PathNode.h">
<Filter>Utility</Filter>
</ClInclude>
<ClInclude Include="ModelManager.h">
<Filter>Archivos de recursos</Filter>
</ClInclude>
</ItemGroup>
</Project>

0 comments on commit 53f4ec3

Please sign in to comment.