Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commite8beb5604c

README.md

geometry.bevel

Round the sharp edges of a mesh. Every selected edge is replaced by a strip of segments quads that follows a circular arc tangent to both faces; the faces are trimmed back from the edge to make room, and what is left open where several bevelled edges meet is closed with a patch.

The mesh is triangulated and welded (core.weld, a merged point standing where its lowest-numbered point stood) at a millionth of the length of its longest side. Then:

  1. An edge is selected when exactly two faces meet along it and they turn by more than angle (the least that counts is a ten-thousandth of a radian), narrowed to the edges whose two ends are in group. Selecting no edge is refused, naming the sharpest turn the mesh has.
  2. One width serves the whole mesh: a face trimmed back by w from each of its bevelled sides keeps an area while the sum of w over the altitudes to those sides stays under 1, so the narrowest face sets the limit. maxWidth is 0.999 of it; a width past it is clamped to it, or refused when overflow is "error".
  3. Every corner of every triangle is pulled in to where the offset lines of its bevelled sides meet: along the side before it by the offset of the side after it, and along the side after it by the offset of the side before it, each over the sine of the corner's angle.
  4. Where a face's corner stopped short of its neighbour's along an unbevelled edge, the neighbour's side takes the farther corner as a point, and a face that took a point is a fan of triangles around the middle of its ring of points, so the two faces meet along the whole edge.
  5. At each end of a bevelled edge the strip runs along a circle of radius width times the cotangent of half the turn between the faces, tangent to both, from the first face's corner to the second's (segments - 1 points between them), and is cut into triangles wound the way the two faces are.
  6. The openings left where strips meet are found as the loops of open edges of the welded faces and strips (core.boundary); a loop of three edges closes with the one triangle its points make and a longer one with a triangle on each of its edges to a point at the middle of the loop.

The trimmed faces keep three points of their own each, on the normal of the face they came from. The strips and patches share the points they meet at. shading "flat" gives every bevel triangle points of its own on its face's normal; "smooth" shades the bevel as one surface; "auto" is flat at one segment and smooth above.

Inputs

  • geometry (Surface). The surface whose edges are rounded.
  • angle (Float, default 30, 0 to 180). The turn, in degrees, past which an edge is bevelled.
  • class (String, default "edge", one of "edge", "point", "primitive", "vertex"). The class group lives on.
  • group (String, default ""). An attribute naming the part of the surface whose edges are bevelled; an edge is in it when both of its ends are. Left empty, every sharp edge is bevelled.
  • overflow (String, default "clamp", one of "clamp", "error"). What a width past the widest the mesh admits does: "clamp" narrows it for the whole mesh, "error" refuses.
  • promote (String, default "all", one of "all", "any"). How a group on a class other than the point class reaches the points of an edge.
  • segments (Float, default 1, at least 1). Quads across a bevelled edge; 1 is a flat chamfer.
  • shading (String, default "auto", one of "auto", "flat", "smooth"). How the bevel is shaded, as described above.
  • threshold (Float, default 0.5). The value a group element has to exceed to be in the group.
  • width (Float, default 0.05, above 0). How far the bevel reaches onto each face.

Outputs

  • geometry (Geometry). The surface with its edges bevelled.
  • info (Data). bevelledEdges, pairedEdges (the edges with two faces), cornerPatches, width (used), requestedWidth, maxWidth, clamped, segments, vertexCount and triangleCount.
local rounded = g.geometry.bevel({ geometry = g.mesh.box({}), width = 0.1, segments = 3 })