MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / exportOBJ

Function exportOBJ

Tools/MeshSkinning/main.cpp:967–1008  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

965
966
967void exportOBJ()
968{
969 std::string fileName = convertFileName(output, currentFrame);
970 LOG_INFO << "Writing: " << fileName;
971
972 FileSystem::makeDir(FileSystem::getFilePath(FileSystem::normalizePath(output)));
973
974 // Open the file
975 std::ofstream outfile(fileName);
976 if (!outfile)
977 {
978 LOG_WARN << "Cannot open a file to save OBJ mesh.";
979 return;
980 }
981
982 // Header
983 outfile << "# Created by SPlisHSPlasH version " << SPLISHSPLASH_VERSION << "\n";
984 outfile << "g default\n";
985
986 const std::vector<Vector3r>& vertices = meshX;
987 const std::vector<unsigned int>& faces = mesh.getFaces();
988 int n_vertices = (int)vertices.size();
989 int n_triangles = (int)faces.size() / 3;
990
991 // Vertices
992 {
993 for (int j = 0u; j < n_vertices; j++)
994 {
995 Vector3r x = vertices[j];
996 outfile << "v " << x[0] << " " << x[1] << " " << x[2] << "\n";
997 }
998 }
999
1000 // faces
1001 {
1002 for (int j = 0; j < n_triangles; j++)
1003 {
1004 outfile << "f " << faces[3 * j + 0] + 1 << " " << faces[3 * j + 1] + 1 << " " << faces[3 * j + 2] + 1 << "\n";
1005 }
1006 }
1007 outfile.close();
1008}
1009
1010// VTK expects big endian
1011template<typename T>

Callers 1

writeCurrentFrameFunction · 0.85

Calls 3

convertFileNameFunction · 0.70
sizeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected