| 77 | } |
| 78 | |
| 79 | void OBJWriter::write_mesh(Mesh& mesh) { |
| 80 | using namespace OBJWriterHelper; |
| 81 | std::ofstream fout(m_filename.c_str()); |
| 82 | if (!is_anonymous()) { |
| 83 | fout << "# Generated with PyMesh" << std::endl; |
| 84 | } |
| 85 | VectorF texture; |
| 86 | VectorI texture_indices; |
| 87 | if (mesh.has_attribute("corner_texture")) { |
| 88 | texture = mesh.get_attribute("corner_texture"); |
| 89 | const size_t num_faces = mesh.get_num_faces(); |
| 90 | const size_t vertex_per_face = mesh.get_vertex_per_face(); |
| 91 | if (texture.size() != num_faces * vertex_per_face * 2) { |
| 92 | // Texture invalid. |
| 93 | texture.resize(0); |
| 94 | } else { |
| 95 | write_texture(fout, texture); |
| 96 | texture_indices.resize(num_faces * vertex_per_face); |
| 97 | for (size_t i=0; i<num_faces; i++) { |
| 98 | for (size_t j=0; j<vertex_per_face; j++) { |
| 99 | texture_indices[i*vertex_per_face+j] = i*vertex_per_face+j; |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | write_vertices(fout, mesh.get_vertices(), mesh.get_dim()); |
| 106 | write_faces(fout, mesh.get_faces(), mesh.get_vertex_per_face(), |
| 107 | texture_indices); |
| 108 | fout.close(); |
| 109 | } |
| 110 | |
| 111 | void OBJWriter::write( |
| 112 | const VectorF& vertices, |
nothing calls this directly
no test coverage detected