mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 14:10:19 +00:00
25bfa80e60
# 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.
80 lines
2.2 KiB
Rust
80 lines
2.2 KiB
Rust
//! This example tests that all texture dimensions are supported by
|
|
//! `FallbackImage`.
|
|
//!
|
|
//! When running this example, you should expect to see a window that only draws
|
|
//! the clear color. The test material does not shade any geometry; this example
|
|
//! only tests that the images are initialized and bound so that the app does
|
|
//! not panic.
|
|
use bevy::{
|
|
prelude::*,
|
|
reflect::TypePath,
|
|
render::render_resource::{AsBindGroup, ShaderRef},
|
|
};
|
|
|
|
/// This example uses a shader source file from the assets subdirectory
|
|
const SHADER_ASSET_PATH: &str = "shaders/fallback_image_test.wgsl";
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins((
|
|
DefaultPlugins,
|
|
MaterialPlugin::<FallbackTestMaterial>::default(),
|
|
))
|
|
.add_systems(Startup, setup)
|
|
.run();
|
|
}
|
|
|
|
fn setup(
|
|
mut commands: Commands,
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
mut materials: ResMut<Assets<FallbackTestMaterial>>,
|
|
) {
|
|
commands.spawn((
|
|
Mesh3d(meshes.add(Cuboid::default())),
|
|
MeshMaterial3d(materials.add(FallbackTestMaterial {
|
|
image_1d: None,
|
|
image_2d: None,
|
|
image_2d_array: None,
|
|
image_cube: None,
|
|
image_cube_array: None,
|
|
image_3d: None,
|
|
})),
|
|
));
|
|
commands.spawn((
|
|
Camera3d::default(),
|
|
Transform::from_xyz(5.0, 5.0, 5.0).looking_at(Vec3::new(1.5, 0.0, 0.0), Vec3::Y),
|
|
));
|
|
}
|
|
|
|
#[derive(AsBindGroup, Debug, Clone, Asset, TypePath)]
|
|
struct FallbackTestMaterial {
|
|
#[texture(0, dimension = "1d")]
|
|
#[sampler(1)]
|
|
image_1d: Option<Handle<Image>>,
|
|
|
|
#[texture(2, dimension = "2d")]
|
|
#[sampler(3)]
|
|
image_2d: Option<Handle<Image>>,
|
|
|
|
#[texture(4, dimension = "2d_array")]
|
|
#[sampler(5)]
|
|
image_2d_array: Option<Handle<Image>>,
|
|
|
|
#[texture(6, dimension = "cube")]
|
|
#[sampler(7)]
|
|
image_cube: Option<Handle<Image>>,
|
|
|
|
#[texture(8, dimension = "cube_array")]
|
|
#[sampler(9)]
|
|
image_cube_array: Option<Handle<Image>>,
|
|
|
|
#[texture(10, dimension = "3d")]
|
|
#[sampler(11)]
|
|
image_3d: Option<Handle<Image>>,
|
|
}
|
|
|
|
impl Material for FallbackTestMaterial {
|
|
fn fragment_shader() -> ShaderRef {
|
|
SHADER_ASSET_PATH.into()
|
|
}
|
|
}
|