Start out with bevy vello example

This commit is contained in:
Niklas Korz 2025-03-30 14:57:27 +02:00
commit ff438eae2c
4 changed files with 5386 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/target
.cargo/config.toml

5324
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

16
Cargo.toml Normal file
View file

@ -0,0 +1,16 @@
[package]
name = "norenorn"
version = "0.1.0"
edition = "2024"
# Enable a small amount of optimization in the dev profile.
[profile.dev]
opt-level = 1
# Enable a large amount of optimization in the dev profile for dependencies.
[profile.dev.package."*"]
opt-level = 3
[dependencies]
bevy = "0.15.3"
bevy_vello = "0.7.1"

44
src/main.rs Normal file
View file

@ -0,0 +1,44 @@
use bevy::prelude::*;
use bevy_vello::{VelloPlugin, prelude::*};
use std::ops::DerefMut;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(VelloPlugin::default())
.add_systems(Startup, setup_vector_graphics)
.add_systems(Update, simple_animation)
.run();
}
fn setup_vector_graphics(mut commands: Commands) {
commands.spawn((Camera2d, VelloView));
commands.spawn(VelloScene::new());
}
fn simple_animation(mut query_scene: Single<(&mut Transform, &mut VelloScene)>, time: Res<Time>) {
let sin_time = time.elapsed_secs().sin().mul_add(0.5, 0.5);
let (transform, scene) = query_scene.deref_mut();
// Reset scene every frame
scene.reset();
// Animate color green to blue
let c = Vec3::lerp(
Vec3::new(-1.0, 1.0, -1.0),
Vec3::new(-1.0, 1.0, 1.0),
sin_time + 0.5,
);
// Animate the corner radius
scene.fill(
peniko::Fill::NonZero,
kurbo::Affine::default(),
peniko::Color::new([c.x, c.y, c.z, 1.]),
None,
&kurbo::RoundedRect::new(-50.0, -50.0, 50.0, 50.0, (sin_time as f64) * 50.0),
);
transform.scale = Vec3::lerp(Vec3::ONE * 0.5, Vec3::ONE * 1.0, sin_time);
transform.translation = Vec3::lerp(Vec3::X * -100.0, Vec3::X * 100.0, sin_time);
transform.rotation = Quat::from_rotation_z(-std::f32::consts::TAU * sin_time);
}