Skip to content

Commit

Permalink
bug fixes & example
Browse files Browse the repository at this point in the history
wip
  • Loading branch information
juliapaci committed Jun 28, 2024
1 parent e1d8c73 commit 2f9bc29
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 8 deletions.
18 changes: 16 additions & 2 deletions examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,27 @@ fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
}

fn render_shapes(mut commands: Commands) {
fn render_shapes(mut commands: Commands, shapes: Option<ResMut<Shapes>>) {
let Some(shapes) = shapes else { return };
let shapes = shapes.into_inner();

// Head
let head_scene = vello::Scene::default();

let head = (VelloCircle::new(1.0), Fill::new().with_color(Color::WHITE));
commands
.spawn(VelloSceneBundle {
scene: VelloScene::from(head_scene.clone()),
..default()
})
.insert(head);

// Line
let line = (
VelloLine::new(DVec2::new(0.0, 100.0), DVec2::new(0.0, -100.0)),
Head::new(DVec2::new(0.0, 100.0), DVec2::new(0.0, -100.0)),
Stroke::new(5.0).with_color(Color::WHITE),
Transform::from_xyz(-300.0, 0.0, 0.0),
Head::default().with_shape_id(shapes.insert(head_scene)),
);

// Rectangle
Expand Down
58 changes: 53 additions & 5 deletions src/head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bevy_vello::prelude::*;
#[derive(Default, Copy, Clone, PartialEq, Eq, Hash)]
pub struct ShapeId(Uuid);

#[derive(Component, Default, Copy, Clone)]
#[derive(Component, Copy, Clone)]
pub struct Head {
pub shape_id: ShapeId,
pub time: f64,
Expand All @@ -15,13 +15,61 @@ pub struct Head {
pub rotation_offset: f32,
}

// impl Head {
// pub fn new()
// }
impl Default for Head {
fn default() -> Self {
Self {
shape_id: ShapeId(Uuid::new_v4()),
time: 1.0,
scale: 1.0,
offset: 0.0,
rotation_offset: 0.0,
}
}
}

impl Head {
pub fn new(shape_id: ShapeId, scale: f64, offset: f32, rotation_offset: f32) -> Self {
Self {
shape_id,
scale,
offset,
rotation_offset,
..default()
}
}

pub fn with_shape_id(mut self, shape_id: ShapeId) -> Self {
self.shape_id = shape_id;
self
}

pub fn with_scale(mut self, scale: f64) -> Self {
self.scale = scale;
self
}

pub fn with_offset(mut self, offset: f32) -> Self {
self.offset = offset;
self
}

pub fn with_rotation_offset(mut self, rotation_offset: f32) -> Self {
self.rotation_offset = rotation_offset;
self
}
}

#[derive(Resource, Default)]
pub struct Shapes {
pub scenes: std::collections::HashMap<ShapeId, &'static mut vello::Scene>,
pub scenes: std::collections::HashMap<ShapeId, vello::Scene>,
}

impl Shapes {
pub fn insert(&mut self, scene: vello::Scene) -> ShapeId {
let shape_id = ShapeId(Uuid::new_v4());
self.scenes.insert(shape_id, scene);
shape_id
}
}

pub trait VectorBorder {
Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ fn append_heads<HeadEquipt: VelloVector + VectorBorder + Component>(
(&HeadEquipt, &Head, &mut VelloScene),
(Without<Stroke>, Or<(Changed<HeadEquipt>, Changed<Fill>)>),
>,

shapes: Option<Res<Shapes>>,
) {
let Some(shapes) = shapes else { return };
Expand All @@ -116,7 +117,10 @@ fn append_heads<HeadEquipt: VelloVector + VectorBorder + Component>(
fn build_fill_only_vector<Vector: VelloVector + Component>(
mut q_vectors: Query<
(&Vector, &Fill, &mut VelloScene),
(Without<Stroke>, Or<(Changed<Vector>, Changed<Fill>)>),
(
Without<Stroke>,
Or<(Without<Head>, Changed<Vector>, Changed<Fill>)>,
),
>,
) {
for (vector, fill, mut scene) in q_vectors.iter_mut() {
Expand Down

0 comments on commit 2f9bc29

Please sign in to comment.