Engine

Struct Engine 

Source
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: AssetManager

Implementations§

Source§

impl Engine

Source

pub fn new<C>(clock: C, backend_state: BackendState) -> Engine
where C: Clock + 'static,

Source

pub fn exit(&mut self)

Source

pub fn load_default_font<P>(&mut self, path: P)
where P: AsRef<Path>,

Load default font

Source

pub fn set_snap_to_px(&mut self, snap_to_px: bool)

Set snap to px

Source

pub fn set_default_font(&mut self, handle: Handle)

Set default font

Source

pub fn set_font_config(&mut self, config: FontConfig)

Set default font

Source

pub fn render_text(&mut self, text: &Text) -> Result<(Handle, UVec2), Error>

Render text

Source

pub fn draw_text( &mut self, text: &Text, anchor: Option<Vec2>, transform: Transform, )

Draw text

§Arguments
  • text - Text
  • anchor - 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))
   );
Source

pub fn draw3d(&mut self, draw: Draw3D)

Draw 3d mesh

Source

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));
Source

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));
Source

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));
Source

pub fn create_text_texture( &mut self, text: &Text, ) -> Result<(Handle, UVec2), Error>

Create text texture

Source

pub fn create_raw_texture(&mut self, texture: Texture) -> Result<Handle, Error>

Create raw texture

Source

pub fn with_ui<R, F>(&mut self, f: F) -> R
where F: FnOnce(&mut Engine) -> R,

Draw within Ui context

Source

pub fn draw_rect( &mut self, color: Color, size: Vec2, anchor: Option<Vec2>, transform: Transform, )

Draw rectangle

§Arguments
  • color - Color, color of the rectangle
  • anchor - Anchor, default is (0.5, 0.5), min value (0.0, 0.0), max value (1.0, 1.0)
  • transform - Transform
§Examples
// draw a blue rectangle
  g.draw_rect(
      BLUE,
      Vec2::splat(40.0),
      None,
      Transform::new(Vec3::new(50.0, 100.0, 1.0)),
  );
Source

pub fn draw_line(&mut self, line: Line, z: f32)

Draw line

§Arguments
  • line - Line struct containing start, end, thickness, color, and z-index
§Examples
// draw a red line from (10, 10) to (100, 50) with 2px thickness at z-index 1.0
  g.draw_line(Line {
      start: Vec2::new(10.0, 10.0),
      end: Vec2::new(100.0, 50.0),
      thickness: 2.0,
      color: RED,
  }, 1.0);
Source

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-index
  • pattern - 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
  );
Source

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);
Source

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.

Source

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).

Source

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.

Source

pub fn draw_circle(&mut self, center: Vec3, radius: f32, color: Color)

Draw circle

§Arguments
  • center - Center point of the circle (x, y, z)
  • radius - Circle radius
  • color - Circle color
§Examples
// draw a blue circle at (50, 50) with radius 25 at z-index 0.5
  g.draw_circle(
      Vec3::new(50.0, 50.0, 0.5),
      25.0,
      BLUE
  );
Source

pub fn draw(&mut self, sprite: &Sprite, transform: Transform)

Draw image

§Arguments
  • image - Sprite to draw
  • transform - Position
§Examples
// draw entity's sprite
  let transform = Transform::new(Vec2::ZERO.extend(1.0));
  g.draw(
      &sprite,
      transform
  );
Source

pub fn view_size(&self) -> Vec2

View size

Source

pub fn screen_size(&self) -> Vec2

Screen size

Source

pub fn dpi_scale_factor(&self) -> f64

DPI scale factor

Source

pub fn is_window_resized(&self) -> bool

Source

pub fn scale_mode(&self) -> ScaleMode

Source

pub fn set_scale_mode(&mut self, mode: ScaleMode)

Set scale mode

Source

pub fn now(&mut self) -> f32

Source

pub fn camera(&self) -> &Camera2D

Source

pub fn camera_mut(&mut self) -> &mut Camera2D

Source

pub fn ui_camera(&self) -> &Camera2D

Source

pub fn ui_camera_mut(&mut self) -> &mut Camera2D

Source

pub fn camera3d(&self) -> &Camera3D

Source

pub fn camera3d_mut(&mut self) -> &mut Camera3D

Source

pub fn lighting(&self) -> &LightingState

Get the 3D lighting state (immutable)

Source

pub fn lighting_mut(&mut self) -> &mut LightingState

Get the 3D lighting state (mutable)

Source

pub fn set_ambient_light(&mut self, color: Color)

Set the ambient light color

Source

pub fn set_light(&mut self, index: usize, light: Option<Light3D>)

Set a light at the given index (0-3)

Source

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.

Source

pub fn skybox(&self) -> Option<&Skybox>

Get the current skybox (if any)

Source

pub fn input(&self) -> &InputState

Source

pub fn input_mut(&mut self) -> &mut InputState

Source

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

Source

pub fn is_running(&self) -> bool

Whether the engine is running

Source

pub fn backend_state(&self) -> &BackendState

Get wgpu state

Source

pub fn with_renderer<Ret, F>(&mut self, renderer: Rc<dyn Shader>, f: F) -> Ret
where F: FnOnce(&mut Engine) -> Ret,

With shader

Source

pub fn set_renderer(&mut self, renderer: Option<Rc<dyn Shader>>)

Set shader

Source

pub fn send_renderer_data(&mut self, data: Vec<u8>)

Send args to renderer The args only used for next draw call

Source

pub fn set_post_renderer<R>(&mut self, post_renderer: Option<R>)
where R: PostShader + 'static,

Setup post renderer

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more