Operator problem

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

Operator problem

j12t
The problem:
* sometimes I want to print something that’s larger than my printer’s print bed.
* if I print two parts, they need to have some kind of join beyond just gluing them together
* that’s a lot of work every time I have to do this.

Idea:
* I define an OpenSCAD “operator” module that can be applied to any kind of too-big-part, and splits it into two parts.
* Even better: I could define an entire library of such “cut” operators that split my part in different ways, such as with a clean edge, and various types of joins: rectangular, triangle, and various kinds of interlocks. One could get fancy if one could define those only once and reuse for any too-big-part.

State of the implementation:
* It’s beginning to work. Here are some examples: https://github.com/jernst/openscad-cuts/tree/master/examples
e.g.

Example part for testing: simply a cube:

    module MyPart() {
        translate( [ -50, 0, 0 ] ) {
            cube( [ 100, 100, 5 ] );
        }
    }

Now I’m applying one of my operators (it creates a comb-like join):

    Combs() {
        MyPart();
    }

and I get a left and a right part, split by the x=0 plane, with some offset, and using a “comb” pattern to connect the left and the right part.

So far so good. But my implementation is not as neat as I would like. If you look at the Combs module: https://github.com/jernst/openscad-cuts/blob/master/cuts/comb.scad , you see that I am repeating the two “cube” statements for both the Right and the Left part.

    module Combs( … ) {
        Right( ... ) {
            cube( [ insert+play, step+2*play, height ] );
            cube( [ insert-play, step-2*play, height ] );
            children();
        };
        …
        Left( … ) {
            cube( [ insert+play, step+2*play, height ] );
            cube( [ insert-play, step-2*play, height ] );
            children();
        }
    }

These three items: two cubes and children() are passed to the Left and the Right module, which extract them:
* child 1 and child 2 are used as the pattern for the cut
* child 3 is the part to be cut

I was thinking I should be able to do something like this, declaring the two cubes only once and reusing them via children():

    module Combs2( ... ) {
        LeftRight( ... ) {
            cube( [ insert+play, step+2*play, height ] );
            cube( [ insert-play, step-2*play, height ] );
            children();
        };
    };

    module LeftRight( ... ) {
        translate( [ apart, 0, 0 ] )
        Right( ... )
        children();

        translate( [ -apart, 0, 0 ] )
        Left( ... )
        children();
    };

but somehow the children() aren’t making it down over multiple levels.

What am I doing wrong?

Thanks,



Johannes.


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

Re: Operator problem

Tim V. Shaporev
https://www.thingiverse.com/thing:35834 ?

On 3/28/2019 6:30 AM, Johannes Ernst wrote:

> The problem:
> * sometimes I want to print something that’s larger than my printer’s print bed.
> * if I print two parts, they need to have some kind of join beyond just gluing them together
> * that’s a lot of work every time I have to do this.
>
> Idea:
> * I define an OpenSCAD “operator” module that can be applied to any kind of too-big-part, and splits it into two parts.
> * Even better: I could define an entire library of such “cut” operators that split my part in different ways, such as with a clean edge, and various types of joins: rectangular, triangle, and various kinds of interlocks. One could get fancy if one could define those only once and reuse for any too-big-part.
>
> State of the implementation:
> * It’s beginning to work. Here are some examples: https://github.com/jernst/openscad-cuts/tree/master/examples
> e.g.
>
> Example part for testing: simply a cube:
>
>      module MyPart() {
>          translate( [ -50, 0, 0 ] ) {
>              cube( [ 100, 100, 5 ] );
>          }
>      }
>
> Now I’m applying one of my operators (it creates a comb-like join):
>
>      Combs() {
>          MyPart();
>      }
>
> and I get a left and a right part, split by the x=0 plane, with some offset, and using a “comb” pattern to connect the left and the right part.
>
> So far so good. But my implementation is not as neat as I would like. If you look at the Combs module: https://github.com/jernst/openscad-cuts/blob/master/cuts/comb.scad , you see that I am repeating the two “cube” statements for both the Right and the Left part.
>
>      module Combs( … ) {
>          Right( ... ) {
>              cube( [ insert+play, step+2*play, height ] );
>              cube( [ insert-play, step-2*play, height ] );
>              children();
>          };
>          …
>          Left( … ) {
>              cube( [ insert+play, step+2*play, height ] );
>              cube( [ insert-play, step-2*play, height ] );
>              children();
>          }
>      }
>
> These three items: two cubes and children() are passed to the Left and the Right module, which extract them:
> * child 1 and child 2 are used as the pattern for the cut
> * child 3 is the part to be cut
>
> I was thinking I should be able to do something like this, declaring the two cubes only once and reusing them via children():
>
>      module Combs2( ... ) {
>          LeftRight( ... ) {
>              cube( [ insert+play, step+2*play, height ] );
>              cube( [ insert-play, step-2*play, height ] );
>              children();
>          };
>      };
>
>      module LeftRight( ... ) {
>          translate( [ apart, 0, 0 ] )
>          Right( ... )
>          children();
>
>          translate( [ -apart, 0, 0 ] )
>          Left( ... )
>          children();
>      };
>
> but somehow the children() aren’t making it down over multiple levels.
>
> What am I doing wrong?
>
> Thanks,
>
>
>
> Johannes.
>
>
> _______________________________________________
> 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: Operator problem

j12t
> On Mar 28, 2019, at 4:40, Tim V. Shaporev <[hidden email]> wrote:
>
> https://www.thingiverse.com/thing:35834 ?

This is cool, and might solve my bigger problem better than I would have. Thanks!

However, my post was mostly about: how do I get OpenSCAD to do what I want it to do? How do I correctly pass children() over multiple levels?

Cheers,



Johannes.


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

Re: Operator problem

adrianv
What you're trying to do is (currently) impossible.  Modules can return only
one child up to the calling module.   It will be the union of all the
children if you don't use some other operator to combine them in a different
way.  



--
Sent from: http://forum.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: Operator problem

j12t
Darn!

(Perhaps the operator idea could benefit from some inspiration from some other (software) languages that have comparable notions. None have something like children() that I’m aware of…)

P.S. Thanks.

> On Mar 28, 2019, at 13:43, adrianv <[hidden email]> wrote:
>
> What you're trying to do is (currently) impossible.  Modules can return only
> one child up to the calling module.   It will be the union of all the
> children if you don't use some other operator to combine them in a different
> way.  
>
>
>
> --
> 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: Operator problem

JordanBrown
In reply to this post by adrianv
On 3/28/2019 1:43 PM, adrianv wrote:
What you're trying to do is (currently) impossible.  Modules can return only
one child up to the calling module.   It will be the union of all the
children if you don't use some other operator to combine them in a different
way.  


And in particular this seems to apply to the children() module-like-thing.
module i() {
    intersection()
        children();
}
i() {
    cube(1,center=true);
    sphere(.6,$fn=20);
}
yields the union of the cube and the sphere, not the intersection.

However, going back to the original problem:
* child 1 and child 2 are used as the pattern for the cut
* child 3 is the part to be cut
...
    module Combs2( ... ) {
        LeftRight( ... ) {
            cube( [ insert+play, step+2*play, height ] );
            cube( [ insert-play, step-2*play, height ] );
            children();
        };
    };

    module LeftRight( ... ) {
        translate( [ apart, 0, 0 ] )
        Right( ... )
        children();

        translate( [ -apart, 0, 0 ] )
        Left( ... )
        children();
    };

The problem is that children() is implicitly unioning the children.  But if you pass them separately it should be OK:

    module Combs2( ... ) {
        LeftRight( ... ) {
            cube( [ insert+play, step+2*play, height ] );
            cube( [ insert-play, step-2*play, height ] );
            children();
        };
    };

    module LeftRight( ... ) {
        translate( [ apart, 0, 0 ] )
        Right( ... ) {
            children(0);
            children(1);
            children(2);
        }
        translate( [ -apart, 0, 0 ] )
        Left( ... ) {
            children(0);
            children(1);
            children(2);
        }
    };


And indeed my intersection example works right if I do it like so:

module i() {
    intersection() {
        children(0);
        children(1);
    }
}
i() {
    cube(1,center=true);
    sphere(.6,$fn=20);
}

Note that if you want to collect up all of the children after the first two you can use children([2:$children-1]).  (But they'll be implicitly unioned.)




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

debug modifier flicker

boxcarmib
I don’t know if it’s RC4 or the result of my recent upgrade to macOS 10.14.4 but even the simplest program using the debug modifier ‘#’ now displays the selected object in a flickering pink.
I don’t know if it's a feature or a bug, and perhaps only relevant to the Mac.
Anyway, here’s a short program that reveals the problem … at least on my machine… just wondering if anyone else is experiencing it as well…


        difference() {
                cube([22,14,4], center = true);
# translate([0, 2,0])
                        cube([14, 7, 8], center = true);
        }


NOTE: the window has to be in focus for the flicker to reveal itself.


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