Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PbrMotion, motion traits, and new crate bevy_vello_graphics #44

Merged
merged 7 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ resolver = "2"

[dependencies]
motiongfx_core = { path = "crates/motiongfx_core" }
# motiongfx_bevy = { path = "crates/motiongfx_bevy" }
motiongfx_vello = { path = "crates/motiongfx_vello" }
motiongfx_typst = { path = "crates/motiongfx_typst" }
bevy_vello_graphics = { path = "crates/bevy_vello_graphics" }

[dev-dependencies]
bevy = "0.13"
Expand Down
16 changes: 16 additions & 0 deletions crates/bevy_vello_graphics/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "bevy_vello_graphics"
version = "0.1.0"
edition = "2021"

[dependencies]
motiongfx_core = { path = "../motiongfx_core", optional = true }
bevy_vello_renderer = { git = "https://github.com/nixon-voxell/bevy_vello_renderer", rev = "49ef841842b3170f225614c7d3ffffba31522150" }
bevy = "0.13"

[features]
default = ["motiongfx"]
motiongfx = ["dep:motiongfx_core"]

[lints]
workspace = true
41 changes: 41 additions & 0 deletions crates/bevy_vello_graphics/src/brush.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use bevy::prelude::*;
use bevy_vello_renderer::vello::{kurbo, peniko};

#[derive(Default, Clone)]
pub struct Brush {
pub value: peniko::Brush,
pub transform: kurbo::Affine,
}

impl Brush {
pub fn from_brush(brush: peniko::Brush) -> Self {
Self {
value: brush,
..default()
}
}

pub fn from_color(color: Color) -> Self {
Self {
value: peniko::Brush::Solid(peniko::Color::rgba(
color.r() as f64,
color.g() as f64,
color.b() as f64,
color.a() as f64,
)),
..default()
}
}

pub fn from_gradient(gradient: peniko::Gradient) -> Self {
Self {
value: peniko::Brush::Gradient(gradient),
..default()
}
}

pub fn with_transform(mut self, transform: kurbo::Affine) -> Self {
self.transform = transform;
self
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy::prelude::*;
use bevy_vello_renderer::vello::kurbo;
#[cfg(feature = "motiongfx")]
use motiongfx_core::f32lerp::F32Lerp;

use super::VelloVector;
Expand All @@ -26,6 +27,7 @@ impl VelloVector for VelloCircle {
}
}

#[cfg(feature = "motiongfx")]
impl F32Lerp for VelloCircle {
fn f32lerp(&self, rhs: &Self, t: f32) -> Self {
VelloCircle {
Expand Down
39 changes: 39 additions & 0 deletions crates/bevy_vello_graphics/src/fill.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use bevy::prelude::*;
use bevy_vello_renderer::vello::peniko;

use crate::brush::Brush;

#[derive(Component, Clone)]
pub struct Fill {
pub style: peniko::Fill,
pub brush: Brush,
}

impl Fill {
pub fn new() -> Self {
Self::default()
}

pub fn from_style(style: peniko::Fill) -> Self {
Self { style, ..default() }
}

pub fn with_brush(mut self, brush: Brush) -> Self {
self.brush = brush;
self
}

pub fn with_color(mut self, color: Color) -> Self {
self.brush = Brush::from_color(color);
self
}
}

impl Default for Fill {
fn default() -> Self {
Self {
style: peniko::Fill::NonZero,
brush: default(),
}
}
}
Original file line number Diff line number Diff line change
@@ -1,118 +1,42 @@
use bevy::{ecs::schedule::SystemConfigs, prelude::*};
use bevy_vello_renderer::{
prelude::*,
vello::{self, kurbo, peniko},
vello::{self, kurbo},
};
use bezpath::VelloBezPath;
use circle::VelloCircle;
use fill::Fill;
use line::VelloLine;
use rect::VelloRect;
use stroke::Stroke;

pub mod bezpath;
pub mod brush;
pub mod circle;
pub mod fill;
pub mod line;
pub mod rect;
pub mod stroke;

#[derive(Default, Clone)]
pub struct Brush {
value: peniko::Brush,
transform: Option<kurbo::Affine>,
pub mod prelude {
pub use crate::VelloGraphicsPlugin;
pub use crate::{bezpath::VelloBezPath, circle::VelloCircle, line::VelloLine, rect::VelloRect};
pub use crate::{brush::Brush, fill::Fill, stroke::Stroke};
}

impl Brush {
pub fn from_brush(brush: peniko::Brush) -> Self {
Self {
value: brush,
..default()
}
}

pub fn from_color(color: Color) -> Self {
Self {
value: peniko::Brush::Solid(peniko::Color::rgba(
color.r() as f64,
color.g() as f64,
color.b() as f64,
color.a() as f64,
)),
..default()
}
}

pub fn from_gradient(gradient: peniko::Gradient) -> Self {
Self {
value: peniko::Brush::Gradient(gradient),
..default()
}
}

pub fn with_transform(mut self, transform: kurbo::Affine) -> Self {
self.transform = Some(transform);
self
}

pub fn clear_transform(&mut self) {
self.transform = None;
}
}

#[derive(Component, Clone)]
pub struct Fill {
pub style: peniko::Fill,
pub brush: Brush,
}

impl Fill {
pub fn new() -> Self {
Self::default()
}

pub fn from_style(style: peniko::Fill) -> Self {
Self { style, ..default() }
}

pub fn with_brush(mut self, brush: Brush) -> Self {
self.brush = brush;
self
}

pub fn with_color(mut self, color: Color) -> Self {
self.brush = Brush::from_color(color);
self
}
}

impl Default for Fill {
fn default() -> Self {
Self {
style: peniko::Fill::NonZero,
brush: default(),
}
}
}

#[derive(Component, Default, Clone)]
pub struct Stroke {
pub style: kurbo::Stroke,
pub brush: Brush,
}

impl Stroke {
pub fn new(width: f64) -> Self {
Self {
style: kurbo::Stroke::new(width),
..default()
}
}

pub fn from_style(style: kurbo::Stroke) -> Self {
Self { style, ..default() }
}

pub fn with_brush(mut self, brush: Brush) -> Self {
self.brush = brush;
self
}

pub fn with_color(mut self, color: Color) -> Self {
self.brush = Brush::from_color(color);
self
pub struct VelloGraphicsPlugin;

impl Plugin for VelloGraphicsPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
Update,
(
build_vector::<VelloRect>(),
build_vector::<VelloCircle>(),
build_vector::<VelloLine>(),
build_vector::<VelloBezPath>(),
),
);
}
}

Expand All @@ -125,7 +49,7 @@ pub trait VelloVector {
fill.style,
default(),
&fill.brush.value,
fill.brush.transform,
Some(fill.brush.transform),
&self.shape(),
);
}
Expand All @@ -136,7 +60,7 @@ pub trait VelloVector {
&stroke.style,
default(),
&stroke.brush.value,
stroke.brush.transform,
Some(stroke.brush.transform),
&self.shape(),
);
}
Expand Down Expand Up @@ -207,10 +131,7 @@ fn build_fill_and_stroke_vector<Vector: VelloVector + Component>(

// Build the vector to the VelloScene
vector.build_fill(fill, &mut scene);
// Skip building stroke if there is no width to it
if stroke.style.width != 0.0 {
vector.build_stroke(stroke, &mut scene);
}
vector.build_stroke(stroke, &mut scene);

// Replace with new scene
vello_scene.scene = scene.into();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use bevy::{math::DVec2, prelude::*};
use bevy_vello_renderer::vello::kurbo;
#[cfg(feature = "motiongfx")]
use motiongfx_core::f32lerp::F32Lerp;

use crate::vello_vector::VelloVector;
use super::VelloVector;

#[derive(Component, Default, Debug, Clone, Copy)]
pub struct VelloLine {
Expand Down Expand Up @@ -42,6 +43,7 @@ impl VelloVector for VelloLine {
}
}

#[cfg(feature = "motiongfx")]
impl F32Lerp for VelloLine {
fn f32lerp(&self, rhs: &Self, t: f32) -> Self {
Self {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy::{math::DVec2, prelude::*};
use bevy_vello_renderer::vello::kurbo;
#[cfg(feature = "motiongfx")]
use motiongfx_core::f32lerp::F32Lerp;

use super::VelloVector;
Expand Down Expand Up @@ -40,6 +41,7 @@ impl VelloVector for VelloRect {
}
}

#[cfg(feature = "motiongfx")]
impl F32Lerp for VelloRect {
fn f32lerp(&self, rhs: &Self, t: f32) -> Self {
Self {
Expand Down
Loading