1 #include <IO/deprecated/OBJFileManager.hpp>
12 OBJFileManager::OBJFileManager() :
FileManager<Geometry::TriangleMesh>() {}
26 bool OBJFileManager::importData( std::istream& file, Geometry::TriangleMesh& data ) {
29 Geometry::TriangleMesh::PointAttribHandle::Container vertices;
30 Geometry::TriangleMesh::NormalAttribHandle::Container normals;
31 Geometry::TriangleMesh::IndexContainerType indices;
32 while ( std::getline( file, line ) ) {
33 std::istringstream iss( line );
37 if ( token ==
"#" ) {
continue; }
40 iss >> v[0] >> v[1] >> v[2];
41 vertices.push_back( v );
43 if ( token ==
"vn" ) {
45 iss >> n[0] >> n[1] >> n[2];
46 normals.push_back( n );
48 if ( token ==
"vt" ) {
continue; }
49 if ( token ==
"vp" ) {
continue; }
55 std::getline( iss, ltoken,
' ' );
56 while ( std::getline( iss, ltoken,
' ' ) ) {
57 std::istringstream ss( ltoken );
63 addLogErrorEntry(
"MESH CONTAINS QUADS." );
68 indices.push_back( f );
71 if ( vertices.size() == 0 ) {
72 addLogErrorEntry(
"MESH IS EMPTY." );
76 data.setVertices( std::move( vertices ) );
77 data.setNormals( std::move( normals ) );
78 data.setIndices( std::move( indices ) );
82 bool OBJFileManager::exportData( std::ostream& file,
const Geometry::TriangleMesh& data ) {
83 std::string content =
"";
84 if ( data.vertices().size() == 0 ) {
85 addLogErrorEntry(
"MESH IS EMPTY." );
89 for (
const auto& v : data.vertices() ) {
90 content +=
"v " + std::to_string( v[0] ) +
" " + std::to_string( v[1] ) +
" " +
91 std::to_string( v[2] ) +
"\n";
94 for (
const auto& n : data.normals() ) {
95 content +=
"vn " + std::to_string( n[0] ) +
" " + std::to_string( n[1] ) +
" " +
96 std::to_string( n[2] ) +
"\n";
99 for (
const auto& f : data.getIndices() ) {
100 content +=
"f " + std::to_string( f[0] + 1 ) +
" " + std::to_string( f[1] + 1 ) +
" " +
101 std::to_string( f[2] + 1 ) +
"\n";
std::string fileExtension() const override
INTERFACE.
~OBJFileManager() override
DESTRUCTOR.