Expand description
A simple Bevy plugin for generating 3D text meshes from fonts.
This plugin provides an easy way to create 3D text geometry in Bevy applications. It handles only mesh generation, leaving materials, lighting, transforms, and rendering to Bevy’s standard systems.
§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(TextMeshBundle {
text_mesh: TextMesh {
text: "Hello!".to_string(),
font: asset_server.load("fonts/font.ttf"),
..default()
},
material: MeshMaterial3d(materials.add(StandardMaterial::default())),
..default()
});
}§Custom Materials
To use a custom material type, add FontMeshPlugin a second time with your material:
use bevy::prelude::*;
use bevy_fontmesh::FontMeshPlugin;
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(FontMeshPlugin::<StandardMaterial>::default())
.add_plugins(FontMeshPlugin::<MyCustomMaterial>::default())
.run();§Features
- Generates 3D mesh geometry from TrueType fonts
- Supports multiline text with
\nline breaks - Configurable text anchoring (9 presets + custom pivot points)
- Text justification (left, center, right)
- Adjustable extrusion depth and curve subdivision
- Automatic mesh regeneration when text or style changes
§Font Format Support
- TrueType (
.ttf) fonts are fully supported - OpenType (
.otf) fonts with TrueType outlines work - OpenType fonts with CFF/PostScript outlines are not supported (ttf-parser limitation)
Modules§
Structs§
- Font
Mesh - Asset containing font data for 3D text mesh generation.
- Font
Mesh Plugin - Plugin that enables 3D text mesh generation from fonts.
- Font
Metrics - Font-level metrics
- Glyph
Mesh - Marker component for individual glyph mesh entities.
- Glyph
Metrics - Metrics for a single glyph
- 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 Bundle - Convenience bundle for spawning 3D text entities.
- Text
Mesh Computed - Marker component indicating that a
TextMeshhas been processed. - Text
Mesh Glyphs - Component for generating individual 3D mesh entities for each character.
- Text
Mesh Glyphs Bundle - Convenience bundle for spawning 3D text with per-character entities.
- Text
Mesh Glyphs Computed - Marker component indicating that a
TextMeshGlyphshas been processed. - 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§
- generate_
glyph_ mesh - Generate a Bevy mesh for a single character. Useful for manual glyph updates.
- scale_
screen_ size - For each entity with
ScreenSize, rewrite itsTransform.scaleso that one line of text at unit scale coverspixel_heightpixels of the active camera’s logical target. - update_
glyph_ meshes - System to generate per-character mesh entities for
TextMeshGlyphscomponents.