address feedback * inherit edition, repo and license from workspace * rename integrations -> crates and move velato crate to subdir * change files arg of winit demo to read both svg and lottie json
diff --git a/Cargo.toml b/Cargo.toml index fb01f0a..497259c 100644 --- a/Cargo.toml +++ b/Cargo.toml
@@ -2,9 +2,8 @@ resolver = "2" members = [ - "velato", - - "integrations/vello_svg", + "crates/velato", + "crates/vello_svg", "examples/headless", "examples/with_winit",
diff --git a/crates/velato/Cargo.toml b/crates/velato/Cargo.toml new file mode 100644 index 0000000..4bc4e38 --- /dev/null +++ b/crates/velato/Cargo.toml
@@ -0,0 +1,14 @@ +[package] +name = "velato" +version = "0.0.1" +description = "Lottie renderer built on vello." +categories = ["rendering", "graphics"] +keywords = ["2d", "vector-graphics", "animation", "lottie"] + +license.workspace = true +edition.workspace = true +repository.workspace = true + +[dependencies] +vello = { path = "../../" } +bodymovin = { git = "https://github.com/dfrg/bodymovin-rs", rev= "c156dda9" }
diff --git a/velato/README.md b/crates/velato/README.md similarity index 100% rename from velato/README.md rename to crates/velato/README.md
diff --git a/velato/src/import.rs b/crates/velato/src/import.rs similarity index 100% rename from velato/src/import.rs rename to crates/velato/src/import.rs
diff --git a/velato/src/lib.rs b/crates/velato/src/lib.rs similarity index 100% rename from velato/src/lib.rs rename to crates/velato/src/lib.rs
diff --git a/velato/src/model/animated.rs b/crates/velato/src/model/animated.rs similarity index 100% rename from velato/src/model/animated.rs rename to crates/velato/src/model/animated.rs
diff --git a/velato/src/model/fixed.rs b/crates/velato/src/model/fixed.rs similarity index 100% rename from velato/src/model/fixed.rs rename to crates/velato/src/model/fixed.rs
diff --git a/velato/src/model/mod.rs b/crates/velato/src/model/mod.rs similarity index 100% rename from velato/src/model/mod.rs rename to crates/velato/src/model/mod.rs
diff --git a/velato/src/model/spline.rs b/crates/velato/src/model/spline.rs similarity index 100% rename from velato/src/model/spline.rs rename to crates/velato/src/model/spline.rs
diff --git a/velato/src/model/value.rs b/crates/velato/src/model/value.rs similarity index 100% rename from velato/src/model/value.rs rename to crates/velato/src/model/value.rs
diff --git a/velato/src/render.rs b/crates/velato/src/render.rs similarity index 100% rename from velato/src/render.rs rename to crates/velato/src/render.rs
diff --git a/integrations/vello_svg/Cargo.toml b/crates/vello_svg/Cargo.toml similarity index 100% rename from integrations/vello_svg/Cargo.toml rename to crates/vello_svg/Cargo.toml
diff --git a/integrations/vello_svg/src/lib.rs b/crates/vello_svg/src/lib.rs similarity index 100% rename from integrations/vello_svg/src/lib.rs rename to crates/vello_svg/src/lib.rs
diff --git a/examples/scenes/Cargo.toml b/examples/scenes/Cargo.toml index 9a21a5b..4ed2f0c 100644 --- a/examples/scenes/Cargo.toml +++ b/examples/scenes/Cargo.toml
@@ -12,7 +12,8 @@ [dependencies] vello = { path = "../../" } -vello_svg = { path = "../../integrations/vello_svg" } +vello_svg = { path = "../../crates/vello_svg" } +velato = { path = "../../crates/velato" } anyhow = { workspace = true } clap = { workspace = true, features = ["derive"] }
diff --git a/examples/scenes/src/svg.rs b/examples/scenes/src/file.rs similarity index 60% rename from examples/scenes/src/svg.rs rename to examples/scenes/src/file.rs index 9f4f5c0..f4a77d9 100644 --- a/examples/scenes/src/svg.rs +++ b/examples/scenes/src/file.rs
@@ -5,7 +5,10 @@ }; use anyhow::{Ok, Result}; -use vello::{kurbo::Vec2, SceneBuilder, SceneFragment}; +use vello::{ + kurbo::{Affine, Vec2}, + SceneBuilder, SceneFragment, +}; use vello_svg::usvg; use crate::{ExampleScene, SceneSet}; @@ -49,11 +52,9 @@ let start_index = scenes.len(); for file in read_dir(path)? { let entry = file?; - if let Some(extension) = Path::new(&entry.file_name()).extension() { - if extension == "svg" { - count += 1; - scenes.push(example_scene_of(entry.path())) - } + if let Some(scene) = example_scene_of(entry.path()) { + count += 1; + scenes.push(scene); } } // Ensure a consistent order within directories @@ -62,13 +63,26 @@ empty_dir(); } } else { - scenes.push(example_scene_of(path.to_owned())) + if let Some(scene) = example_scene_of(path.to_owned()) { + scenes.push(scene); + } } } Ok(SceneSet { scenes }) } -fn example_scene_of(file: PathBuf) -> ExampleScene { +fn example_scene_of(file: PathBuf) -> Option<ExampleScene> { + let extension = file.extension()?; + if extension == "svg" { + Some(example_scene_of_svg(file)) + } else if extension == "json" { + Some(example_scene_of_lottie(file)) + } else { + None + } +} + +fn example_scene_of_svg(file: PathBuf) -> ExampleScene { let name = file .file_stem() .map(|it| it.to_string_lossy().to_string()) @@ -102,3 +116,40 @@ }, } } + +fn example_scene_of_lottie(file: PathBuf) -> ExampleScene { + let name = file + .file_stem() + .map(|it| it.to_string_lossy().to_string()) + .unwrap_or_else(|| "unknown".to_string()); + let name_stored = name.clone(); + let mut cached_scene = None; + ExampleScene { + function: Box::new(move |builder, params| { + let (composition, renderer, resolution) = cached_scene.get_or_insert_with(|| { + let start = Instant::now(); + let contents = std::fs::read(&file).expect("failed to read lottie file"); + let composition = velato::Composition::from_bytes(&contents) + .expect("failed to parse lottie file"); + eprintln!( + "Parsing Lottie {name_stored} took {:?} (file `{file:?}`", + start.elapsed() + ); + let resolution = Vec2::new(composition.width as f64, composition.height as f64); + (composition, velato::Renderer::new(), resolution) + }); + renderer.render( + composition, + params.time as f32, + Affine::IDENTITY, + 1.0, + builder, + ); + params.resolution = Some(*resolution); + }), + config: crate::SceneConfig { + animated: true, + name, + }, + } +}
diff --git a/examples/scenes/src/lib.rs b/examples/scenes/src/lib.rs index b23e54a..defbc50 100644 --- a/examples/scenes/src/lib.rs +++ b/examples/scenes/src/lib.rs
@@ -1,16 +1,16 @@ pub mod download; -mod simple_text; #[cfg(not(target_arch = "wasm32"))] -mod svg; +mod file; +mod simple_text; mod test_scenes; use std::path::PathBuf; use anyhow::Result; use clap::{Args, Subcommand}; use download::Download; -pub use simple_text::SimpleText; #[cfg(not(target_arch = "wasm32"))] -pub use svg::{default_scene, scene_from_files}; +pub use file::{default_scene, scene_from_files}; +pub use simple_text::SimpleText; pub use test_scenes::test_scenes; use vello::{kurbo::Vec2, SceneBuilder}; @@ -44,8 +44,8 @@ /// Whether to use the test scenes created by code test_scenes: bool, #[arg(help_heading = "Scene Selection", global(false))] - /// The svg files paths to render - svgs: Option<Vec<PathBuf>>, + /// The files paths to render (svg or lottie json) + files: Option<Vec<PathBuf>>, #[clap(subcommand)] command: Option<Command>, } @@ -71,7 +71,7 @@ #[cfg(not(target_arch = "wasm32"))] if self.test_scenes { Ok(test_scenes()) - } else if let Some(svgs) = &self.svgs { + } else if let Some(svgs) = &self.files { scene_from_files(&svgs) } else { default_scene(command)
diff --git a/velato/Cargo.toml b/velato/Cargo.toml deleted file mode 100644 index 652f5b6..0000000 --- a/velato/Cargo.toml +++ /dev/null
@@ -1,15 +0,0 @@ -[package] -name = "velato" -version = "0.1.0" -edition = "2021" -license = "MIT/Apache-2.0" -# homepage = "https://vello.dev" - Domain owned by us, but unused at present -# rust-version = -repository = "https://github.com/linebender/vello" -description = "Lottie renderer built on vello." -categories = ["rendering", "graphics"] -keywords = ["2d", "vector-graphics", "animation", "lottie"] - -[dependencies] -vello = { path = "../" } -bodymovin = { git = "https://github.com/dfrg/bodymovin-rs", rev= "c156dda9" }