diff --git a/QtMeshViewer/Header/FileInterface.h b/QtMeshViewer/Header/FileInterface.h index 6db9b5c..26fee9c 100644 --- a/QtMeshViewer/Header/FileInterface.h +++ b/QtMeshViewer/Header/FileInterface.h @@ -42,10 +42,10 @@ struct Material { QString tx3d; QOpenGLTexture* texture0 = Q_NULLPTR; QOpenGLTexture* texture1 = Q_NULLPTR; - QVector4D specularColor = { 1.0, 1.0, 1.0, 1.0 }; + QVector4D specularColor = { 0.1f, 0.1f, 0.1f, 1.0 }; QVector4D diffuseColor = { 1.0, 0.0, 0.0, 1.0 }; QVector4D ambientColor = { 1.0, 1.0, 1.0, 1.0 }; - float shininess = 80; + float shininess = 1; bool flags[8] = { false }; bool transparent = false; quint8 rendertype = 0; diff --git a/QtMeshViewer/Source/MshFile.cpp b/QtMeshViewer/Source/MshFile.cpp index 8a15b6f..c3f52aa 100644 --- a/QtMeshViewer/Source/MshFile.cpp +++ b/QtMeshViewer/Source/MshFile.cpp @@ -1,6 +1,7 @@ #include "..\Header\MshFile.h" #include "..\Header\tga.h" #include "..\Header\OutputDevice.h" +#include // helper function to save data from file to any variable type @@ -662,12 +663,26 @@ void MshFile::analyseClthChunks(Model * dataDestination, QList& ch m_file.read(F2V(tmp_size), sizeof(tmp_size)); // for every triangle.. - for (unsigned int i = 0; i < tmp_size * 3; i++) + for (unsigned int i = 0; i < tmp_size; i++) { - quint32 tmp_value; - m_file.read(F2V(tmp_value), sizeof(quint32)); + quint32 tmp_value[3]; + for (unsigned int j = 0; j < 3; j++) + { + m_file.read(F2V(tmp_value[j]), sizeof(quint32)); + new_segment->indices.push_back((GLuint)tmp_value[j]); + } - new_segment->indices.push_back((GLuint)tmp_value); + QVector3D vec1, vec2, norm; + + vec1 = new_segment->vertices[new_segment->indices[i * 3]].position - new_segment->vertices[new_segment->indices[i * 3 + 1]].position; + vec2 = new_segment->vertices[new_segment->indices[i * 3]].position - new_segment->vertices[new_segment->indices[i * 3 + 2]].position; + norm = QVector3D::crossProduct(vec1, vec2); + + for (int k = 0; k < 3; k++) + { + new_segment->vertices[new_segment->indices[i * 3 + k]].vertexNormal += norm; + new_segment->vertices[new_segment->indices[i * 3 + k]].vertexNormal.normalize(); + } } } }