Native Bézier Curve & Path Rendering Support in Bevy
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## **What problem does this solve?**
Bevy **lacks native support** for rendering Bézier curves and paths, making procedural graphics like **L-Systems, plant growth, and vector-based 2D rendering** more difficult without extra dependencies.
Currently, users must:
- **Manually calculate Bézier points** and generate meshes.
- **Use `bevy_prototype_lyon`**, a third-party crate that isn't officially part of Bevy.
- **Rely on Bevy’s Gizmos**, which are debugging tools, not real rendering solutions.
While Bevy provides `CubicBezier` in `bevy_math::cubic_splines`, it **only supports calculations, not rendering**.
---
## **What solution would you like?**
- Introduce a **native Bézier curve API**, similar to `PathBuilder::cubic_bezier_to()`from [`bevy_prototype_lyon`](https://github.com/Nilirad/bevy_prototype_lyon) .
- Expand Bevy’s **2D rendering** to support **paths, strokes, and fills** (including Bézier curves and polylines).
- Add stroke customization (**thickness, joins, caps**).
- Optimize Bézier rendering for **performance**, avoiding manual mesh generation.
- Expose **quadratic and cubic Bézier curves** directly in Bevy’s `Mesh` system.
---
## **What alternatives have you considered?**
- **Bevy’s `CubicBezier` struct**: Good for math but **doesn’t render curves**.
- **Manual Mesh Generation**: Inefficient for dynamic paths.
- **Using `bevy_prototype_lyon`**:
- Already provides **cubic Bézier rendering via `PathBuilder::cubic_bezier_to()`**.
- **Proves** this is possible, but it’s **not part of Bevy’s roadmap**.
- Adds an **external dependency**, which native support could eliminate.
- **Bevy’s `cubic_splines` Example**:
- Uses `Gizmos` to debug curve points but **doesn’t actually render Béziers**.
- **No stroke customization, no fills, no dynamic paths**.
---
## **Additional Context**
- `main.rs` basic code linked showing prototype lyon capabilities. requires `bevy = "0.15"` and `bevy_prototype_lyon = "0.13"`. (Output Image Linked Below)
- **Godot and Unity** have built-in Bézier curve and vector path rendering.
- **Procedural generation, UI elements, and physics simulations** all benefit from Bézier support.
- **Lyon already handles Bézier rendering well in `bevy_prototype_lyon`**, proving it’s feasible.
- **Bringing this natively to Bevy removes the need for external crates**, making it more self-contained.
Example Reference Below
```
use bevy::prelude::*;
use bevy_prototype_lyon::prelude::*;
/// Bezier curve control points
const P0: Vec2 = Vec2::new(-200.0, -100.0);
const P1: Vec2 = Vec2::new(-100.0, 200.0);
const P2: Vec2 = Vec2::new(100.0, -200.0);
const P3: Vec2 = Vec2::new(200.0, 100.0);
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(ShapePlugin)
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands) {
// Spawn Camera
commands.spawn(Camera2d::default());
// Define a cubic Bézier curve path using Lyon
let path = {
let mut builder = PathBuilder::new();
builder.move_to(P0);
builder.cubic_bezier_to(P1, P2, P3);
builder.build()
};
// Spawn the shape
commands.spawn((
ShapeBundle {
path: GeometryBuilder::build_as(&path),
..default()
},
Stroke::new(Color::WHITE, 3.0),
));
}
```
Contributor guide
Assessment
This issue has not been assessed yet.