# 3D bubble textures in Bread (and other solids)

Bread has a bubbly texture that I would like to be able to recreate using Mathematica.

Here are some examples of bubble textures:

• Swiss cheese

• Foam

Note that most of the bubbles are ellipsoids or more complex 3D forms (only 'isolated' bubbles in the second case are approximately spherical). Bubbles generally do not intersect but are deformable by each other (and by the original 'pre-cut' boundary of the object - e.g. in the case of bread). Closely spaced bubbles approach polyhedrons with a minimum curvature at the 'vertices' (like 3D Voronoi texture).

I can generate a bunch of spheres intersecting a cube easily using something like:

Graphics3D[{Cuboid[{-2, -2, -5}, {8, 10, 10}],
Sphere[RandomReal[10, {500, 3}], RandomReal[{0.1, 1}]]}]


But I can't see how to variably change their shape or allow them to deform without intersecting. Ultimately I'm looking to make bubbles that are deformed by each other and the 'pre-cut' boundary of the solid. I am thinking that one way to visualise this would be generate the bubbles (for example, within a 'pre-cut loaf' shape) and combining this with a surface slice using ParametricPlot3D to end up with something like this:

(but with nice bubbles inside!)

I realise that it may be non-trivial to work out how the bubbles deform...

Also, it would be nice to be able to add colours and 2D textures to the different surfaces to, for example, brown the crust, add wholemeal flakes etc.

How would one go about creating a semi-realistic bubble texture intersecting a 3D surface and/or volume?

(P.S - Not entirely relevant but there are some inspiring forms here and here)

-
I gave it a college try almost a year ago. Perhaps it's time to revisit this... – J. M. Jun 4 '13 at 4:28
@J. M. shuffles feet nervously, your answer to that question may have been a tiny inspiration for this question... :} That said, I am explicitly looking for 3D bubbles that cut the surface not 2D approximations painted on a surface. – geordie Jun 4 '13 at 4:53
Apart from Perlin noise, I also played a bit with Voronoi, but the bubbles looked a tad too unnatural... – J. M. Jun 4 '13 at 4:58
I guess one way to visualise it is that the spheres sit within variably sized Voronoi cells and only deform when they approach the margin of the cell... – geordie Jun 4 '13 at 5:54
ExampleData[{"TestImage3D", "CTengine"}] – Rojo Jun 6 '13 at 15:46

Here's a rather simple first attempt using RegionPlot3D to define a solid with Voronoi cell type voids.

I start with a set of random void locations. The region function says that a point is in the solid if the distance to the nearest void centre is almost the same as the distance to the second nearest void centre (i.e. we are close to a Voronoi cell boundary), or if the distance to the nearest void centre is greater than some threshold.

pts = RandomReal[{-1, 1}, {200, 3}];
nf = Nearest[pts];

r[x_, y_, z_] := Module[{d1, d2},
{d1, d2} = EuclideanDistance[{x, y, z}, #] & /@ nf[{x, y, z}, 2];
d1 > 0.3 || d2 - d1 < 0.05]

RegionPlot3D[r[x, y, z], {x, -1, 1}, {y, -1, 1}, {z, -1, 1},
Mesh -> None, Boxed -> False, Axes -> False, BoxRatios -> Automatic, PlotPoints -> 50]


While being some way from resembling bread, I think with some tweaking one could make an acceptable Swiss cheese using this approach.

-
+1. Very nice. Probably to get bread one would have to model the tension in the dough. – Michael E2 Jun 4 '13 at 16:02