mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-25 07:34:03 -06:00
Fixed import of multi-material AMF files, broken due to admesh eradication.
This commit is contained in:
parent
bac7d2b961
commit
afbbb36fa4
2 changed files with 28 additions and 13 deletions
|
@ -1922,7 +1922,7 @@ namespace Slic3r {
|
||||||
{
|
{
|
||||||
int min_id = its.indices.front()[0];
|
int min_id = its.indices.front()[0];
|
||||||
int max_id = min_id;
|
int max_id = min_id;
|
||||||
for (const Vec3i& face : its.indices) {
|
for (const Vec3i face : its.indices) {
|
||||||
for (const int tri_id : face) {
|
for (const int tri_id : face) {
|
||||||
if (tri_id < 0 || tri_id >= int(geometry.vertices.size())) {
|
if (tri_id < 0 || tri_id >= int(geometry.vertices.size())) {
|
||||||
add_error("Found invalid vertex id");
|
add_error("Found invalid vertex id");
|
||||||
|
|
|
@ -617,19 +617,35 @@ void AMFParserContext::endElement(const char * /* name */)
|
||||||
case NODE_TYPE_VOLUME:
|
case NODE_TYPE_VOLUME:
|
||||||
{
|
{
|
||||||
assert(m_object && m_volume);
|
assert(m_object && m_volume);
|
||||||
// Verify validity of face indices.
|
if (m_volume_facets.empty()) {
|
||||||
for (Vec3i face : m_volume_facets)
|
this->stop("An empty triangle mesh found");
|
||||||
for (unsigned int tri_id : face)
|
return;
|
||||||
if (tri_id < 0 || tri_id >= m_object_vertices.size()) {
|
}
|
||||||
this->stop("Malformed triangle mesh");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
TriangleMesh triangle_mesh { std::move(m_object_vertices), std::move(m_volume_facets) };
|
// Verify validity of face indices, find the vertex span.
|
||||||
if (triangle_mesh.volume() < 0)
|
int min_id = m_volume_facets.front()[0];
|
||||||
triangle_mesh.flip_triangles();
|
int max_id = min_id;
|
||||||
m_volume->set_mesh(std::move(triangle_mesh));
|
for (const Vec3i face : m_volume_facets) {
|
||||||
|
for (const int tri_id : face) {
|
||||||
|
if (tri_id < 0 || tri_id >= int(m_object_vertices.size())) {
|
||||||
|
this->stop("Malformed triangle mesh");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
min_id = std::min(min_id, tri_id);
|
||||||
|
max_id = std::max(max_id, tri_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// rebase indices to the current vertices list
|
||||||
|
for (Vec3i &face : m_volume_facets)
|
||||||
|
face -= Vec3i(min_id, min_id, min_id);
|
||||||
|
|
||||||
|
indexed_triangle_set its { std::move(m_volume_facets), { m_object_vertices.begin() + min_id, m_object_vertices.begin() + max_id + 1 } };
|
||||||
|
its_compactify_vertices(its);
|
||||||
|
if (its_volume(its) < 0)
|
||||||
|
its_flip_triangles(its);
|
||||||
|
m_volume->set_mesh(std::move(its));
|
||||||
}
|
}
|
||||||
|
|
||||||
// stores the volume matrix taken from the metadata, if present
|
// stores the volume matrix taken from the metadata, if present
|
||||||
|
@ -646,7 +662,6 @@ void AMFParserContext::endElement(const char * /* name */)
|
||||||
|
|
||||||
m_volume->calculate_convex_hull();
|
m_volume->calculate_convex_hull();
|
||||||
m_volume_facets.clear();
|
m_volume_facets.clear();
|
||||||
m_object_vertices.clear();
|
|
||||||
m_volume = nullptr;
|
m_volume = nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue