tiramisu/background

Scene background configuration.

Set the background of your 3D scene to a solid color, 2D texture, equirectangular panorama, or cubemap skybox.

Example

// Set a solid color background
background.set(ctx.scene, background.Color(0x1a1a2e), BackgroundSet, BackgroundFailed)

// Load a skybox
background.set(
  ctx.scene,
  background.CubeTexture(["px.jpg", "nx.jpg", "py.jpg", "ny.jpg", "pz.jpg", "nz.jpg"]),
  SkyboxLoaded,
  SkyboxFailed,
)

Types

pub type Background {
  Color(Int)
  Texture(String)
  EquirectangularTexture(String)
  CubeTexture(List(String))
}

Constructors

  • Color(Int)

    Solid color background (hex color, e.g., 0x111111)

  • Texture(String)

    2D texture background loaded from URL or path

  • EquirectangularTexture(String)

    Equirectangular (360° spherical) texture background

  • CubeTexture(List(String))

    TODO: This should be a type instead of a list of strings Cube texture (skybox) with 6 face images [px, nx, py, ny, pz, nz]

Values

pub fn set(
  game_scene: savoiardi.Scene,
  background: Background,
  on_success on_success: msg,
  on_error on_error: msg,
) -> effect.Effect(msg)

Set the scene background dynamically.

Use ctx.scene from the game context to get the scene reference.

Example

fn update(model: Model, msg: Msg, ctx: tiramisu.Context) {
  case msg {
    LoadSkybox -> {
      let effect = background.set(
        ctx.scene,
        background.CubeTexture(["px.jpg", "nx.jpg", "py.jpg", "ny.jpg", "pz.jpg", "nz.jpg"]),
        SkyboxLoaded,
        SkyboxFailed,
      )
      #(model, effect, ctx.physics_world)
    }
  }
}
Search Document