From 1115e77b38ae974f67252524fc401282bec1209f Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Mon, 23 Sep 2019 13:54:49 +0200 Subject: [PATCH] ENABLE_ENHANCED_RELOAD_FROM_DISK -> Fixed export/import to/from .amf to keep compatibility with 3rd part software. --- src/libslic3r/Format/AMF.cpp | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/libslic3r/Format/AMF.cpp b/src/libslic3r/Format/AMF.cpp index 3f85b4b603..490a479d69 100644 --- a/src/libslic3r/Format/AMF.cpp +++ b/src/libslic3r/Format/AMF.cpp @@ -568,10 +568,30 @@ void AMFParserContext::endElement(const char * /* name */) stl.stats.number_of_facets = int(m_volume_facets.size() / 3); stl.stats.original_num_facets = stl.stats.number_of_facets; stl_allocate(&stl); + +#if ENABLE_ENHANCED_RELOAD_FROM_DISK + Slic3r::Geometry::Transformation transform; + if (m_version > 2) + transform = m_volume->get_transformation(); + + Transform3d inv_matrix = transform.get_matrix().inverse(); +#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK + for (size_t i = 0; i < m_volume_facets.size();) { stl_facet &facet = stl.facet_start[i/3]; - for (unsigned int v = 0; v < 3; ++ v) + for (unsigned int v = 0; v < 3; ++v) +#if ENABLE_ENHANCED_RELOAD_FROM_DISK + { + unsigned int tri_id = m_volume_facets[i++] * 3; + Vec3f vertex(m_object_vertices[tri_id + 0], m_object_vertices[tri_id + 1], m_object_vertices[tri_id + 2]); + if (m_version > 2) + // revert the vertices to the original mesh reference system + vertex = (inv_matrix * vertex.cast()).cast(); + ::memcpy((void*)facet.vertex[v].data(), (const void*)vertex.data(), 3 * sizeof(float)); + } +#else memcpy(facet.vertex[v].data(), &m_object_vertices[m_volume_facets[i ++] * 3], 3 * sizeof(float)); +#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK } stl_get_size(&stl); mesh.repair(); @@ -1067,18 +1087,6 @@ bool store_amf(const char *path, Model *model, const DynamicPrintConfig *config) if (! volume->mesh().has_shared_vertices()) throw std::runtime_error("store_amf() requires shared vertices"); const indexed_triangle_set &its = volume->mesh().its; -#if ENABLE_ENHANCED_RELOAD_FROM_DISK - for (const Vec3f& v : its.vertices) - { - stream << " \n"; - stream << " \n"; - stream << " " << v(0) << "\n"; - stream << " " << v(1) << "\n"; - stream << " " << v(2) << "\n"; - stream << " \n"; - stream << " \n"; - } -#else const Transform3d& matrix = volume->get_matrix(); for (size_t i = 0; i < its.vertices.size(); ++i) { stream << " \n"; @@ -1090,7 +1098,6 @@ bool store_amf(const char *path, Model *model, const DynamicPrintConfig *config) stream << " \n"; stream << " \n"; } -#endif // ENABLE_ENHANCED_RELOAD_FROM_DISK num_vertices += (int)its.vertices.size(); } stream << " \n";