+ circle: function(r, n) {
+ var points = [];
+ for (var i = 0; i < n; i++) {
+ points.push([r*Math.cos(2*Math.PI*i/n),
+ r*Math.sin(2*Math.PI*i/n),
+ 0]);
+ }
+ return points;
+ },
+ cone: function(base_center, apex, radius, steps) {
+ var base = this.circle(radius, steps);
+ base = this.rotate_onto(base, [0,0,1], this.sub(apex, base_center));
+ base = this.translate(base, base_center);
+ return this.closed_trianglefan([apex].concat(base)).concat(
+ this.trianglefan(base.reverse()));
+ },
+ shapenormals_from_closed_path: function(path) {
+ return function(i) {
+ var prev = (i == 0) ? path.length-1 : i-1;
+ var next = (i == path.length-1) ? 0 : i+1;
+ return nt3d.sub(path[next], path[prev]);
+ };
+ },
+ shapenormals_from_path_and_extra_points: function(path, first_point, last_point) {
+ return function(i) {
+ var prev = (i == 0) ? first_point : path[i-1];
+ var next = (i == path.length-1) ? last_point : path[i+1];
+ return nt3d.sub(next, prev);
+ };
+ },
+ shapenormals_from_path_and_first_and_last_normals: function(path, first_normal, last_normal) {
+ return function(i) {
+ if (i == 0) { return first_normal; }
+ if (i == path.length-1) { return last_normal; }
+ return nt3d.sub(path[i+1], path[i-1]);
+ };
+ },
+ to_function: function(thing, make_indexer) {
+ // If thing is a point, just yield thing every time.
+ // If thing is a list of points && make_indexer, index into thing.
+ // If thing is already a function, just return it.
+ if (({}).toString.call(thing) === "[object Function]") {
+ return thing; // Already a function
+ }
+ if (make_indexer && Array.isArray(thing[0])) {
+ // Looks like a list of points.
+ return function(i) { return thing[i]; }
+ }
+ return function() { return thing; }
+ },
+ extrude: function(path, shape, shapenormals, pathnormals) {
+
+ var guts_result = nt3d._extrude_guts(path, shape, shapenormals, pathnormals);