Skip to content
Snippets Groups Projects

De/Serialization for wavefront object files

Merged Ludwig Jaeck requested to merge serialization into main
All threads resolved!
@@ -22,18 +22,15 @@ namespace {
std::ostream& serialize_as_wavefront(std::ostream& out, const ff::Polyhedron* polyhedron)
{
out << std::setprecision(10);
out << "o 1"
<< "\n";
out << "o 1 \n";
for (auto vertice : polyhedron->vertices())
out << "v"
<< " " << vertice.x() << " " << vertice.y() << " " << vertice.z() << "\n";
out << "v " << vertice.x() << " " << vertice.y() << " " << vertice.z() << "\n";
out << "usemtl Default\n";
for (auto& poly : polyhedron->topology().faces) {
if (poly.vertexIndices.size() == 0)
continue;
out << "f"
<< " ";
out << "f ";
for (size_t i = 0; i < poly.vertexIndices.size(); i++) {
out << poly.vertexIndices[i] + 1;
out << (i == poly.vertexIndices.size() - 1 ? "\n" : " ");
Loading