diff --git a/src/OpenCSGRenderer.cc b/src/OpenCSGRenderer.cc index 3c6f0b48..aa2d6bbb 100644 --- a/src/OpenCSGRenderer.cc +++ b/src/OpenCSGRenderer.cc @@ -90,7 +90,12 @@ void OpenCSGRenderer::renderCSGChain(CSGChain *chain, GLint *shaderinfo, const Color4f &c = j_obj.color; glPushMatrix(); glMultMatrixd(j_obj.matrix.data()); - csgmode_e csgmode = j_obj.type == CSGTerm::TYPE_DIFFERENCE ? CSGMODE_DIFFERENCE : CSGMODE_NORMAL; + csgmode_e csgmode = csgmode_e( + (highlight ? + CSGMODE_HIGHLIGHT : + (background ? CSGMODE_BACKGROUND : CSGMODE_NORMAL)) | + (j_obj.type == CSGTerm::TYPE_DIFFERENCE ? CSGMODE_DIFFERENCE : 0)); + ColorMode colormode = COLORMODE_NONE; if (background) { if (j_obj.flag & CSGTerm::FLAG_HIGHLIGHT) { @@ -99,11 +104,9 @@ void OpenCSGRenderer::renderCSGChain(CSGChain *chain, GLint *shaderinfo, else { colormode = COLORMODE_BACKGROUND; } - csgmode = csgmode_e(csgmode + 10); } else if (j_obj.type == CSGTerm::TYPE_DIFFERENCE) { if (j_obj.flag & CSGTerm::FLAG_HIGHLIGHT) { colormode = COLORMODE_HIGHLIGHT; - csgmode = csgmode_e(csgmode + 20); } else { colormode = COLORMODE_CUTOUT; @@ -111,7 +114,6 @@ void OpenCSGRenderer::renderCSGChain(CSGChain *chain, GLint *shaderinfo, } else { if (j_obj.flag & CSGTerm::FLAG_HIGHLIGHT) { colormode = COLORMODE_HIGHLIGHT; - csgmode = csgmode_e(csgmode + 20); } else { colormode = COLORMODE_MATERIAL; @@ -139,9 +141,12 @@ void OpenCSGRenderer::renderCSGChain(CSGChain *chain, GLint *shaderinfo, prim->geom = i_obj.geom; prim->m = i_obj.matrix; - prim->csgmode = i_obj.type == CSGTerm::TYPE_DIFFERENCE ? CSGMODE_DIFFERENCE : CSGMODE_NORMAL; - if (highlight) prim->csgmode = csgmode_e(prim->csgmode + 20); - else if (background) prim->csgmode = csgmode_e(prim->csgmode + 10); + prim->csgmode = csgmode_e( + (highlight ? + CSGMODE_HIGHLIGHT : + (background ? CSGMODE_BACKGROUND : CSGMODE_NORMAL)) | + (i_obj.type == CSGTerm::TYPE_DIFFERENCE ? CSGMODE_DIFFERENCE : 0)); + primitives.push_back(prim); } } diff --git a/src/ThrownTogetherRenderer.cc b/src/ThrownTogetherRenderer.cc index 4b114041..dbdf527c 100644 --- a/src/ThrownTogetherRenderer.cc +++ b/src/ThrownTogetherRenderer.cc @@ -74,12 +74,15 @@ void ThrownTogetherRenderer::renderCSGChain(CSGChain *chain, bool highlight, const Color4f &c = obj.color; glPushMatrix(); glMultMatrixd(m.data()); - csgmode_e csgmode = obj.type == CSGTerm::TYPE_DIFFERENCE ? CSGMODE_DIFFERENCE : CSGMODE_NORMAL; + csgmode_e csgmode = csgmode_e( + (highlight ? + CSGMODE_HIGHLIGHT : + (background ? CSGMODE_BACKGROUND : CSGMODE_NORMAL)) | + (obj.type == CSGTerm::TYPE_DIFFERENCE ? CSGMODE_DIFFERENCE : 0)); ColorMode colormode = COLORMODE_NONE; ColorMode edge_colormode = COLORMODE_NONE; if (highlight) { - csgmode = csgmode_e(csgmode + 20); colormode = COLORMODE_HIGHLIGHT; edge_colormode = COLORMODE_HIGHLIGHT_EDGES; } else if (background) { @@ -89,16 +92,11 @@ void ThrownTogetherRenderer::renderCSGChain(CSGChain *chain, bool highlight, else { colormode = COLORMODE_BACKGROUND; } - csgmode = csgmode_e(csgmode + 10); edge_colormode = COLORMODE_BACKGROUND_EDGES; } else if (fberror) { - if (highlight) csgmode = csgmode_e(csgmode + 20); - else if (background) csgmode = csgmode_e(csgmode + 10); - else csgmode = csgmode_e(csgmode); } else if (obj.type == CSGTerm::TYPE_DIFFERENCE) { if (obj.flag & CSGTerm::FLAG_HIGHLIGHT) { colormode = COLORMODE_HIGHLIGHT; - csgmode = csgmode_e(csgmode + 20); } else { colormode = COLORMODE_CUTOUT; @@ -107,7 +105,6 @@ void ThrownTogetherRenderer::renderCSGChain(CSGChain *chain, bool highlight, } else { if (obj.flag & CSGTerm::FLAG_HIGHLIGHT) { colormode = COLORMODE_HIGHLIGHT; - csgmode = csgmode_e(csgmode + 20); } else { colormode = COLORMODE_MATERIAL; diff --git a/src/polyset.cc b/src/polyset.cc index ad6b6e59..00ae963f 100644 --- a/src/polyset.cc +++ b/src/polyset.cc @@ -240,7 +240,7 @@ void PolySet::render_surface(Renderer::csgmode_e csgmode, const Transform3d &m, #endif /* ENABLE_OPENCSG */ if (this->dim == 2) { // Render 2D objects 1mm thick, but differences slightly larger - double zbase = 1 + (csgmode & CSGMODE_DIFFERENCE_FLAG) * 0.1; + double zbase = 1 + ((csgmode & CSGMODE_DIFFERENCE_FLAG) ? 0.1 : 0); glBegin(GL_TRIANGLES); // Render top+bottom @@ -369,7 +369,7 @@ void PolySet::render_edges(Renderer::csgmode_e csgmode) const } else { // Render 2D objects 1mm thick, but differences slightly larger - double zbase = 1 + (csgmode & CSGMODE_DIFFERENCE_FLAG) * 0.1; + double zbase = 1 + ((csgmode & CSGMODE_DIFFERENCE_FLAG) ? 0.1 : 0); BOOST_FOREACH(const Outline2d &o, polygon.outlines()) { // Render top+bottom outlines diff --git a/testdata/scad/2D/features/highlight-modifier-2d.scad b/testdata/scad/2D/features/highlight-modifier-2d.scad new file mode 100644 index 00000000..7779fd69 --- /dev/null +++ b/testdata/scad/2D/features/highlight-modifier-2d.scad @@ -0,0 +1,10 @@ +difference() { + square(10, center=true); + #circle(3); +} +#if (true) square([11,12]); + +#translate([0,-12]) difference() { + square(10, center = true); + square(5, center = true); +} diff --git a/tests/regression/cgalpngtest/highlight-modifier-2d-expected.png b/tests/regression/cgalpngtest/highlight-modifier-2d-expected.png new file mode 100644 index 00000000..9c2cedf1 Binary files /dev/null and b/tests/regression/cgalpngtest/highlight-modifier-2d-expected.png differ diff --git a/tests/regression/dumptest/highlight-modifier-2d-expected.csg b/tests/regression/dumptest/highlight-modifier-2d-expected.csg new file mode 100644 index 00000000..833d1ea4 --- /dev/null +++ b/tests/regression/dumptest/highlight-modifier-2d-expected.csg @@ -0,0 +1,15 @@ +group() { + difference() { + square(size = [10, 10], center = true); +# circle($fn = 0, $fa = 12, $fs = 2, r = 3); + } +# group() { + square(size = [11, 12], center = false); + } +# multmatrix([[1, 0, 0, 0], [0, 1, 0, -12], [0, 0, 1, 0], [0, 0, 0, 1]]) { + difference() { + square(size = [10, 10], center = true); + square(size = [5, 5], center = true); + } + } +} diff --git a/tests/regression/opencsgtest/difference-tests-expected.png b/tests/regression/opencsgtest/difference-tests-expected.png index 69a4ac2e..4ffb06fd 100644 Binary files a/tests/regression/opencsgtest/difference-tests-expected.png and b/tests/regression/opencsgtest/difference-tests-expected.png differ diff --git a/tests/regression/opencsgtest/highlight-modifier-2d-expected.png b/tests/regression/opencsgtest/highlight-modifier-2d-expected.png new file mode 100644 index 00000000..24342191 Binary files /dev/null and b/tests/regression/opencsgtest/highlight-modifier-2d-expected.png differ diff --git a/tests/regression/throwntogethertest/difference-tests-expected.png b/tests/regression/throwntogethertest/difference-tests-expected.png index 4702fbff..fb1753c5 100644 Binary files a/tests/regression/throwntogethertest/difference-tests-expected.png and b/tests/regression/throwntogethertest/difference-tests-expected.png differ diff --git a/tests/regression/throwntogethertest/highlight-modifier-2d-expected.png b/tests/regression/throwntogethertest/highlight-modifier-2d-expected.png new file mode 100644 index 00000000..404d9e18 Binary files /dev/null and b/tests/regression/throwntogethertest/highlight-modifier-2d-expected.png differ