mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-18 04:08:02 -06:00
Fighting the ASCII STL import.
Fix of 2.1.0-rc: Loading MMU STL's results in object placement off the plater (#2868)
It has been broken with 9abef2241d
when trying to fix "Error on importing stl" #2813
This commit is contained in:
parent
326eb5e343
commit
07798510fc
1 changed files with 18 additions and 11 deletions
|
@ -173,13 +173,20 @@ static bool stl_read(stl_file *stl, FILE *fp, int first_facet, bool first)
|
||||||
assert(res_vertex1 == 3);
|
assert(res_vertex1 == 3);
|
||||||
int res_vertex2 = fscanf(fp, " vertex %f %f %f", &facet.vertex[1](0), &facet.vertex[1](1), &facet.vertex[1](2));
|
int res_vertex2 = fscanf(fp, " vertex %f %f %f", &facet.vertex[1](0), &facet.vertex[1](1), &facet.vertex[1](2));
|
||||||
assert(res_vertex2 == 3);
|
assert(res_vertex2 == 3);
|
||||||
|
// Trailing whitespace is there to eat all whitespaces and empty lines up to the next non-whitespace.
|
||||||
int res_vertex3 = fscanf(fp, " vertex %f %f %f ", &facet.vertex[2](0), &facet.vertex[2](1), &facet.vertex[2](2));
|
int res_vertex3 = fscanf(fp, " vertex %f %f %f ", &facet.vertex[2](0), &facet.vertex[2](1), &facet.vertex[2](2));
|
||||||
assert(res_vertex3 == 3);
|
assert(res_vertex3 == 3);
|
||||||
int res_endloop = fscanf(fp, " endloop %*[^\n]\n");
|
// Some G-code generators tend to produce text after "endloop" and "endfacet". Just ignore it.
|
||||||
assert(res_endloop == 0);
|
char buf[2048];
|
||||||
// There is a leading and trailing white space around endfacet to eat up all leading and trailing white spaces including numerous tabs and new lines.
|
fgets(buf, 2047, fp);
|
||||||
int res_endfacet = fscanf(fp, " endfacet %*[^\n]\n");
|
bool endloop_ok = strncmp(buf, "endloop", 7) == 0 && (buf[7] == '\n' || buf[7] == ' ' || buf[7] == '\t');
|
||||||
if (res_normal != 3 || res_outer_loop != 0 || res_vertex1 != 3 || res_vertex2 != 3 || res_vertex3 != 3 || res_endloop != 0 || res_endfacet != 0) {
|
assert(endloop_ok);
|
||||||
|
// Skip the trailing whitespaces and empty lines.
|
||||||
|
fscanf(fp, " ");
|
||||||
|
fgets(buf, 2047, fp);
|
||||||
|
bool endfacet_ok = strncmp(buf, "endfacet", 8) == 0 && (buf[8] == '\n' || buf[8] == ' ' || buf[8] == '\t');
|
||||||
|
assert(endfacet_ok);
|
||||||
|
if (res_normal != 3 || res_outer_loop != 0 || res_vertex1 != 3 || res_vertex2 != 3 || res_vertex3 != 3 || ! endloop_ok || ! endfacet_ok) {
|
||||||
BOOST_LOG_TRIVIAL(error) << "Something is syntactically very wrong with this ASCII STL! ";
|
BOOST_LOG_TRIVIAL(error) << "Something is syntactically very wrong with this ASCII STL! ";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue