summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--csgops.cc4
-rw-r--r--csgterm.cc4
-rw-r--r--examples/example017.scad6
-rw-r--r--mainwin.cc26
-rw-r--r--module.cc6
-rw-r--r--openscad.h12
-rw-r--r--polyset.cc4
-rw-r--r--render.cc6
-rw-r--r--transform.cc46
9 files changed, 77 insertions, 37 deletions
diff --git a/csgops.cc b/csgops.cc
index 5e55ed1..be29ede 100644
--- a/csgops.cc
+++ b/csgops.cc
@@ -45,7 +45,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, QVector<CSGTerm*> *background) const;
+ CSGTerm *render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const;
virtual QString dump(QString indent) const;
};
@@ -110,7 +110,7 @@ CGAL_Nef_polyhedron CsgNode::render_cgal_nef_polyhedron() const
#endif /* ENABLE_CGAL */
-CSGTerm *CsgNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
+CSGTerm *CsgNode::render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
{
CSGTerm *t1 = NULL;
foreach (AbstractNode *v, children) {
diff --git a/csgterm.cc b/csgterm.cc
index d542ea4..ebad060 100644
--- a/csgterm.cc
+++ b/csgterm.cc
@@ -22,14 +22,14 @@
#include "openscad.h"
-CSGTerm::CSGTerm(PolySet *polyset, double m[16], QString label)
+CSGTerm::CSGTerm(PolySet *polyset, double m[20], QString label)
{
this->type = TYPE_PRIMITIVE;
this->polyset = polyset;
this->label = label;
this->left = NULL;
this->right = NULL;
- for (int i = 0; i < 16; i++)
+ for (int i = 0; i < 20; i++)
this->m[i] = m[i];
refcounter = 1;
}
diff --git a/examples/example017.scad b/examples/example017.scad
index d6c9173..2b624e2 100644
--- a/examples/example017.scad
+++ b/examples/example017.scad
@@ -99,10 +99,9 @@ module exploded()
translate([ 0, 0, total_height + thickness ]) linear_extrude(height = thickness, convexity = 4) shape_inner_disc();
linear_extrude(height = thickness, convexity = 4) shape_outer_disc();
- for (alpha = [ 0, 120, 240 ])
+ color([ 0.7, 0.7, 1 ]) for (alpha = [ 0, 120, 240 ])
rotate(alpha) translate([ 0, thickness*2 + locklen1 + inner1_to_inner2 + boltlen + midhole, 1.5*thickness ])
rotate([ 90, 0, -90 ]) linear_extrude(height = thickness, convexity = 10, center = true) shape_tripod();
-
}
module assembled()
@@ -110,10 +109,9 @@ module assembled()
translate([ 0, 0, total_height - thickness*2 ]) linear_extrude(height = thickness, convexity = 4) shape_inner_disc();
linear_extrude(height = thickness, convexity = 4) shape_outer_disc();
- for (alpha = [ 0, 120, 240 ])
+ color([ 0.7, 0.7, 1 ]) for (alpha = [ 0, 120, 240 ])
rotate(alpha) translate([ 0, thickness*2 + locklen1 + inner1_to_inner2 + boltlen + midhole, 0 ])
rotate([ 90, 0, -90 ]) linear_extrude(height = thickness, convexity = 10, center = true) shape_tripod();
-
}
parts();
diff --git a/mainwin.cc b/mainwin.cc
index 1eacf1c..dff93cb 100644
--- a/mainwin.cc
+++ b/mainwin.cc
@@ -535,10 +535,12 @@ void MainWindow::compile(bool procevents)
if (procevents)
QApplication::processEvents();
- double m[16];
+ double m[20];
for (int i = 0; i < 16; i++)
m[i] = i % 5 == 0 ? 1.0 : 0.0;
+ for (int i = 16; i < 20; i++)
+ m[i] = -1;
root_raw_term = root_node->render_csg_term(m, &highlight_terms, &background_terms);
@@ -1171,13 +1173,21 @@ static void renderCSGChainviaOpenCSG(CSGChain *chain, GLint *shaderinfo, bool hi
if (shaderinfo)
glUseProgram(shaderinfo[0]);
for (; j < i; j++) {
+ double *m = chain->matrices[j];
glPushMatrix();
- glMultMatrixd(chain->matrices[j]);
+ glMultMatrixd(m);
int csgmode = chain->types[j] == CSGTerm::TYPE_DIFFERENCE ? PolySet::CSGMODE_DIFFERENCE : PolySet::CSGMODE_NORMAL;
if (highlight) {
chain->polysets[j]->render_surface(PolySet::COLORMODE_HIGHLIGHT, PolySet::csgmode_e(csgmode + 20), shaderinfo);
} else if (background) {
chain->polysets[j]->render_surface(PolySet::COLORMODE_BACKGROUND, PolySet::csgmode_e(csgmode + 10), shaderinfo);
+ } else if (m[16] >= 0 || m[17] >= 0 || m[18] >= 0 || m[19] >= 0) {
+ glColor4d(m[16], m[17], m[18], m[19]);
+ if (shaderinfo) {
+ glUniform4f(shaderinfo[1], m[16], m[17], m[18], m[19]);
+ glUniform4f(shaderinfo[2], (m[16]+1)/2, (m[17]+1)/2, (m[18]+1)/2, 1.0);
+ }
+ chain->polysets[j]->render_surface(PolySet::COLORMODE_NONE, PolySet::csgmode_e(csgmode), shaderinfo);
} else if (chain->types[j] == CSGTerm::TYPE_DIFFERENCE) {
chain->polysets[j]->render_surface(PolySet::COLORMODE_CUTOUT, PolySet::csgmode_e(csgmode), shaderinfo);
} else {
@@ -1390,8 +1400,9 @@ static void renderGLThrownTogetherChain(MainWindow *m, CSGChain *chain, bool hig
for (int i = 0; i < chain->polysets.size(); i++) {
if (polySetVisitMark[QPair<PolySet*,double*>(chain->polysets[i], chain->matrices[i])]++ > 0)
continue;
+ double *m = chain->matrices[i];
glPushMatrix();
- glMultMatrixd(chain->matrices[i]);
+ glMultMatrixd(m);
int csgmode = chain->types[i] == CSGTerm::TYPE_DIFFERENCE ? PolySet::CSGMODE_DIFFERENCE : PolySet::CSGMODE_NORMAL;
if (highlight) {
chain->polysets[i]->render_surface(PolySet::COLORMODE_HIGHLIGHT, PolySet::csgmode_e(csgmode + 20));
@@ -1415,6 +1426,15 @@ static void renderGLThrownTogetherChain(MainWindow *m, CSGChain *chain, bool hig
} else {
chain->polysets[i]->render_surface(PolySet::COLORMODE_NONE, PolySet::csgmode_e(csgmode));
}
+ } else if (m[16] >= 0 || m[17] >= 0 || m[18] >= 0 || m[19] >= 0) {
+ glColor4d(m[16], m[17], m[18], m[19]);
+ chain->polysets[i]->render_surface(PolySet::COLORMODE_NONE, PolySet::csgmode_e(csgmode));
+ if (showEdges) {
+ glDisable(GL_LIGHTING);
+ glColor4d((m[16]+1)/2, (m[17]+1)/2, (m[18]+1)/2, 1.0);
+ chain->polysets[i]->render_edges(PolySet::COLORMODE_NONE, PolySet::csgmode_e(csgmode));
+ glEnable(GL_LIGHTING);
+ }
} else if (chain->types[i] == CSGTerm::TYPE_DIFFERENCE) {
chain->polysets[i]->render_surface(PolySet::COLORMODE_CUTOUT, PolySet::csgmode_e(csgmode));
if (showEdges) {
diff --git a/module.cc b/module.cc
index b02ce78..e58cdd1 100644
--- a/module.cc
+++ b/module.cc
@@ -288,7 +288,7 @@ CGAL_Nef_polyhedron AbstractIntersectionNode::render_cgal_nef_polyhedron() const
#endif /* ENABLE_CGAL */
-static CSGTerm *render_csg_term_backend(const AbstractNode *that, bool intersect, double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background)
+static CSGTerm *render_csg_term_backend(const AbstractNode *that, bool intersect, double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background)
{
CSGTerm *t1 = NULL;
foreach(AbstractNode *v, that->children) {
@@ -311,12 +311,12 @@ static CSGTerm *render_csg_term_backend(const AbstractNode *that, bool intersect
return t1;
}
-CSGTerm *AbstractNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
+CSGTerm *AbstractNode::render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
{
return render_csg_term_backend(this, false, m, highlights, background);
}
-CSGTerm *AbstractIntersectionNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
+CSGTerm *AbstractIntersectionNode::render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
{
return render_csg_term_backend(this, true, m, highlights, background);
}
diff --git a/openscad.h b/openscad.h
index 680d366..69fb326 100644
--- a/openscad.h
+++ b/openscad.h
@@ -595,10 +595,10 @@ public:
QString label;
CSGTerm *left;
CSGTerm *right;
- double m[16];
+ double m[20];
int refcounter;
- CSGTerm(PolySet *polyset, double m[16], QString label);
+ CSGTerm(PolySet *polyset, double m[20], QString label);
CSGTerm(type_e type, CSGTerm *left, CSGTerm *right);
CSGTerm *normalize();
@@ -650,7 +650,7 @@ public:
static QCache<QString, cgal_nef_cache_entry> cgal_nef_cache;
virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const;
#endif
- virtual CSGTerm *render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const;
+ virtual CSGTerm *render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const;
virtual QString dump(QString indent) const;
};
@@ -661,7 +661,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, QVector<CSGTerm*> *background) const;
+ virtual CSGTerm *render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const;
virtual QString dump(QString indent) const;
};
@@ -677,8 +677,8 @@ 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, QVector<CSGTerm*> *background) const;
- static CSGTerm *render_csg_term_from_ps(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background, PolySet *ps, const ModuleInstantiation *modinst, int idx);
+ virtual CSGTerm *render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const;
+ static CSGTerm *render_csg_term_from_ps(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background, PolySet *ps, const ModuleInstantiation *modinst, int idx);
};
extern int progress_report_count;
diff --git a/polyset.cc b/polyset.cc
index ab8e404..a4275fa 100644
--- a/polyset.cc
+++ b/polyset.cc
@@ -448,13 +448,13 @@ CGAL_Nef_polyhedron AbstractPolyNode::render_cgal_nef_polyhedron() const
#endif /* ENABLE_CGAL */
-CSGTerm *AbstractPolyNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
+CSGTerm *AbstractPolyNode::render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
{
PolySet *ps = render_polyset(RENDER_OPENCSG);
return render_csg_term_from_ps(m, highlights, background, ps, modinst, idx);
}
-CSGTerm *AbstractPolyNode::render_csg_term_from_ps(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background, PolySet *ps, const ModuleInstantiation *modinst, int idx)
+CSGTerm *AbstractPolyNode::render_csg_term_from_ps(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background, PolySet *ps, const ModuleInstantiation *modinst, int idx)
{
CSGTerm *t = new CSGTerm(ps, m, QString("n%1").arg(idx));
if (modinst->tag_highlight && highlights)
diff --git a/render.cc b/render.cc
index 1fe2e80..7c82d92 100644
--- a/render.cc
+++ b/render.cc
@@ -42,7 +42,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, QVector<CSGTerm*> *background) const;
+ CSGTerm *render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const;
virtual QString dump(QString indent) const;
};
@@ -122,7 +122,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, QVector<CSGTerm*> *background) const
+CSGTerm *RenderNode::render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
{
QString key = mk_cache_id();
if (PolySet::ps_cache.contains(key)) {
@@ -228,7 +228,7 @@ CSGTerm *RenderNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights
#else
-CSGTerm *RenderNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
+CSGTerm *RenderNode::render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
{
CSGTerm *t1 = NULL;
PRINT("WARNING: Found render() statement but compiled without CGAL support!");
diff --git a/transform.cc b/transform.cc
index 5e86bde..a920dd5 100644
--- a/transform.cc
+++ b/transform.cc
@@ -27,7 +27,8 @@ enum transform_type_e {
SCALE,
ROTATE,
TRANSLATE,
- MULTMATRIX
+ MULTMATRIX,
+ COLOR
};
class TransformModule : public AbstractModule
@@ -41,12 +42,12 @@ public:
class TransformNode : public AbstractNode
{
public:
- double m[16];
+ double m[20];
TransformNode(const ModuleInstantiation *mi) : AbstractNode(mi) { }
#ifdef ENABLE_CGAL
virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const;
#endif
- virtual CSGTerm *render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const;
+ virtual CSGTerm *render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const;
virtual QString dump(QString indent) const;
};
@@ -54,9 +55,10 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti
{
TransformNode *node = new TransformNode(inst);
- for (int i = 0; i < 16; i++) {
+ for (int i = 0; i < 16; i++)
node->m[i] = i % 5 == 0 ? 1.0 : 0.0;
- }
+ for (int i = 16; i < 20; i++)
+ node->m[i] = -1;
QVector<QString> argnames;
QVector<Expression*> argexpr;
@@ -73,6 +75,9 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti
if (type == MULTMATRIX) {
argnames = QVector<QString>() << "m";
}
+ if (type == COLOR) {
+ argnames = QVector<QString>() << "c";
+ }
Context c(ctx);
c.args(argnames, argexpr, inst->argnames, inst->argvalues);
@@ -173,6 +178,14 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti
}
}
}
+ if (type == COLOR)
+ {
+ Value v = c.lookup_variable("c");
+ if (v.type == Value::VECTOR) {
+ for (int i = 0; i < 4; i++)
+ node->m[16+i] = i < v.vec.size() ? v.vec[i]->num : 1.0;
+ }
+ }
foreach (ModuleInstantiation *v, inst->children) {
AbstractNode *n = v->evaluate(inst->ctx);
@@ -255,9 +268,9 @@ CGAL_Nef_polyhedron TransformNode::render_cgal_nef_polyhedron() const
#endif /* ENABLE_CGAL */
-CSGTerm *TransformNode::render_csg_term(double c[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
+CSGTerm *TransformNode::render_csg_term(double c[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
{
- double x[16];
+ double x[20];
for (int i = 0; i < 16; i++)
{
@@ -268,6 +281,9 @@ CSGTerm *TransformNode::render_csg_term(double c[16], QVector<CSGTerm*> *highlig
x[i] += c[c_row + j*4] * m[m_col*4 + j];
}
+ for (int i = 16; i < 20; i++)
+ x[i] = m[i] < 0 ? c[i] : m[i];
+
CSGTerm *t1 = NULL;
foreach(AbstractNode *v, children)
{
@@ -291,11 +307,16 @@ QString TransformNode::dump(QString indent) const
{
if (dump_cache.isEmpty()) {
QString text;
- text.sprintf("n%d: multmatrix([[%f, %f, %f, %f], [%f, %f, %f, %f], [%f, %f, %f, %f], [%f, %f, %f, %f]])", idx,
- m[0], m[4], m[ 8], m[12],
- m[1], m[5], m[ 9], m[13],
- m[2], m[6], m[10], m[14],
- m[3], m[7], m[11], m[15]);
+ if (m[16] >= 0 || m[17] >= 0 || m[18] >= 0 || m[19] >= 0)
+ text.sprintf("n%d: color([%f, %f, %f, %f])", idx,
+ m[16], m[17], m[18], m[19]);
+ else
+ text.sprintf("n%d: multmatrix([[%f, %f, %f, %f], [%f, %f, %f, %f], "
+ "[%f, %f, %f, %f], [%f, %f, %f, %f]])", idx,
+ m[0], m[4], m[ 8], m[12],
+ m[1], m[5], m[ 9], m[13],
+ m[2], m[6], m[10], m[14],
+ m[3], m[7], m[11], m[15]);
text = indent + text + " {\n";
foreach (AbstractNode *v, children)
text += v->dump(indent + QString("\t"));
@@ -310,5 +331,6 @@ void register_builtin_transform()
builtin_modules["rotate"] = new TransformModule(ROTATE);
builtin_modules["translate"] = new TransformModule(TRANSLATE);
builtin_modules["multmatrix"] = new TransformModule(MULTMATRIX);
+ builtin_modules["color"] = new TransformModule(COLOR);
}
contact: Jan Huwald // Impressum