summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2011-12-25 23:38:03 (GMT)
committerMarius Kintel <marius@kintel.net>2011-12-25 23:38:03 (GMT)
commitc4bffdaf37fdf72a84a225ec584d3698fe398857 (patch)
tree503b819d69c00f007709cfee0f332c7adc7ad818
parent3e64e63b0113a99666ad68aa3e82bb7b80324d9b (diff)
Color overriding now works. The outermost color will win if multiple colors are specified for the same object
-rw-r--r--openscad.pro10
-rw-r--r--src/CSGTermEvaluator.cc2
-rw-r--r--src/OpenCSGRenderer.cc4
-rw-r--r--src/ThrownTogetherRenderer.cc6
-rw-r--r--src/colornode.h3
-rw-r--r--src/csgterm.cc7
-rw-r--r--src/csgterm.h8
-rw-r--r--src/linalg.h6
-rw-r--r--src/renderer.cc2
-rw-r--r--src/renderer.h2
-rw-r--r--src/state.h16
-rw-r--r--tests/regression/dumptest/testcolornames-expected.txt4
-rw-r--r--tests/regression/opencsgtest/color-tests-expected.pngbin10950 -> 10389 bytes
-rw-r--r--tests/regression/throwntogethertest/color-tests-expected.pngbin10215 -> 9795 bytes
14 files changed, 38 insertions, 32 deletions
diff --git a/openscad.pro b/openscad.pro
index 50a419d..89804a7 100644
--- a/openscad.pro
+++ b/openscad.pro
@@ -187,8 +187,8 @@ HEADERS += src/renderer.h \
src/system-gl.h \
src/stl-utils.h
-SOURCES += src/openscad.cc \
- src/mainwin.cc \
+SOURCES += src/mathc99.cc \
+ src/linalg.cc \
src/handle_dep.cc \
src/renderer.cc \
src/rendersettings.cc \
@@ -231,10 +231,10 @@ SOURCES += src/openscad.cc \
src/nodedumper.cc \
src/CSGTermEvaluator.cc \
src/Tree.cc \
- src/mathc99.cc \
- src/linalg.cc \
src/PolySetCache.cc \
- src/PolySetEvaluator.cc
+ src/PolySetEvaluator.cc \
+ src/openscad.cc \
+ src/mainwin.cc
opencsg {
HEADERS += src/OpenCSGRenderer.h
diff --git a/src/CSGTermEvaluator.cc b/src/CSGTermEvaluator.cc
index fc76d56..34f22da 100644
--- a/src/CSGTermEvaluator.cc
+++ b/src/CSGTermEvaluator.cc
@@ -159,7 +159,7 @@ Response CSGTermEvaluator::visit(State &state, const TransformNode &node)
Response CSGTermEvaluator::visit(State &state, const ColorNode &node)
{
if (state.isPrefix()) {
- state.setColor(node.color);
+ if (!state.color().isValid()) state.setColor(node.color);
}
if (state.isPostfix()) {
applyToChildren(node, CSGT_UNION);
diff --git a/src/OpenCSGRenderer.cc b/src/OpenCSGRenderer.cc
index 233124b..eb66687 100644
--- a/src/OpenCSGRenderer.cc
+++ b/src/OpenCSGRenderer.cc
@@ -86,7 +86,7 @@ void OpenCSGRenderer::renderCSGChain(CSGChain *chain, GLint *shaderinfo,
if (shaderinfo) glUseProgram(shaderinfo[0]);
for (; j < i; j++) {
const Transform3d &m = chain->matrices[j];
- double *c = chain->colors[j];
+ const Color4f &c = chain->colors[j];
glPushMatrix();
glMultMatrixd(m.data());
PolySet::csgmode_e csgmode = chain->types[j] == CSGTerm::TYPE_DIFFERENCE ? PolySet::CSGMODE_DIFFERENCE : PolySet::CSGMODE_NORMAL;
@@ -99,7 +99,7 @@ void OpenCSGRenderer::renderCSGChain(CSGChain *chain, GLint *shaderinfo,
csgmode = PolySet::csgmode_e(csgmode + 10);
} else if (c[0] >= 0 || c[1] >= 0 || c[2] >= 0 || c[3] >= 0) {
// User-defined color or alpha from source
- setColor(c, shaderinfo);
+ setColor(c.data(), shaderinfo);
} else if (chain->types[j] == CSGTerm::TYPE_DIFFERENCE) {
setColor(COLORMODE_CUTOUT, shaderinfo);
} else {
diff --git a/src/ThrownTogetherRenderer.cc b/src/ThrownTogetherRenderer.cc
index 36f7b95..146d2e1 100644
--- a/src/ThrownTogetherRenderer.cc
+++ b/src/ThrownTogetherRenderer.cc
@@ -67,7 +67,7 @@ void ThrownTogetherRenderer::renderCSGChain(CSGChain *chain, bool highlight,
if (polySetVisitMark[std::make_pair(chain->polysets[i].get(), &chain->matrices[i])]++ > 0)
continue;
const Transform3d &m = chain->matrices[i];
- double *c = chain->colors[i];
+ const Color4f &c = chain->colors[i];
glPushMatrix();
glMultMatrixd(m.data());
PolySet::csgmode_e csgmode = chain->types[i] == CSGTerm::TYPE_DIFFERENCE ? PolySet::CSGMODE_DIFFERENCE : PolySet::CSGMODE_NORMAL;
@@ -93,10 +93,10 @@ void ThrownTogetherRenderer::renderCSGChain(CSGChain *chain, bool highlight,
else csgmode = PolySet::csgmode_e(csgmode);
chain->polysets[i]->render_surface(csgmode, m);
} else if (c[0] >= 0 || c[1] >= 0 || c[2] >= 0 || c[3] >= 0) {
- setColor(c);
+ setColor(c.data());
chain->polysets[i]->render_surface(csgmode, m);
if (showedges) {
- glColor4d((c[0]+1)/2, (c[1]+1)/2, (c[2]+1)/2, 1.0);
+ glColor4f((c[0]+1)/2, (c[1]+1)/2, (c[2]+1)/2, 1.0);
chain->polysets[i]->render_edges(csgmode);
}
} else if (chain->types[i] == CSGTerm::TYPE_DIFFERENCE) {
diff --git a/src/colornode.h b/src/colornode.h
index b41e2a9..9323638 100644
--- a/src/colornode.h
+++ b/src/colornode.h
@@ -3,6 +3,7 @@
#include "node.h"
#include "visitor.h"
+#include "linalg.h"
class ColorNode : public AbstractNode
{
@@ -14,7 +15,7 @@ public:
virtual std::string toString() const;
virtual std::string name() const;
- double color[4];
+ Color4f color;
};
#endif
diff --git a/src/csgterm.cc b/src/csgterm.cc
index 56fcbb5..890b0c9 100644
--- a/src/csgterm.cc
+++ b/src/csgterm.cc
@@ -89,10 +89,9 @@ shared_ptr<CSGTerm> CSGTerm::createCSGTerm(type_e type, CSGTerm *left, CSGTerm *
return createCSGTerm(type, shared_ptr<CSGTerm>(left), shared_ptr<CSGTerm>(right));
}
-CSGTerm::CSGTerm(const shared_ptr<PolySet> &polyset, const Transform3d &matrix, const double color[4], const std::string &label)
- : type(TYPE_PRIMITIVE), polyset(polyset), label(label), m(matrix)
+CSGTerm::CSGTerm(const shared_ptr<PolySet> &polyset, const Transform3d &matrix, const Color4f &color, const std::string &label)
+ : type(TYPE_PRIMITIVE), polyset(polyset), label(label), m(matrix), color(color)
{
- for (int i = 0; i < 4; i++) this->color[i] = color[i];
initBoundingBox();
}
@@ -281,7 +280,7 @@ CSGChain::CSGChain()
{
}
-void CSGChain::add(const shared_ptr<PolySet> &polyset, const Transform3d &m, double *color, CSGTerm::type_e type, std::string label)
+void CSGChain::add(const shared_ptr<PolySet> &polyset, const Transform3d &m, const Color4f &color, CSGTerm::type_e type, std::string label)
{
polysets.push_back(polyset);
matrices.push_back(m);
diff --git a/src/csgterm.h b/src/csgterm.h
index 4930349..570af53 100644
--- a/src/csgterm.h
+++ b/src/csgterm.h
@@ -28,7 +28,7 @@ public:
shared_ptr<CSGTerm> right;
BoundingBox bbox;
- CSGTerm(const shared_ptr<PolySet> &polyset, const Transform3d &matrix, const double color[4], const std::string &label);
+ CSGTerm(const shared_ptr<PolySet> &polyset, const Transform3d &matrix, const Color4f &color, const std::string &label);
~CSGTerm();
const BoundingBox &getBoundingBox() const { return this->bbox; }
@@ -44,7 +44,7 @@ private:
void initBoundingBox();
Transform3d m;
- double color[4];
+ Color4f color;
friend class CSGChain;
};
@@ -54,13 +54,13 @@ class CSGChain
public:
std::vector<shared_ptr<PolySet> > polysets;
std::vector<Transform3d> matrices;
- std::vector<double*> colors;
+ std::vector<Color4f> colors;
std::vector<CSGTerm::type_e> types;
std::vector<std::string> labels;
CSGChain();
- void add(const shared_ptr<PolySet> &polyset, const Transform3d &m, double *color, CSGTerm::type_e type, std::string label);
+ void add(const shared_ptr<PolySet> &polyset, const Transform3d &m, const Color4f &color, CSGTerm::type_e type, std::string label);
void import(shared_ptr<CSGTerm> term, CSGTerm::type_e type = CSGTerm::TYPE_UNION);
std::string dump();
diff --git a/src/linalg.h b/src/linalg.h
index c1a14d1..15ef870 100644
--- a/src/linalg.h
+++ b/src/linalg.h
@@ -15,4 +15,10 @@ using Eigen::Transform3d;
BoundingBox operator*(const Transform3d &m, const BoundingBox &box);
+class Color4f : public Eigen::Vector4f
+{
+public:
+ bool isValid() const { return this->minCoeff() >= 0.0f; }
+};
+
#endif
diff --git a/src/renderer.cc b/src/renderer.cc
index b791673..5a767b8 100644
--- a/src/renderer.cc
+++ b/src/renderer.cc
@@ -2,7 +2,7 @@
#include "rendersettings.h"
#include <QColor>
-void Renderer::setColor(const double color[4], GLint *shaderinfo) const
+void Renderer::setColor(const float color[4], GLint *shaderinfo) const
{
QColor col = RenderSettings::inst()->color(RenderSettings::OPENCSG_FACE_FRONT_COLOR);
double c[4] = {color[0], color[1], color[2], color[3]};
diff --git a/src/renderer.h b/src/renderer.h
index 8deabe8..2bc482d 100644
--- a/src/renderer.h
+++ b/src/renderer.h
@@ -25,7 +25,7 @@ public:
COLORMODE_BACKGROUND_EDGES
};
- virtual void setColor(const double color[4], GLint *shaderinfo = NULL) const;
+ virtual void setColor(const float color[4], GLint *shaderinfo = NULL) const;
virtual void setColor(ColorMode colormode, GLint *shaderinfo = NULL) const;
};
diff --git a/src/state.h b/src/state.h
index 5dc74df..df202aa 100644
--- a/src/state.h
+++ b/src/state.h
@@ -9,8 +9,8 @@ class State
public:
State(const class AbstractNode *parent)
: parentnode(parent), isprefix(false), ispostfix(false), numchildren(0) {
- m = Transform3d::Identity();
- for (int i=0;i<4;i++) this->c[i] = -1.0;
+ this->matrix_ = Transform3d::Identity();
+ this->color_.fill(-1.0f);
}
virtual ~State() {}
@@ -18,15 +18,15 @@ public:
void setPostfix(bool on) { this->ispostfix = on; }
void setNumChildren(unsigned int numc) { this->numchildren = numc; }
void setParent(const AbstractNode *parent) { this->parentnode = parent; }
- void setMatrix(const Transform3d &m) { this->m = m; }
- void setColor(const double c[4]) { memcpy(this->c, c, 4*sizeof(double)); }
+ void setMatrix(const Transform3d &m) { this->matrix_ = m; }
+ void setColor(const Color4f &c) { this->color_ = c; }
bool isPrefix() const { return this->isprefix; }
bool isPostfix() const { return this->ispostfix; }
unsigned int numChildren() const { return this->numchildren; }
const AbstractNode *parent() const { return this->parentnode; }
- const Transform3d &matrix() const { return this->m; }
- const double *color() const { return this->c; }
+ const Transform3d &matrix() const { return this->matrix_; }
+ const Color4f &color() const { return this->color_; }
private:
const AbstractNode * parentnode;
@@ -35,8 +35,8 @@ private:
unsigned int numchildren;
// Transformation matrix and color. FIXME: Generalize such state variables?
- Transform3d m;
- double c[4];
+ Transform3d matrix_;
+ Color4f color_;
};
#endif
diff --git a/tests/regression/dumptest/testcolornames-expected.txt b/tests/regression/dumptest/testcolornames-expected.txt
index 56e664f..63b5e70 100644
--- a/tests/regression/dumptest/testcolornames-expected.txt
+++ b/tests/regression/dumptest/testcolornames-expected.txt
@@ -49,7 +49,7 @@
}
}
multmatrix([[1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]]) {
- color([1, 0.713725, 0.756863, 1]) {
+ color([1, 0.713726, 0.756863, 1]) {
sphere($fn = 5, $fa = 12, $fs = 2, r = 0.8);
}
}
@@ -79,7 +79,7 @@
}
}
multmatrix([[1, 0, 0, 8], [0, 1, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]]) {
- color([1, 0.498039, 0.313725, 1]) {
+ color([1, 0.498039, 0.313726, 1]) {
sphere($fn = 5, $fa = 12, $fs = 2, r = 0.8);
}
}
diff --git a/tests/regression/opencsgtest/color-tests-expected.png b/tests/regression/opencsgtest/color-tests-expected.png
index 82ba36a..5b35312 100644
--- a/tests/regression/opencsgtest/color-tests-expected.png
+++ b/tests/regression/opencsgtest/color-tests-expected.png
Binary files differ
diff --git a/tests/regression/throwntogethertest/color-tests-expected.png b/tests/regression/throwntogethertest/color-tests-expected.png
index 5d4ed89..8fb69b1 100644
--- a/tests/regression/throwntogethertest/color-tests-expected.png
+++ b/tests/regression/throwntogethertest/color-tests-expected.png
Binary files differ
contact: Jan Huwald // Impressum