From 9d11d493dc0402da57091d938b255d4f4d593960 Mon Sep 17 00:00:00 2001 From: AzurIce <973562770@qq.com> Date: Wed, 25 Feb 2026 10:22:21 +0800 Subject: [PATCH 1/3] refactor: remove ranim-app into ranim with feature gate --- Cargo.lock | 34 +++---------- Cargo.toml | 32 ++++++++++-- example-packages/app/Cargo.toml | 3 +- example-packages/app/src/main.rs | 2 +- examples/aabb/lib.rs | 2 - examples/animating_pi/lib.rs | 2 - examples/arc/lib.rs | 2 - examples/arc_between_points/lib.rs | 2 - examples/basic/lib.rs | 2 - examples/bubble_sort/lib.rs | 3 -- examples/ellipse/lib.rs | 3 -- examples/extract_vitem_visualize/lib.rs | 3 -- examples/getting_started0/lib.rs | 3 -- examples/getting_started1/lib.rs | 3 -- examples/getting_started2/lib.rs | 3 -- examples/hanoi/lib.rs | 2 - examples/hello_ranim/lib.rs | 3 -- examples/perspective_blend/lib.rs | 3 -- examples/ranim_logo/lib.rs | 3 -- examples/regular_polygon/lib.rs | 3 -- examples/selective_sort/lib.rs | 3 -- examples/text_item/lib.rs | 3 -- packages/ranim-app/Cargo.toml | 49 ------------------- packages/ranim-cli/Cargo.toml | 5 +- packages/ranim-cli/src/cli/preview.rs | 8 +-- src/cmd/mod.rs | 7 +++ .../src => src/cmd/preview}/depth_visual.rs | 2 +- .../src/lib.rs => src/cmd/preview/mod.rs | 35 ++++++------- .../cmd/preview}/shaders/depth_visual.wgsl | 0 .../src => src/cmd/preview}/timeline.rs | 2 +- src/cmd/{render.rs => render/mod.rs} | 0 src/lib.rs | 5 +- 32 files changed, 74 insertions(+), 158 deletions(-) delete mode 100644 packages/ranim-app/Cargo.toml rename {packages/ranim-app/src => src/cmd/preview}/depth_visual.rs (98%) rename packages/ranim-app/src/lib.rs => src/cmd/preview/mod.rs (96%) rename {packages/ranim-app/src => src/cmd/preview}/shaders/depth_visual.wgsl (100%) rename {packages/ranim-app/src => src/cmd/preview}/timeline.rs (99%) rename src/cmd/{render.rs => render/mod.rs} (100%) diff --git a/Cargo.lock b/Cargo.lock index c4b03805..b7597ec6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -275,7 +275,6 @@ dependencies = [ "log", "pretty_env_logger", "ranim", - "ranim-app", ] [[package]] @@ -4761,7 +4760,11 @@ dependencies = [ "anyhow", "assert_float_eq", "async-channel", + "bytemuck", + "console_error_panic_hook", "derive_more", + "eframe", + "egui", "flate2", "getrandom 0.3.4", "indicatif", @@ -4775,7 +4778,6 @@ dependencies = [ "rand 0.9.2", "rand_chacha 0.9.0", "ranim-anims", - "ranim-app", "ranim-core", "ranim-items", "ranim-macros", @@ -4784,6 +4786,10 @@ dependencies = [ "tracing", "tracing-indicatif", "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-tracing", + "web-sys", + "web-time", "wgpu", "which", ] @@ -4796,29 +4802,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "ranim-app" -version = "0.1.5" -dependencies = [ - "async-channel", - "bytemuck", - "console_error_panic_hook", - "eframe", - "egui", - "pollster", - "profiling", - "puffin", - "puffin_http", - "ranim", - "tracing", - "wasm-bindgen", - "wasm-bindgen-futures", - "wasm-tracing", - "web-sys", - "web-time", - "wgpu", -] - [[package]] name = "ranim-cli" version = "0.1.5" @@ -4833,7 +4816,6 @@ dependencies = [ "notify", "notify-debouncer-full", "ranim", - "ranim-app", "toml 0.9.12+spec-1.1.0", "tracing", "tracing-indicatif", diff --git a/Cargo.toml b/Cargo.toml index 9edd1b4a..138e958d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,6 @@ ranim-core = { path = "packages/ranim-core", version = "0.1.5" } ranim-items = { path = "packages/ranim-items", version = "0.1.5" } ranim-anims = { path = "packages/ranim-anims", version = "0.1.5" } ranim-macros = { path = "packages/ranim-macros", version = "0.1.5" } -ranim-app = { path = "packages/ranim-app", version = "0.1.5" } ranim-render = { path = "packages/ranim-render", version = "0.1.5" } wgpu-profiler = { version = "0.25.0", features = ["puffin"] } wasm-bindgen = "0.2.108" @@ -68,6 +67,17 @@ render = [ "dep:flate2", "dep:reqwest", ] +preview = [ + "render", + "dep:egui", + "dep:eframe", + "dep:web-time", + "dep:bytemuck", + "dep:wasm-bindgen-futures", + "dep:web-sys", + "dep:console_error_panic_hook", + "dep:wasm-tracing", +] # serde = ["dep:serde", "glam/serde"] [dependencies] @@ -91,6 +101,10 @@ anyhow = "1.0.100" ranim-render = { workspace = true, optional = true } # render feature (wasm-compatible deps here, rest in target-specific section below) wgpu = { workspace = true, optional = true } +# app feature +egui = { version = "0.33.0", optional = true } +web-time = { version = "1.1.0", optional = true } +bytemuck = { workspace = true, features = ["derive"], optional = true } # profiling puffin = { version = "0.19.1", optional = true } puffin_http = { version = "0.16.1", optional = true } @@ -102,6 +116,17 @@ inventory = "0.3.21" [target.'cfg(target_family = "wasm")'.dependencies] wasm-bindgen.workspace = true +# app feature (wasm) +eframe = { version = "0.33.0", default-features = false, features = [ + "accesskit", + "default_fonts", + "web_screen_reader", + "wgpu", +], optional = true } +wasm-bindgen-futures = { version = "0.4.54", optional = true } +web-sys = { version = "0.3.81", optional = true } +console_error_panic_hook = { version = "0.1.7", optional = true } +wasm-tracing = { version = "2.1.0", optional = true } [target.'cfg(not(target_family = "wasm"))'.dependencies] # render deps (wasm-incompatible, only used in cfg(not(wasm)) code) @@ -111,13 +136,12 @@ indicatif = { version = "0.18.3", optional = true } tracing-indicatif = { workspace = true, optional = true } flate2 = { version = "1.1.8", optional = true } reqwest = { version = "0.13.1", features = ["blocking"], optional = true } +# app feature (native) +eframe = { version = "0.33.0", features = ["wgpu"], optional = true } [target.'cfg(not(target_family = "wasm"))'.dev-dependencies] pretty_env_logger = "0.5.0" -[target.'cfg(target_family = "wasm")'.dev-dependencies] -ranim-app.workspace = true - [dev-dependencies] assert_float_eq = "1.2.0" rand = "0.9.2" diff --git a/example-packages/app/Cargo.toml b/example-packages/app/Cargo.toml index 626888ed..e6cbc243 100644 --- a/example-packages/app/Cargo.toml +++ b/example-packages/app/Cargo.toml @@ -8,5 +8,4 @@ publish = false console_error_panic_hook = "0.1.7" log = "0.4.27" pretty_env_logger = "0.5.0" -ranim.workspace = true -ranim-app.workspace = true +ranim = { workspace = true, features = ["preview", "anims", "items"] } diff --git a/example-packages/app/src/main.rs b/example-packages/app/src/main.rs index cf83700b..f3de5a93 100644 --- a/example-packages/app/src/main.rs +++ b/example-packages/app/src/main.rs @@ -6,5 +6,5 @@ fn main() { .filter(Some("ranim"), log::LevelFilter::Info) .init(); - ranim_app::preview_scene!(hello_ranim); + ranim::preview_scene!(hello_ranim); } diff --git a/examples/aabb/lib.rs b/examples/aabb/lib.rs index 93056362..de1b11a8 100644 --- a/examples/aabb/lib.rs +++ b/examples/aabb/lib.rs @@ -1,5 +1,3 @@ -#[cfg(target_arch = "wasm32")] -use ranim_app as _; use std::f64::consts::PI; use ranim::{ diff --git a/examples/animating_pi/lib.rs b/examples/animating_pi/lib.rs index 862a3435..f3e83e0c 100644 --- a/examples/animating_pi/lib.rs +++ b/examples/animating_pi/lib.rs @@ -1,5 +1,3 @@ -#[cfg(target_arch = "wasm32")] -use ranim_app as _; use std::f64::consts::TAU; use itertools::Itertools; diff --git a/examples/arc/lib.rs b/examples/arc/lib.rs index f46f4567..f079f3ea 100644 --- a/examples/arc/lib.rs +++ b/examples/arc/lib.rs @@ -7,8 +7,6 @@ use ranim::{ items::vitem::geometry::Arc, prelude::*, }; -#[cfg(target_arch = "wasm32")] -use ranim_app as _; use ranim_items::vitem::geometry::anchor::Origin; #[scene] diff --git a/examples/arc_between_points/lib.rs b/examples/arc_between_points/lib.rs index 6cae9a08..bfb0ee15 100644 --- a/examples/arc_between_points/lib.rs +++ b/examples/arc_between_points/lib.rs @@ -7,8 +7,6 @@ use ranim::{ items::vitem::geometry::ArcBetweenPoints, prelude::*, }; -#[cfg(target_arch = "wasm32")] -use ranim_app as _; #[scene] #[output(dir = "arc_between_points")] diff --git a/examples/basic/lib.rs b/examples/basic/lib.rs index 247c37b6..cb29696d 100644 --- a/examples/basic/lib.rs +++ b/examples/basic/lib.rs @@ -1,6 +1,4 @@ use ranim::glam; -#[cfg(target_arch = "wasm32")] -use ranim_app as _; use glam::DVec3; use ranim::{ diff --git a/examples/bubble_sort/lib.rs b/examples/bubble_sort/lib.rs index 52a54f33..90a98972 100644 --- a/examples/bubble_sort/lib.rs +++ b/examples/bubble_sort/lib.rs @@ -1,6 +1,3 @@ -#[cfg(target_arch = "wasm32")] -use ranim_app as _; - use rand::{SeedableRng, seq::SliceRandom}; use ranim::{ anims::morph::MorphAnim, diff --git a/examples/ellipse/lib.rs b/examples/ellipse/lib.rs index 0561fbe5..22afd33e 100644 --- a/examples/ellipse/lib.rs +++ b/examples/ellipse/lib.rs @@ -1,6 +1,3 @@ -#[cfg(target_arch = "wasm32")] -use ranim_app as _; - use ranim::{ anims::{creation::WritingAnim, fading::FadingAnim, morph::MorphAnim}, color::palettes::manim, diff --git a/examples/extract_vitem_visualize/lib.rs b/examples/extract_vitem_visualize/lib.rs index 484c9575..2ff23216 100644 --- a/examples/extract_vitem_visualize/lib.rs +++ b/examples/extract_vitem_visualize/lib.rs @@ -1,6 +1,3 @@ -#[cfg(target_arch = "wasm32")] -use ranim_app as _; - use ranim::glam; use ranim_core::core_item::CoreItem; use ranim_items::vitem::DEFAULT_STROKE_WIDTH; diff --git a/examples/getting_started0/lib.rs b/examples/getting_started0/lib.rs index a1ddafec..79fa7b8e 100644 --- a/examples/getting_started0/lib.rs +++ b/examples/getting_started0/lib.rs @@ -1,6 +1,3 @@ -#[cfg(target_arch = "wasm32")] -use ranim_app as _; - use ranim::{ anims::fading::FadingAnim, color::palettes::manim, items::vitem::geometry::Square, prelude::*, }; diff --git a/examples/getting_started1/lib.rs b/examples/getting_started1/lib.rs index e235b8c1..e764b687 100644 --- a/examples/getting_started1/lib.rs +++ b/examples/getting_started1/lib.rs @@ -1,6 +1,3 @@ -#[cfg(target_arch = "wasm32")] -use ranim_app as _; - use ranim::{ anims::{creation::WritingAnim, morph::MorphAnim}, color::palettes::manim, diff --git a/examples/getting_started2/lib.rs b/examples/getting_started2/lib.rs index b3532b59..0b5926a5 100644 --- a/examples/getting_started2/lib.rs +++ b/examples/getting_started2/lib.rs @@ -1,6 +1,3 @@ -#[cfg(target_arch = "wasm32")] -use ranim_app as _; - use ranim::{ anims::{ creation::{CreationAnim, WritingAnim}, diff --git a/examples/hanoi/lib.rs b/examples/hanoi/lib.rs index 998b44e5..5fd30f5e 100644 --- a/examples/hanoi/lib.rs +++ b/examples/hanoi/lib.rs @@ -6,8 +6,6 @@ use ranim::{ prelude::*, utils::rate_functions::{ease_in_quad, ease_out_quad, linear}, }; -#[cfg(target_arch = "wasm32")] -use ranim_app as _; fn solve_hanoi( n: usize, diff --git a/examples/hello_ranim/lib.rs b/examples/hello_ranim/lib.rs index 2f37f4c6..e6e90e01 100644 --- a/examples/hello_ranim/lib.rs +++ b/examples/hello_ranim/lib.rs @@ -1,6 +1,3 @@ -#[cfg(target_arch = "wasm32")] -use ranim_app as _; - use std::f64::consts::PI; use ranim::{ diff --git a/examples/perspective_blend/lib.rs b/examples/perspective_blend/lib.rs index b00b4f4c..34bb267b 100644 --- a/examples/perspective_blend/lib.rs +++ b/examples/perspective_blend/lib.rs @@ -1,6 +1,3 @@ -#[cfg(target_arch = "wasm32")] -use ranim_app as _; - use ranim::{ anims::morph::MorphAnim, color, diff --git a/examples/ranim_logo/lib.rs b/examples/ranim_logo/lib.rs index 06a5c759..71cc9ef8 100644 --- a/examples/ranim_logo/lib.rs +++ b/examples/ranim_logo/lib.rs @@ -1,6 +1,3 @@ -#[cfg(target_arch = "wasm32")] -use ranim_app as _; - use ranim::glam; use std::f64::consts::PI; diff --git a/examples/regular_polygon/lib.rs b/examples/regular_polygon/lib.rs index 4a55940e..150c135b 100644 --- a/examples/regular_polygon/lib.rs +++ b/examples/regular_polygon/lib.rs @@ -1,6 +1,3 @@ -#[cfg(target_arch = "wasm32")] -use ranim_app as _; - use std::f64::consts::PI; use ranim::{ diff --git a/examples/selective_sort/lib.rs b/examples/selective_sort/lib.rs index 6034bf43..608f7435 100644 --- a/examples/selective_sort/lib.rs +++ b/examples/selective_sort/lib.rs @@ -1,6 +1,3 @@ -#[cfg(target_arch = "wasm32")] -use ranim_app as _; - use glam::{DVec3, dvec2}; use rand::{SeedableRng, seq::SliceRandom}; use ranim::glam::{self, dvec3}; diff --git a/examples/text_item/lib.rs b/examples/text_item/lib.rs index ee960702..0247523a 100644 --- a/examples/text_item/lib.rs +++ b/examples/text_item/lib.rs @@ -1,6 +1,3 @@ -#[cfg(target_arch = "wasm32")] -use ranim_app as _; - use std::f64::consts::TAU; use ranim::{color::palettes::manim, glam::DVec3, prelude::*}; diff --git a/packages/ranim-app/Cargo.toml b/packages/ranim-app/Cargo.toml deleted file mode 100644 index a40a0d77..00000000 --- a/packages/ranim-app/Cargo.toml +++ /dev/null @@ -1,49 +0,0 @@ -[package] -name = "ranim-app" -description = "The preview application for Ranim." -version.workspace = true -edition.workspace = true -license.workspace = true -repository.workspace = true - -[features] -profiling = ["dep:puffin", "dep:puffin_http", "dep:profiling"] - -[dependencies] -ranim = { workspace = true, default-features = false, features = ["render"] } -tracing.workspace = true -wgpu.workspace = true -bytemuck = { workspace = true, features = ["derive"] } -egui = "0.33.0" -async-channel = "2.5.0" -web-time = "1.1.0" -# profiling -puffin = { version = "0.19.1", optional = true } -puffin_http = { version = "0.16.1", optional = true } -profiling = { version = "1.0.17", optional = true, features = [ - "profile-with-puffin", -] } - -[target.'cfg(not(target_family = "wasm"))'.dependencies] -eframe = { version = "0.33.0", features = ["wgpu"] } -pollster = "0.4.0" - -[target.'cfg(target_family = "wasm")'.dependencies] -eframe = { version = "0.33.0", default-features = false, features = [ - "accesskit", - "default_fonts", - "web_screen_reader", - "wgpu", -] } -wasm-bindgen.workspace = true -wasm-bindgen-futures = "0.4.54" -web-sys = "0.3.81" -console_error_panic_hook = "0.1.7" -wasm-tracing = "2.1.0" - -[package.metadata.docs.rs] -all-features = true -rustdoc-args = ["--cfg", "docsrs"] - -[package.metadata.release] -tag = false diff --git a/packages/ranim-cli/Cargo.toml b/packages/ranim-cli/Cargo.toml index a1e9afe3..1d483188 100644 --- a/packages/ranim-cli/Cargo.toml +++ b/packages/ranim-cli/Cargo.toml @@ -7,7 +7,7 @@ license.workspace = true repository.workspace = true [features] -profiling = ["ranim/profiling", "ranim-app/profiling"] +profiling = ["ranim/profiling"] [[bin]] name = "ranim" @@ -15,8 +15,7 @@ path = "src/main.rs" doc = false [dependencies] -ranim = { workspace = true, features = ["render"] } -ranim-app.workspace = true +ranim = { workspace = true, features = ["render", "preview"] } anyhow = "1.0.100" cargo_toml = "0.22.3" clap = { version = "4.5.53", features = ["derive"] } diff --git a/packages/ranim-cli/src/cli/preview.rs b/packages/ranim-cli/src/cli/preview.rs index dd7d4253..a2fc0c4d 100644 --- a/packages/ranim-cli/src/cli/preview.rs +++ b/packages/ranim-cli/src/cli/preview.rs @@ -5,7 +5,7 @@ use std::{ use krates::Kid; use notify_debouncer_full::{DebouncedEvent, Debouncer}; -use ranim_app::{AppCmd, RanimApp}; +use ranim::cmd::preview::{RanimPreviewApp, RanimPreviewAppCmd}; use anyhow::Result; use async_channel::{Receiver, bounded, unbounded}; @@ -160,7 +160,7 @@ pub fn preview_command(args: &CliArgs, scene_name: &Option) -> Result<() // info!("- {:?}", scene.name); // } // panic!("Failed to get preview scene"); - let mut app = RanimApp::new(scene.constructor, scene.name.clone()); + let mut app = RanimPreviewApp::new(scene.constructor, scene.name.clone()); app.set_clear_color_str(&scene.config.clear_color); let cmd_tx = app.cmd_tx.clone(); @@ -192,7 +192,7 @@ pub fn preview_command(args: &CliArgs, scene_name: &Option) -> Result<() let (tx, rx) = bounded(1); cmd_tx - .send_blocking(AppCmd::ReloadScene(scene.clone(), tx)) + .send_blocking(RanimPreviewAppCmd::ReloadScene(scene.clone(), tx)) .unwrap(); rx.recv_blocking().unwrap(); lib.replace(new_lib); @@ -204,7 +204,7 @@ pub fn preview_command(args: &CliArgs, scene_name: &Option) -> Result<() std::thread::sleep(Duration::from_millis(200)); } }); - ranim_app::run_app(app); + ranim::cmd::preview::run_app(app); shutdown_tx.send_blocking(()).unwrap(); daemon.join().unwrap(); Ok(()) diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 00bbaf57..f58bf9b0 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -3,3 +3,10 @@ pub mod render; #[cfg(all(not(target_family = "wasm"), feature = "render"))] pub use render::{render_scene, render_scene_output}; + +/// The preview application +#[cfg(feature = "preview")] +#[allow(missing_docs)] +pub mod preview; +#[cfg(feature = "preview")] +pub use preview::{preview_constructor_with_name, preview_scene, preview_scene_with_name}; diff --git a/packages/ranim-app/src/depth_visual.rs b/src/cmd/preview/depth_visual.rs similarity index 98% rename from packages/ranim-app/src/depth_visual.rs rename to src/cmd/preview/depth_visual.rs index 9f15b9da..9f6b48d1 100644 --- a/packages/ranim-app/src/depth_visual.rs +++ b/src/cmd/preview/depth_visual.rs @@ -1,4 +1,4 @@ -use ranim::render::utils::WgpuContext; +use crate::render::utils::WgpuContext; use std::borrow::Cow; pub struct DepthVisualPipeline { diff --git a/packages/ranim-app/src/lib.rs b/src/cmd/preview/mod.rs similarity index 96% rename from packages/ranim-app/src/lib.rs rename to src/cmd/preview/mod.rs index 9d47a609..a2bb32ec 100644 --- a/packages/ranim-app/src/lib.rs +++ b/src/cmd/preview/mod.rs @@ -1,10 +1,7 @@ mod depth_visual; mod timeline; -use async_channel::{Receiver, Sender, unbounded}; -use depth_visual::DepthVisualPipeline; -use eframe::egui; -use ranim::{ +use crate::{ Scene, SceneConstructor, core::{ SealedRanimScene, @@ -17,6 +14,9 @@ use ranim::{ utils::WgpuContext, }, }; +use async_channel::{Receiver, Sender, unbounded}; +use depth_visual::DepthVisualPipeline; +use eframe::egui; use timeline::TimelineState; use tracing::{error, info}; use web_time::Instant; @@ -47,7 +47,7 @@ impl TimelineInfoState { } } -pub enum AppCmd { +pub enum RanimPreviewAppCmd { ReloadScene(Scene, Sender<()>), } @@ -57,9 +57,9 @@ pub enum ViewMode { Depth, } -pub struct RanimApp { - cmd_rx: Receiver, - pub cmd_tx: Sender, +pub struct RanimPreviewApp { + cmd_rx: Receiver, + pub cmd_tx: Sender, #[allow(unused)] title: String, clear_color: wgpu::Color, @@ -87,7 +87,7 @@ pub struct RanimApp { depth_visual_view: Option, } -impl RanimApp { +impl RanimPreviewApp { pub fn new(scene_constructor: impl SceneConstructor, title: String) -> Self { let t = Instant::now(); info!("building scene..."); @@ -144,7 +144,7 @@ impl RanimApp { fn handle_events(&mut self) { if let Ok(cmd) = self.cmd_rx.try_recv() { match cmd { - AppCmd::ReloadScene(scene, tx) => { + RanimPreviewAppCmd::ReloadScene(scene, tx) => { let timeline = scene.constructor.build_scene(); let timeline_infos = timeline.get_timeline_infos(); let old_cur_second = self.timeline_state.current_sec; @@ -314,7 +314,7 @@ impl RanimApp { } } -impl eframe::App for RanimApp { +impl eframe::App for RanimPreviewApp { fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { self.prepare_renderer(frame); self.handle_events(); @@ -435,7 +435,7 @@ impl eframe::App for RanimApp { } } -pub fn run_app(app: RanimApp, #[cfg(target_arch = "wasm32")] container_id: String) { +pub fn run_app(app: RanimPreviewApp, #[cfg(target_arch = "wasm32")] container_id: String) { #[cfg(not(target_arch = "wasm32"))] { let native_options = eframe::NativeOptions { @@ -492,7 +492,7 @@ pub fn run_app(app: RanimApp, #[cfg(target_arch = "wasm32")] container_id: Strin } pub fn preview_constructor_with_name(scene: impl SceneConstructor, name: &str) { - let app = RanimApp::new(scene, name.to_string()); + let app = RanimPreviewApp::new(scene, name.to_string()); run_app( app, #[cfg(target_arch = "wasm32")] @@ -507,7 +507,7 @@ pub fn preview_scene(scene: &Scene) { /// Preview a scene with a custom name pub fn preview_scene_with_name(scene: &Scene, name: &str) { - let mut app = RanimApp::new(scene.constructor, name.to_string()); + let mut app = RanimPreviewApp::new(scene.constructor, name.to_string()); app.set_clear_color_str(&scene.config.clear_color); run_app( app, @@ -519,12 +519,13 @@ pub fn preview_scene_with_name(scene: &Scene, name: &str) { /// Preview a scene by name. /// /// ```rust,ignore -/// ranim_app::preview_scene!(fading); +/// ranim::preview_scene!(fading); +/// ranim::preview_scene!(ranim_020::code_structure); /// ``` #[macro_export] macro_rules! preview_scene { - ($scene:ident) => { - $crate::preview_scene(&$scene::scene()) + ($($scene:tt)::+) => { + $crate::cmd::preview_scene(&$($scene)::+::scene()) }; } diff --git a/packages/ranim-app/src/shaders/depth_visual.wgsl b/src/cmd/preview/shaders/depth_visual.wgsl similarity index 100% rename from packages/ranim-app/src/shaders/depth_visual.wgsl rename to src/cmd/preview/shaders/depth_visual.wgsl diff --git a/packages/ranim-app/src/timeline.rs b/src/cmd/preview/timeline.rs similarity index 99% rename from packages/ranim-app/src/timeline.rs rename to src/cmd/preview/timeline.rs index 9ee729c3..1abb0c9a 100644 --- a/packages/ranim-app/src/timeline.rs +++ b/src/cmd/preview/timeline.rs @@ -3,7 +3,7 @@ use egui::{ emath::GuiRounding, pos2, remap_clamp, }; -use ranim::core::{TimelineInfo, color::palettes::manim}; +use crate::core::{TimelineInfo, color::palettes::manim}; use super::TimelineInfoState; diff --git a/src/cmd/render.rs b/src/cmd/render/mod.rs similarity index 100% rename from src/cmd/render.rs rename to src/cmd/render/mod.rs diff --git a/src/lib.rs b/src/lib.rs index 061854d0..299436d7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,12 +55,13 @@ pub use ranim_core::RanimScene; /// /// ```rust,ignore /// render_scene!(fading); +/// render_scene!(ranim_020::code_structure); /// ``` #[cfg(all(not(target_family = "wasm"), feature = "render"))] #[macro_export] macro_rules! render_scene { - ($scene:ident) => { - $crate::cmd::render_scene(&$scene::scene(), 2) + ($($scene:tt)::+) => { + $crate::cmd::render_scene(&$($scene)::+::scene(), 2) }; } From 4c814ce765d3705c87d9e6f8f325a5e26f505aa0 Mon Sep 17 00:00:00 2001 From: AzurIce <973562770@qq.com> Date: Wed, 25 Feb 2026 13:06:20 +0800 Subject: [PATCH 2/3] some cleanup --- packages/ranim-cli/src/cli/preview.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/ranim-cli/src/cli/preview.rs b/packages/ranim-cli/src/cli/preview.rs index a2fc0c4d..5aff2d8f 100644 --- a/packages/ranim-cli/src/cli/preview.rs +++ b/packages/ranim-cli/src/cli/preview.rs @@ -188,11 +188,9 @@ pub fn preview_command(args: &CliArgs, scene_name: &Option) -> Result<() error!("Failed to find preview scene: {err}"); continue; } - let scene = scene.unwrap(); - let (tx, rx) = bounded(1); cmd_tx - .send_blocking(RanimPreviewAppCmd::ReloadScene(scene.clone(), tx)) + .send_blocking(RanimPreviewAppCmd::ReloadScene(scene.unwrap(), tx)) .unwrap(); rx.recv_blocking().unwrap(); lib.replace(new_lib); From 9acc77c43296ab4a12aff79a5bc41bb7f6a167e4 Mon Sep 17 00:00:00 2001 From: AzurIce <973562770@qq.com> Date: Wed, 25 Feb 2026 13:11:09 +0800 Subject: [PATCH 3/3] move render and preview macros defination to cmd module's root --- src/cmd/mod.rs | 27 +++++++++++++++++++++++++++ src/cmd/preview/mod.rs | 13 ------------- src/lib.rs | 14 -------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index f58bf9b0..e3c1ae77 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -4,9 +4,36 @@ pub mod render; #[cfg(all(not(target_family = "wasm"), feature = "render"))] pub use render::{render_scene, render_scene_output}; +/// Render a scene by name. +/// +/// ```rust,ignore +/// render_scene!(fading); +/// render_scene!(ranim_020::code_structure); +/// ``` +#[cfg(all(not(target_family = "wasm"), feature = "render"))] +#[macro_export] +macro_rules! render_scene { + ($($scene:tt)::+) => { + $crate::cmd::render_scene(&$($scene)::+::scene(), 2) + }; +} + /// The preview application #[cfg(feature = "preview")] #[allow(missing_docs)] pub mod preview; #[cfg(feature = "preview")] pub use preview::{preview_constructor_with_name, preview_scene, preview_scene_with_name}; + +/// Preview a scene by name. +/// +/// ```rust,ignore +/// ranim::preview_scene!(fading); +/// ranim::preview_scene!(ranim_020::code_structure); +/// ``` +#[macro_export] +macro_rules! preview_scene { + ($($scene:tt)::+) => { + $crate::cmd::preview_scene(&$($scene)::+::scene()) + }; +} diff --git a/src/cmd/preview/mod.rs b/src/cmd/preview/mod.rs index a2bb32ec..05e01413 100644 --- a/src/cmd/preview/mod.rs +++ b/src/cmd/preview/mod.rs @@ -516,19 +516,6 @@ pub fn preview_scene_with_name(scene: &Scene, name: &str) { ); } -/// Preview a scene by name. -/// -/// ```rust,ignore -/// ranim::preview_scene!(fading); -/// ranim::preview_scene!(ranim_020::code_structure); -/// ``` -#[macro_export] -macro_rules! preview_scene { - ($($scene:tt)::+) => { - $crate::cmd::preview_scene(&$($scene)::+::scene()) - }; -} - // WASM support needs refactoring, mostly keeping it commented or adapting basic entry point. #[cfg(target_arch = "wasm32")] mod wasm { diff --git a/src/lib.rs b/src/lib.rs index 299436d7..1d3c116d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,20 +51,6 @@ pub use scene::*; pub use core::glam; pub use ranim_core::RanimScene; -/// Render a scene by name. -/// -/// ```rust,ignore -/// render_scene!(fading); -/// render_scene!(ranim_020::code_structure); -/// ``` -#[cfg(all(not(target_family = "wasm"), feature = "render"))] -#[macro_export] -macro_rules! render_scene { - ($($scene:tt)::+) => { - $crate::cmd::render_scene(&$($scene)::+::scene(), 2) - }; -} - /// The preludes pub mod prelude { pub use ranim_core::prelude::*;