Text rendering in 3D is provided via the bevy_rich_text3d crate, which bevy_lunex re-exports. If you have disabled default features, you must enable the text3d feature to use it.
To render 3D text, you must spawn an entity with a specific combination of components. Unlike 2D text, Text3d requires a Mesh3d and a MeshMaterial3d to function.
Required Components
Text3d: Specifies the actual text content.UiLayout: Specifies position and anchor (size is ignored).UiTextSize: Specifies the height of the text in proportion to the parent node.Mesh3d: Must include an empty Mesh3d::default() component.MeshMaterial3d: Requires a material. It is recommended to use a StandardMaterial with unlit: true and alpha_mode: AlphaMode::Blend using the TextAtlas::DEFAULT_IMAGE texture.
Important Constraints
- Camera Requirement:
Text3d can ONLY be rendered with a Camera3d. - Font Loading: Unlike standard Bevy text, you do not provide a font handle in
Text3dStyling. Instead, you must load fonts into a fontdb using the LoadFonts resource, then reference the font by its name string.
ui.spawn((
Name::new("Panel"),
// Set the layout of this mesh
UiLayout::window().pos(Rl(50.0)).anchor(Anchor::Center).pack(),
// This controls the height of the text, so 10% of the parent's node height
UiTextSize::from(Rh(10.0)),
// Set the text value
Text3d::new("Hello 3D UI!"),
// Style the 3D text
Text3dStyling {
size: 64.0,
color: Srgba::new(1., 1., 1., 1.),
align: TextAlign::Center,
font: Arc::from("Rajdhani"),
weight: Weight::BOLD,
..Default::default()
},
// Provide a material to this mesh
MeshMaterial3d(materials.add(
StandardMaterial {
base_color_texture: Some(TextAtlas::DEFAULT_IMAGE),
alpha_mode: AlphaMode::Blend,
unlit: true,
..Default::default()
}
)),
// Requires an empty mesh
Mesh3d::default(),
));