Adrian Lopez
Adrian Lopez

Reputation: 1853

Algorithm to produce rounded edges and corners in a 3D mesh

Starting with a 3D mesh, how would you give a rounded appearance to the edges and corners between the polygons of that mesh?


Without wishing to discourage other approaches, here's how I'm currently approaching the problem:

Given the mesh for a regular polyhedron, I can give the mesh's edges a rounded appearance by scaling each polygon along its plane and connecting the edges using cylinder segments such that each cylinder is tangent to each polygon where it meets that polygon.

Here's an example involving a cube:

Cube

Here's the cube after scaling its polygons:

Cube after scaling polygons

Here's the cube after connecting the polygons' edges using cylinders:

Cube with rounded edges

What I'm having trouble with is figuring out how to deal with the corners between polygons, especially in cases where more than three edges meet at each corner. I'd also like an algorithm that works for all closed polyhedra instead of just those that are regular.

Upvotes: 5

Views: 6671

Answers (6)

Fedor
Fedor

Reputation: 21307

The general solution to producing rounded corners in place of convex sharp edges (as in the cube) in mesh with given radius R of rounding is to perform two offset operations:

  1. The first offset is done inside with the value R
  2. And the second offset - outside with the same radius R

Typically offset is implemented by first filling voxel grid with signed distance field values from the input mesh with positive distances outside and negative distances inside. And then offset mesh is extracted from voxel volume as a iso-surface using algorithms like Marching Cubes or similar. Offset outside is get by using positive iso-value, and offset inside - by negative iso-value.

More about offsetting and existing implementations can be read in How can I offset / thicken / solidify a 3D mesh in Python?

If offset is implemented via intermediate conversion in voxel's representation, then at the end one can run mesh simplification (or decimation) to replace too small mesh elements with larger ones.

Consider cube example with the length of edges 1 and R=0.2. Here input cube is semi-transparent to show the result of inside offset as well (which is also a cube with edges 1-2*0.2=0.6): inside offset

And here are both input semi-transparent cube, and the final result with rounded corners in blue: rounded mesh

Mesh wireframe of the result after automatic decimation: mesh of rounded cube

(the images were prepared in MeshInspector)

Upvotes: 0

FabienRohrer
FabienRohrer

Reputation: 1834

As @Raymond suggests, I also think that the nepluno repo provides a very good implementation to solve this issue; efficient and simple.

To complete his answer, I just wrote a solution to this issue in JS, based on the BabylonJS 3D engine. This solution can be found here, and can be quite easily replaced by another 3D engine:

https://playground.babylonjs.com/#AY7B23

Upvotes: 1

Stefan
Stefan

Reputation: 4317

I post this as an answer because I can't put images into comments.

Sattle point

Here's an image of two brothers camping:

sattlepoint

They placed their simple tents right beside each other in the middle of a steep walley (that's one bad place for tents, but thats not the point), so one end of each tent points upwards. At the point where the four squares meet you have a sattle point. The two edges on top of each tent can be rounded normally as well as the two downward edges. But at the sattle point you have different curvature in both directions and therefore its not possible to use a sphere. This rules out Svante's solution.

Selfintersection

The following image shows some 3D polygons if viewed from the side. Its some sharp thing with a hole drilled into it from the other side. The left image shows it before, the right after rounding.

alt text .

The mass thats get removed from the sharp edge containts the end of the drill hole.

There is someething else to see here. The drill holes sides might be very large polygons (lets say it's not a hole but a slit). Still you only get small radii at the top. you can't just scale your polygons, you have to take into account the neighboring polygon.

Convexity

You say you're only removing mass, this is only true if your geometry is convex. Look at the image you posted. But now assume that the viewer is inside the volume. The radii turn away from you and therefore add mass.

NURBS

I'm not a nurbs specialist my self. But the constraints would look something like this: The corners of the nurbs patch must be at the same position as the corners of the scaled-down polygons. The normal vectors of the nurb surface at the corners must be equal to the normal of the polygon. This should be sufficent to gurarantee that the nurb edge will be a straight line following the polygon edge. The normals also ensure that no visible edges will result at the border between polygon and nurbs patch.

I'd just do the math myself. nurbs are just polygons. You'll have some unknown coefficients and your constraints. This gives you a system of equations (often linear) that you can solve.

Upvotes: 2

Raymond
Raymond

Reputation: 41

Here we have a single C++ header for generating triangulated rounded 3D boxes. The code is in C++ but also easy to transplant to other coding languages. Also it's easy to be modified for other primitives like quads.

https://github.com/nepluno/RoundCornerBox

Upvotes: 1

Svante
Svante

Reputation: 51501

Extrapolating your cylinder-edge approach, the corners should be spheres, resp. sphere segments, that have the same radius as the cylinders meeting there and the centre at the intersection of the cylinders' axes.

Upvotes: 1

shuhalo
shuhalo

Reputation: 6462

Is there any upper bound on the number of faces, that meet at that corner?

You might you might employ concepts from CAGD, especially Non-Uniform Rational B-Splines (NURBS) might be of interest for you.

Your current approach - glueing some fixed geometrical primitives might be too inflexible to solve the problem. NURBS require some mathematical work to get used to, but might be more suitable for your needs.

Upvotes: 1

Related Questions