diff options
-rw-r--r-- | csgops.cc | 12 | ||||
-rw-r--r-- | mainwin.cc | 42 | ||||
-rw-r--r-- | module.cc | 10 | ||||
-rw-r--r-- | openscad.h | 12 | ||||
-rw-r--r-- | parser.y | 4 | ||||
-rw-r--r-- | polyset.cc | 17 | ||||
-rw-r--r-- | render.cc | 16 | ||||
-rw-r--r-- | transform.cc | 12 |
8 files changed, 100 insertions, 25 deletions
@@ -44,7 +44,7 @@ public: #ifdef ENABLE_CGAL virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const; #endif - CSGTerm *render_csg_term(double m[16], QVector<CSGTerm*> *highlights) const; + CSGTerm *render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const; virtual QString dump(QString indent) const; }; @@ -91,11 +91,11 @@ CGAL_Nef_polyhedron CsgNode::render_cgal_nef_polyhedron() const #endif /* ENABLE_CGAL */ -CSGTerm *CsgNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights) const +CSGTerm *CsgNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const { CSGTerm *t1 = NULL; foreach (AbstractNode *v, children) { - CSGTerm *t2 = v->render_csg_term(m, highlights); + CSGTerm *t2 = v->render_csg_term(m, highlights, background); if (t2 && !t1) { t1 = t2; } else if (t2 && t1) { @@ -108,8 +108,12 @@ CSGTerm *CsgNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights) c } } } - if (modinst->tag_highlight && highlights) + if (t1 && modinst->tag_highlight && highlights) highlights->append(t1->link()); + if (t1 && modinst->tag_background && background) { + background->append(t1); + return NULL; + } return t1; } @@ -50,6 +50,7 @@ MainWindow::MainWindow(const char *filename) #endif highlights_chain = NULL; + background_chain = NULL; root_node = NULL; enableOpenCSG = false; @@ -248,6 +249,14 @@ void MainWindow::compile() delete highlights_chain; highlights_chain = NULL; } + foreach(CSGTerm *v, background_terms) { + v->unlink(); + } + background_terms.clear(); + if (background_chain) { + delete background_chain; + background_chain = NULL; + } root_node = NULL; enableOpenCSG = false; @@ -280,7 +289,7 @@ void MainWindow::compile() for (int i = 0; i < 16; i++) m[i] = i % 5 == 0 ? 1.0 : 0.0; - root_raw_term = root_node->render_csg_term(m, &highlight_terms); + root_raw_term = root_node->render_csg_term(m, &highlight_terms, &background_terms); if (!root_raw_term) goto fail; @@ -329,6 +338,24 @@ void MainWindow::compile() } } + if (background_terms.size() > 0) + { + PRINTF("Compiling background (%d CSG Trees)...", background_terms.size()); + QApplication::processEvents(); + + background_chain = new CSGChain(); + for (int i = 0; i < background_terms.size(); i++) { + while (1) { + CSGTerm *n = background_terms[i]->normalize(); + background_terms[i]->unlink(); + if (background_terms[i] == n) + break; + background_terms[i] = n; + } + background_chain->import(background_terms[i]); + } + } + if (1) { PRINT("Compilation finished."); QApplication::processEvents(); @@ -635,7 +662,7 @@ void MainWindow::actionDisplayCSGProducts() QTextEdit *e = new QTextEdit(NULL); e->setTabStopWidth(30); e->setWindowTitle("CSG Products Dump"); - e->setPlainText(QString("\nCSG before normalization:\n%1\n\n\nCSG after normalization:\n%2\n\n\nCSG rendering chain:\n%3\n\n\nHighlights CSG rendering chain:\n%4\n").arg(root_raw_term ? root_raw_term->dump() : "N/A", root_norm_term ? root_norm_term->dump() : "N/A", root_chain ? root_chain->dump() : "N/A", highlights_chain ? highlights_chain->dump() : "N/A")); + e->setPlainText(QString("\nCSG before normalization:\n%1\n\n\nCSG after normalization:\n%2\n\n\nCSG rendering chain:\n%3\n\n\nHighlights CSG rendering chain:\n%4\n\n\nBackground CSG rendering chain:\n%5\n").arg(root_raw_term ? root_raw_term->dump() : "N/A", root_norm_term ? root_norm_term->dump() : "N/A", root_chain ? root_chain->dump() : "N/A", highlights_chain ? highlights_chain->dump() : "N/A", background_chain ? background_chain->dump() : "N/A")); e->show(); e->resize(600, 400); current_win = NULL; @@ -773,7 +800,7 @@ public: } }; -static void renderCSGChainviaOpenCSG(CSGChain *chain, GLint *shaderinfo, bool highlight) +static void renderCSGChainviaOpenCSG(CSGChain *chain, GLint *shaderinfo, bool highlight, bool background) { std::vector<OpenCSG::Primitive*> primitives; int j = 0; @@ -790,6 +817,8 @@ static void renderCSGChainviaOpenCSG(CSGChain *chain, GLint *shaderinfo, bool hi for (; j < i; j++) { if (highlight) { chain->polysets[j]->render_surface(PolySet::COLOR_HIGHLIGHT, shaderinfo); + } else if (background) { + chain->polysets[j]->render_surface(PolySet::COLOR_BACKGROUND, shaderinfo); } else if (chain->types[j] == CSGTerm::DIFFERENCE) { chain->polysets[j]->render_surface(PolySet::COLOR_CUTOUT, shaderinfo); } else { @@ -833,10 +862,13 @@ static void renderGLviaOpenCSG(void *vp) GLint *shaderinfo = m->screen->shaderinfo; if (!shaderinfo[0]) shaderinfo = NULL; - renderCSGChainviaOpenCSG(m->root_chain, m->actViewModeShowEdges->isChecked() ? shaderinfo : NULL, false); + renderCSGChainviaOpenCSG(m->root_chain, m->actViewModeShowEdges->isChecked() ? shaderinfo : NULL, false, false); + if (m->background_chain) { + renderCSGChainviaOpenCSG(m->background_chain, shaderinfo, false, true); + } if (m->highlights_chain) { glDisable(GL_LIGHTING); - renderCSGChainviaOpenCSG(m->highlights_chain, shaderinfo, true); + renderCSGChainviaOpenCSG(m->highlights_chain, shaderinfo, true, false); } } } @@ -249,19 +249,23 @@ CGAL_Nef_polyhedron AbstractNode::render_cgal_nef_polyhedron() const #endif /* ENABLE_CGAL */ -CSGTerm *AbstractNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights) const +CSGTerm *AbstractNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const { CSGTerm *t1 = NULL; foreach(AbstractNode *v, children) { - CSGTerm *t2 = v->render_csg_term(m, highlights); + CSGTerm *t2 = v->render_csg_term(m, highlights, background); if (t2 && !t1) { t1 = t2; } else if (t2 && t1) { t1 = new CSGTerm(CSGTerm::UNION, t1, t2); } } - if (modinst->tag_highlight && highlights) + if (t1 && modinst->tag_highlight && highlights) highlights->append(t1->link()); + if (t1 && modinst->tag_background && background) { + background->append(t1); + return NULL; + } return t1; } @@ -334,9 +334,10 @@ public: bool tag_root; bool tag_highlight; + bool tag_background; const Context *ctx; - ModuleInstanciation() : tag_root(false), tag_highlight(false), ctx(NULL) { } + ModuleInstanciation() : tag_root(false), tag_highlight(false), tag_background(false), ctx(NULL) { } ~ModuleInstanciation(); QString dump(QString indent) const; @@ -481,7 +482,8 @@ public: COLOR_NONE, COLOR_MATERIAL, COLOR_CUTOUT, - COLOR_HIGHLIGHT + COLOR_HIGHLIGHT, + COLOR_BACKGROUND }; void render_surface(colormode_e colormode, GLint *shaderinfo = NULL) const; @@ -555,7 +557,7 @@ public: virtual QString cgal_nef_cache_id() const; virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const; #endif - virtual CSGTerm *render_csg_term(double m[16], QVector<CSGTerm*> *highlights) const; + virtual CSGTerm *render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const; virtual QString dump(QString indent) const; }; @@ -571,7 +573,7 @@ public: #ifdef ENABLE_CGAL virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const; #endif - virtual CSGTerm *render_csg_term(double m[16], QVector<CSGTerm*> *highlights) const; + virtual CSGTerm *render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const; }; extern int progress_report_count; @@ -646,6 +648,8 @@ public: QVector<CSGTerm*> highlight_terms; CSGChain *highlights_chain; + QVector<CSGTerm*> background_terms; + CSGChain *background_chain; AbstractNode *root_node; bool enableOpenCSG; @@ -179,6 +179,10 @@ single_module_instantciation: '#' single_module_instantciation { $$ = $2; $$->tag_highlight = true; + } | + '%' single_module_instantciation { + $$ = $2; + $$->tag_background = true; }; expr: @@ -123,6 +123,15 @@ void PolySet::render_surface(colormode_e colormode, GLint *shaderinfo) const } #endif /* ENABLE_OPENCSG */ } + if (colormode == COLOR_BACKGROUND) { + glColor3ub(180, 180, 180); +#ifdef ENABLE_OPENCSG + if (shaderinfo) { + glUniform4f(shaderinfo[1], 180 / 255.0, 180 / 255.0, 180 / 255.0, 0.5); + glUniform4f(shaderinfo[2], 150 / 255.0, 150 / 255.0, 150 / 255.0, 0.5); + } +#endif /* ENABLE_OPENCSG */ + } #ifdef ENABLE_OPENCSG if (shaderinfo) { glUniform1f(shaderinfo[7], shaderinfo[9]); @@ -168,6 +177,8 @@ void PolySet::render_edges(colormode_e colormode) const glColor3ub(171, 216, 86); if (colormode == COLOR_HIGHLIGHT) glColor3ub(255, 171, 86); + if (colormode == COLOR_BACKGROUND) + glColor3ub(150, 150, 150); for (int i = 0; i < polygons.size(); i++) { const Polygon *poly = &polygons[i]; glBegin(GL_LINE_STRIP); @@ -305,13 +316,17 @@ CGAL_Nef_polyhedron AbstractPolyNode::render_cgal_nef_polyhedron() const #endif /* ENABLE_CGAL */ -CSGTerm *AbstractPolyNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights) const +CSGTerm *AbstractPolyNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const { PolySet *ps = render_polyset(RENDER_OPENCSG); ps->setmatrix(m); CSGTerm *t = new CSGTerm(ps, QString("n%1").arg(idx)); if (modinst->tag_highlight && highlights) highlights->append(t->link()); + if (modinst->tag_background && background) { + background->append(t); + return NULL; + } return t; } @@ -40,7 +40,7 @@ public: #ifdef ENABLE_CGAL virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const; #endif - CSGTerm *render_csg_term(double m[16], QVector<CSGTerm*> *highlights) const; + CSGTerm *render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const; virtual QString dump(QString indent) const; }; @@ -110,7 +110,7 @@ static void report_func(const class AbstractNode*, void *vp, int mark) QApplication::processEvents(); } -CSGTerm *RenderNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights) const +CSGTerm *RenderNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const { CGAL_Nef_polyhedron N; @@ -177,17 +177,21 @@ CSGTerm *RenderNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights CSGTerm *term = new CSGTerm(ps, QString("n%1").arg(idx)); if (modinst->tag_highlight && highlights) highlights->append(term->link()); + if (modinst->tag_background && background) { + background->append(term); + return NULL; + } return term; } #else -CSGTerm *RenderNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights) const +CSGTerm *RenderNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const { CSGTerm *t1 = NULL; PRINT("WARNING: Found render() statement but compiled without CGAL support!"); foreach(AbstractNode * v, children) { - CSGTerm *t2 = v->render_csg_term(m, highlights); + CSGTerm *t2 = v->render_csg_term(m, highlights, background); if (t2 && !t1) { t1 = t2; } else if (t2 && t1) { @@ -196,6 +200,10 @@ CSGTerm *RenderNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights } if (modinst->tag_highlight && highlights) highlights->append(t1->link()); + if (t1 && modinst->tag_background && background) { + background->append(t1); + return NULL; + } return t1; } diff --git a/transform.cc b/transform.cc index c4f76f6..ac6017d 100644 --- a/transform.cc +++ b/transform.cc @@ -45,7 +45,7 @@ public: #ifdef ENABLE_CGAL virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const; #endif - virtual CSGTerm *render_csg_term(double m[16], QVector<CSGTerm*> *highlights) const; + virtual CSGTerm *render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const; virtual QString dump(QString indent) const; }; @@ -168,7 +168,7 @@ CGAL_Nef_polyhedron TransformNode::render_cgal_nef_polyhedron() const #endif /* ENABLE_CGAL */ -CSGTerm *TransformNode::render_csg_term(double c[16], QVector<CSGTerm*> *highlights) const +CSGTerm *TransformNode::render_csg_term(double c[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const { double x[16]; @@ -184,15 +184,19 @@ CSGTerm *TransformNode::render_csg_term(double c[16], QVector<CSGTerm*> *highlig CSGTerm *t1 = NULL; foreach(AbstractNode *v, children) { - CSGTerm *t2 = v->render_csg_term(x, highlights); + CSGTerm *t2 = v->render_csg_term(x, highlights, background); if (t2 && !t1) { t1 = t2; } else if (t2 && t1) { t1 = new CSGTerm(CSGTerm::UNION, t1, t2); } } - if (modinst->tag_highlight && highlights) + if (t1 && modinst->tag_highlight && highlights) highlights->append(t1->link()); + if (t1 && modinst->tag_background && background) { + background->append(t1); + return NULL; + } return t1; } |