18 bool OBJWriter::write(
const std::string &path,
const Eigen::MatrixXd &v,
const Eigen::MatrixXi &e,
const Eigen::MatrixXi &f)
20 const Eigen::IOFormat OBJ_VERTEX_FORMAT(
26 v.cols() == 2 ?
" 0\n" :
"\n",
30 std::ofstream obj(path, std::ios::out);
35 "# Vertices: {:d}\n# Edges: {:d}\n# Faces: {:d}\n",
36 v.rows(), e.rows(), f.rows());
38 for (
int i = 0; i < v.rows(); ++i)
39 obj << v.row(i).format(OBJ_VERTEX_FORMAT);
41 for (
int i = 0; i < e.rows(); ++i)
42 obj << fmt::format(
"l {} {}\n", e(i, 0) + 1, e(i, 1) + 1);
44 for (
int i = 0; i < f.rows(); ++i)
45 obj << fmt::format(
"f {} {} {}\n", f(i, 0) + 1, f(i, 1) + 1, f(i, 2) + 1);