tiramisu/debug

Types

pub type PerformanceStats {
  PerformanceStats(
    fps: Float,
    frame_time: Float,
    draw_calls: Int,
    triangles: Int,
    memory_mb: Float,
  )
}

Constructors

  • PerformanceStats(
      fps: Float,
      frame_time: Float,
      draw_calls: Int,
      triangles: Int,
      memory_mb: Float,
    )

Values

pub fn axes(
  id: id,
  origin: vec3.Vec3(Float),
  size: Float,
) -> scene.Node(id)
pub fn bounding_box(
  id: id,
  min: vec3.Vec3(Float),
  max: vec3.Vec3(Float),
  color: Int,
) -> scene.Node(id)
pub fn box_from_transform(
  id: id,
  t: transform.Transform,
  color: Int,
) -> scene.Node(id)
pub fn collider(
  id: id,
  shape: physics.ColliderShape,
  transform: transform.Transform,
  color: Int,
) -> scene.Node(id)

Visualize a physics collider shape at a given transform.

This function converts a physics collider into debug visualization nodes that can be added to your scene for debugging physics shapes.

Example

import tiramisu/debug
import tiramisu/physics
import tiramisu/transform
import vec/vec3

pub fn view(model: Model) {
  let body_transform = transform.at(position: vec3.Vec3(0.0, 5.0, 0.0))
  let collider = physics.Box(width: 2.0, height: 2.0, depth: 2.0)

  [
    // Your normal scene nodes...
    // Debug visualization for the collider
    debug.collider(
      id: "player-collider-debug",
      shape: collider,
      transform: body_transform,
      color: debug.color_green,
    ),
  ]
}
pub const color_black: Int
pub const color_blue: Int
pub const color_cyan: Int
pub const color_green: Int
pub const color_magenta: Int
pub const color_orange: Int
pub const color_purple: Int
pub const color_red: Int
pub const color_white: Int
pub const color_yellow: Int
pub fn cross(
  id: id,
  position: vec3.Vec3(Float),
  size: Float,
  color: Int,
) -> List(scene.Node(id))
pub fn get_performance_stats() -> PerformanceStats
pub fn grid(
  id: id,
  size: Float,
  divisions: Int,
  color: Int,
) -> scene.Node(id)
pub fn line(
  id: id,
  from: vec3.Vec3(Float),
  to: vec3.Vec3(Float),
  color: Int,
) -> scene.Node(id)
pub fn path(
  id: fn(Int) -> id,
  points: List(vec3.Vec3(Float)),
  color: Int,
) -> List(scene.Node(id))

Create multiple lines forming a path through points

pub fn point(
  id: id,
  position: vec3.Vec3(Float),
  size: Float,
  color: Int,
) -> scene.Node(id)
pub fn ray(
  id: id,
  origin: vec3.Vec3(Float),
  direction: vec3.Vec3(Float),
  length: Float,
  color: Int,
) -> scene.Node(id)
pub fn show_collider_wireframes(
  physics_world: physics.PhysicsWorld(id),
  enabled: Bool,
) -> Nil

Enable or disable debug wireframe visualization for all physics colliders in the scene.

This function uses Rapier’s built-in collider visualization which renders wireframes for all physics bodies in the physics world. The wireframes update automatically each frame as objects move and rotate.

Note: This function requires access to the physics world, which is available in the view function via the Context parameter.

Example

import tiramisu/debug
import gleam/option

pub fn view(model: Model, ctx: tiramisu.Context) {
  // Enable/disable debug visualization based on model state
  case ctx.physics_world, model.debug_mode {
    option.Some(physics_world), True -> {
      debug.show_collider_wireframes(physics_world, True)
    }
    _, _ -> Nil
  }

  // Return scene as normal
  [
    scene.Mesh(
      id: "cube",
      geometry: geometry,
      material: material,
      transform: transform,
      physics: option.Some(physics_body),  // Will show wireframe when enabled
    ),
    // ... more scene nodes
  ]
}
pub fn sphere(
  id: id,
  center: vec3.Vec3(Float),
  radius: Float,
  color: Int,
) -> scene.Node(id)
pub fn with_collider_wireframes(
  nodes: List(scene.Node(id)),
  color: Int,
) -> List(scene.Node(id))

@deprecated Use show_collider_wireframes with the physics world from context instead.

This function is kept for backwards compatibility but will be removed in a future version.

Search Document