Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

three dimensional cosmic text #104

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ bevy = { version = "0.12", default-features = false, features = [
"bevy_winit",
"png",
"x11",
"bevy_pbr",
"tonemapping_luts"
] }
cosmic-text = { version = "0.10" }

# TODO: move crossbeam to wasm32, once input.rs has separate wasm copy/paste fn
crossbeam-channel = "0.5.8"
image = "0.24.6"
Expand Down
82 changes: 82 additions & 0 deletions examples/3d.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use bevy::prelude::*;
use bevy_cosmic_edit::*;

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(CosmicEditPlugin {
change_cursor: CursorConfig::None,
..default()
})
.add_systems(Startup, setup)
.add_systems(Update, set_texture)
.run();
}

fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let editor = commands
.spawn((
CosmicEditBundle {
text_setter: CosmicText::OneStyle("It is a period of civil wars in the galaxy. A brave alliance of underground freedom fighters has challenged the tyranny and oppression of the awesome GALACTIC EMPIRE.
Striking from a fortress hidden among the billion stars of the galaxy, rebel spaceships have won their first victory in a battle with the powerful Imperial Starfleet. The EMPIRE fears that another defeat could bring a thousand more solar systems into the rebellion, and Imperial control over the galaxy would be lost forever.

To crush the rebellion once and for all, the EMPIRE is constructing a sinister new battle station. Powerful enough to destroy an entire planet, its completion spells certain doom for the champions of freedom.".into()),
fill_color: FillColor(Color::NONE),
attrs: CosmicAttrs(AttrsOwned::new(Attrs::new().color(CosmicColor::rgba(255,200,0,255)))),
metrics: CosmicMetrics {
font_size: 20.0,
line_height: 20.0,
..default()
},
..default()
},
))
.id();

commands.insert_resource(Focus(Some(editor)));

commands.spawn(PointLightBundle {
point_light: PointLight {
intensity: 9000.0,
range: 100.,
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(8.0, 16.0, 8.0),
..default()
});

commands.spawn((
PbrBundle {
mesh: meshes.add(shape::Plane::from_size(1.0).into()),
material: materials.add(Color::RED.into()),
transform: Transform::from_scale(Vec3::ONE * 10.0),
..default()
},
CosmicSource(editor),
));

commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.0, 6., 12.0).looking_at(Vec3::new(0., 1., 0.), Vec3::Y),
..default()
});
}

fn set_texture(
plane_q: Query<&Handle<StandardMaterial>>,
canvas_q: Query<&Handle<Image>, With<CosmicEditor>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
for handle in plane_q.iter() {
if let Some(mut material) = materials.get_mut(handle) {
if let Ok(canvas) = canvas_q.get_single() {
material.base_color = Color::WHITE;
material.base_color_texture = Some(canvas.clone_weak());
}
}
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ impl Plugin for CosmicEditPlugin {
let render_systems = (
render::new_image_from_default.in_set(CosmicRenderSet::Setup),
render::set_size_from_ui.in_set(CosmicRenderSet::Setup),
render::set_size_from_transform.in_set(CosmicRenderSet::Setup),
render::cosmic_reshape.in_set(CosmicRenderSet::Shaping),
render::cosmic_widget_size.in_set(CosmicRenderSet::Sizing),
render::cosmic_buffer_size.in_set(CosmicRenderSet::Sizing),
Expand Down
11 changes: 9 additions & 2 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,15 @@ pub(crate) fn set_size_from_ui(
}
}

pub(crate) fn _set_size_from_mesh() {
// TODO
pub(crate) fn set_size_from_transform(
mut source_q: Query<&mut Sprite, With<CosmicEditor>>,
dest_q: Query<(&Transform, &CosmicSource), With<Handle<Mesh>>>,
) {
for (transform, source) in dest_q.iter() {
if let Ok(mut sprite) = source_q.get_mut(source.0) {
sprite.custom_size = Some(transform.scale.truncate() * 64.0);
}
}
}

fn draw_pixel(
Expand Down