Why is this causing OpenSCAD to lag and crash?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Why is this causing OpenSCAD to lag and crash?

brenzo
This post was updated on .
Edit: I've discovered that after building the project, I'm able to view it without lag. Could this simply be an issue with my Intel chip? I'm on a laptop with an integrated Intel HD620.

I have an object I"m creating with patterns on the side.

One thing I'd like to do is to continue the horizontal line around the
curved portion (render code this will be obvious).

I've done this by creating a hollow cylinder, diffing it from some cubes to
retain only a portion of it, then subtracting that form my overall shape.

Somehow, though, I've made this into a computationally intensive operation.
Uncommenting one ring will make OpenSCAD noticeably slower. 2 will make it
almost unusable. Uncommenting them all causes it to crash on my machine.

Rendering the rings alone causes no lag so it must be something to do with
using them in the difference() block.

How can I do this differently to avoid this?

//Block base.
module base() {
  difference() {
    union() {
      cube([100, 150, 40]);
      translate([50, 150, 0])
        cylinder(40, 50, 50);
    }
    translate([50, 150, 20])
      cylinder(60, 40, 40);
    translate([50, 50, 25])
      cylinder(20, 10.3, 10.7);
  }

}

//Make 1/4 of shape, mirror to complete.
module pattern() {
  module makepoly() {
    polygon([[-1, 10],
            [3, 10],
            [2, 7],
            [6, 7],
            [5, 4],
            [10, 4],
            [6, 0],
            [5, 0],
            [8, 3],
            [4, 3],
            [5, 6],
            [1, 6],
            [2, 9],
            [0, 9]]);
  }

  //Mirrors child but leaves original in place.
  module copy_mirror(vec) {
    children();
    mirror(vec)
      children();
  }

  //Make pattern 3D
  linear_extrude(2)
  copy_mirror([1, 0, 0])
  copy_mirror([0, 1, 0])
    makepoly();

  linear_extrude(2)
  rotate([0, 0, 45])
    square(5, center=true);
}

//Pattern on wall.
module wall_pattern(n) {
  for (i = [0:n])
    translate([18 + i * 32, 1, 0])
    scale([1.4, 1.4, 1.4])
    translate([0, 0, 14])
    rotate([90, 0, 0])
      pattern();
}

//Continue ring around curved portion.
module ring(height, a) {
  difference() {
    //Form a hollow cylinder by diffing 2 clyinders.
    translate([0, 0, height])
    difference() {
      cylinder(2, 51, 51);

      translate([0, 0, -1])
        cylinder(4, 48, 48);
    }

    //Rotate cubes about z axis and diff, to create portion of cylinder
    union() {
      rotate([0, 0, a])
      translate([-100, -200, 0])
        cube([400, 200, 200]);

      rotate([0, 0, -a])
      translate([-300, -200, 0])
        cube([400, 200, 200]);
    }
  }
}

//translate([50, 50, 30])
//plant();
difference() {
  base();
   
  //Carve out patterns and such
  wall_pattern(2);

  rotate([0, 0, 90])
    wall_pattern(4);

  translate([100, 0, 0])
  rotate([0, 0, 90])
    wall_pattern(4);

  translate([-1, -1, 35])
    cube([102, 3, 2]);

  translate([-1, -1, 2])
     cube([102, 3, 2]);
 
  translate([98, 0, 35])
    cube([3, 400, 2]);

  translate([98, 0, 2])
    cube([3, 400, 2]);

  translate([-1, 0, 35])
    cube([3, 400, 2]);

  translate([-1, 0, 2])
    cube([3, 400, 2]);

//  translate([50, 150, 0])
//  ring(35, 0);
//
//  translate([50, 150, 0])
//  ring(2, 0);
//
//  translate([50, 150, 0])
//  ring(10, 10);
//
//  translate([50, 150, 0])
//  ring(18, 20);
//
//  translate([50, 150, 0])
//  ring(30, 10);
}



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

_______________________________________________
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Why is this causing OpenSCAD to lag and crash?

kdtop
I just dropped this code into my OpenSCAD on my macMini, and it renders just fine.  There are the cool patterns all around the side.  It only takes a few seconds to get going.  

Is there something to do to make it slow?

Kevin

On Mon, Dec 24, 2018 at 2:17 AM brenzo <[hidden email]> wrote:
I have an object I"m creating with patterns on the side.

One thing I'd like to do is to continue the horizontal line around the
curved portion (render code this will be obvious).

I've done this by creating a hollow cylinder, diffing it from some cubes to
retain only a portion of it, then subtracting that form my overall shape.

Somehow, though, I've made this into a computationally intensive operation.
Uncommenting one right will make OpenSCAD noticeably slower. 2 will make it
almost unusable. Uncommenting them all causes it to crash on my machine.

Rendering the rings alone causes no lag so it must be something to do with
using them in the difference() block.

How can I do this differently to avoid this?

//Block base.
module base() {
  difference() {
    union() {
      cube([100, 150, 40]);
      translate([50, 150, 0])
        cylinder(40, 50, 50);
    }
    translate([50, 150, 20])
      cylinder(60, 40, 40);
    translate([50, 50, 25])
      cylinder(20, 10.3, 10.7);
  }

}

//Make 1/4 of shape, mirror to complete.
module pattern() {
  module makepoly() {
    polygon([[-1, 10],
            [3, 10],
            [2, 7],
            [6, 7],
            [5, 4],
            [10, 4],
            [6, 0],
            [5, 0],
            [8, 3],
            [4, 3],
            [5, 6],
            [1, 6],
            [2, 9],
            [0, 9]]);
  }

  //Mirrors child but leaves original in place.
  module copy_mirror(vec) {
    children();
    mirror(vec)
      children();
  }

  //Make pattern 3D
  linear_extrude(2)
  copy_mirror([1, 0, 0])
  copy_mirror([0, 1, 0])
    makepoly();

  linear_extrude(2)
  rotate([0, 0, 45])
    square(5, center=true);
}

//Pattern on wall.
module wall_pattern(n) {
  for (i = [0:n])
    translate([18 + i * 32, 1, 0])
    scale([1.4, 1.4, 1.4])
    translate([0, 0, 14])
    rotate([90, 0, 0])
      pattern();
}

//Continue ring around curved portion.
module ring(height, a) {
  difference() {
    //Form a hollow cylinder by diffing 2 clyinders.
    translate([0, 0, height])
    difference() {
      cylinder(2, 51, 51);

      translate([0, 0, -1])
        cylinder(4, 48, 48);
    }

    //Rotate cubes about z axis and diff, to create portion of cylinder
    union() {
      rotate([0, 0, a])
      translate([-100, -200, 0])
        cube([400, 200, 200]);

      rotate([0, 0, -a])
      translate([-300, -200, 0])
        cube([400, 200, 200]);
    }
  }
}

//translate([50, 50, 30])
//plant();
difference() {
  base();

  //Carve out patterns and such
  wall_pattern(2);

  rotate([0, 0, 90])
    wall_pattern(4);

  translate([100, 0, 0])
  rotate([0, 0, 90])
    wall_pattern(4);

  translate([-1, -1, 35])
    cube([102, 3, 2]);

  translate([-1, -1, 2])
     cube([102, 3, 2]);

  translate([98, 0, 35])
    cube([3, 400, 2]);

  translate([98, 0, 2])
    cube([3, 400, 2]);

  translate([-1, 0, 35])
    cube([3, 400, 2]);

  translate([-1, 0, 2])
    cube([3, 400, 2]);

//  translate([50, 150, 0])
//  ring(35, 0);
//
//  translate([50, 150, 0])
//  ring(2, 0);
//
//  translate([50, 150, 0])
//  ring(10, 10);
//
//  translate([50, 150, 0])
//  ring(18, 20);
//
//  translate([50, 150, 0])
//  ring(30, 10);
}



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

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Why is this causing OpenSCAD to lag and crash?

Peter Ragosch
Am Tue, 25 Dec 2018 08:56:53 -0500
schrieb Kevin Toppenberg <[hidden email]>:

> I just dropped this code into my OpenSCAD on my macMini, and it
> renders just fine.  There are the cool patterns all around the side.
> It only takes a few seconds to get going.
>
> Is there something to do to make it slow?
>
> Kevin
>
> On Mon, Dec 24, 2018 at 2:17 AM brenzo <[hidden email]>
> wrote:
>
> > I have an object I"m creating with patterns on the side.
> >
> > One thing I'd like to do is to continue the horizontal line around
> > the curved portion (render code this will be obvious).
> >
> > I've done this by creating a hollow cylinder, diffing it from some
> > cubes to retain only a portion of it, then subtracting that form my
> > overall shape.
> >
> > Somehow, though, I've made this into a computationally intensive
> > operation. Uncommenting one right will make OpenSCAD noticeably
> > slower. 2 will make it almost unusable. Uncommenting them all
> > causes it to crash on my machine.
> >
> > Rendering the rings alone causes no lag so it must be something to
> > do with using them in the difference() block.
> >
> > How can I do this differently to avoid this?
> >
> > //Block base.
> > module base() {
> >   difference() {
> >     union() {
> >       cube([100, 150, 40]);
> >       translate([50, 150, 0])
> >         cylinder(40, 50, 50);
> >     }
> >     translate([50, 150, 20])
> >       cylinder(60, 40, 40);
> >     translate([50, 50, 25])
> >       cylinder(20, 10.3, 10.7);
> >   }
> >
> > }
> >
> > //Make 1/4 of shape, mirror to complete.
> > module pattern() {
> >   module makepoly() {
> >     polygon([[-1, 10],
> >             [3, 10],
> >             [2, 7],
> >             [6, 7],
> >             [5, 4],
> >             [10, 4],
> >             [6, 0],
> >             [5, 0],
> >             [8, 3],
> >             [4, 3],
> >             [5, 6],
> >             [1, 6],
> >             [2, 9],
> >             [0, 9]]);
> >   }
> >
> >   //Mirrors child but leaves original in place.
> >   module copy_mirror(vec) {
> >     children();
> >     mirror(vec)
> >       children();
> >   }
> >
> >   //Make pattern 3D
> >   linear_extrude(2)
> >   copy_mirror([1, 0, 0])
> >   copy_mirror([0, 1, 0])
> >     makepoly();
> >
> >   linear_extrude(2)
> >   rotate([0, 0, 45])
> >     square(5, center=true);
> > }
> >
> > //Pattern on wall.
> > module wall_pattern(n) {
> >   for (i = [0:n])
> >     translate([18 + i * 32, 1, 0])
> >     scale([1.4, 1.4, 1.4])
> >     translate([0, 0, 14])
> >     rotate([90, 0, 0])
> >       pattern();
> > }
> >
> > //Continue ring around curved portion.
> > module ring(height, a) {
> >   difference() {
> >     //Form a hollow cylinder by diffing 2 clyinders.
> >     translate([0, 0, height])
> >     difference() {
> >       cylinder(2, 51, 51);
> >
> >       translate([0, 0, -1])
> >         cylinder(4, 48, 48);
> >     }
> >
> >     //Rotate cubes about z axis and diff, to create portion of
> > cylinder union() {
> >       rotate([0, 0, a])
> >       translate([-100, -200, 0])
> >         cube([400, 200, 200]);
> >
> >       rotate([0, 0, -a])
> >       translate([-300, -200, 0])
> >         cube([400, 200, 200]);
> >     }
> >   }
> > }
> >
> > //translate([50, 50, 30])
> > //plant();
> > difference() {
> >   base();
> >
> >   //Carve out patterns and such
> >   wall_pattern(2);
> >
> >   rotate([0, 0, 90])
> >     wall_pattern(4);
> >
> >   translate([100, 0, 0])
> >   rotate([0, 0, 90])
> >     wall_pattern(4);
> >
> >   translate([-1, -1, 35])
> >     cube([102, 3, 2]);
> >
> >   translate([-1, -1, 2])
> >      cube([102, 3, 2]);
> >
> >   translate([98, 0, 35])
> >     cube([3, 400, 2]);
> >
> >   translate([98, 0, 2])
> >     cube([3, 400, 2]);
> >
> >   translate([-1, 0, 35])
> >     cube([3, 400, 2]);
> >
> >   translate([-1, 0, 2])
> >     cube([3, 400, 2]);
> >
> > //  translate([50, 150, 0])
> > //  ring(35, 0);
> > //
> > //  translate([50, 150, 0])
> > //  ring(2, 0);
> > //
> > //  translate([50, 150, 0])
> > //  ring(10, 10);
> > //
> > //  translate([50, 150, 0])
> > //  ring(18, 20);
> > //
> > //  translate([50, 150, 0])
> > //  ring(30, 10);
> > }
> >
> >
> >
> > --
> > Sent from: http://forum.openscad.org/
> >
> > _______________________________________________
> > OpenSCAD mailing list
> > [hidden email]
> > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
> >  

Only a hint:

If the last four rings are not commented out, F5 and F6 will be
slowed down. May be the reason is based on the difference of base() and
the Carve out patterns. There, the rings should not only cut the
base(), which is build up using difference(), but also its child
cylinders. For doing that, the children() method seems to be needed
here.

I'm sorry, I can't give you an code example, because I'm very unfamiliar
with this method. But have a look at the documentation.

--
Mit freundlichen Grüßen
Best Regards

Peter Ragosch


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org