# Objective Yet another PR for migrating stuff to required components. This time, cameras! ## Solution As per the [selected proposal](https://hackmd.io/tsYID4CGRiWxzsgawzxG_g#Combined-Proposal-1-Selected), deprecate `Camera2dBundle` and `Camera3dBundle` in favor of `Camera2d` and `Camera3d`. Adding a `Camera` without `Camera2d` or `Camera3d` now logs a warning, as suggested by Cart [on Discord](https://discord.com/channels/691052431525675048/1264881140007702558/1291506402832945273). I would personally like cameras to work a bit differently and be split into a few more components, to avoid some footguns and confusing semantics, but that is more controversial, and shouldn't block this core migration. ## Testing I ran a few 2D and 3D examples, and tried cameras with and without render graphs. --- ## Migration Guide `Camera2dBundle` and `Camera3dBundle` have been deprecated in favor of `Camera2d` and `Camera3d`. Inserting them will now also insert the other components required by them automatically.
		
			
				
	
	
		
			82 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			82 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
//! Text pipeline benchmark.
 | 
						|
//!
 | 
						|
//! Continuously recomputes a large `Text` component with 100 sections.
 | 
						|
 | 
						|
use bevy::{
 | 
						|
    color::palettes::basic::{BLUE, YELLOW},
 | 
						|
    diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
 | 
						|
    prelude::*,
 | 
						|
    text::{LineBreak, TextBounds},
 | 
						|
    window::{PresentMode, WindowResolution},
 | 
						|
    winit::{UpdateMode, WinitSettings},
 | 
						|
};
 | 
						|
 | 
						|
fn main() {
 | 
						|
    App::new()
 | 
						|
        .add_plugins((
 | 
						|
            DefaultPlugins.set(WindowPlugin {
 | 
						|
                primary_window: Some(Window {
 | 
						|
                    present_mode: PresentMode::AutoNoVsync,
 | 
						|
                    resolution: WindowResolution::new(1920.0, 1080.0)
 | 
						|
                        .with_scale_factor_override(1.0),
 | 
						|
                    ..default()
 | 
						|
                }),
 | 
						|
                ..default()
 | 
						|
            }),
 | 
						|
            FrameTimeDiagnosticsPlugin,
 | 
						|
            LogDiagnosticsPlugin::default(),
 | 
						|
        ))
 | 
						|
        .insert_resource(WinitSettings {
 | 
						|
            focused_mode: UpdateMode::Continuous,
 | 
						|
            unfocused_mode: UpdateMode::Continuous,
 | 
						|
        })
 | 
						|
        .add_systems(Startup, spawn)
 | 
						|
        .add_systems(Update, update_text_bounds)
 | 
						|
        .run();
 | 
						|
}
 | 
						|
 | 
						|
fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
 | 
						|
    warn!(include_str!("warning_string.txt"));
 | 
						|
 | 
						|
    commands.spawn(Camera2d);
 | 
						|
    let sections = (1..=50)
 | 
						|
        .flat_map(|i| {
 | 
						|
            [
 | 
						|
                TextSection {
 | 
						|
                    value: "text".repeat(i),
 | 
						|
                    style: TextStyle {
 | 
						|
                        font: asset_server.load("fonts/FiraMono-Medium.ttf"),
 | 
						|
                        font_size: (4 + i % 10) as f32,
 | 
						|
                        color: BLUE.into(),
 | 
						|
                    },
 | 
						|
                },
 | 
						|
                TextSection {
 | 
						|
                    value: "pipeline".repeat(i),
 | 
						|
                    style: TextStyle {
 | 
						|
                        font: asset_server.load("fonts/FiraSans-Bold.ttf"),
 | 
						|
                        font_size: (4 + i % 11) as f32,
 | 
						|
                        color: YELLOW.into(),
 | 
						|
                    },
 | 
						|
                },
 | 
						|
            ]
 | 
						|
        })
 | 
						|
        .collect::<Vec<_>>();
 | 
						|
    commands.spawn(Text2dBundle {
 | 
						|
        text: Text {
 | 
						|
            sections,
 | 
						|
            justify: JustifyText::Center,
 | 
						|
            linebreak: LineBreak::AnyCharacter,
 | 
						|
            ..default()
 | 
						|
        },
 | 
						|
        ..Default::default()
 | 
						|
    });
 | 
						|
}
 | 
						|
 | 
						|
// changing the bounds of the text will cause a recomputation
 | 
						|
fn update_text_bounds(time: Res<Time>, mut text_bounds_query: Query<&mut TextBounds>) {
 | 
						|
    let width = (1. + ops::sin(time.elapsed_seconds())) * 600.0;
 | 
						|
    for mut text_bounds in text_bounds_query.iter_mut() {
 | 
						|
        text_bounds.width = Some(width);
 | 
						|
    }
 | 
						|
}
 |