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    }
129}
130
131// ============================================================================
132// Prelude – common imports for everyday use
133// ============================================================================
134
135pub mod prelude {
136    // Application
137    #[cfg(feature = "winit")]
138    pub use myth_app::winit::App;
139    pub use myth_app::{AppHandler, Window};
140    pub use myth_app::{Engine, FrameState};
141
142    // Scene graph
143    pub use myth_core::{NodeHandle, SkeletonKey, Transform};
144    pub use myth_scene::camera::ProjectionType;
145    pub use myth_scene::{
146        BackgroundMapping, BackgroundMode, BackgroundSettings, Camera, Light, LightKind, Node,
147        Scene, SceneLogic, SceneNode,
148    };
149
150    // Resources
151    pub use myth_resources::{
152        AlphaMode, BloomSettings, FxaaQuality, FxaaSettings, Geometry, Image, Material,
153        MaterialType, Mesh, PhongMaterial, PhysicalMaterial, Side, SsaoSettings, TaaSettings,
154        Texture, TextureSlot, UnlitMaterial,
155    };
156
157    // Assets
158    pub use myth_assets::ColorSpace;
159    pub use myth_assets::SceneExt;
160    #[cfg(feature = "gltf")]
161    pub use myth_assets::loaders::gltf::GltfLoader;
162    pub use myth_assets::{AssetServer, GeometryHandle, MaterialHandle, TextureHandle};
163
164    // Animation
165    pub use myth_animation::{
166        AnimationAction, AnimationClip, AnimationEvent, AnimationMixer, ClipBinding, FiredEvent,
167        LoopMode, Rig,
168    };
169
170    // Math
171    pub use glam::{Affine3A, EulerRot, Mat3, Mat4, Quat, Vec2, Vec3, Vec4};
172
173    // Utilities
174    pub use myth_app::OrbitControls;
175
176    // Renderer
177    #[cfg(feature = "debug_view")]
178    pub use myth_render::graph::DebugViewTarget;
179    pub use myth_render::graph::FrameComposer;
180    pub use myth_render::settings::{
181        AntiAliasingMode, RenderPath, RendererInitConfig, RendererSettings,
182    };
183}
184
185// ============================================================================
186// Top-level re-exports for convenience
187// ============================================================================
188
189// Application
190#[cfg(feature = "winit")]
191pub use myth_app::winit::App;
192pub use myth_app::{AppHandler, Window};
193pub use myth_app::{Engine, FrameState};
194
195// Scene
196pub use myth_core::{NodeHandle, Transform};
197pub use myth_scene::{
198    BackgroundMapping, BackgroundMode, BackgroundSettings, Camera, Light, Node, Scene,
199};
200
201// Resources
202pub use myth_resources::primitives::{
203    PlaneOptions, SphereOptions, create_box, create_plane, create_sphere,
204};
205pub use myth_resources::{
206    AlphaMode, AntiAliasingMode, Attribute, FxaaQuality, FxaaSettings, Geometry, Image,
207    IndexFormat, Material, MaterialTrait, MaterialType, Mesh, PhongMaterial, PhysicalMaterial,
208    RenderableMaterialTrait, ShaderDefines, Side, TaaSettings, Texture, TextureSlot,
209    TextureTransform, ToneMappingMode, ToneMappingSettings, UnlitMaterial, VertexFormat,
210};
211
212// Assets
213pub use myth_assets::{AssetServer, GeometryHandle, MaterialHandle, TextureHandle};
214pub use myth_assets::{ColorSpace, GeometryQuery, ResolveGeometry, ResolveMaterial, SceneExt};
215
216// Animation
217pub use myth_animation::{
218    AnimationAction, AnimationClip, AnimationEvent, AnimationMixer, AnimationSystem, Binder,
219    ClipBinding, FiredEvent, InterpolationMode, LoopMode, Rig, Track, TrackBinding, TrackData,
220    TrackMeta,
221};
222
223// Renderer
224pub use myth_render::Renderer;
225pub use myth_render::graph::FrameComposer;
226pub use myth_render::settings::{RenderPath, RendererInitConfig, RendererSettings};
227
228// Errors
229pub use myth_core::{AssetError, Error, PlatformError, RenderError, Result};
230
231// Utilities
232pub use myth_app::OrbitControls;
233pub use myth_core::utils::interner;