#pragma once #include #include #include "../Mesh.hh" namespace polymesh { template void write_obj(std::string const& filename, vertex_attribute> const& position); template bool read_obj(std::string const& filename, Mesh& mesh, vertex_attribute>& position); template struct obj_writer { obj_writer(std::string const& filename); obj_writer(std::ostream& out); ~obj_writer(); void write_object_name(std::string object_name); void write_mesh(vertex_attribute> const& position, halfedge_attribute> const* tex_coord = nullptr, halfedge_attribute> const* normal = nullptr); void write_mesh(vertex_attribute> const& position, vertex_attribute> const* tex_coord = nullptr, vertex_attribute> const* normal = nullptr); // TODO: tex coords and normals as half-edge attributes private: std::ostream* tmp_out = nullptr; std::ostream* out = nullptr; int vertex_idx = 1; int texture_idx = 1; int normal_idx = 1; }; // clears the given mesh before adding data // obj must be manifold // no negative indices template struct obj_reader { obj_reader(std::string const& filename, Mesh& mesh); obj_reader(std::istream& in, Mesh& mesh); // get properties of the obj public: vertex_attribute> const& get_positions() const { return positions; } halfedge_attribute> const& get_tex_coords() const { return tex_coords; } halfedge_attribute> const& get_normals() const { return normals; } /// Number of faces that could not be added int error_faces() const { return n_error_faces; } private: void parse(std::istream& in, Mesh& mesh); vertex_attribute> positions; halfedge_attribute> tex_coords; halfedge_attribute> normals; int n_error_faces = 0; }; } // namespace polymesh