pub struct Engine {
pub clock: Box<dyn Clock>,
pub time_real: f32,
pub time: f32,
pub time_scale: f32,
pub tick: f32,
pub frame: f32,
pub perf: Perf,
pub input: InputState,
pub camera_mode: CameraMode,
pub assets: AssetManager,
/* private fields */
}Fields§
§clock: Box<dyn Clock>§time_real: f32§time: f32§time_scale: f32§tick: f32§frame: f32§perf: Perf§input: InputState§camera_mode: CameraMode§assets: AssetManagerImplementations§
Source§impl Engine
impl Engine
pub fn new<C>(clock: C, backend_state: BackendState) -> Enginewhere
C: Clock + 'static,
pub fn exit(&mut self)
Sourcepub fn load_default_font<P>(&mut self, path: P)
pub fn load_default_font<P>(&mut self, path: P)
Load default font
Sourcepub fn set_snap_to_px(&mut self, snap_to_px: bool)
pub fn set_snap_to_px(&mut self, snap_to_px: bool)
Set snap to px
Sourcepub fn set_default_font(&mut self, handle: Handle)
pub fn set_default_font(&mut self, handle: Handle)
Set default font
Sourcepub fn set_font_config(&mut self, config: FontConfig)
pub fn set_font_config(&mut self, config: FontConfig)
Set default font
Sourcepub fn draw_text(
&mut self,
text: &Text,
anchor: Option<Vec2>,
transform: Transform,
)
pub fn draw_text( &mut self, text: &Text, anchor: Option<Vec2>, transform: Transform, )
Draw text
§Arguments
text- Textanchor- Anchor, center is (0.5, 0.5), min value (0.0, 0.0), max value (1.0, 1.0)transform- Transform, the size will be multiplied by text size
§Examples
// draw a text with left-top anchor (0, 0)
let text = Text::new(format!("Hello"), 20.0, BLUE);
g.draw_text(
&text,
None,
Transform::new(Vec3::new(0.0, 20.0, 1.0))
);Sourcepub fn draw3d_instanced(&mut self, draw: InstancedDraw3D)
pub fn draw3d_instanced(&mut self, draw: InstancedDraw3D)
Draw many instances of a 3D mesh efficiently.
Use this for rendering large numbers of similar objects like grass, trees, particles, or any repeated geometry. All instances share the same mesh, texture, and material, but each has its own transform and color.
§Example
let instances: Vec<InstanceData> = (0..1000)
.map(|i| InstanceData::from_position_color(
Vec3::new((i % 10) as f32, (i / 10) as f32, 0.0),
Color::rgb(rand(), rand(), rand()),
))
.collect();
g.draw3d_instanced(InstancedDraw3D::new(cube_mesh.clone(), instances));Sourcepub fn draw3d_pbr(&mut self, draw: Draw3DPbr)
pub fn draw3d_pbr(&mut self, draw: Draw3DPbr)
Draw a 3D mesh with PBR (Physically Based Rendering) material.
Uses Cook-Torrance BRDF with metallic-roughness workflow for physically accurate lighting. Supports directional, point, and spot lights.
§Example
let material = PbrMaterial::metal(Color::rgb(1.0, 0.8, 0.0), 0.3); // Gold
g.draw3d_pbr(Draw3DPbr::new(mesh.clone(), Mat4::IDENTITY).with_material(material));Sourcepub fn draw3d_skinned(&mut self, draw: Draw3DSkinned)
pub fn draw3d_skinned(&mut self, draw: Draw3DSkinned)
Draw a skinned 3D mesh with skeletal animation.
Use this for rendering animated characters, creatures, or other models with bone-based deformation.
§Example
// Load skinned mesh from glTF
let mesh = SkinnedMesh3D::from_gltf(g, "character.glb").unwrap();
let mut player = mesh.create_player();
player.play(0); // Play first animation
// Each frame: update and draw
player.update(g.tick, &mesh.skeleton, &mesh.animations);
g.draw3d_skinned(Draw3DSkinned::new(mesh.clone(), Mat4::IDENTITY, &player));Sourcepub fn create_text_texture(
&mut self,
text: &Text,
) -> Result<(Handle, UVec2), Error>
pub fn create_text_texture( &mut self, text: &Text, ) -> Result<(Handle, UVec2), Error>
Create text texture
Sourcepub fn create_raw_texture(&mut self, texture: Texture) -> Result<Handle, Error>
pub fn create_raw_texture(&mut self, texture: Texture) -> Result<Handle, Error>
Create raw texture
Sourcepub fn draw_rect(
&mut self,
color: Color,
size: Vec2,
anchor: Option<Vec2>,
transform: Transform,
)
pub fn draw_rect( &mut self, color: Color, size: Vec2, anchor: Option<Vec2>, transform: Transform, )
Sourcepub fn draw_line_ex(
&mut self,
line: Line,
z: f32,
pattern: LinePattern,
offset: f32,
)
pub fn draw_line_ex( &mut self, line: Line, z: f32, pattern: LinePattern, offset: f32, )
Draw line with extended styling options
§Arguments
line- Line struct containing start, end, thickness, color, and z-indexpattern- Line pattern (Solid, Dashed, or Dotted)offset- Pattern offset for animation effects
§Examples
// draw a dashed red line from (10, 10) to (100, 50)
g.draw_line_ex(
Line {
start: Vec2::new(10.0, 10.0),
end: Vec2::new(100.0, 50.0),
thickness: 2.0,
color: RED,
},
1.0,
LinePattern::Dashed { dash_length: 10.0, gap_length: 5.0 },
0.0
);Sourcepub fn draw_lines(&mut self, lines: Vec<Line>, z: f32)
pub fn draw_lines(&mut self, lines: Vec<Line>, z: f32)
Draw a batch of lines
§Arguments
lines- Slice of Line structs to draw
§Examples
// draw multiple lines in a single batch
g.draw_lines(vec![
Line {
start: Vec2::new(10.0, 10.0),
end: Vec2::new(100.0, 50.0),
thickness: 2.0,
color: RED,
},
Line {
start: Vec2::new(20.0, 20.0),
end: Vec2::new(120.0, 70.0),
thickness: 3.0,
color: BLUE,
},
], 1.0);Sourcepub fn draw_poly(
&mut self,
center: Vec3,
sides: u32,
radius: f32,
rotation: f32,
color: Color,
)
pub fn draw_poly( &mut self, center: Vec3, sides: u32, radius: f32, rotation: f32, color: Color, )
Draw a filled regular polygon (3+ sides) with the provided center, radius, rotation, and color.
Sourcepub fn draw_poly_textured(
&mut self,
center: Vec3,
sides: u32,
radius: f32,
rotation: f32,
sprite: &Sprite,
)
pub fn draw_poly_textured( &mut self, center: Vec3, sides: u32, radius: f32, rotation: f32, sprite: &Sprite, )
Draw a textured regular polygon with UVs covering the sprite (respecting optional src rect).
Sourcepub fn draw_poly_lines(
&mut self,
center: Vec3,
sides: u32,
radius: f32,
rotation: f32,
thickness: f32,
color: Color,
)
pub fn draw_poly_lines( &mut self, center: Vec3, sides: u32, radius: f32, rotation: f32, thickness: f32, color: Color, )
Draw the outline of a regular polygon, using the line renderer internally.
Sourcepub fn draw_circle(&mut self, center: Vec3, radius: f32, color: Color)
pub fn draw_circle(&mut self, center: Vec3, radius: f32, color: Color)
Sourcepub fn screen_size(&self) -> Vec2
pub fn screen_size(&self) -> Vec2
Screen size
Sourcepub fn dpi_scale_factor(&self) -> f64
pub fn dpi_scale_factor(&self) -> f64
DPI scale factor
pub fn is_window_resized(&self) -> bool
pub fn scale_mode(&self) -> ScaleMode
Sourcepub fn set_scale_mode(&mut self, mode: ScaleMode)
pub fn set_scale_mode(&mut self, mode: ScaleMode)
Set scale mode
pub fn now(&mut self) -> f32
pub fn camera(&self) -> &Camera2D
pub fn camera_mut(&mut self) -> &mut Camera2D
pub fn ui_camera(&self) -> &Camera2D
pub fn ui_camera_mut(&mut self) -> &mut Camera2D
pub fn camera3d(&self) -> &Camera3D
pub fn camera3d_mut(&mut self) -> &mut Camera3D
Sourcepub fn lighting(&self) -> &LightingState
pub fn lighting(&self) -> &LightingState
Get the 3D lighting state (immutable)
Sourcepub fn lighting_mut(&mut self) -> &mut LightingState
pub fn lighting_mut(&mut self) -> &mut LightingState
Get the 3D lighting state (mutable)
Sourcepub fn set_ambient_light(&mut self, color: Color)
pub fn set_ambient_light(&mut self, color: Color)
Set the ambient light color
Sourcepub fn set_light(&mut self, index: usize, light: Option<Light3D>)
pub fn set_light(&mut self, index: usize, light: Option<Light3D>)
Set a light at the given index (0-3)
Sourcepub fn set_skybox(&mut self, skybox: Option<Skybox>)
pub fn set_skybox(&mut self, skybox: Option<Skybox>)
Set the skybox for 3D rendering.
The skybox is rendered at infinity and follows camera rotation but not position.
Pass None to disable the skybox.
pub fn input(&self) -> &InputState
pub fn input_mut(&mut self) -> &mut InputState
Sourcepub fn set_scene(&mut self, scene: impl Scene + 'static)
pub fn set_scene(&mut self, scene: impl Scene + 'static)
Set a scene, the scene swap do not happened instantly, it is happened in engine update
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Whether the engine is running
Sourcepub fn backend_state(&self) -> &BackendState
pub fn backend_state(&self) -> &BackendState
Get wgpu state
Sourcepub fn with_renderer<Ret, F>(&mut self, renderer: Rc<dyn Shader>, f: F) -> Ret
pub fn with_renderer<Ret, F>(&mut self, renderer: Rc<dyn Shader>, f: F) -> Ret
With shader
Sourcepub fn set_renderer(&mut self, renderer: Option<Rc<dyn Shader>>)
pub fn set_renderer(&mut self, renderer: Option<Rc<dyn Shader>>)
Set shader
Sourcepub fn send_renderer_data(&mut self, data: Vec<u8>)
pub fn send_renderer_data(&mut self, data: Vec<u8>)
Send args to renderer The args only used for next draw call
Sourcepub fn set_post_renderer<R>(&mut self, post_renderer: Option<R>)where
R: PostShader + 'static,
pub fn set_post_renderer<R>(&mut self, post_renderer: Option<R>)where
R: PostShader + 'static,
Setup post renderer
pub fn text_cache(&mut self) -> &mut FontManager
Auto Trait Implementations§
impl Freeze for Engine
impl !RefUnwindSafe for Engine
impl !Send for Engine
impl !Sync for Engine
impl Unpin for Engine
impl !UnwindSafe for Engine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.