Skip to main content

myth/
lib.rs

1//! # Myth - A High-Performance, WGPU-Based Rendering Engine for Rust.
2//!
3//! Myth-Engine is a modern 3D rendering engine built with Rust and wgpu.
4//! It provides a flexible, high-performance foundation for real-time graphics applications.
5//!
6//! ## Quick Start
7//!
8//! ```rust,ignore
9//! use myth::prelude::*;
10
11//! struct MyApp;
12
13//! impl AppHandler for MyApp {
14//!    fn init(engine: &mut Engine, _: &dyn Window) -> Self {
15//!        // 0. Create a Scene
16//!        let scene = engine.scene_manager.create_active();
17//!
18//!        // 1. Create a cube mesh with a checkerboard texture
19//!        let tex_handle = engine.assets.checkerboard(512, 64);
20//!        let mesh_handle = scene.spawn_box(
21//!            1.0, 1.0, 1.0,
22//!            PhongMaterial::new(Vec4::new(1.0, 0.76, 0.33, 1.0)).with_map(tex_handle),
23//!            &engine.assets,
24//!        );
25//!        // 2. Setup Camera
26//!        let cam_node_id = scene.add_camera(Camera::new_perspective(45.0, 1280.0 / 720.0, 0.1));
27//!        scene.node(&cam_node_id).set_position(0.0, 0.0, 5.0).look_at(Vec3::ZERO);
28//!        scene.active_camera = Some(cam_node_id);
29//!        // 3. Add Light
30//!        scene.add_light(Light::new_directional(Vec3::ONE, 5.0));
31//!
32//!        // 4. Setup update callback to rotate the cube
33//!        scene.on_update(move |scene, _input, _dt| {
34//!            if let Some(node) = scene.get_node_mut(mesh_handle) {
35//!                let rot_y = Quat::from_rotation_y(0.02);
36//!                let rot_x = Quat::from_rotation_x(0.01);
37//!                node.transform.rotation = node.transform.rotation * rot_y * rot_x;
38//!            }
39//!        });
40//!        Self {}
41//!    }
42//! }
43
44//! fn main() -> myth::Result<()> {
45//!     App::new().with_title("Myth-Engine Demo").run::<MyApp>()
46//! }
47//! ```
48//!
49//! ## Feature Flags
50//!
51//! | Feature | Default | Description |
52//! |---------|---------|-------------|
53//! | `winit` | **yes** | Window management via winit |
54//! | `gltf` | **yes** | glTF 2.0 model loading |
55//! | `http` | **yes** | HTTP asset loading |
56//! | `gltf-meshopt` | no | Meshopt decompression for glTF |
57//! | `debug_view` | no | Render graph debug view targets |
58//! | `rdg_inspector` | no | Render graph inspector |
59//!
60
61// ============================================================================
62// Sub-crate re-exports (facade modules matching the old monolith paths)
63// ============================================================================
64
65/// Error types and `Result` alias.
66pub mod errors {
67    pub use myth_core::errors::*;
68}
69
70/// Scene graph – nodes, cameras, lights, transforms.
71pub use myth_scene as scene;
72
73/// GPU resource definitions – geometry, material, texture, mesh, etc.
74pub use myth_resources as resources;
75
76/// Animation system – clips, mixers, tracks, skeletal / morph-target.
77pub use myth_animation as animation;
78
79/// Asset loading – server, storage, glTF loaders.
80pub use myth_assets as assets;
81
82/// Renderer internals – core, graph, pipeline.
83pub use myth_render as renderer;
84
85/// Application framework – engine, handlers, windowing.
86#[cfg(feature = "winit")]
87pub use myth_app as app;
88
89/// Engine core without windowing (always available even without `winit`).
90pub mod engine {
91    pub use myth_app::engine::*;
92}
93
94// ============================================================================
95// Local utilities (re-exports from sub-crates)
96// ============================================================================
97
98pub mod utils {
99    pub use myth_app::OrbitControls;
100    pub use myth_core::utils::FpsCounter;
101    pub mod fps_counter {
102        pub use myth_core::utils::FpsCounter;
103    }
104}
105
106// ============================================================================
107// Math module – re-exported glam types
108// ============================================================================
109
110pub mod math {
111    pub use glam::*;
112}
113
114// ============================================================================
115// Render module – high-level rendering API alias
116// ============================================================================
117
118pub mod render {
119    pub use myth_render::graph::{FrameComposer, RenderState};
120    pub use myth_render::renderer::Renderer;
121    pub use myth_render::settings::{RenderPath, RendererInitConfig, RendererSettings};
122
123    /// Low-level GPU context access.
124    pub mod core {
125        pub use myth_render::core::ResourceManager;
126        pub use myth_render::core::WgpuContext;
127        pub use myth_render::core::{BindingResource, Bindings, ResourceBuilder};
128        pub use myth_render::core::{ReadbackError, ReadbackFrame, ReadbackStream};
129    }
130}
131
132// ============================================================================
133// Prelude – common imports for everyday use
134// ============================================================================
135
136pub mod prelude {
137    // Application
138    #[cfg(feature = "winit")]
139    pub use myth_app::winit::App;
140    pub use myth_app::{AppHandler, Window};
141    pub use myth_app::{Engine, FrameState};
142
143    // Scene graph
144    pub use myth_core::{NodeHandle, SkeletonKey, Transform};
145    pub use myth_scene::camera::ProjectionType;
146    pub use myth_scene::{
147        BackgroundMapping, BackgroundMode, BackgroundSettings, Camera, Light, LightKind, Node,
148        Scene, SceneLogic, SceneNode,
149    };
150
151    // Resources
152    pub use myth_resources::{
153        AlphaMode, BloomSettings, FxaaQuality, FxaaSettings, Geometry, Image, Material,
154        MaterialType, Mesh, PhongMaterial, PhysicalMaterial, Side, SsaoSettings, TaaSettings,
155        Texture, TextureSlot, UnlitMaterial,
156    };
157
158    // Assets
159    pub use myth_assets::ColorSpace;
160    pub use myth_assets::SceneExt;
161    #[cfg(feature = "gltf")]
162    pub use myth_assets::loaders::gltf::GltfLoader;
163    pub use myth_assets::{
164        AssetServer, GeometryHandle, ImageHandle, MaterialHandle, PrefabHandle, TextureHandle,
165    };
166
167    // Animation
168    pub use myth_animation::{
169        AnimationAction, AnimationClip, AnimationEvent, AnimationMixer, ClipBinding, FiredEvent,
170        LoopMode, Rig,
171    };
172
173    // Math
174    pub use glam::{Affine3A, EulerRot, Mat3, Mat4, Quat, Vec2, Vec3, Vec4};
175
176    // Utilities
177    pub use myth_app::OrbitControls;
178
179    // Renderer
180    pub use myth_render::graph::FrameComposer;
181    pub use myth_render::settings::{
182        AntiAliasingMode, RenderPath, RendererInitConfig, RendererSettings,
183    };
184    #[cfg(feature = "debug_view")]
185    pub use myth_scene::{DebugViewMode, DebugViewSettings};
186}
187
188// ============================================================================
189// Top-level re-exports for convenience
190// ============================================================================
191
192// Application
193#[cfg(feature = "winit")]
194pub use myth_app::winit::App;
195pub use myth_app::{AppHandler, Window};
196pub use myth_app::{Engine, FrameState};
197
198// Scene
199pub use myth_core::{NodeHandle, Transform};
200pub use myth_scene::{
201    BackgroundMapping, BackgroundMode, BackgroundSettings, Camera, Light, Node, Scene,
202};
203
204// Resources
205pub use myth_resources::primitives::{
206    PlaneOptions, SphereOptions, create_box, create_plane, create_sphere,
207};
208pub use myth_resources::{
209    AlphaMode, AntiAliasingMode, Attribute, FxaaQuality, FxaaSettings, Geometry, Image,
210    IndexFormat, Material, MaterialTrait, MaterialType, Mesh, PhongMaterial, PhysicalMaterial,
211    RenderableMaterialTrait, ShaderDefines, Side, TaaSettings, Texture, TextureSlot,
212    TextureTransform, ToneMappingMode, ToneMappingSettings, UnlitMaterial, VertexFormat,
213};
214
215// Assets
216pub use myth_assets::{AssetServer, GeometryHandle, ImageHandle, MaterialHandle, TextureHandle};
217pub use myth_assets::{ColorSpace, GeometryQuery, ResolveGeometry, ResolveMaterial, SceneExt};
218
219// Animation
220pub use myth_animation::{
221    AnimationAction, AnimationClip, AnimationEvent, AnimationMixer, AnimationSystem, Binder,
222    ClipBinding, FiredEvent, InterpolationMode, LoopMode, Rig, Track, TrackBinding, TrackData,
223    TrackMeta,
224};
225
226// Renderer
227pub use myth_render::Renderer;
228pub use myth_render::graph::FrameComposer;
229pub use myth_render::settings::{RenderPath, RendererInitConfig, RendererSettings};
230
231// Errors
232pub use myth_core::{AssetError, Error, PlatformError, RenderError, Result};
233
234// Utilities
235pub use myth_app::OrbitControls;
236pub use myth_core::utils::interner;