mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
~ | Vertex normal obj handling
This commit is contained in:
@ -26,20 +26,22 @@ class ObjParser
|
||||
private:
|
||||
glm::vec3 getVertex(std::stringstream &line);
|
||||
glm::vec2 getUV(std::stringstream &line);
|
||||
glm::vec3 getNormals(std::stringstream &line);
|
||||
void addFace(std::stringstream &line);
|
||||
long int checkVertexIndex(int index, size_t size);
|
||||
void parseMtl(std::stringstream &line, Scene &scene);
|
||||
bool addTriangleFromPolygon(std::vector<glm::vec3> &vertices, std::vector<glm::vec2> &textureVertices, int inv);
|
||||
void addTriangle(glm::vec3 v1, glm::vec3 v2, glm::vec3 v3, std::vector<glm::vec2> textureVertices);
|
||||
bool addTriangleFromPolygon(std::vector<glm::vec3> &vertices, std::vector<glm::vec2> &textureVertices, std::vector<glm::vec3> &normalVertices, int inv);
|
||||
void addTriangle(glm::vec3 v1, glm::vec3 v2, glm::vec3 v3, std::vector<glm::vec2> textureVertices, std::vector<glm::vec3> normalVertices);
|
||||
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::vector<glm::vec2> &textureVertices, std::stringstream &line);
|
||||
void getFaceVertices(std::vector<glm::vec3> &faceVertices, std::vector<glm::vec2> &textureVertices, std::vector<glm::vec3> &normalVertices, std::stringstream &line);
|
||||
|
||||
std::string _filename;
|
||||
std::ifstream _file;
|
||||
std::vector<glm::vec3> _vertices;
|
||||
std::vector<glm::vec2> _textureVertices;
|
||||
std::vector<glm::vec3> _normalVertices;
|
||||
int _mat;
|
||||
std::map<std::string, int> _matNames;
|
||||
|
||||
|
@ -38,11 +38,14 @@ struct GPUTriangle
|
||||
alignas(16) glm::vec3 position;
|
||||
alignas(16) glm::vec3 vertex1;
|
||||
alignas(16) glm::vec3 vertex2;
|
||||
alignas(16) glm::vec3 normal;
|
||||
|
||||
alignas(16) glm::vec3 normal_vertex1;
|
||||
alignas(16) glm::vec3 normal_vertex2;
|
||||
alignas(16) glm::vec3 normal_vertex3;
|
||||
|
||||
alignas(8) glm::vec2 texture_vertex1;
|
||||
alignas(8) glm::vec2 texture_vertex2;
|
||||
alignas(8) glm::vec2 texture_vertex3;
|
||||
alignas(8) glm::vec2 texture_vertex1;
|
||||
alignas(8) glm::vec2 texture_vertex2;
|
||||
alignas(8) glm::vec2 texture_vertex3;
|
||||
|
||||
int mat_index;
|
||||
};
|
||||
|
@ -52,12 +52,20 @@ class Triangle : public Object
|
||||
_mat_index = mat_index;
|
||||
}
|
||||
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)
|
||||
const glm::vec2& vt1, const glm::vec2& vt2, const glm::vec2& vt3,
|
||||
const glm::vec3& vn1, const glm::vec3& vn2, const glm::vec3& vn3,
|
||||
const int mat_index)
|
||||
: Object(position, mat_index), _vertex2(vertex2), _vertex3(vertex3),
|
||||
_texture_vertex1(vt1), _texture_vertex2(vt2), _texture_vertex3(vt3)
|
||||
_texture_vertex1(vt1), _texture_vertex2(vt2), _texture_vertex3(vt3),
|
||||
_normal_vertex1(vn1), _normal_vertex2(vn2), _normal_vertex3(vn3)
|
||||
{
|
||||
|
||||
_normal = glm::normalize(glm::cross(_vertex2 - _position, _vertex3 - _position)); //optimization
|
||||
if (vn1 == glm::vec3(0.0f) && vn2 == glm::vec3(0.0f) && vn3 == glm::vec3(0.0f))
|
||||
{
|
||||
glm::vec3 normal = glm::normalize(glm::cross(_vertex2 - _position, _vertex3 - _position));
|
||||
_normal_vertex1 = normal;
|
||||
_normal_vertex2 = normal;
|
||||
_normal_vertex3 = normal;
|
||||
}
|
||||
_centroid = (_position + _vertex2 + _vertex3) / 3.0f;
|
||||
// _vertex2 -= _position; //optimization
|
||||
// _vertex3 -= _position; //optimization
|
||||
@ -67,6 +75,10 @@ class Triangle : public Object
|
||||
const glm::vec2 &getTextureVertex2() const {return (_texture_vertex2); }
|
||||
const glm::vec2 &getTextureVertex3() const {return (_texture_vertex3); }
|
||||
|
||||
const glm::vec3 &getNormalVertex1() const {return (_normal_vertex1); }
|
||||
const glm::vec3 &getNormalVertex2() const {return (_normal_vertex2); }
|
||||
const glm::vec3 &getNormalVertex3() const {return (_normal_vertex3); }
|
||||
|
||||
const glm::vec3 &getVertex2() const { return (_vertex2); }
|
||||
const glm::vec3 &getVertex3() const { return (_vertex3); }
|
||||
const glm::vec3 &getNormal() const { return (_normal); }
|
||||
@ -83,6 +95,10 @@ class Triangle : public Object
|
||||
glm::vec2 _texture_vertex2;
|
||||
glm::vec2 _texture_vertex3;
|
||||
|
||||
glm::vec3 _normal_vertex1;
|
||||
glm::vec3 _normal_vertex2;
|
||||
glm::vec3 _normal_vertex3;
|
||||
|
||||
glm::vec3 _normal;
|
||||
|
||||
glm::vec3 _centroid;
|
||||
|
Reference in New Issue
Block a user