From f789f39f7518c16ceeecd08104a66e2774a7a469 Mon Sep 17 00:00:00 2001 From: clifford Date: Mon, 5 Oct 2009 09:38:48 +0000 Subject: Clifford Wolf: Added polyeder primitive git-svn-id: http://svn.clifford.at/openscad/trunk@94 b57f626f-c46c-0410-a088-ec61d464b74c diff --git a/examples/example011.scad b/examples/example011.scad new file mode 100644 index 0000000..c11e65b --- /dev/null +++ b/examples/example011.scad @@ -0,0 +1,16 @@ +polyeder( + points = [ + [10 0 0], + [ 0 10 0], + [ -10 0 0], + [ 0 -10 0], + [ 0 0 10] + ], + triangles = [ + [0 1 2 3], + [4 1 0], + [4 2 1], + [4 3 2], + [4 0 3] + ] +); diff --git a/primitives.cc b/primitives.cc index f93755c..997b04f 100644 --- a/primitives.cc +++ b/primitives.cc @@ -25,7 +25,8 @@ enum primitive_type_e { CUBE, SPHERE, - CYLINDER + CYLINDER, + POLYEDER }; class PrimitiveModule : public AbstractModule @@ -43,6 +44,7 @@ public: double x, y, z, h, r1, r2; double fn, fs, fa; primitive_type_e type; + Value points, triangles; PrimitiveNode(const ModuleInstanciation *mi, primitive_type_e type) : AbstractPolyNode(mi), type(type) { } virtual PolySet *render_polyset(render_mode_e mode) const; virtual QString dump(QString indent) const; @@ -67,6 +69,9 @@ AbstractNode *PrimitiveModule::evaluate(const Context *ctx, const ModuleInstanci if (type == CYLINDER) { argnames = QVector() << "h" << "r1" << "r2" << "center"; } + if (type == POLYEDER) { + argnames = QVector() << "points" << "triangles"; + } Context c(ctx); c.args(argnames, argexpr, inst->argnames, inst->argvalues); @@ -120,6 +125,11 @@ AbstractNode *PrimitiveModule::evaluate(const Context *ctx, const ModuleInstanci } } + if (type == POLYEDER) { + node->points = c.lookup_variable("points"); + node->triangles = c.lookup_variable("triangles"); + } + return node; } @@ -128,6 +138,7 @@ void register_builtin_primitives() builtin_modules["cube"] = new PrimitiveModule(CUBE); builtin_modules["sphere"] = new PrimitiveModule(SPHERE); builtin_modules["cylinder"] = new PrimitiveModule(CYLINDER); + builtin_modules["polyeder"] = new PrimitiveModule(POLYEDER); } int get_fragments_from_r(double r, double fn, double fs, double fa) @@ -331,6 +342,21 @@ sphere_next_r2: } } + if (type == POLYEDER) + { + for (int i=0; iappend_poly(); + for (int j=0; jvec.size(); j++) { + int pt = triangles.vec[i]->vec[j]->num; + double px = points.vec[pt]->vec[0]->num; + double py = points.vec[pt]->vec[1]->num; + double pz = points.vec[pt]->vec[2]->num; + p->insert_vertex(px, py, pz); + } + } + } + return p; } @@ -344,6 +370,8 @@ QString PrimitiveNode::dump(QString indent) const text.sprintf("sphere($fn = %f, $fa = %f, $fs = %f, r = %f);\n", fn, fa, fs, r1); if (type == CYLINDER) text.sprintf("cylinder($fn = %f, $fa = %f, $fs = %f, h = %f, r1 = %f, r2 = %f, center = %s);\n", fn, fa, fs, h, r1, r2, center ? "true" : "false"); + if (type == POLYEDER) + text.sprintf("polyeder(points = %s, triangles = %s);\n", points.dump().toAscii().data(), triangles.dump().toAscii().data()); ((AbstractNode*)this)->dump_cache = indent + QString("n%1: ").arg(idx) + text; } return dump_cache; -- cgit v0.10.1