Path: blob/main/release-content/release-notes/ring_primitive.md
7223 views
------Ring / hollow shapes
There is a new generic primitive Ring, which takes as input any Primitive2d, with two instances of that primitive shape: the outer and the inner (or hollow). A Ring here is what an Annulus is to a Circle. This allows us to have (or at least approximate - more on that later) "hollow" shapes or "outlines".
How it works
The mesh for a RingMeshBuilder is constructed by concatenating the vertices of the outer and inner meshes, then walking the perimeter to join corresponding vertices like so:
Examples of generated meshes:
Extrusions
A Ring for a type that is Extrudable is also Extrudable.
Inset shapes
Some shapes can be "inset", that is, we can produce a smaller shape where the lines/curves/vertices are equidistant from the outer shape's when they share the same origin. This is represented by the Inset trait. Inset shapes give us nice "outlines" when combined with Ring, so for these shapes we provide a ToRing method that takes an inset distance.
The implementation of Inset can be unintuitive - have a look at the source at crates/bevy_math/src/primitives/inset.rs. For example, the inset CircularSegment in our implementation is actually constructed by shortening the radius and the angle.
Some shapes can't be represented by an inset: Ellipse for example doesn't implement Inset, because concentric ellipses do not have parallel lines.
If the ellipse is not a circle, the inset shape is not actually an ellipse (although it may look like one) but can also be a lens-like shape. The following image shows an ellipse in white and all points at a constant distance from that ellipse in blue. Neither of the blue shapes is an ellipse.
For the sake of flexibility, however, we don't require Ring shapes to be Inset.
Limitations
It's assumed that the inner and outer meshes have the same number of vertices.
It's currently assumed the vertex positions are well ordered (i.e. walking around the perimeter, without zig-zagging), otherwise it will result in incorrect geometries.
The outer_shape must contain the inner_shape for the generated meshes to be accurate. If there are vertices in the inner_shape that escape the outer_shape (for example, if the inner_shape is in fact larger), it may result in incorrect geometries.
Because the origin of the generated mesh matters when constructing a Ring, some "outline" shapes can't currently be easily represented.