# How can I bevel the edges of a cube with geometry nodes?

I would like to use Geometry Nodes to add beveled edges to a cube, exactly (!) like the modifier Bevel would do.

I am interested in reconstructing the effect as detailed as possible.

Any ideas?

Since you're creating a new cube, it makes the problem simpler, as you can easily create a desired topology when creating a new cube (subdivision has limitations). And since you're using default profile, the problem comes down to casting a cube to a sphere...

1. First squeeze middle faces (those that are supposed to be flat and that visually are the original geometry remaining after beveling) to 0:

1. Now cast to a sphere: (shader shows distance to origin)

Reproducing the modifier in geometry nodes is trivial:

1. Finally reverse the move towards 0 offset from p. 1. This could be done by capturing the attribute before Set Position node, and saving it on geometry, but instead, let's do it all in a single node tree, with a single Set Position:

The shader below is Normal -> Vector Math: Snap to 0.999×3 to show only normals aligned with axes:

So that's it, a beveled cube. It might not seem like it, it might look more like a sphere (in fact it's almost a perfect sphere), but that's because the bevel width is very high, you can decrease it, by multiplying the last step. Normalizing the resulting shape is easy with dividing the coordinates by range...

## Spacing the edges correctly

How to ensure bevel segments of equal width? Working backwards, knowing where the vertices are going to end (on a sphere, on the diagram where the orange dotted lines $$\color{#D60}{·····}$$ and blue dashed lines $${\color{#44D}{---}}$$ meet), calculate where they have to be before normalization - that's where the green arrows $$\color{#080}{→}$$ point:

So the angle increments are constant: $$\color{#B00}{∡}α = {{45°}\over{\mathrm{resolution}-1}}$$

It's the horizontal increment that is variable and needs to be calculated. It's sine, but we don't know the ("radius") multiplier.

Positions of those arrows could be discovered with raycasting, but obviously a math solution is faster. Calculate the $$\cos(α)$$, then the reciprocal $$1\over{\cos(α)}$$ is the "radius". Let's try it:

The function works: $${1\over\cos(α)}\times\sin(α)$$ which btw is just $$\tan(α)$$ (reinventing the wheel again).

## Correct Bevel Width

Reversing the offset was stupid. After normalization the sphere's radius (and so bevel width) is $$1$$, so:

• multiply the coords by bevel %, and then offset them by (1 - bevel%)*sign to get a normalized beveled cube, then scale to the desired size;

or to allow for a cuboid:

• multiply the coords by bevel width (not percent), then offset them by (axis size - bevel width)*sign

I chose the first solution, since the question asks for a cube:

White cube is mine, black is the vanilla Bevel modifier. The z-fighting shows the edges are great, but the corners are clearly not-so-great ;)

• This is incredibly great, brilliant approach to the solution! I am very excited to see the finished answer, because it definitely deserves a star! Commented May 21, 2022 at 15:43
• ... a gold star, and I'll polish it for you. :) Commented May 21, 2022 at 18:23
• just....amazing Commented Jun 16, 2022 at 19:17
• Thanks for the reward, @RobinBetts! I've been looking into improving the corners, but it seems the procedural nature of the intersection grid fill Blender does is hard to reproduce mathematically (I didn't investigate the source code, though). Commented Jun 20, 2022 at 11:13
• @MarkusvonBroady ...that's exactly what I meant, it's really not an easy task. I have now also come to take a closer look at your solution, and still find it ingenious! I am very curious if you manage to solve the puzzle completely. ;-) Commented Jun 20, 2022 at 22:30

An exact reconstruction would probably require studying the source code, as well as a myriad of nodes.

Therefore, there can really only be one approximation to the optimal reconstruction.

Here's how I would do it:

1. Create a cube and extrude the faces.

2. Then create another cube, in the size of your beveled edge, and apply the node Subdivision Surface.

This will give you a (relatively accurately) mesh for the corners.

However, applying Subdivision Surface also made the mesh a little smaller, so capture the size of the result and scale the mesh again to match the specified radius of the beveled edge.

Unfortunately, the node doesn't really produce a sphere either, so I additionally bring the individual points to the radius of a sphere here.

3. Then instantiate the "spheres" at the vertices of your cube and merge the previously extruded shape with these instantiated objects.

4. Finally, use the Convex Hull node, which turns the outer hull of all objects into a new mesh.

5. Since this method triangulates the mesh at the corners, I have to use the modifier Decimate to convert these triangulated faces back into quads.

Except for this last step, this produces a similar result as the modifier with Geometry Nodes only. Similar and not the same, because I did not reproduce the algorithm here, but only used similar shapes.

On the left is the result created with Geometry Nodes, on the right a cube with the Bevel modifier.

However, if you want to keep it simple, you can directly apply the node Convex Hull to the cube with the extruded faces:

• great work! +1 so we need a tris to quad and a quad to tris node, we need bevel node and a decimate node ;) Commented May 21, 2022 at 6:42