From 45d7055c4afabacbead35e924ebb07894ff8a833 Mon Sep 17 00:00:00 2001 From: Abe Pazos Date: Fri, 14 Jun 2019 00:02:22 +0200 Subject: [PATCH] Implement ofMesh .save() of triangle strips --- libs/openFrameworks/3d/ofMesh.inl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libs/openFrameworks/3d/ofMesh.inl b/libs/openFrameworks/3d/ofMesh.inl index a3a6179f978..7e206365acf 100644 --- a/libs/openFrameworks/3d/ofMesh.inl +++ b/libs/openFrameworks/3d/ofMesh.inl @@ -1310,6 +1310,9 @@ void ofMesh_::save(const std::filesystem::path& path, bool useBinary) c } else if(data.getMode() == OF_PRIMITIVE_TRIANGLES) { os << "element face " << data.getNumVertices() / faceSize << std::endl; os << "property list uchar int vertex_indices" << std::endl; + } else if(data.getMode() == OF_PRIMITIVE_TRIANGLE_STRIP && data.getNumVertices() >= 4) { + os << "element face " << data.getNumVertices() - 2 << std::endl; + os << "property list uchar int vertex_indices" << std::endl; } os << "end_header" << std::endl; @@ -1367,6 +1370,20 @@ void ofMesh_::save(const std::filesystem::path& path, bool useBinary) c os << (std::size_t) faceSize << " " << indices[0] << " " << indices[1] << " " << indices[2] << std::endl; } } + } else if(data.getMode() == OF_PRIMITIVE_TRIANGLE_STRIP && data.getNumVertices() >= 4) { + for(uint32_t i = 0; i < data.getNumVertices() - 2; i += 2) { + uint32_t indices1[] = {i, i + 1, i + 2}; + uint32_t indices2[] = {i + 1, i + 3, i + 2}; + if(useBinary) { + os.write((char*) &faceSize, sizeof(unsigned char)); + os.write((char*) indices1, sizeof(indices1)); + os.write((char*) &faceSize, sizeof(unsigned char)); + os.write((char*) indices2, sizeof(indices2)); + } else { + os << (std::size_t) faceSize << " " << indices1[0] << " " << indices1[1] << " " << indices1[2] << std::endl; + os << (std::size_t) faceSize << " " << indices2[0] << " " << indices2[1] << " " << indices2[2] << std::endl; + } + } } //TODO: add index generation for other OF_PRIMITIVE cases