Skip to main content

kvas_engine/
lib.rs

1//! Kvas gameplay engine: scenes, physics, procedural geometry and hot-reloadable scripts.
2//!
3//! # Start here
4//! - [`prelude`] contains the common script-facing types.
5//! - [`scene::Scene`] owns registered ECS components and environment settings.
6//! - [`runtime::Runtime`] runs the same simulation in the editor and the player.
7//! - [`script::Script`] defines gameplay callbacks; [`script::Ctx`] accesses host state.
8//! - [`assets::Assets`] reads loose project assets or a packed game archive.
9//!
10//! # Units and lifecycle
11//! Positions and collider sizes use metres; time uses seconds; [`components::Transform`]
12//! stores Euler angles in degrees, in Y-X-Z order. The world is right-handed with
13//! +Y up and local -Z forward. Refresh cached world matrices with
14//! [`hierarchy::update_globals`] after editing transforms outside the runtime.
15//!
16//! # Native scripts
17//! Host and script libraries must use identical engine sources, dependencies and
18//! compiler. Rebuild scripts after changing the engine. Script callbacks share
19//! host-owned built-in components through `Ctx`; creating custom ECS storage in
20//! an unloadable library would leave dangling vtables after hot reload.
21//!
22//! ```
23//! use kvas_engine::{prelude::*, scene::Scene, runtime::Runtime};
24//! let mut scene = Scene::default();
25//! let cube = scene.spawn("Spinning cube");
26//! scene.world.insert(cube, MeshRenderer::default());
27//! scene.world.insert(cube, Spin { speed: Vec3::new(0.0, 90.0, 0.0) });
28//! let mut runtime = Runtime::new(scene, None);
29//! runtime.tick(1.0 / 60.0);
30//! assert!(runtime.scene.world.get::<Transform>(cube).unwrap().rotation.y > 0.0);
31//! ```
32#![warn(missing_docs)]
33
34pub mod assets;
35pub mod animation;
36pub mod audio;
37pub mod cloth;
38pub mod components;
39pub mod events;
40pub mod fx;
41mod file_io;
42pub mod gameplay;
43pub mod grass;
44pub mod tree;
45pub mod decal;
46pub mod canvas;
47pub mod storage;
48pub mod script_game;
49pub mod gui;
50pub mod hierarchy;
51pub mod input;
52pub mod interaction;
53pub mod material_graph;
54pub mod material_nodes;
55pub mod material_nodes_ext;
56pub mod material_nodes_v4;
57pub mod material_presets;
58pub mod material_presets_v4;
59pub mod materials;
60pub mod math;
61pub mod mesh;
62pub mod mesh_deform;
63pub mod mesh_edit;
64pub mod mesh_uv;
65pub mod meshmod;
66pub mod modifiers;
67pub mod noise;
68pub mod neural;
69pub mod paint;
70pub mod params;
71pub mod particles;
72pub mod skeletal;
73pub mod humanoid;
74pub mod ik;
75pub mod ragdoll;
76pub mod physics;
77pub mod procedural;
78pub mod project;
79pub mod random;
80pub mod reflect;
81pub mod registry;
82pub mod runtime;
83pub mod scene;
84pub mod script;
85mod script_ext;
86pub mod signals;
87pub mod sky;
88pub mod spatial;
89pub mod timer;
90pub mod tween;
91pub mod voxel;
92mod voxel_mesh;
93pub mod water;
94
95#[doc = include_str!("../../../docs/ENGINE_API.md")]
96pub mod guide {}
97
98/// Everything a script author needs.
99pub mod prelude {
100    pub use crate::audio::{AudioBus, AudioSource, SoundId};
101    pub use crate::cloth::{Cloth, ClothPin};
102    pub use crate::components::*;
103    pub use crate::events::EventQueue;
104    pub use crate::fx::{PostEffect, PostSettings, ShadowSettings, Upscaler};
105    pub use crate::gameplay::{Lifetime, Tags, Visibility};
106    pub use crate::grass::Grass;
107    pub use crate::tree::TreeStyle;
108    pub use crate::decal::{DecalBlend, DecalShape};
109    pub use crate::canvas::{Align, ButtonStyle, Canvas};
110    pub use crate::storage::{SaveInfo, Storage};
111    pub use crate::hierarchy;
112    pub use crate::input::Hud;
113    pub use crate::math::{approach, approach_degrees, damp, ease_smooth, ease_smoother, smooth_damp, delta_degrees, inverse_lerp, lerp, remap, remap_clamped, smoothstep, wrap_degrees};
114    pub use crate::random::Rng;
115    pub use crate::paint::TexturePaint;
116    pub use crate::particles::{EmitterShape, ParticleEmitter};
117    pub use crate::params::{Color, EntityRef, Local, MeshRef, Param, SoundRef, TextureRef};
118    pub use crate::{fields, script, script_params};
119    pub use crate::input::{Input, Key, MouseButton};
120    pub use crate::interaction::{press, Slider, Switch, SwitchKind};
121    pub use crate::meshmod::{MeshModifiers, ModAxis, Modifier};
122    pub use crate::modifiers::{hsv_to_rgb, Bob, ColorCycle, Pulse, Spin, Wobble};
123    pub use crate::noise::{Noise, NoiseKind, NoiseTexture};
124    pub use crate::physics::{QueryOptions, RayHit};
125    pub use crate::reflect::Field;
126    pub use crate::register_scripts;
127    pub use crate::script::{Ctx, Script};
128    pub use crate::signals::{Signal, SignalBus, SignalError};
129    pub use crate::spatial::{Aabb, Frustum, Ray};
130    pub use crate::timer::{Timer, TimerMode};
131    pub use crate::tween::{Ease, MoveTween, TweenMode};
132    pub use crate::voxel::{VoxelClouds, VoxelSmoke};
133    pub use crate::water::{VoxelWater, WaterStyle};
134    pub use glam::{Mat4, Quat, Vec2, Vec3};
135    pub use serde_json::json;
136    pub use kvas_ecs::{Entity, World};
137}