Clifford Wolf:

Added convexity handling
	Split up example.scad file to examples/*



git-svn-id: http://svn.clifford.at/openscad/trunk@56 b57f626f-c46c-0410-a088-ec61d464b74c
stl_dim
clifford 2009-07-14 21:47:32 +00:00
parent f950feace3
commit cc3291a4f1
11 changed files with 163 additions and 127 deletions

View File

@ -1,124 +0,0 @@
module test001()
{
function r_from_dia(d) = d / 2;
module rotcy(rot, r, h) {
rotate(90, rot) cylinder(r = r, h = h, center = true);
}
difference() {
sphere(r = r_from_dia(size));
rotcy([0 0 0], cy_r, cy_h);
rotcy([1 0 0], cy_r, cy_h);
rotcy([ 0 1 0], cy_r, cy_h);
}
size = 50;
hole = 25;
cy_r = r_from_dia(hole);
cy_h = r_from_dia(size * 2.5);
}
module test002()
{
intersection() {
difference() {
union() {
cube([30 30 30], center = true);
translate([0 0 -25])
cube([15 15 50], center = true);
}
union() {
cube([50 10 10], center = true);
cube([10 50 10], center = true);
cube([10 10 50], center = true);
}
}
translate([0 0 5])
cylinder(h = 50, r1 = 20, r2 = 5, center = true);
}
}
module test003()
{
difference() {
union() {
cube([30 30 30], center = true);
cube([40 15 15], center = true);
cube([15 40 15], center = true);
cube([15 15 40], center = true);
}
union() {
cube([50 10 10], center = true);
cube([10 50 10], center = true);
cube([10 10 50], center = true);
}
}
}
module test004()
{
difference() {
cube(30, center = true);
sphere(20);
}
}
module test005()
{
translate([0 0 -120]) {
difference() {
cylinder(h = 50, r = 100);
translate([0 0 10]) cylinder(h = 50, r = 80);
translate([100 0 35]) cube(50, center = true);
}
for (i = [0:5]) {
echo(360*i/6, sin(360*i/6)*80, cos(360*i/6)*80);
translate([sin(360*i/6)*80, cos(360*i/6)*80, 0 ])
cylinder(h = 200, r=10);
}
translate([0 0 200])
cylinder(h = 80, r1 = 120, r2 = 0);
}
}
module test006()
{
module edgeprofile()
{
render() difference() {
cube([20 20 150], center = true);
translate([-10 -10 0])
cylinder(h = 150, r = 10, center = true);
}
}
difference()
{
cube(100, center = true);
for (rot = [ [0 0 0], [1 0 0], [0 1 0] ]) {
rotate(90, rot)
for (p = [[+1 +1 0], [-1 +1 90], [-1 -1 180], [+1 -1 270]]) {
translate([ p[0]*50, p[1]*50, 0 ])
rotate(p[2], [0 0 1])
edgeprofile();
}
}
for (i = [
[ 0, 0, [ [0 0] ] ],
[ 90, 0, [ [-20 -20], [+20 +20] ] ],
[ 180, 0, [ [-20 -30], [-20 0], [-20 +30], [+20 -30], [+20 0], [+20 +30] ] ],
[ 270, 0, [ [0 0], [-30 -30], [+30 -30], [-30 +30], [+30 +30] ] ],
[ 0, 90, [ [-30 -30], [0 0], [+30 +30] ] ],
[ 0, -90, [ [-25 -25], [+25 -25], [-25 +25], [+25 +25] ] ]
]) {
rotate(i[0], [0 0 1]) rotate(i[1], [1 0 0]) translate([0 -50 0])
for (j = i[2])
translate([j[0], 0, j[1]]) sphere(10);
}
}
}
test006();

25
examples/example001.scad Normal file
View File

@ -0,0 +1,25 @@
module example001()
{
function r_from_dia(d) = d / 2;
module rotcy(rot, r, h) {
rotate(90, rot) cylinder(r = r, h = h, center = true);
}
difference() {
sphere(r = r_from_dia(size));
rotcy([0 0 0], cy_r, cy_h);
rotcy([1 0 0], cy_r, cy_h);
rotcy([ 0 1 0], cy_r, cy_h);
}
size = 50;
hole = 25;
cy_r = r_from_dia(hole);
cy_h = r_from_dia(size * 2.5);
}
example001();

23
examples/example002.scad Normal file
View File

@ -0,0 +1,23 @@
module example002()
{
intersection() {
difference() {
union() {
cube([30 30 30], center = true);
translate([0 0 -25])
cube([15 15 50], center = true);
}
union() {
cube([50 10 10], center = true);
cube([10 50 10], center = true);
cube([10 10 50], center = true);
}
}
translate([0 0 5])
cylinder(h = 50, r1 = 20, r2 = 5, center = true);
}
}
example002();

20
examples/example003.scad Normal file
View File

@ -0,0 +1,20 @@
module example003()
{
difference() {
union() {
cube([30 30 30], center = true);
cube([40 15 15], center = true);
cube([15 40 15], center = true);
cube([15 15 40], center = true);
}
union() {
cube([50 10 10], center = true);
cube([10 50 10], center = true);
cube([10 10 50], center = true);
}
}
}
example003();

11
examples/example004.scad Normal file
View File

@ -0,0 +1,11 @@
module example004()
{
difference() {
cube(30, center = true);
sphere(20);
}
}
example004();

21
examples/example005.scad Normal file
View File

@ -0,0 +1,21 @@
module example005()
{
translate([0 0 -120]) {
difference() {
cylinder(h = 50, r = 100);
translate([0 0 10]) cylinder(h = 50, r = 80);
translate([100 0 35]) cube(50, center = true);
}
for (i = [0:5]) {
echo(360*i/6, sin(360*i/6)*80, cos(360*i/6)*80);
translate([sin(360*i/6)*80, cos(360*i/6)*80, 0 ])
cylinder(h = 200, r=10);
}
translate([0 0 200])
cylinder(h = 80, r1 = 120, r2 = 0);
}
}
example005();

44
examples/example006.scad Normal file
View File

@ -0,0 +1,44 @@
module example006()
{
module edgeprofile()
{
render(convexity = 2) difference() {
cube([20 20 150], center = true);
translate([-10 -10 0])
cylinder(h = 80, r = 10, center = true);
translate([-10 -10 +40])
sphere(r = 10);
translate([-10 -10 -40])
sphere(r = 10);
}
}
difference()
{
cube(100, center = true);
for (rot = [ [0 0 0], [1 0 0], [0 1 0] ]) {
rotate(90, rot)
for (p = [[+1 +1 0], [-1 +1 90], [-1 -1 180], [+1 -1 270]]) {
translate([ p[0]*50, p[1]*50, 0 ])
rotate(p[2], [0 0 1])
edgeprofile();
}
}
for (i = [
[ 0, 0, [ [0 0] ] ],
[ 90, 0, [ [-20 -20], [+20 +20] ] ],
[ 180, 0, [ [-20 -25], [-20 0], [-20 +25], [+20 -25], [+20 0], [+20 +25] ] ],
[ 270, 0, [ [0 0], [-25 -25], [+25 -25], [-25 +25], [+25 +25] ] ],
[ 0, 90, [ [-25 -25], [0 0], [+25 +25] ] ],
[ 0, -90, [ [-25 -25], [+25 -25], [-25 +25], [+25 +25] ] ]
]) {
rotate(i[0], [0 0 1]) rotate(i[1], [1 0 0]) translate([0 -50 0])
for (j = i[2])
translate([j[0], 0, j[1]]) sphere(10);
}
}
}
example006();

View File

@ -807,7 +807,7 @@ static void renderCSGChainviaOpenCSG(CSGChain *chain, GLint *shaderinfo, bool hi
break;
OpenCSGPrim *prim = new OpenCSGPrim(chain->types[i] == CSGTerm::DIFFERENCE ?
OpenCSG::Subtraction : OpenCSG::Intersection, 1);
OpenCSG::Subtraction : OpenCSG::Intersection, chain->polysets[i]->convexity);
prim->p = chain->polysets[i];
primitives.push_back(prim);
}

View File

@ -327,6 +327,7 @@ public:
typedef QList<Point> Polygon;
QVector<Polygon> polygons;
double m[16];
int convexity;
PolySet();

View File

@ -26,6 +26,7 @@ PolySet::PolySet()
{
for (int i = 0; i < 16; i++)
m[i] = i % 5 == 0 ? 1.0 : 0.0;
convexity = 1;
}
void PolySet::append_poly()

View File

@ -35,7 +35,8 @@ public:
class RenderNode : public AbstractNode
{
public:
RenderNode(const ModuleInstanciation *mi) : AbstractNode(mi) { }
int convexity;
RenderNode(const ModuleInstanciation *mi) : AbstractNode(mi), convexity(1) { }
#ifdef ENABLE_CGAL
virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const;
#endif
@ -43,14 +44,26 @@ public:
virtual QString dump(QString indent) const;
};
AbstractNode *RenderModule::evaluate(const Context*, const ModuleInstanciation *inst) const
AbstractNode *RenderModule::evaluate(const Context *ctx, const ModuleInstanciation *inst) const
{
RenderNode *node = new RenderNode(inst);
QVector<QString> argnames = QVector<QString>() << "convexity";
QVector<Expression*> argexpr;
Context c(ctx);
c.args(argnames, argexpr, inst->argnames, inst->argvalues);
Value v = c.lookup_variable("convexity");
if (v.type == Value::NUMBER)
node->convexity = v.num;
foreach (ModuleInstanciation *v, inst->children) {
AbstractNode *n = v->evaluate(inst->ctx);
if (n != NULL)
node->children.append(n);
}
return node;
}
@ -138,6 +151,7 @@ CSGTerm *RenderNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights
PolySet *ps = new PolySet();
ps->setmatrix(m);
ps->convexity = convexity;
CGAL_Polyhedron P;
N.convert_to_Polyhedron(P);