# Adjustable rounded cube mesh generator

This has probably been asked before, but I couldn’t find anything in a search.

I need to devise a function to generate a rounded cube mesh of vertices and triangles that can output varied-degrees of roundness. Like this .

I’ve figured how to generate a rounded cylinder ( Example ), but a cube is more challenging. Any suggestions?

Are you looking for a general corner rounding (and by implication, re-tesselation) algorithm, or just trying to avoid writing arbitrary code to generate six faces, eight sphere eighths, and twelve quarter cylinders?

Can’t help with the former, and I’d be inclined toward a bit of research, too, faced with the latter

However, have a think about the following:

Test for 2r > l, length of cube side, which makes degeneracy easy to spot.
If degeneracy occurs, handle it as a special case.
Otherwise, make a sphere of radius r, by subdividing the triangles of an octahedron.
Then, translate the points that originate from each face of the octahedron by plus or minus (l-2r)/2 on each axis, with the sign being decided by the face of the octahedron that the point came from.
Then join the dots…

Why don’t you just use subdivision?
It doesn’t matter what shape the object is, all edges becomes smooth.

I can generate a standard cube with adjustable subdivision (ie. you can generate as many faces as you want). I’ve no idea how to turn it into a rounded cube however.

Could you maybe provide the formula to apply to each vertex, or perhaps some pseudo code?

i think Dat was talking about subdivision surfaces. that is an iterative algorithm which creates smooth transitions between a set of faces.

I don’t see how a subdivison algo would help me here - I want the shape to have the same level-of-detail at both 1.0 (straight cube) and 0 (sphere).

I can already generate a cube with adjustable level of detail: what I need now is a function to apply to each vertex to translate them so that final mesh is that of a rounded-cube at that parameter value.

Superquadrics can generate rounded boxes as well as many other shapes.

True, I considered Superquadratics, but in this case their must be a simpler way. If you use a superquadtric, you’ll get bunching of the vertices towards the rounded-corners which is not what I want; I need a even-distrubution of vertices along both edges and faces.

I generated a rounded-cylinder by producing a 2D profile and lathing it 360 degrees, but that wont work for a cube…

I did it interactively with Blender, making an UV sphere, extruding half the vertices along each of the 3 axes, and voilÃ . I didn’t get an equal distribution of the vertex density on the rounded corners however, they get dense near the poles of the original sphere.

And it works with an Icosphere, too. This way, one gets nearly equal distribution of vertices on the rounded corners. I imagine that it will be tricky to generate this mesh with a program.

Thanks, but importing a mesh from another prog is not an option in this case. I’m still investing superellipses.

I generated a rounded-cylinder by producing a 2D profile and lathing it 360 degrees, but that wont work for a cube…
Come on, you made the hardest part.
What is a rounded box actually ?

• 6 planes (ok)
• 8 times 1/8 of a sphere (each corner)
• 12 times 3/4 of a cylinder (each edge)

You just have to be careful to stitch all these together (share normals).

That’s too unwieldily. I must keep the vertex/poly count down. Plus it would mean generating only parts of objects. Also, vertices are shared.

One idea I’m playing with is to lathe my rounded-cylinder 2D profile by 90 degrees at the origin and then move it out to a corner of the cube, and then repeat the process for the other 3 corners. Then I’d ‘just’ have to generate the 6 flat faces and extrude the top-curve portion between the gaps.

You might have to read that again…

The superellipse still looks like the easiest solution.