mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 20:53:53 +00:00
0166db33f7
# Objective #11431 and #11688 implemented meshing support for Bevy's new geometric primitives. The next step is to deprecate the shapes in `bevy_render::mesh::shape` and to later remove them completely for 0.14. ## Solution Deprecate the shapes and reduce code duplication by utilizing the primitive meshing API for the old shapes where possible. Note that some shapes have behavior that can't be exactly reproduced with the new primitives yet: - `Box` is more of an AABB with min/max extents - `Plane` supports a subdivision count - `Quad` has a `flipped` property These types have not been changed to utilize the new primitives yet. --- ## Changelog - Deprecated all shapes in `bevy_render::mesh::shape` - Changed all examples to use new primitives for meshing ## Migration Guide Bevy has previously used rendering-specific types like `UVSphere` and `Quad` for primitive mesh shapes. These have now been deprecated to use the geometric primitives newly introduced in version 0.13. Some examples: ```rust let before = meshes.add(shape::Box::new(5.0, 0.15, 5.0)); let after = meshes.add(Cuboid::new(5.0, 0.15, 5.0)); let before = meshes.add(shape::Quad::default()); let after = meshes.add(Rectangle::default()); let before = meshes.add(shape::Plane::from_size(5.0)); // The surface normal can now also be specified when using `new` let after = meshes.add(Plane3d::default().mesh().size(5.0, 5.0)); let before = meshes.add( Mesh::try_from(shape::Icosphere { radius: 0.5, subdivisions: 5, }) .unwrap(), ); let after = meshes.add(Sphere::new(0.5).mesh().ico(5).unwrap()); ```
78 lines
2.1 KiB
Rust
78 lines
2.1 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},
|
|
};
|
|
|
|
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(MaterialMeshBundle {
|
|
mesh: meshes.add(Cuboid::default()),
|
|
material: materials.add(FallbackTestMaterial {
|
|
image_1d: None,
|
|
image_2d: None,
|
|
image_2d_array: None,
|
|
image_cube: None,
|
|
image_cube_array: None,
|
|
image_3d: None,
|
|
}),
|
|
..default()
|
|
});
|
|
commands.spawn(Camera3dBundle {
|
|
transform: Transform::from_xyz(5.0, 5.0, 5.0).looking_at(Vec3::new(1.5, 0.0, 0.0), Vec3::Y),
|
|
..default()
|
|
});
|
|
}
|
|
|
|
#[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 {
|
|
"shaders/fallback_image_test.wgsl".into()
|
|
}
|
|
}
|