| 927 | } |
| 928 | |
| 929 | void DemoBase::loadMesh(const std::string& filename, VertexData& vd, Utilities::IndexedFaceMesh& mesh, const Vector3r& translation, |
| 930 | const Matrix3r& rotation, const Vector3r& scale) |
| 931 | { |
| 932 | string ext = FileSystem::getFileExt(filename); |
| 933 | transform(ext.begin(), ext.end(), ext.begin(), ::toupper); |
| 934 | |
| 935 | std::vector<std::array<float, 3>> x; |
| 936 | if (ext == "OBJ") |
| 937 | { |
| 938 | std::vector<OBJLoader::Vec3f> normals; |
| 939 | std::vector<OBJLoader::Vec2f> texCoords; |
| 940 | std::vector<MeshFaceIndices> faces; |
| 941 | OBJLoader::Vec3f s = { (float)scale[0], (float)scale[1], (float)scale[2] }; |
| 942 | OBJLoader::loadObj(filename, &x, &faces, &normals, &texCoords, s); |
| 943 | |
| 944 | mesh.release(); |
| 945 | const unsigned int nPoints = (unsigned int)x.size(); |
| 946 | const unsigned int nFaces = (unsigned int)faces.size(); |
| 947 | const unsigned int nTexCoords = (unsigned int)texCoords.size(); |
| 948 | mesh.initMesh(nPoints, nFaces * 2, nFaces); |
| 949 | vd.reserve(nPoints); |
| 950 | for (unsigned int i = 0; i < nPoints; i++) |
| 951 | { |
| 952 | vd.addVertex(Vector3r(x[i][0], x[i][1], x[i][2])); |
| 953 | } |
| 954 | for (unsigned int i = 0; i < nTexCoords; i++) |
| 955 | { |
| 956 | mesh.addUV(texCoords[i][0], texCoords[i][1]); |
| 957 | } |
| 958 | for (unsigned int i = 0; i < nFaces; i++) |
| 959 | { |
| 960 | int posIndices[3]; |
| 961 | int texIndices[3]; |
| 962 | for (int j = 0; j < 3; j++) |
| 963 | { |
| 964 | posIndices[j] = faces[i].posIndices[j]; |
| 965 | if (nTexCoords > 0) |
| 966 | { |
| 967 | texIndices[j] = faces[i].texIndices[j]; |
| 968 | mesh.addUVIndex(texIndices[j]); |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | mesh.addFace(&posIndices[0]); |
| 973 | } |
| 974 | mesh.buildNeighbors(); |
| 975 | |
| 976 | mesh.updateNormals(vd, 0); |
| 977 | mesh.updateVertexNormals(vd); |
| 978 | |
| 979 | LOG_INFO << "Number of triangles: " << nFaces; |
| 980 | LOG_INFO << "Number of vertices: " << nPoints; |
| 981 | } |
| 982 | else if (ext == "PLY") |
| 983 | { |
| 984 | std::vector<std::array<int, 3>> faces; |
| 985 | OBJLoader::Vec3f s = { (float)scale[0], (float)scale[1], (float)scale[2] }; |
| 986 | PLYLoader::loadPly(filename, x, faces, s); |
nothing calls this directly
no test coverage detected