Functional OpenSCAD, working with vertex data

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Functional OpenSCAD, working with vertex data

thehans
I've been working on a library that re-implements OpenSCAD's builtin
modules as functions that basically operate on vectors of 2D and 3D
point data.

Its now at a point where I feel its usable and accurate enough to
share, so I made an initial commit here:
https://github.com/thehans/FunctionalOpenSCAD/blob/master/functional.scad

Building the geometry from the bottom up like this makes it possible
for all kinds of computations performed over geometry that would
otherwise require modifying OpenSCAD's own source code.
For example the library contains a "bounds" function for computing the
bounding box on a shape or list of shapes.
Another potential function (not yet written) would be computing the
volume of a solid.

I added some documentation in the file's comments, but it could
probably use more improvement.
I've had my head in this for a while, so I'm not sure if I'm glossing
over any non-obvious aspects of what's going on here.

I think it can potentially be pretty powerful for certain cases where
OpenSCAD's programming interface is otherwise limiting in some way.

I'm curious what others on the list think of this.  Suggestions are welcome.

Hans

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

Re: Functional OpenSCAD, working with vertex data

MichaelAtOz
Administrator
Interesting. Any feeling on performance v's builtins?
Admin - PM me if you need anything,
or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Functional OpenSCAD, working with vertex data

MichaelAtOz
Administrator
// OpenSCAD Modules not (yet) implemented as Functions
& text()
;)
Admin - PM me if you need anything,
or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Functional OpenSCAD, working with vertex data

Neon22
In reply to this post by thehans
That is pretty darn cool.
No changes to the language - results are in poly or polyhedron form.
well done sir !!!

Now if we could get the sweeps and lofts incorporated into this same model that will be fantastic.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Functional OpenSCAD, working with vertex data

TLC123
In reply to this post by thehans
Very nice.
Subdivision and tesselletions?
Domain warps?  
Be ware of self intersections though.  

 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Functional OpenSCAD, working with vertex data

Parkinbot
In reply to this post by thehans
A very nice and consequent step into the right direction. However, OpenSCAD gains most of its power from its Boolean operations. At most you could offer some lazy union and bounding box calculations for "intended" Boolean operations but not more.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Functional OpenSCAD, working with vertex data

thehans
In reply to this post by MichaelAtOz
On Wed, Apr 5, 2017 at 1:31 AM, MichaelAtOz <[hidden email]> wrote:
> Interesting. Any feeling on performance v's builtins?
Haven't done a ton of testing.  Things like sphere take a little
longer to process when initially hitting f5, but the actual framerate
of previewing them should be nearly the same.

In general I would expect slightly worse performance if for example
translating an existing script to a functional version, one-to-one for
every operation.  The advantage comes when you use some of the
features to generate a shape in an alternate way.  For example one
enhancement I made was supporting radius on squares.  Internally it
concatenates 4 90-degree arc paths, which isn't directly comparable to
any builtin modules.  I did a little bit of comparing this with other
methods of generating rounded squares (hull of 4 circles, etc.) and it
was the fastest of the methods I tested.

On Wed, Apr 5, 2017 at 1:34 AM, MichaelAtOz <[hidden email]> wrote:
> & text()
> ;)

Yeah I didn't put text since I consider that completely out of the
question. Its not possible to open files to read font definitions or
any other lower level font api that would give vertex data.  Even if I
could read files, i'm not particularly interested in implementing my
own truetype library or whatever it is that would be needed.

The other ones listed I could see maybe being feasible, but will
require some more research on my part as to what algorithms to use and
how to shoehorn them into the openscad language.

On Wed, Apr 5, 2017 at 9:21 AM, TLC123 <[hidden email]> wrote:
> Very nice.
> Subdivision and tesselletions?
> Domain warps?
> Be ware of self intersections though.

I haven't looked into the others, but subdivision is definitely a
possibility!  I developed some alternative sphere implementations
shortly before releasing this functional library:
https://gist.github.com/thehans/052129033443d8a8c14ac1e69b42e8da

At the bottom of the file is a subdivision function that is used for
generating the icosahedron based sphere.
I think I will add these to the repo soon, I just need to rewrite some
of the functions to be consistent with the interface conventions of
the rest of the library.

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

Re: Functional OpenSCAD, working with vertex data

Ronaldo
In reply to this post by thehans
It is a nice initiative towards filling a gap in the OpenSCAD arsenal: the access of vertex and face data. But it is unlikely that someone comes to write codes to the missing boolean , convex hull and minkowski operators of the library. So, IMO, the library value would be as test bed for the development of functions and operators demanding geometry inquires (like volume, centroid and non-linear operators) and as a good source for beginners learning.

There are proposals to fill that gap without any significant language change (#1324 and #1585) but it seems they have been postponed.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Functional OpenSCAD, working with vertex data

thehans
In reply to this post by Parkinbot
On Wed, Apr 5, 2017 at 10:28 AM, Parkinbot <[hidden email]> wrote:
> A very nice and consequent step into the right direction. However, OpenSCAD
> gains most of its power from its Boolean operations. At most you could offer
> some lazy union and bounding box calculations for "intended" Boolean
> operations but not more.

I think it should be theoretically possible to perform boolean
operations directly on the vertex/face data from within openscad.
They are definitely going to be some of the more involved code
compared with the other functions, that is why I put them off for some
of the last things to attempt.

I would probably try to replicate the simplest implementation that
I've seen which is this: http://evanw.github.io/csg.js/docs/
That code was the basis for the original OpenJSCAD code.  It actually
makes it look not so bad, though translating some of these functions
into openscad might prove difficult.  I'm not sure as I haven't yet
attempted it.

Wouldn't it be something if it could be done faster than the current
CGAL implementation?  :P
I'd give it 50% odds of being faster, assuming it gets written.

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

Re: Functional OpenSCAD, working with vertex data

thehans
I just added some more files to the repo.

The alternative_spheres and subdivision I had mentioned in a previous
post and those might have some niche uses, but double_fillet.scad is
one that I think is quite versatile and applicable to a wide range of
designs.
It creates a 2d path for a smooth transition between two heights by
having a top radius and bottom radius, and calculating the line
tangent to both for the slope in between the radii.
Then you can linear_extrude this 2d shape to create a sort of ledge on
a part, or rotate extrude to create a mound, protrusion, knob, and
even shapes roughly resembling a mushroom cloud!

If you load the double_fillet.scad file in OpenSCAD, you can view an
animated example of some of the possibilities with different
combinations of radii and offsets.

Or watch this short video animation:
https://photos.google.com/share/AF1QipPO5TCMSigJob_mThznq7jmtVjRaA_dSE-_LTLx76KZnfHrLHYEYpivonuTdGaWDQ?key=QzkwX2l2QUtmVXdpWjU3Q05SLW5DNUpFY29YSUJB

I've been developing some of these functions and ideas gradually over
time as I design new parts that need particular difficult features,
etc.  And I think the most powerful concept I've taken away from it is
a fairly simple one:  The creation of 2d paths, building them up by
concatenating lists of points and arcs, can be used to make really
nice designs with smooth fillets, and does so quite efficiently.
Every arc that can be placed as part of a 2d path before its extruded
is at least one less boolean operation required to make that shape.
At its heart the double fillet is just two arcs on a path.

Another example is this endstop mount design which I'm quite proud of:
  http://www.thingiverse.com/thing:2204123
In the scad for that, there is a module to create the "base_profile"
which is a fairly complex 2d shape that would have otherwise used
quite a lot of boolean operations.
All it is, is a bunch of arcs concatenated together (in the script the
function is called arcPath, I've since shortened it to just "arc" in
functional.scad )

http://i.imgur.com/FKqiiNr.png




On Wed, Apr 5, 2017 at 1:31 PM, Hans L <[hidden email]> wrote:

> On Wed, Apr 5, 2017 at 10:28 AM, Parkinbot <[hidden email]> wrote:
>> A very nice and consequent step into the right direction. However, OpenSCAD
>> gains most of its power from its Boolean operations. At most you could offer
>> some lazy union and bounding box calculations for "intended" Boolean
>> operations but not more.
>
> I think it should be theoretically possible to perform boolean
> operations directly on the vertex/face data from within openscad.
> They are definitely going to be some of the more involved code
> compared with the other functions, that is why I put them off for some
> of the last things to attempt.
>
> I would probably try to replicate the simplest implementation that
> I've seen which is this: http://evanw.github.io/csg.js/docs/
> That code was the basis for the original OpenJSCAD code.  It actually
> makes it look not so bad, though translating some of these functions
> into openscad might prove difficult.  I'm not sure as I haven't yet
> attempted it.
>
> Wouldn't it be something if it could be done faster than the current
> CGAL implementation?  :P
> I'd give it 50% odds of being faster, assuming it gets written.

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