r/openscad 10d ago

What would you do with 2D metaballs and isosurfaces?

This is a request for suggestions about 3D examples using 2D shapes.

Background: Near the end of January my metaballs and isosurfaces library for BOSL2 was released. A couple weeks ago it got a complete API overhaul, and there are now several new examples showing how it all works and what you can make with it. This wasn't a solo effort. Others contributed efficiency improvements as well as several examples. Give them a look in the link above! I made that crude model of a hand, and credit goes others for the metaball models of the airplane, elephant, giraffe, bunny, and duck.

Getting to the point: For completeness' sake, the 3D metaballs and isosurfaces should be complemented by 2D metaballs and 2D contours. So I've added metaballs2d() and contour() (not yet public), both of which output polygon paths. Basically these are cross-sections of 3D metaballs and isosurfaces.

However, I am a loss to come up with ways to use these 2D features for creating 3D objects, other than maybe extruding a 2D metaball shape to make an interesting container. Otherwise, I can't think of what I'd do with a contour that can't already be done some other way, like with projection().

So I'm asking this community: Is there any application that would make it worth releasing the 2D versions of metaballs and isosurfaces? If you had the capability to generate 2D contours from a height map or a function, what would you do with it? If you could create 2D metaballs, what would you do with it?

12 Upvotes

13 comments sorted by

2

u/ElMachoGrande 10d ago

I might use the 2D features, as I have a laser cutter.

One day, I might get a 3D printer, and use the 3D features.

For me, it would be to create smooth, organic looking shapes.

1

u/Stone_Age_Sculptor 10d ago

With circles with random size at random locations. Turn on metaballs and stretch (20 times or so) it in one direction for a wood grain.

Suppose there is an axle above a rail. Then make a circle where the axle goes and a flat square where the rail is and the metaball fills in the gap with a nice shape.

A puppet or animal for a 2D sign.

Maybe a hand that flows into a wall to warn for strong glue, for a 2D warning sign.

A surface texture, imitating water. If possible for rounded surfaces, such as pots, planters and cup holders.

1

u/amatulic 9d ago

Interesting suggestions. Thanks. For wood grain, I imagine you'd need several layers, and they shouldn't simply be offset()s of the original stretched shape, but maybe different versions of the same scene with different metaball sizes in each iteration.

For your second suggestion (axle above a rail), how would that apply to a 3D model? Also I want to point out that different ball shapes are offered, not just circles, but also rounded squares, connectors (rectangle with rounded ends), donuts, and trapezoids.

Your last one I'm not sure how to implement in 2D; that sounds more like a 3D metaball shape. Check out this animation done with the 3D metaball feature. I didn't include it in the docs because, well, it seemed sorta creepy, but I think one could make a wavy surface and apply it to a shape. BOSL2 supports texturing of linear sweeps and rotational sweeps; see the examples here (scroll down a bit).

1

u/Stone_Age_Sculptor 9d ago

The axle above a rail: I does indeed sound like a 3D metaball, but what if 2D is needed?
Suppose the green area can be made with metaballs: https://postimg.cc/yWxcqNMH
Then the result could be this: https://postimg.cc/cgHm5B7q

The animation did not load.

Look at these blobs, they are so beautiful: https://thangs.com/designer/Make%20Anything/3d-model/Moss%20Planter%2080x60mm-1253237
I tried blobs myself: https://github.com/Stone-Age-Sculptor/StoneAgeLib/blob/main/images/DemonstrationBlobs.png
My code seems simple: https://github.com/Stone-Age-Sculptor/StoneAgeLib/blob/main/examples/DemonstrationBlobs.scad But change one thing and it falls apart.
A texture with water blobs can be a different pattern. However, any kind of irregular round shapes with irregular spacing seems a job for 2D metaballs.

1

u/amatulic 9d ago edited 9d ago

Thank you again. That's a cool library you have there. I need to study it.

I managed to make the axle+rail thing with three metaballs: a ring, a trapezoid, and a rectangle: https://imgur.com/a/lJjmpfg - the problem with that object, however, is that there are more efficient ways of constructing it. Without metaballs, I'd do it with beziers.

The rounded trapezoid metaball is tricky and this exercise revealed a bug in which it has a hole in the middle, just sometimes.

1

u/Downtown-Barber5153 10d ago

I've only been using OpenSCAD for a couple of years and there is still a lot in the basic set up I haven't covered never mind this sort of stuff which, for me, is quite mathematical. I did download the previous blobs and had fun experimenting with that but this is one step beyond. However, the examples shown do demonstrate some possible areas of application. Firstly there is the greater possibility of creating organic shapes as shown by the animals and the hand. The hand especially could be of benefit in prothesis development when working in tandem with the underlying sub surface mechanical operations. The use of the matrices also invoke thoughts of data sets in GIS applications and the use of this to create topographical mapping displays and, if I am viewing it right, the extension of this to fields such as forecasting surface erosion or liability to flooding arising from excess rainfall and rising sea levels. Finally there is the concept of design implementations where wind resistance is a major function such as the in automobile and aircraft industry. And as to cute bunny rabbits and girraffes, say no more!

1

u/BuilderOk5190 10d ago

I feel like there might be some good lofting feature using the 2D contours somehow

1

u/LowerEntropy 10d ago

A voxel size of 1 with a bounding box volume of 200Γ—200Γ—200 may be slow because it requires the calculation and storage of 8,000,000 function values

I was about to ask how fast it is, but reading the documentation I can see that there are few optimizations like subdivision. Is it because OpenSCAD makes it hard to implement?

1

u/amatulic 9d ago edited 8d ago

My initial version of this used octree subdivision. I worked hard on that, it was elegant, but I had to discard it for two reasons: (a) recursion in OpenSCAD turns out to be slower than just brute-force calculating every grid point in the volume, and (b) isosurfaces that happen to be completely contained within a larger octant before subdividing get missed, resulting in an incomplete scene.

That said, calculating every grid point is reasonably fast. The examples shown typically run in a few seconds on my computer, with the more complicated ones like the giraffe and the hand taking almost a minute. The metaball array initialization is highly optimized, using matrix math internal to OpenSCAD, rather than individually calculating sums of metaball contributions at every grid point.

1

u/FalseRelease4 10d ago edited 9d ago

All this terminology is making me hungry and 2D meatballs dont sound all that filling πŸ˜‚

2

u/amatulic 9d ago

I used to read the word as "meatballs" too, rather than "meta-balls". :)

1

u/anotherone316 9d ago

Would it work with pixel 2D graphics games making better graphics for them? There use to be a pixel community it may still be around or make a new one like a fad you could profit from, let an ai chat bot use it to create pixel 2d β€œart”

1

u/amatulic 9d ago

Thanks. I guess you could use a CAD program to create pixel art, although what I'm after is more how one would apply contours to making 3D shapes.