Converting to GLM shit from tinyobjloader, having trouble with normals / indicies
This commit is contained in:
@@ -31,9 +31,8 @@ Mesh::Mesh(ObjLMesh mesh) {
|
||||
}
|
||||
|
||||
void Mesh::loadFromObj(ObjLMesh mesh) {
|
||||
// OBJLtoGLM(objMesh.Vertices, vertices, normals, texCoords);
|
||||
// indices = objMesh.Indices;
|
||||
// name = objMesh.MeshName;
|
||||
OBJLtoGLM(mesh, vertices, normals, texCoords);
|
||||
OBJLtoIndices(mesh, indices);
|
||||
|
||||
//Logger logger;
|
||||
//for (int i = 0; i < 100; i++) {
|
||||
|
||||
@@ -2,39 +2,48 @@
|
||||
|
||||
#include <logger.h>
|
||||
|
||||
void OBJLtoGLM(std::vector<objl::Vertex>& inVertArr,
|
||||
void OBJLtoGLM(ObjLMesh& mesh,
|
||||
std::vector<glm::vec3>& outVert,
|
||||
std::vector<glm::vec3>& outNorm,
|
||||
std::vector<glm::vec3>& outTexCoord) {
|
||||
std::vector<glm::vec3>& outTexCoord,
|
||||
std::vector<GLuint>& outIndices) {
|
||||
|
||||
for (int i = 0; i < inVertArr.size() - 1; i++) {
|
||||
|
||||
glm::vec3 tempVert {inVertArr[i].Position.X, inVertArr[i].Position.Y, inVertArr[i].Position.Z};
|
||||
outVert.push_back(tempVert);
|
||||
for (const auto &shape : mesh.shapes) {
|
||||
for (const auto& index : shape.mesh.indices) {
|
||||
|
||||
glm::vec3 tempNorm {inVertArr[i].Normal.X, inVertArr[i].Normal.Y, inVertArr[i].Normal.Z};
|
||||
outNorm.push_back(tempNorm);
|
||||
outVert.push_back({
|
||||
mesh.attrib.vertices[3 * index.vertex_index + 0],
|
||||
mesh.attrib.vertices[3 * index.vertex_index + 1],
|
||||
mesh.attrib.vertices[3 * index.vertex_index + 2]
|
||||
});
|
||||
|
||||
glm::vec3 tempTexCoord {inVertArr[i].TextureCoordinate.X, inVertArr[i].TextureCoordinate.Y, 1.0f};
|
||||
outTexCoord.push_back(tempTexCoord);
|
||||
outNorm.push_back({
|
||||
mesh.attrib.normals[0],
|
||||
mesh.attrib.normals[0],
|
||||
mesh.attrib.normals[0]
|
||||
});
|
||||
|
||||
outTexCoord.push_back({
|
||||
mesh.attrib.texcoords[2 * index.texcoord_index + 0],
|
||||
mesh.attrib.texcoords[2 * index.texcoord_index + 1],
|
||||
0.0f
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void UintToGLuint(std::vector<unsigned int>& inIndices,
|
||||
void UintToGLuint(ObjLMesh& mesh,
|
||||
std::vector<GLuint>& outIndices) {
|
||||
|
||||
for (int i = 0; i < inIndices.size(); i++) {
|
||||
outIndices.push_back(inIndices[i]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void OBJLVec3toGLM(objl::Vector3& inVec, glm::vec3& outVec) {
|
||||
|
||||
outVec.x = inVec.X;
|
||||
outVec.y = inVec.Y;
|
||||
outVec.z = inVec.Z;
|
||||
|
||||
}
|
||||
// void OBJLVec3toGLM(objl::Vector3& inVec, glm::vec3& outVec) {
|
||||
|
||||
// outVec.x = inVec.X;
|
||||
// outVec.y = inVec.Y;
|
||||
// outVec.z = inVec.Z;
|
||||
|
||||
// }
|
||||
|
||||
@@ -7,14 +7,21 @@
|
||||
|
||||
#include <tiny_obj_loader.h>
|
||||
|
||||
void OBJLtoGLM(std::vector<objl::Vertex>& inVertArr,
|
||||
struct ObjLMesh {
|
||||
tinyobj::attrib_t attrib;
|
||||
std::vector<tinyobj::shape_t> shapes;
|
||||
std::vector<tinyobj::material_t> materials;
|
||||
};
|
||||
|
||||
void OBJLtoGLM(ObjLMesh& mesh,
|
||||
std::vector<glm::vec3>& outVert,
|
||||
std::vector<glm::vec3>& outNorm,
|
||||
std::vector<glm::vec3>& outTexCoord);
|
||||
std::vector<glm::vec3>& outTexCoord,
|
||||
std::vector<GLuint>& outIndices);
|
||||
|
||||
void UintToGLuint(std::vector<unsigned int>& inIndices,
|
||||
void UintToGLuint(ObjLMesh& mesh,
|
||||
std::vector<GLuint>& outIndices);
|
||||
|
||||
void OBJLVec3toGLM(objl::Vector3& inVec, glm::vec3& outVec);
|
||||
// void OBJLVec3toGLM(objl::Vector3& inVec, glm::vec3& outVec);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user