[OpenSCAD] Functional OpenSCAD, working with vertex data

Parkinbot rudolf at parkinbot.com
Tue Jan 30 10:42:27 EST 2018

thehans wrote
> Here is a quick implementation of the rounded cube concept which I
> made as a module, since this version *does* still require one hull
> operation.
> https://gist.github.com/thehans/2c96601af4e5c8c2d232e50252dd37b1

let me annote that hull() itself is not the problem. To avoid a time
consuming CGAL round trip, don't use (implicit) unions inside a hull(). If
you implement rounded_cube() more explicitely, rendering is fast (seconds). 

$fa = 0.1;
$fs = 0.1;
rounded_cube_([4, 20, 5], r=1, center=[1,1,1]);

module rounded_cube_(size, r=0, center=false)
  sz = size[0]==undef?[size, size, size]:size; 
  ce = center[0]==undef?[center, center, center]:center; 
  r_ = min(abs(r), abs(size.x/2), abs(size.y/2), abs(size.z/2));  // correct
  translate([ce.x?-sz.x/2:0,ce.y?-sz.y/2:0, ce.z?-sz.z/2:0])
      translate([r_, r_, r_]) sphere(r_); 
      translate([r_, r_, sz.z-r_]) sphere(r_); 
      translate([r_, sz.y-r_, r_]) sphere(r_); 
      translate([r_, sz.y-r_, sz.z-r_]) sphere(r_); 
      translate([sz.x-r_, r_, r_]) sphere(r_); 
      translate([sz.x-r_, r_, sz.z-r_]) sphere(r_); 
      translate([sz.x-r_, sz.y-r_, r_]) sphere(r_); 
      translate([sz.x-r_, sz.y-r_, sz.z-r_]) sphere(r_); 

in contrast the following call of hull will take minutes. 

  for(x=[r_,size.x-r_], y=[r_,size.y-r_], z=[r_,size.z-r_])
    translate([x,y,z]) sphere(r_); 

However, rounded_cube_ is currently a typical libary module. I wouldn't add
it to the core language unless cylinder(), linear_extrude() and maybe hull()
also get a r parameter. 

Sent from: http://forum.openscad.org/

More information about the Discuss mailing list