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?
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.
Sign up to join this communityI 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...
Reproducing the modifier in geometry nodes is trivial:
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...
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).
Reversing the offset was stupid. After normalization the sphere's radius (and so bevel width) is $1$, so:
or to allow for a cuboid:
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 ;)
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:
Create a cube and extrude the faces.
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.
Then instantiate the "spheres" at the vertices of your cube and merge the previously extruded shape with these instantiated objects.
Finally, use the Convex Hull
node, which turns the outer hull of all objects into a new mesh.
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: