-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit explodes the code. I'm just saving progress in case apoca…
…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
Showing
11 changed files
with
293 additions
and
6 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters