use std::num::NonZero;
use bevy::{
app::{App, Startup},
asset::{AssetServer, Assets},
color::{Color, Srgba},
math::{Vec2, Vec3},
pbr::{AmbientLight, MeshMaterial3d, StandardMaterial},
prelude::{
AlphaMode, Camera3d, Commands, Mesh, Mesh3d, OrthographicProjection, Plane3d, Projection,
Res, ResMut, Transform,
},
DefaultPlugins,
};
use bevy_rich_text3d::{Text3d, Text3dPlugin, Text3dStyling, TextAtlas};
pub fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(Text3dPlugin {
load_system_fonts: true,
..Default::default()
})
.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 800.,
})
.add_systems(Startup, |mut commands: Commands, server: Res<AssetServer>, mut standard_materials: ResMut<Assets<StandardMaterial>>| {
let mat = standard_materials.add(
StandardMaterial {
base_color_texture: Some(TextAtlas::DEFAULT_IMAGE.clone_weak()),
alpha_mode: AlphaMode::Blend,
unlit: true,
..Default::default()
}
);
commands.spawn((
Text3d::new("Hello World!"),
Text3dStyling {
size: 64.,
stroke: NonZero::new(10),
color: Srgba::new(0., 1., 1., 1.),
stroke_color: Srgba::BLACK,
..Default::default()
},
Mesh3d::default(),
MeshMaterial3d(mat.clone()),
));
commands.spawn((
Text3d::new("This application is powered by bevy, cosmic_text, zeno and bevy_rich_text3d!"),
Text3dStyling {
color: Srgba::new(0., 1., 1., 1.),
..Default::default()
},
Mesh3d::default(),
MeshMaterial3d(mat.clone()),
Transform::from_translation(Vec3::new(50., -100., 0.))
));
commands.spawn((
Mesh3d(server.add(Mesh::from(Plane3d::new(Vec3::Z, Vec2::new(200., 200.))))),
MeshMaterial3d(mat.clone()),
Transform::from_translation(Vec3::new(0., 100., -1.))
));
commands.spawn((
Camera3d::default(),
Projection::Orthographic(OrthographicProjection::default_3d()),
Transform::from_translation(Vec3::new(0., 0., 1.))
.looking_at(Vec3::new(0., 0., 0.), Vec3::Y)
));
})
.run();
}