make use of TexturedModel

This commit is contained in:
2023-06-28 22:19:18 +02:00
parent 385dcf11d0
commit b985cc7ade
6 changed files with 91 additions and 33 deletions

View File

@@ -1,5 +1,6 @@
#include "Defines.h"
#include "render/loader/MobLoader.h"
#include "render/loader/TextureLoader.h"
#include <fstream>
#include <map>
@@ -7,6 +8,20 @@
#include <algorithm>
namespace td {
namespace render {
TexturedModel::TexturedModel(GL::VertexArray&& vao, GL::Texture&& texture) {
m_Vao = std::make_unique<GL::VertexArray>(std::move(vao));
m_Texture = std::make_unique<GL::Texture>(std::move(texture));
}
TexturedModel::TexturedModel(TexturedModel&& other) {
m_Vao = std::move(other.m_Vao);
m_Texture = std::move(other.m_Texture);
m_Positon = other.m_Positon;
m_Color = other.m_Color;
}
namespace MobLoader {
const static int POSITION_VERTEX_SIZE = 3;
@@ -17,9 +32,9 @@ typedef Vec2f TextureUV;
typedef Vec3f Normal;
struct Index {
int vertexIndex;
int textureIndex;
int normalIndex;
std::size_t vertexIndex;
std::size_t textureIndex;
std::size_t normalIndex;
};
enum DataType : std::uint8_t {
@@ -43,8 +58,8 @@ static DataType GetDataType(const std::string& type) {
return it != Types.end() ? it->second : dt_None;
}
GL::VertexArray LoadMobModel() {
std::ifstream fileStream{ "Assets/zombie.obj" };
static GL::VertexArray LoadMobVao(const std::string& objFile) {
std::ifstream fileStream{ objFile };
std::string line;
std::vector<Vertex> tempVertecies;
@@ -104,20 +119,20 @@ GL::VertexArray LoadMobModel() {
Index tempIndicies[4];
for (size_t i = 0; i < 4; i++){
for (std::size_t i = 0; i < 4; i++){
ss >> tempIndicies[i].vertexIndex;
ss >> tempIndicies[i].textureIndex;
ss >> tempIndicies[i].normalIndex;
}
static const std::vector<int> vertexOrder = {0, 1, 2, 0, 2, 3};
static const std::vector<std::size_t> vertexOrder = {0, 1, 2, 0, 2, 3};
for(int i = 0; i < vertexOrder.size(); i++) {
for(std::size_t i = 0; i < vertexOrder.size(); i++) {
Index& index = tempIndicies[vertexOrder[i]];
int vertexIndex = index.vertexIndex - 1;
int textureIndex = index.textureIndex - 1;
int normalIndex = index.normalIndex - 1;
std::size_t vertexIndex = index.vertexIndex - 1;
std::size_t textureIndex = index.textureIndex - 1;
std::size_t normalIndex = index.normalIndex - 1;
Vertex vertex = tempVertecies[vertexIndex];
TextureUV texture = tempTextureUvs[textureIndex];
@@ -138,7 +153,7 @@ GL::VertexArray LoadMobModel() {
break;
}
case dt_None:
default:
break;
}
}
@@ -153,8 +168,14 @@ GL::VertexArray LoadMobModel() {
mobVao.BindVertexBuffer(positionVBO);
mobVao.BindVertexBuffer(textureVBO);
mobVao.Unbind();
return mobVao;
}
} // namespace loader
TexturedModel LoadMobModel() {
return {LoadMobVao("Assets/zombie.obj"), TextureLoader::LoadTexture("Assets/zombie.png")};
}
} // namespace MobLoader
} // namespace render
} // namespace td