diff options
-rw-r--r-- | src/import.cc | 17 | ||||
-rw-r--r-- | testdata/scad/features/import_bin_solid.stl | bin | 0 -> 2384 bytes | |||
-rw-r--r-- | testdata/scad/templates/import_stl-tests-template.scad | 2 | ||||
-rw-r--r-- | tests/regression/cgalpngtest/import_stl-tests-expected.png | bin | 5758 -> 10193 bytes | |||
-rw-r--r-- | tests/regression/dumptest/import_stl-tests-expected.txt | 3 | ||||
-rw-r--r-- | tests/regression/opencsgtest/import_stl-tests-expected.png | bin | 6207 -> 10720 bytes | |||
-rw-r--r-- | tests/regression/throwntogethertest/import_stl-tests-expected.png | bin | 6207 -> 10720 bytes |
7 files changed, 20 insertions, 2 deletions
diff --git a/src/import.cc b/src/import.cc index 40d34fa..6a6d925 100644 --- a/src/import.cc +++ b/src/import.cc @@ -119,7 +119,8 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const if (this->type == TYPE_STL) { handle_dep((std::string)this->filename); - std::ifstream f(this->filename.c_str(), std::ios::in | std::ios::binary); + // Open file and position at the end + std::ifstream f(this->filename.c_str(), std::ios::in | std::ios::binary | std::ios::ate); if (!f.good()) { PRINTB("WARNING: Can't open import file '%s'.", this->filename); return p; @@ -132,9 +133,20 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const boost::regex ex_vertex("vertex"); boost::regex ex_vertices("\\s*vertex\\s+([^\\s]+)\\s+([^\\s]+)\\s+([^\\s]+)"); + bool binary = false; + int file_size = f.tellg(); + f.seekg(80); + if (!f.eof()) { + int facenum = 0; + // FIXME: Assumes little endian + f.read((char *)&facenum, sizeof(int)); + if (file_size == 80 + 4 + 50*facenum) binary = true; + } + f.seekg(0); + char data[5]; f.read(data, 5); - if (!f.eof() && !memcmp(data, "solid", 5)) { + if (!binary && !f.eof() && !memcmp(data, "solid", 5)) { int i = 0; double vdata[3][3]; std::string line; @@ -174,6 +186,7 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const else { f.ignore(80-5+4); + // FIXME: Assumes little endian while (1) { #ifdef _MSC_VER #pragma pack(push,1) diff --git a/testdata/scad/features/import_bin_solid.stl b/testdata/scad/features/import_bin_solid.stl Binary files differnew file mode 100644 index 0000000..c1886db --- /dev/null +++ b/testdata/scad/features/import_bin_solid.stl diff --git a/testdata/scad/templates/import_stl-tests-template.scad b/testdata/scad/templates/import_stl-tests-template.scad index 685b868..2cc886d 100644 --- a/testdata/scad/templates/import_stl-tests-template.scad +++ b/testdata/scad/templates/import_stl-tests-template.scad @@ -1,4 +1,6 @@ import_stl("import.stl"); translate([2,0,0]) import("import.stl"); translate([4,0,0]) import("import_bin.stl"); +// Test binary STLs which happen to start with the string "solid" +translate([0,4,0]) import("import_bin_solid.stl"); translate([0,2,0]) import("@CMAKE_SOURCE_DIR@/../testdata/scad/features/import.stl"); diff --git a/tests/regression/cgalpngtest/import_stl-tests-expected.png b/tests/regression/cgalpngtest/import_stl-tests-expected.png Binary files differindex de7638a..c6a4b2d 100644 --- a/tests/regression/cgalpngtest/import_stl-tests-expected.png +++ b/tests/regression/cgalpngtest/import_stl-tests-expected.png diff --git a/tests/regression/dumptest/import_stl-tests-expected.txt b/tests/regression/dumptest/import_stl-tests-expected.txt index 947f137..0d46a6f 100644 --- a/tests/regression/dumptest/import_stl-tests-expected.txt +++ b/tests/regression/dumptest/import_stl-tests-expected.txt @@ -5,6 +5,9 @@ multmatrix([[1, 0, 0, 4], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { import(file = "import_bin.stl", layer = "", origin = [0, 0], scale = 1, convexity = 1, $fn = 0, $fa = 12, $fs = 2); } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 4], [0, 0, 1, 0], [0, 0, 0, 1]]) { + import(file = "import_bin_solid.stl", layer = "", origin = [0, 0], scale = 1, convexity = 1, $fn = 0, $fa = 12, $fs = 2); + } multmatrix([[1, 0, 0, 0], [0, 1, 0, 2], [0, 0, 1, 0], [0, 0, 0, 1]]) { import(file = "import.stl", layer = "", origin = [0, 0], scale = 1, convexity = 1, $fn = 0, $fa = 12, $fs = 2); } diff --git a/tests/regression/opencsgtest/import_stl-tests-expected.png b/tests/regression/opencsgtest/import_stl-tests-expected.png Binary files differindex 0bd9ab6..583f3f6 100644 --- a/tests/regression/opencsgtest/import_stl-tests-expected.png +++ b/tests/regression/opencsgtest/import_stl-tests-expected.png diff --git a/tests/regression/throwntogethertest/import_stl-tests-expected.png b/tests/regression/throwntogethertest/import_stl-tests-expected.png Binary files differindex 0bd9ab6..583f3f6 100644 --- a/tests/regression/throwntogethertest/import_stl-tests-expected.png +++ b/tests/regression/throwntogethertest/import_stl-tests-expected.png |