+ | Texture parsing on obj

This commit is contained in:
TheRedShip
2025-01-28 12:20:09 +01:00
parent e9c77cfdd4
commit 7b81995724
14 changed files with 2940 additions and 1195 deletions

View File

@ -30,11 +30,11 @@ class ObjParser
long int checkVertexIndex(int index, size_t size);
void parseMtl(std::stringstream &line, Scene &scene);
bool addTriangleFromPolygon(std::vector<glm::vec3> &vertices, int inv);
void addTriangle(glm::vec3 v1, glm::vec3 v2, glm::vec3 v3);
void addTriangle(glm::vec3 v1, glm::vec3 v2, glm::vec3 v3, glm::vec2 vt1, glm::vec2 vt2, glm::vec2 vt3);
std::string getFilePath(std::string &file);
int pointInTriangle(glm::vec3 pts[3], std::vector<glm::vec3> vertices, size_t cur);
std::vector<std::string> objSplit(std::string str, std::string delim);
void getFaceVertices(std::vector<glm::vec3> &faceVertices, std::stringstream &line);
void getFaceVertices(std::vector<glm::vec3> &faceVertices, std::vector<glm::vec2> &textureVertices, std::stringstream &line);
std::string _filename;
std::ifstream _file;

View File

@ -40,6 +40,11 @@ struct GPUTriangle
alignas(16) glm::vec3 vertex2;
alignas(16) glm::vec3 normal;
glm::vec2 texture_vertex1;
glm::vec2 texture_vertex2;
glm::vec2 texture_vertex3;
int mat_index;
};
@ -121,6 +126,7 @@ class Scene
std::vector<GPUMaterial> &getMaterialData();
std::vector<GLuint> &getTextureIDs();
std::vector<std::string> &getTextures();
std::vector<GPUBvhData> &getBvhData();
std::vector<GPUBvh> &getBvh();

View File

@ -51,16 +51,22 @@ class Triangle : public Object
_mat_index = mat_index;
}
Triangle(const glm::vec3& position, const glm::vec3& vertex2, const glm::vec3& vertex3, const int mat_index)
: Object(position, mat_index), _vertex2(vertex2), _vertex3(vertex3) {
Triangle(const glm::vec3& position, const glm::vec3& vertex2, const glm::vec3& vertex3,
const glm::vec2& vt1, const glm::vec2& vt2, const glm::vec2& vt3, const int mat_index)
: Object(position, mat_index), _vertex2(vertex2), _vertex3(vertex3),
_texture_vertex1(vt1), _texture_vertex2(vt2), _texture_vertex3(vt3)
{
_normal = glm::normalize(glm::cross(_vertex2 - _position, _vertex3 - _position)); //optimization
_centroid = (_position + _vertex2 + _vertex3) / 3.0f;
// _vertex2 -= _position; //optimization
// _vertex3 -= _position; //optimization
}
const glm::vec2 &getTextureVertex1() const {return (_texture_vertex1); }
const glm::vec2 &getTextureVertex2() const {return (_texture_vertex2); }
const glm::vec2 &getTextureVertex3() const {return (_texture_vertex3); }
const glm::vec3 &getVertex2() const { return (_vertex2); }
const glm::vec3 &getVertex3() const { return (_vertex3); }
const glm::vec3 &getNormal() const { return (_normal); }
@ -73,6 +79,11 @@ class Triangle : public Object
glm::vec3 _vertex2;
glm::vec3 _vertex3;
glm::vec2 _texture_vertex1;
glm::vec2 _texture_vertex2;
glm::vec2 _texture_vertex3;
glm::vec3 _normal;
glm::vec3 _centroid;