Adding docking support through ImGui , Adding multiviewport support through ImGui, Moving header file back into the src directory , started building the editor, Added framebuffer to renderer.
BUG: The framebuffer will not be displayed in the editor for some reason
This commit is contained in:
99
BarinkEngine/src/AssetManager/ModelImporter.cpp
Normal file
99
BarinkEngine/src/AssetManager/ModelImporter.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
#include "ModelImporter.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
BarinkEngine::SceneObject* BarinkEngine::ModelImporter::Import(const std::string path)
|
||||
{
|
||||
SceneObject* root = new SceneObject(std::string(path), nullptr);
|
||||
|
||||
Assimp::Importer importer;
|
||||
const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);
|
||||
|
||||
aiNode* currentNode = scene->mRootNode;
|
||||
|
||||
std::vector<BarinkEngine::Mesh> meshes = processNode(currentNode, scene);
|
||||
|
||||
std::cout << "[DEBUG]: Loaded "<< meshes.size() << " meshes!" << std::endl;
|
||||
|
||||
// create a renderable (per mesh ?? )
|
||||
root->renderable = new Renderable();
|
||||
root->renderable->mesh = new Mesh(meshes[0]);
|
||||
|
||||
return root;
|
||||
|
||||
}
|
||||
|
||||
std::vector<BarinkEngine::Mesh> BarinkEngine::ModelImporter::processNode(aiNode* node, const aiScene* scene)
|
||||
{
|
||||
|
||||
std::vector<BarinkEngine::Mesh> meshes;
|
||||
|
||||
for (unsigned int i = 0; i < node->mNumMeshes; i++) {
|
||||
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
||||
meshes.push_back(processMesh(mesh, scene));
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < node->mNumChildren; i++) {
|
||||
auto m2 = processNode(node->mChildren[i], scene);
|
||||
|
||||
for(auto m : m2) {
|
||||
meshes.push_back(m);
|
||||
}
|
||||
}
|
||||
|
||||
return meshes;
|
||||
}
|
||||
|
||||
BarinkEngine::Mesh BarinkEngine::ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) {
|
||||
std::vector<unsigned int> indices;
|
||||
std::vector<BarinkEngine::Vertex> vertices;
|
||||
|
||||
ProcessVertices(mesh, vertices);
|
||||
|
||||
ProcessIndices(mesh, indices);
|
||||
|
||||
BarinkEngine::Mesh result;
|
||||
result.vertices = vertices;
|
||||
result.elements = indices;
|
||||
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
void ProcessVertices(aiMesh* mesh, std::vector<BarinkEngine::Vertex>& out_vertices) {
|
||||
// Process vertices
|
||||
for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
|
||||
BarinkEngine::Vertex v{};
|
||||
glm::vec3 vector;
|
||||
vector.x = mesh->mVertices[i].x;
|
||||
vector.y = mesh->mVertices[i].y;
|
||||
vector.z = mesh->mVertices[i].z;
|
||||
|
||||
v.vertices = vector;
|
||||
|
||||
if (mesh->mTextureCoords[0]) {
|
||||
|
||||
glm::vec2 texCoord;
|
||||
|
||||
texCoord.x = mesh->mTextureCoords[0][i].x;
|
||||
texCoord.y = mesh->mTextureCoords[0][i].y;
|
||||
|
||||
v.uv = texCoord;
|
||||
|
||||
}
|
||||
|
||||
out_vertices.push_back(v);
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices) {
|
||||
// Process Indices
|
||||
for (unsigned int i = 0; i < mesh->mNumFaces; i++) {
|
||||
aiFace face = mesh->mFaces[i];
|
||||
if (face.mNumIndices < 3)
|
||||
continue;
|
||||
for (unsigned int j = 0; j < face.mNumIndices; j++) {
|
||||
out_indices.push_back(face.mIndices[j]);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user