1use ranim_core::{RanimScene, SealedRanimScene};
7
8#[cfg(target_arch = "wasm32")]
9use wasm_bindgen::prelude::*;
10
11#[doc(hidden)]
13#[derive(Clone)]
14#[cfg_attr(target_arch = "wasm32", wasm_bindgen)]
15pub struct Scene {
16 #[cfg_attr(target_arch = "wasm32", wasm_bindgen(skip))]
18 pub name: String,
19 #[cfg_attr(target_arch = "wasm32", wasm_bindgen(skip))]
21 pub constructor: fn(&mut RanimScene),
22 #[cfg_attr(target_arch = "wasm32", wasm_bindgen(skip))]
24 pub config: SceneConfig,
25 #[cfg_attr(target_arch = "wasm32", wasm_bindgen(skip))]
27 pub outputs: Vec<Output>,
28}
29
30#[derive(Debug, Clone)]
32pub struct SceneConfig {
33 pub clear_color: String,
35}
36
37impl Default for SceneConfig {
38 fn default() -> Self {
39 Self {
40 clear_color: "#333333ff".to_string(),
41 }
42 }
43}
44
45#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
47pub enum OutputFormat {
48 #[default]
50 Mp4,
51 Webm,
53 Mov,
55 Gif,
57}
58
59impl std::fmt::Display for OutputFormat {
60 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61 match self {
62 Self::Mp4 => write!(f, "mp4"),
63 Self::Webm => write!(f, "webm"),
64 Self::Mov => write!(f, "mov"),
65 Self::Gif => write!(f, "gif"),
66 }
67 }
68}
69
70#[derive(Debug, Clone)]
72pub struct Output {
73 pub width: u32,
75 pub height: u32,
77 pub fps: u32,
79 pub save_frames: bool,
81 pub name: Option<String>,
85 pub dir: String,
89 pub format: OutputFormat,
91}
92
93impl Default for Output {
94 fn default() -> Self {
95 Self {
96 width: 1920,
97 height: 1080,
98 fps: 60,
99 save_frames: false,
100 name: None,
101 dir: "./".to_string(),
102 format: OutputFormat::default(),
103 }
104 }
105}
106
107pub trait SceneConstructor: Send + Sync {
114 fn construct(&self, r: &mut RanimScene);
116
117 fn build_scene(&self) -> SealedRanimScene {
119 let mut scene = RanimScene::new();
120 self.construct(&mut scene);
121 scene.seal()
122 }
123}
124impl<F: Fn(&mut RanimScene) + Send + Sync> SceneConstructor for F {
127 fn construct(&self, r: &mut RanimScene) {
128 self(r);
129 }
130}