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§
Structs§
- Font
Mesh Plugin - Plugin that enables 3D text mesh generation from fonts.
- Font
Mesh Registry - Tracks which
Handle<Font>we’ve already pushed into cosmic-text’s font database, plus the family name we need to pass back intoAttrsso cosmic picks that exact face. Without this we’d re-register the same bytes every frame, ballooning the db. - Glyph
Mesh - Marker component for individual glyph mesh entities.
- Glyph
Mesh Cache - Caches generated per-glyph meshes keyed by
(font, glyph id, depth, subdivision). - Screen
Size - Render the entity’s text mesh at a constant screen-pixel size, independent of camera distance / zoom.
- Screen
Size Camera - Marker on a
Camerato opt that camera into being the oneScreenSizemeasures against. If no entity in the world has this marker, the screen-size system falls back to whichever cameraQuery<&Camera>returns first — fine for single-camera apps. - Text
Mesh - Component for generating 3D text meshes from fonts.
- Text
Mesh Computed - Text
Mesh Glyphs - Component for generating individual 3D mesh entities for each character.
- Text
Mesh Glyphs Computed - Text
Mesh Style - Visual styling parameters for generated text meshes.
Enums§
- Justify
Text - Controls horizontal alignment of multiline text.
- Text
Anchor - 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.