Skip to main content

Crate bevy_fontmesh

Crate bevy_fontmesh 

Source
Expand description

A Bevy plugin for generating 3D text meshes from fonts.

Starting with 0.4 the plugin uses Bevy’s standard bevy::text::Font asset for font loading and cosmic-text for shaping, so the same Handle<Font> you use for 2D UI text also drives 3D text meshes. This brings real text shaping (kerning, ligatures, BiDi, complex scripts) and full OpenType/CFF support.

§Quick Start

use bevy::prelude::*;
use bevy_fontmesh::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(FontMeshPlugin::<StandardMaterial>::default())
        .add_systems(Startup, setup)
        .run();
}

fn setup(
    mut commands: Commands,
    asset_server: Res<AssetServer>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    commands.spawn((
        TextMesh {
            text: "Hello!".to_string(),
            font: asset_server.load("fonts/font.ttf"),
            ..default()
        },
        MeshMaterial3d(materials.add(StandardMaterial::default())),
    ));
}

§Custom Materials

Add FontMeshPlugin a second time with your material type:

use bevy::prelude::*;
use bevy_fontmesh::FontMeshPlugin;

App::new()
    .add_plugins(DefaultPlugins)
    .add_plugins(FontMeshPlugin::<StandardMaterial>::default())
    .add_plugins(FontMeshPlugin::<MyCustomMaterial>::default())
    .run();

§Font Format Support

Both TrueType (.ttf) and OpenType (.otf, including CFF/PostScript outlines) are supported via skrifa. Loading is handled by Bevy’s standard font loader.

Modules§

prelude

Structs§

FontMeshPlugin
Plugin that enables 3D text mesh generation from fonts.
FontMeshRegistry
Tracks which Handle<Font> we’ve already pushed into cosmic-text’s font database, plus the family name we need to pass back into Attrs so cosmic picks that exact face. Without this we’d re-register the same bytes every frame, ballooning the db.
GlyphMesh
Marker component for individual glyph mesh entities.
GlyphMeshCache
Caches generated per-glyph meshes keyed by (font, glyph id, depth, subdivision).
ScreenSize
Render the entity’s text mesh at a constant screen-pixel size, independent of camera distance / zoom.
ScreenSizeCamera
Marker on a Camera to opt that camera into being the one ScreenSize measures against. If no entity in the world has this marker, the screen-size system falls back to whichever camera Query<&Camera> returns first — fine for single-camera apps.
TextMesh
Component for generating 3D text meshes from fonts.
TextMeshComputed
TextMeshGlyphs
Component for generating individual 3D mesh entities for each character.
TextMeshGlyphsComputed
TextMeshStyle
Visual styling parameters for generated text meshes.

Enums§

JustifyText
Controls horizontal alignment of multiline text.
TextAnchor
Determines where the text mesh is positioned relative to its transform origin.

Functions§

on_font_asset_event
scale_screen_size
update_glyph_meshes
System to generate per-character mesh entities for TextMeshGlyphs.