Skip to main content

ranim/
lib.rs

1//! Ranim is an animation engine written in rust based on wgpu, inspired by [3b1b/manim](https://github.com/3b1b/manim/) and [jkjkil4/JAnim](https://github.com/jkjkil4/JAnim).
2//!
3//! A project binary registers its scenes and hands control to the command
4//! line interface:
5//!
6//! ```ignore
7//! use ranim::prelude::*;
8//!
9//! #[scene]
10//! fn hello(r: &mut RanimScene) { /* ... */ }
11//!
12//! fn main() {
13//!     // cargo run -- preview | output | render hello | inspect scenes
14//!     let mut app = App::new();
15//!     app.add_scenes([hello::scene()]);
16//!     run_cli(app.build());
17//! }
18//! ```
19//!
20//! Plugins organize larger projects and custom render configurations:
21//!
22//! ```
23//! use ranim::{App, Plugin, Resource};
24//!
25//! /// Project resources must implement bevy's `Resource`.
26//! #[derive(Resource)]
27//! struct ProjectConfig(u32);
28//!
29//! struct ProjectPlugin;
30//!
31//! impl Plugin for ProjectPlugin {
32//!     fn build(&self, app: &mut bevy_app::App) {
33//!         app.insert_resource(ProjectConfig(42));
34//!     }
35//! }
36//!
37//! let mut app = App::new();
38//! app.add_plugins(ProjectPlugin);
39//! assert_eq!(app.world().resource::<ProjectConfig>().0, 42);
40//! ```
41//!
42//! ## Coordinate System
43//!
44//! Ranim's coordinate system is right-handed coordinate:
45//!
46//! ```text
47//!      +Y
48//!      |
49//!      |
50//!      +----- +X
51//!    /
52//! +Z
53//! ```
54//!
55#![warn(missing_docs)]
56#![recursion_limit = "256"]
57#![cfg_attr(docsrs, feature(doc_cfg))]
58#![allow(rustdoc::private_intra_doc_links)]
59#![doc(
60    html_logo_url = "https://raw.githubusercontent.com/AzurIce/ranim/refs/heads/main/assets/ranim.svg",
61    html_favicon_url = "https://raw.githubusercontent.com/AzurIce/ranim/refs/heads/main/assets/ranim.svg"
62)]
63
64extern crate self as ranim;
65
66#[cfg(feature = "anims")]
67pub use ranim_anims as anims;
68pub use ranim_core as core;
69#[cfg(feature = "items")]
70pub use ranim_items as items;
71#[cfg(feature = "render")]
72pub use ranim_render as render;
73
74/// The project application: scenes, plugins, and resources
75pub mod app;
76/// Commands like preview and render
77pub mod cmd;
78pub use core::color;
79
80/// Utils
81pub mod utils {
82    pub use ranim_core::utils::*;
83}
84
85/// The WebAssembly host for project binaries
86#[cfg(all(target_arch = "wasm32", feature = "render"))]
87pub mod wasm;
88
89pub use app::{
90    AppExt, Output, OutputFormat, RanimApp, RanimAppExt, Scene, SceneConfig, SceneConstructor,
91    Scenes,
92};
93pub use bevy_app::{App, Plugin};
94pub use bevy_ecs::prelude::Resource;
95
96pub use core::glam;
97pub use ranim_core::{RanimScene, lagged, seq, stack};
98
99/// The preludes
100pub mod prelude {
101    pub use crate::app::{AppExt, RanimAppExt};
102    #[cfg(all(not(target_family = "wasm"), feature = "cmd-render"))]
103    pub use crate::cmd::cli::run_cli;
104    pub use crate::{App, Plugin};
105    pub use ranim_core::prelude::*;
106    pub use ranim_core::{lagged, seq, stack};
107    #[cfg(feature = "items")]
108    pub use ranim_items::camera::CameraFrame;
109    pub use ranim_macros::{output, scene, wasm_demo_doc};
110}