#pragma once #include #include #include #include "../Mesh.hh" namespace polymesh { void write_obj(std::string const& filename, Mesh const& mesh, vertex_attribute const& position, vertex_attribute const* tex_coord = nullptr, vertex_attribute const* normal = nullptr); void read_obj(std::string const& filename, Mesh& mesh, vertex_attribute& position); 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(Mesh const& 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 struct obj_reader { obj_reader(std::string const& filename, Mesh& mesh); obj_reader(std::istream& in, Mesh& mesh); // get properties of the obj // NOTE: these always return fresh copies of the attribute! public: vertex_attribute positions_vec4() const; vertex_attribute positions_vec3() const; halfedge_attribute tex_coords_vec3() const; halfedge_attribute tex_coords_vec2() const; halfedge_attribute normals_vec3() const; private: void parse(std::istream& in, Mesh& mesh); vertex_attribute positions; halfedge_attribute tex_coords; halfedge_attribute normals; }; }