13
$\begingroup$

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

enter image description here

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

Any ideas?

$\endgroup$

2 Answers 2

14
+200
$\begingroup$

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 ;)

$\endgroup$
5
  • 2
    $\begingroup$ This is incredibly great, brilliant approach to the solution! I am very excited to see the finished answer, because it definitely deserves a star! $\endgroup$ May 21 at 15:43
  • 5
    $\begingroup$ ... a gold star, and I'll polish it for you. :) $\endgroup$ May 21 at 18:23
  • 1
    $\begingroup$ just....amazing $\endgroup$
    – Chris
    Jun 16 at 19:17
  • 1
    $\begingroup$ 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). $\endgroup$ Jun 20 at 11:13
  • $\begingroup$ @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. ;-) $\endgroup$ Jun 20 at 22:30
14
$\begingroup$

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.

    Bevel the edges of a cube with geometry nodes - Screen 1

  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.

    Bevel the edges of a cube with geometry nodes - Screen 2

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

    Bevel the edges of a cube with geometry nodes - Screen 3

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

    Bevel the edges of a cube with geometry nodes - Screen 4

  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.

    Bevel the edges of a cube with geometry nodes - Screen 5

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

Bevel the edges of a cube with geometry nodes - Nodes


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

Bevel the edges of a cube with geometry nodes (Simple) - Screen 1

Bevel the edges of a cube with geometry nodes (Simple) - Nodes

$\endgroup$
1
  • 2
    $\begingroup$ great work! +1 so we need a tris to quad and a quad to tris node, we need bevel node and a decimate node ;) $\endgroup$
    – Chris
    May 21 at 6:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.