Slicing a 3D object to SVG: verschil tussen versies

Uit MakerSpace Leiden
Ga naar: navigatie, zoeken
(Example of a CSG object)
(Example with an STL)
Regel 39: Regel 39:
  
 
An example of an STL that is loaded from a file and then sliced. You will have to manually adjust the Z range & slice distance.
 
An example of an STL that is loaded from a file and then sliced. You will have to manually adjust the Z range & slice distance.
 +
 +
  // 30x150x20 bbx
 +
  import("dino.stl", convexity=3);
 +
 +
  z_min = 0;
 +
  z_max = 30;
 +
  x_max = 20
 +
  y_max = 150;
 +
  slice = 0.5;
 +
 +
  n = floor(sqrt((z_max - z_min)/slice)+1);
 +
  for(z = [-z_max:slice:z_min]) {
 +
    i = (z + z_max) / slice;
 +
    x = x_max * (i % n);
 +
    y = Y_max * floor(i / n);
 +
    translate([x,y,0]) {
 +
        projection(cut=true)
 +
            translate([0,0,z]) thing();
 +
    };
 +
  };

Versie van 3 mrt 2018 om 20:10

One can use OpenSCAD to slice a 3D STL or an object made in OpenSCAD into SVG usable with the Lasersaur.

Example of a CSG object

Example of a sphere on top of a cube (thing() in below code) which is sliced; and each slice is then laid out flat.

 module thing() {
   difference() {
       union() {
           translate([-5,-5,0]) 
               cube([10,10,10]);
           translate([0,0,12])
               sphere(r=10);
           };
       union() {
           translate([-5,-5,0]) 
               translate([1,1,1]) cube([8,8,8]);
           translate([0,0,12])
               sphere(r=9);
           };
       };
 }
 
 z_min = 0;
 z_max = 23;
 slice = 1;
 n = 5; // floor(sqrt((z_max - z_min)/slice+10));
 for(z = [-z_max:slice:z_min]) { 
   i = (z + z_max) / slice;
   x = 40 * (i % n);
   y = 40 * floor(i / n);
   translate([x,y,0]) {
       projection(cut=true) 
           translate([0,0,z]) thing();
   };
 };

Example with an STL

An example of an STL that is loaded from a file and then sliced. You will have to manually adjust the Z range & slice distance.

 // 30x150x20 bbx
 import("dino.stl", convexity=3); 
 z_min = 0;
 z_max = 30;
 x_max = 20
 y_max = 150;
 slice = 0.5;
 n = floor(sqrt((z_max - z_min)/slice)+1);
 for(z = [-z_max:slice:z_min]) { 
   i = (z + z_max) / slice;
   x = x_max * (i % n);
   y = Y_max * floor(i / n);
   translate([x,y,0]) {
       projection(cut=true) 
           translate([0,0,z]) thing();
   };
 };