From 074efb6a1dfe526bdce876545a74420ac48c44c7 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Fri, 2 Sep 2011 01:29:51 +0200 Subject: More correct warning diff --git a/src/cgaladv_minkowski2.cc b/src/cgaladv_minkowski2.cc index b722708..2020ab9 100644 --- a/src/cgaladv_minkowski2.cc +++ b/src/cgaladv_minkowski2.cc @@ -92,7 +92,7 @@ CGAL_Poly2 nef2p2(CGAL_Nef_polyhedron2 p) } //if (fit != E.faces_begin()) { if (points.size() != 0) { - PRINT("WARNING: minkowski() is not implemented for 2d objects with holes!"); + PRINT("WARNING: minkowski() and hull() is not implemented for 2d objects with holes!"); break; } -- cgit v0.10.1 From d6df99ea58d90800938b447f79bf4afd44e40942 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Fri, 2 Sep 2011 23:30:42 +0200 Subject: Don't overwrite alpha specified by a 4-component c argument diff --git a/src/transform.cc b/src/transform.cc index 7b15a7e..d774a8c 100644 --- a/src/transform.cc +++ b/src/transform.cc @@ -243,8 +243,6 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti Value alpha = c.lookup_variable("alpha"); if (alpha.type == Value::NUMBER) { node->m[16+3] = alpha.num; - } else { - node->m[16+3] = 1.0; } } -- cgit v0.10.1 From 475cfd17817f9e2fa28e0061462f2818b739a592 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Fri, 2 Sep 2011 23:34:29 +0200 Subject: Added new color() options diff --git a/RELEASE_NOTES b/RELEASE_NOTES index a95d588..880ba91 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -1,6 +1,9 @@ OpenSCAD 20xx.yy ================ +o The color() statement now supports an alpha parameter, e.g. color(c=[1,0,0], alpha=0.4) +o The color() statement now supports specifying colors as strings, e.g. color("Red") + Bugfixes: o square() crashed if any of the dimensions were zero o Flush Caches didn't flush cached USE'd modules -- cgit v0.10.1 From aa3ac2d3000b0fbf5ec5e8d0ecaaaedf44678dc2 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sat, 3 Sep 2011 01:52:39 +0200 Subject: Disable setting alpha without color diff --git a/src/OpenCSGRenderer.cc b/src/OpenCSGRenderer.cc index afb3e98..69013e9 100644 --- a/src/OpenCSGRenderer.cc +++ b/src/OpenCSGRenderer.cc @@ -97,7 +97,7 @@ void OpenCSGRenderer::renderCSGChain(CSGChain *chain, GLint *shaderinfo, chain->polysets[j]->render_surface(PolySet::COLORMODE_HIGHLIGHT, PolySet::csgmode_e(csgmode + 20), m, shaderinfo); } else if (background) { chain->polysets[j]->render_surface(PolySet::COLORMODE_BACKGROUND, PolySet::csgmode_e(csgmode + 10), m, shaderinfo); - } else if (m[16] >= 0 || m[17] >= 0 || m[18] >= 0 || m[19] >= 0) { + } else if (m[16] >= 0 || m[17] >= 0 || m[18] >= 0) { // User-defined color from source glColor4d(m[16], m[17], m[18], m[19]); if (shaderinfo) { diff --git a/src/ThrownTogetherRenderer.cc b/src/ThrownTogetherRenderer.cc index 0a0c9c8..6e0325e 100644 --- a/src/ThrownTogetherRenderer.cc +++ b/src/ThrownTogetherRenderer.cc @@ -91,7 +91,7 @@ void ThrownTogetherRenderer::renderCSGChain(CSGChain *chain, bool highlight, } else { chain->polysets[i]->render_surface(PolySet::COLORMODE_NONE, PolySet::csgmode_e(csgmode), m); } - } else if (m[16] >= 0 || m[17] >= 0 || m[18] >= 0 || m[19] >= 0) { + } else if (m[16] >= 0 || m[17] >= 0 || m[18] >= 0) { glColor4d(m[16], m[17], m[18], m[19]); chain->polysets[i]->render_surface(PolySet::COLORMODE_NONE, PolySet::csgmode_e(csgmode), m); if (showedges) { diff --git a/src/transform.cc b/src/transform.cc index d774a8c..9df9ade 100644 --- a/src/transform.cc +++ b/src/transform.cc @@ -69,8 +69,9 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti for (int i = 0; i < 16; i++) node->m[i] = i % 5 == 0 ? 1.0 : 0.0; - for (int i = 16; i < 20; i++) + for (int i = 16; i < 19; i++) node->m[i] = -1; + node->m[19] = 1; QVector argnames; QVector argexpr; @@ -367,7 +368,7 @@ QString TransformNode::dump(QString indent) const { if (dump_cache.isEmpty()) { QString text; - if (m[16] >= 0 || m[17] >= 0 || m[18] >= 0 || m[19] >= 0) + if (m[16] >= 0 || m[17] >= 0 || m[18] >= 0) text.sprintf("n%d: color([%g, %g, %g, %g])", idx, m[16], m[17], m[18], m[19]); else -- cgit v0.10.1 From f0bd1eed9746e0349700c969292c9eeca58c5635 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 6 Sep 2011 15:47:21 +0200 Subject: Fixes crash bug reported by Brad Pitcher diff --git a/src/polyset.cc b/src/polyset.cc index e34aeb3..9601fef 100644 --- a/src/polyset.cc +++ b/src/polyset.cc @@ -518,7 +518,13 @@ CGAL_Nef_polyhedron PolySet::render_cgal_nef_polyhedron() const double x = ps->polygons[i][j].x; double y = ps->polygons[i][j].y; if (this->grid.has(x, y)) { - this->polygons[this->poly_n].append(this->grid.data(x, y)); + int idx = this->grid.data(x, y); + // Filter away two vertices with the same index (due to grid) + // This could be done in a more general way, but we'd rather redo the entire + // grid concept instead. + if (this->polygons[this->poly_n].indexOf(idx) == -1) { + this->polygons[this->poly_n].append(this->grid.data(x, y)); + } } else { this->grid.align(x, y) = point_n; this->polygons[this->poly_n].append(point_n); @@ -526,8 +532,13 @@ CGAL_Nef_polyhedron PolySet::render_cgal_nef_polyhedron() const point_n++; } } - add_edges(this->poly_n); - this->poly_n++; + if (this->polygons[this->poly_n].size() >= 3) { + add_edges(this->poly_n); + this->poly_n++; + } + else { + this->polygons.remove(this->poly_n); + } } } -- cgit v0.10.1 From 7477292658356cceace081ada960bfc108685ee9 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Thu, 8 Sep 2011 00:07:29 +0200 Subject: typo diff --git a/src/cgaladv.cc b/src/cgaladv.cc index dd797fd..d754c1b 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -169,7 +169,7 @@ CGAL_Nef_polyhedron CgaladvNode::render_cgal_nef_polyhedron() const if (type == GLIDE) { - PRINT("WARNING: subdiv() is not implemented yet!"); + PRINT("WARNING: glide() is not implemented yet!"); } if (type == SUBDIV) -- cgit v0.10.1 From 45c2965034da40f5c4d47620454175cb9f8205d4 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Thu, 8 Sep 2011 00:08:07 +0200 Subject: Export STL as doubles, as an experiment. Seems to fix some issues with importing diff --git a/src/export.cc b/src/export.cc index 8e0ab16..c207f2b 100644 --- a/src/export.cc +++ b/src/export.cc @@ -31,6 +31,7 @@ #include #include #include +#include #ifdef ENABLE_CGAL #include "cgal.h" @@ -86,14 +87,15 @@ void export_stl(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog * setlocale(LC_NUMERIC, "C"); // Ensure radix is . (not ,) in output - FILE *f = fopen(filename.toUtf8().data(), "w"); - if (!f) { + std::ofstream output(filename.toUtf8()); + if (!output.is_open()) { PRINTA("Can't open STL file \"%1\" for STL export: %2", filename, QString(strerror(errno))); set_output_handler(NULL, NULL); return; } - fprintf(f, "solid OpenSCAD_Model\n"); + + output << "solid OpenSCAD_Model\n"; int facet_count = 0; for (FCI fi = P.facets_begin(); fi != P.facets_end(); ++fi) { @@ -114,10 +116,15 @@ void export_stl(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog * double x3 = CGAL::to_double(v3.point().x()); double y3 = CGAL::to_double(v3.point().y()); double z3 = CGAL::to_double(v3.point().z()); - QString vs1, vs2, vs3; - vs1.sprintf("%f %f %f", x1, y1, z1); - vs2.sprintf("%f %f %f", x2, y2, z2); - vs3.sprintf("%f %f %f", x3, y3, z3); + std::stringstream stream; + stream << x1 << " " << y1 << " " << z1; + std::string vs1 = stream.str(); + stream.str(""); + stream << x2 << " " << y2 << " " << z2; + std::string vs2 = stream.str(); + stream.str(""); + stream << x3 << " " << y3 << " " << z3; + std::string vs3 = stream.str(); if (vs1 != vs2 && vs1 != vs3 && vs2 != vs3) { double nx = (y1-y2)*(z1-z3) - (z1-z2)*(y1-y3); @@ -127,14 +134,16 @@ void export_stl(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog * // Avoid generating normals for polygons with zero area double eps = 0.000001; if (nlength < eps) nlength = 1.0; - fprintf(f, " facet normal %f %f %f\n", - nx / nlength, ny / nlength, nz / nlength); - fprintf(f, " outer loop\n"); - fprintf(f, " vertex %s\n", vs1.toAscii().data()); - fprintf(f, " vertex %s\n", vs2.toAscii().data()); - fprintf(f, " vertex %s\n", vs3.toAscii().data()); - fprintf(f, " endloop\n"); - fprintf(f, " endfacet\n"); + output << " facet normal " + << nx / nlength << " " + << ny / nlength << " " + << nz / nlength << "\n"; + output << " outer loop\n"; + output << " vertex " << vs1 << "\n"; + output << " vertex " << vs2 << "\n"; + output << " vertex " << vs3 << "\n"; + output << " endloop\n"; + output << " endfacet\n"; } } while (hc != hc_end); if (pd) { @@ -143,8 +152,8 @@ void export_stl(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog * } } - fprintf(f, "endsolid OpenSCAD_Model\n"); - fclose(f); + output << "endsolid OpenSCAD_Model\n"; + output.close(); setlocale(LC_NUMERIC, ""); // Set default locale } -- cgit v0.10.1 From 4b95dd74138129f49c6ea7d26fbe241bc3981437 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Thu, 8 Sep 2011 03:23:12 +0200 Subject: bugfix: empty renderer wasn't initialized. caused a crash diff --git a/src/cgalrenderer.cc b/src/cgalrenderer.cc index ef44b6a..8a9ac21 100644 --- a/src/cgalrenderer.cc +++ b/src/cgalrenderer.cc @@ -57,6 +57,10 @@ CGALRenderer::CGALRenderer(const CGAL_Nef_polyhedron &root) : root(root) CGAL::OGL::Nef3_Converter::convert_to_OGLPolyhedron(this->root.p3, this->polyhedron); this->polyhedron->init(); } + else { + this->polyhedron = NULL; + this->polyset = NULL; + } } CGALRenderer::~CGALRenderer() -- cgit v0.10.1 From 072d7170e62fea76f54cca66d2f6667c4374b1a0 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Thu, 8 Sep 2011 03:23:42 +0200 Subject: Catch a non-simple polyhedron before export as this crashes CGAL diff --git a/src/openscad.cc b/src/openscad.cc index bf22246..180dbdf 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -318,6 +318,11 @@ int main(int argc, char **argv) fclose(fp); } + if (root_N->dim == 3 && !root_N->p3.is_simple()) { + fprintf(stderr, "Object isn't a valid 2-manifold! Modify your design.\n"); + exit(1); + } + if (stl_output_file) export_stl(root_N, stl_output_file, NULL); -- cgit v0.10.1