From a795de30b40bde55edbf780b0dbfcd4c7a61bb26 Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Tue, 9 Jan 2024 00:14:43 +0200 Subject: [PATCH] Use `impl Into` for `Assets::add` (#10878) # Motivation When spawning entities into a scene, it is very common to create assets like meshes and materials and to add them via asset handles. A common setup might look like this: ```rust fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { commands.spawn(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(StandardMaterial::from(Color::RED)), ..default() }); } ``` Let's take a closer look at the part that adds the assets using `add`. ```rust mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(StandardMaterial::from(Color::RED)), ``` Here, "mesh" and "material" are both repeated three times. It's very explicit, but I find it to be a bit verbose. In addition to being more code to read and write, the extra characters can sometimes also lead to the code being formatted to span multiple lines even though the core task, adding e.g. a primitive mesh, is extremely simple. A way to address this is by using `.into()`: ```rust mesh: meshes.add(shape::Cube { size: 1.0 }.into()), material: materials.add(Color::RED.into()), ``` This is fine, but from the names and the type of `meshes`, we already know what the type should be. It's very clear that `Cube` should be turned into a `Mesh` because of the context it's used in. `.into()` is just seven characters, but it's so common that it quickly adds up and gets annoying. It would be nice if you could skip all of the conversion and let Bevy handle it for you: ```rust mesh: meshes.add(shape::Cube { size: 1.0 }), material: materials.add(Color::RED), ``` # Objective Make adding assets more ergonomic by making `Assets::add` take an `impl Into` instead of `A`. ## Solution `Assets::add` now takes an `impl Into` instead of `A`, so e.g. this works: ```rust commands.spawn(PbrBundle { mesh: meshes.add(shape::Cube { size: 1.0 }), material: materials.add(Color::RED), ..default() }); ``` I also changed all examples to use this API, which increases consistency as well because `Mesh::from` and `into` were being used arbitrarily even in the same file. This also gets rid of some lines of code because formatting is nicer. --- ## Changelog - `Assets::add` now takes an `impl Into` instead of `A` - Examples don't use `T::from(K)` or `K.into()` when adding assets ## Migration Guide Some `into` calls that worked previously might now be broken because of the new trait bounds. You need to either remove `into` or perform the conversion explicitly with `from`: ```rust // Doesn't compile let mesh_handle = meshes.add(shape::Cube { size: 1.0 }.into()), // These compile let mesh_handle = meshes.add(shape::Cube { size: 1.0 }), let mesh_handle = meshes.add(Mesh::from(shape::Cube { size: 1.0 })), ``` ## Concerns I believe the primary concerns might be: 1. Is this too implicit? 2. Does this increase codegen bloat? Previously, the two APIs were using `into` or `from`, and now it's "nothing" or `from`. You could argue that `into` is slightly more explicit than "nothing" in cases like the earlier examples where a `Color` gets converted to e.g. a `StandardMaterial`, but I personally don't think `into` adds much value even in this case, and you could still see the actual type from the asset type. As for codegen bloat, I doubt it adds that much, but I'm not very familiar with the details of codegen. I personally value the user-facing code reduction and ergonomics improvements that these changes would provide, but it might be worth checking the other effects in more detail. Another slight concern is migration pain; apps might have a ton of `into` calls that would need to be removed, and it did take me a while to do so for Bevy itself (maybe around 20-40 minutes). However, I think the fact that there *are* so many `into` calls just highlights that the API could be made nicer, and I'd gladly migrate my own projects for it. --- crates/bevy_asset/src/assets.rs | 4 +-- errors/B0004.md | 8 +++--- examples/2d/2d_shapes.rs | 8 +++--- examples/2d/bloom_2d.rs | 6 ++--- examples/2d/mesh2d.rs | 2 +- examples/3d/3d_gizmos.rs | 8 +++--- examples/3d/3d_scene.rs | 8 +++--- examples/3d/3d_shapes.rs | 18 ++++++------- examples/3d/3d_viewport_to_world.rs | 4 +-- examples/3d/anti_aliasing.rs | 6 ++--- examples/3d/atmospheric_fog.rs | 2 +- examples/3d/blend_modes.rs | 6 ++--- examples/3d/bloom_3d.rs | 5 ++-- examples/3d/deferred_rendering.rs | 10 +++---- examples/3d/fog.rs | 10 +++---- examples/3d/lighting.rs | 26 +++++++++---------- examples/3d/lines.rs | 8 +++--- examples/3d/orthographic.rs | 20 +++++++------- examples/3d/parallax_mapping.rs | 16 +++++------- examples/3d/parenting.rs | 2 +- examples/3d/render_to_texture.rs | 4 +-- examples/3d/shadow_biases.rs | 2 +- examples/3d/shadow_caster_receiver.rs | 10 +++---- examples/3d/spherical_area_lights.rs | 6 ++--- examples/3d/split_screen.rs | 4 +-- examples/3d/spotlight.rs | 16 ++++++------ examples/3d/ssao.rs | 10 +++---- examples/3d/texture.rs | 5 +--- examples/3d/tonemapping.rs | 18 ++++++------- examples/3d/transmission.rs | 8 +++--- examples/3d/transparency_3d.rs | 10 +++---- examples/3d/two_passes.rs | 8 +++--- examples/3d/vertex_colors.rs | 6 ++--- examples/3d/wireframe.rs | 16 ++++++------ examples/animation/animated_fox.rs | 4 +-- examples/animation/animated_transform.rs | 6 ++--- examples/animation/cubic_curve.rs | 8 +++--- examples/animation/custom_skinned_mesh.rs | 22 +++++++--------- examples/async_tasks/async_compute.rs | 4 +-- examples/audio/spatial_audio_2d.rs | 4 +-- examples/audio/spatial_audio_3d.rs | 14 +++++----- examples/ecs/iter_combinations.rs | 13 ++++------ examples/games/breakout.rs | 4 +-- examples/mobile/src/lib.rs | 10 +++---- examples/shader/animate_shader.rs | 2 +- examples/shader/array_texture.rs | 2 +- examples/shader/fallback_image.rs | 6 ++--- examples/shader/post_processing.rs | 4 +-- examples/shader/shader_defs.rs | 4 +-- examples/shader/shader_instancing.rs | 2 +- examples/shader/shader_material.rs | 2 +- examples/shader/shader_material_2d.rs | 2 +- examples/shader/shader_material_glsl.rs | 2 +- .../shader_material_screenspace_texture.rs | 6 ++--- examples/shader/shader_prepass.rs | 12 ++++----- examples/shader/texture_binding_array.rs | 6 ++--- examples/stress_tests/bevymark.rs | 4 +-- examples/stress_tests/many_cubes.rs | 2 +- examples/stress_tests/many_foxes.rs | 4 +-- examples/stress_tests/many_lights.rs | 4 +-- examples/tools/gamepad_viewer.rs | 12 ++++----- examples/transforms/3d_rotation.rs | 4 +-- examples/transforms/scale.rs | 4 +-- examples/transforms/transform.rs | 6 ++--- examples/transforms/translation.rs | 4 +-- examples/window/low_power.rs | 4 +-- examples/window/screenshot.rs | 8 +++--- tests/window/minimising.rs | 10 +++---- tests/window/resizing.rs | 10 +++---- 69 files changed, 247 insertions(+), 268 deletions(-) diff --git a/crates/bevy_asset/src/assets.rs b/crates/bevy_asset/src/assets.rs index 78a038fa55..bcb2cb7bf0 100644 --- a/crates/bevy_asset/src/assets.rs +++ b/crates/bevy_asset/src/assets.rs @@ -361,9 +361,9 @@ impl Assets { /// Adds the given `asset` and allocates a new strong [`Handle`] for it. #[inline] - pub fn add(&mut self, asset: A) -> Handle { + pub fn add(&mut self, asset: impl Into) -> Handle { let index = self.dense_storage.allocator.reserve(); - self.insert_with_index(index, asset).unwrap(); + self.insert_with_index(index, asset.into()).unwrap(); Handle::Strong( self.handle_provider .get_handle(index.into(), false, None, None), diff --git a/errors/B0004.md b/errors/B0004.md index 55a2d3f8da..42cb6af773 100644 --- a/errors/B0004.md +++ b/errors/B0004.md @@ -33,8 +33,8 @@ fn setup_cube( .with_children(|parent| { // cube parent.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }); @@ -80,8 +80,8 @@ fn setup_cube( .with_children(|parent| { // cube parent.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }); diff --git a/examples/2d/2d_shapes.rs b/examples/2d/2d_shapes.rs index 7fa168fe69..382b02fa7a 100644 --- a/examples/2d/2d_shapes.rs +++ b/examples/2d/2d_shapes.rs @@ -18,7 +18,7 @@ fn setup( // Circle commands.spawn(MaterialMesh2dBundle { - mesh: meshes.add(shape::Circle::new(50.).into()).into(), + mesh: meshes.add(shape::Circle::new(50.)).into(), material: materials.add(ColorMaterial::from(Color::PURPLE)), transform: Transform::from_translation(Vec3::new(-150., 0., 0.)), ..default() @@ -37,9 +37,7 @@ fn setup( // Quad commands.spawn(MaterialMesh2dBundle { - mesh: meshes - .add(shape::Quad::new(Vec2::new(50., 100.)).into()) - .into(), + mesh: meshes.add(shape::Quad::new(Vec2::new(50., 100.))).into(), material: materials.add(ColorMaterial::from(Color::LIME_GREEN)), transform: Transform::from_translation(Vec3::new(50., 0., 0.)), ..default() @@ -47,7 +45,7 @@ fn setup( // Hexagon commands.spawn(MaterialMesh2dBundle { - mesh: meshes.add(shape::RegularPolygon::new(50., 6).into()).into(), + mesh: meshes.add(shape::RegularPolygon::new(50., 6)).into(), material: materials.add(ColorMaterial::from(Color::TURQUOISE)), transform: Transform::from_translation(Vec3::new(150., 0., 0.)), ..default() diff --git a/examples/2d/bloom_2d.rs b/examples/2d/bloom_2d.rs index 5fe9ab9bc1..04f8bc752b 100644 --- a/examples/2d/bloom_2d.rs +++ b/examples/2d/bloom_2d.rs @@ -48,7 +48,7 @@ fn setup( // Circle mesh commands.spawn(MaterialMesh2dBundle { - mesh: meshes.add(shape::Circle::new(100.).into()).into(), + mesh: meshes.add(shape::Circle::new(100.)).into(), // 4. Put something bright in a dark environment to see the effect material: materials.add(ColorMaterial::from(Color::rgb(7.5, 0.0, 7.5))), transform: Transform::from_translation(Vec3::new(-200., 0., 0.)), @@ -57,9 +57,7 @@ fn setup( // Hexagon mesh commands.spawn(MaterialMesh2dBundle { - mesh: meshes - .add(shape::RegularPolygon::new(100., 6).into()) - .into(), + mesh: meshes.add(shape::RegularPolygon::new(100., 6)).into(), // 4. Put something bright in a dark environment to see the effect material: materials.add(ColorMaterial::from(Color::rgb(6.25, 9.4, 9.1))), transform: Transform::from_translation(Vec3::new(200., 0., 0.)), diff --git a/examples/2d/mesh2d.rs b/examples/2d/mesh2d.rs index bc419e5321..324276a3c7 100644 --- a/examples/2d/mesh2d.rs +++ b/examples/2d/mesh2d.rs @@ -18,7 +18,7 @@ fn setup( ) { commands.spawn(Camera2dBundle::default()); commands.spawn(MaterialMesh2dBundle { - mesh: meshes.add(Mesh::from(shape::Quad::default())).into(), + mesh: meshes.add(shape::Quad::default()).into(), transform: Transform::default().with_scale(Vec3::splat(128.)), material: materials.add(ColorMaterial::from(Color::PURPLE)), ..default() diff --git a/examples/3d/3d_gizmos.rs b/examples/3d/3d_gizmos.rs index 113b670a11..1fe8d01da3 100644 --- a/examples/3d/3d_gizmos.rs +++ b/examples/3d/3d_gizmos.rs @@ -23,14 +23,14 @@ fn setup( }); // plane commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + mesh: meshes.add(shape::Plane::from_size(5.0)), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }); // cube commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }); diff --git a/examples/3d/3d_scene.rs b/examples/3d/3d_scene.rs index ca142616fd..47cec017d7 100644 --- a/examples/3d/3d_scene.rs +++ b/examples/3d/3d_scene.rs @@ -17,15 +17,15 @@ fn setup( ) { // circular base commands.spawn(PbrBundle { - mesh: meshes.add(shape::Circle::new(4.0).into()), - material: materials.add(Color::WHITE.into()), + mesh: meshes.add(shape::Circle::new(4.0)), + material: materials.add(Color::WHITE), transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)), ..default() }); // cube commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb_u8(124, 144, 255).into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::rgb_u8(124, 144, 255)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }); diff --git a/examples/3d/3d_shapes.rs b/examples/3d/3d_shapes.rs index 8bf490b04f..1207b2ba3c 100644 --- a/examples/3d/3d_shapes.rs +++ b/examples/3d/3d_shapes.rs @@ -37,13 +37,13 @@ fn setup( }); let shapes = [ - meshes.add(shape::Cube::default().into()), - meshes.add(shape::Box::default().into()), - meshes.add(shape::Capsule::default().into()), - meshes.add(shape::Torus::default().into()), - meshes.add(shape::Cylinder::default().into()), - meshes.add(shape::Icosphere::default().try_into().unwrap()), - meshes.add(shape::UVSphere::default().into()), + meshes.add(shape::Cube::default()), + meshes.add(shape::Box::default()), + meshes.add(shape::Capsule::default()), + meshes.add(shape::Torus::default()), + meshes.add(shape::Cylinder::default()), + meshes.add(Mesh::try_from(shape::Icosphere::default()).unwrap()), + meshes.add(shape::UVSphere::default()), ]; let num_shapes = shapes.len(); @@ -78,8 +78,8 @@ fn setup( // ground plane commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(50.0).into()), - material: materials.add(Color::SILVER.into()), + mesh: meshes.add(shape::Plane::from_size(50.0)), + material: materials.add(Color::SILVER), ..default() }); diff --git a/examples/3d/3d_viewport_to_world.rs b/examples/3d/3d_viewport_to_world.rs index 308e379a4e..7b03339d18 100644 --- a/examples/3d/3d_viewport_to_world.rs +++ b/examples/3d/3d_viewport_to_world.rs @@ -51,8 +51,8 @@ fn setup( // plane commands.spawn(( PbrBundle { - mesh: meshes.add(shape::Plane::from_size(20.).into()), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + mesh: meshes.add(shape::Plane::from_size(20.)), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }, Ground, diff --git a/examples/3d/anti_aliasing.rs b/examples/3d/anti_aliasing.rs index 04e0bf969a..8dc14e5483 100644 --- a/examples/3d/anti_aliasing.rs +++ b/examples/3d/anti_aliasing.rs @@ -260,8 +260,8 @@ fn setup( ) { // Plane commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(50.0).into()), - material: materials.add(Color::rgb(0.1, 0.2, 0.1).into()), + mesh: meshes.add(shape::Plane::from_size(50.0)), + material: materials.add(Color::rgb(0.1, 0.2, 0.1)), ..default() }); @@ -273,7 +273,7 @@ fn setup( // Cubes for i in 0..5 { commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 0.25 })), + mesh: meshes.add(shape::Cube { size: 0.25 }), material: cube_material.clone(), transform: Transform::from_xyz(i as f32 * 0.25 - 1.0, 0.125, -i as f32 * 0.5), ..default() diff --git a/examples/3d/atmospheric_fog.rs b/examples/3d/atmospheric_fog.rs index 18180150ad..5439257a40 100644 --- a/examples/3d/atmospheric_fog.rs +++ b/examples/3d/atmospheric_fog.rs @@ -79,7 +79,7 @@ fn setup_terrain_scene( // Sky commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::Box::default())), + mesh: meshes.add(shape::Box::default()), material: materials.add(StandardMaterial { base_color: Color::hex("888888").unwrap(), unlit: true, diff --git a/examples/3d/blend_modes.rs b/examples/3d/blend_modes.rs index 92bb2cd156..194a6f5610 100644 --- a/examples/3d/blend_modes.rs +++ b/examples/3d/blend_modes.rs @@ -146,10 +146,10 @@ fn setup( .id(); // Chessboard Plane - let black_material = materials.add(Color::BLACK.into()); - let white_material = materials.add(Color::WHITE.into()); + let black_material = materials.add(Color::BLACK); + let white_material = materials.add(Color::WHITE); - let plane_mesh = meshes.add(shape::Plane::from_size(2.0).into()); + let plane_mesh = meshes.add(shape::Plane::from_size(2.0)); for x in -3..4 { for z in -3..4 { diff --git a/examples/3d/bloom_3d.rs b/examples/3d/bloom_3d.rs index ad41ca38d3..2b475a33ca 100644 --- a/examples/3d/bloom_3d.rs +++ b/examples/3d/bloom_3d.rs @@ -56,11 +56,10 @@ fn setup_scene( }); let mesh = meshes.add( - shape::Icosphere { + Mesh::try_from(shape::Icosphere { radius: 0.5, subdivisions: 5, - } - .try_into() + }) .unwrap(), ); diff --git a/examples/3d/deferred_rendering.rs b/examples/3d/deferred_rendering.rs index 6b5dbbe466..e7bd647bde 100644 --- a/examples/3d/deferred_rendering.rs +++ b/examples/3d/deferred_rendering.rs @@ -103,16 +103,16 @@ fn setup( // Plane commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(50.0).into()), + mesh: meshes.add(shape::Plane::from_size(50.0)), material: forward_mat_h.clone(), ..default() }); - let cube_h = meshes.add(Mesh::from(shape::Cube { size: 0.1 })); - let sphere_h = meshes.add(Mesh::from(shape::UVSphere { + let cube_h = meshes.add(shape::Cube { size: 0.1 }); + let sphere_h = meshes.add(shape::UVSphere { radius: 0.125, ..default() - })); + }); // Cubes commands.spawn(PbrBundle { @@ -196,7 +196,7 @@ fn setup( // sky commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::Box::default())), + mesh: meshes.add(shape::Box::default()), material: materials.add(StandardMaterial { base_color: Color::hex("888888").unwrap(), unlit: true, diff --git a/examples/3d/fog.rs b/examples/3d/fog.rs index dbeaa23c5f..6115beb751 100644 --- a/examples/3d/fog.rs +++ b/examples/3d/fog.rs @@ -58,14 +58,14 @@ fn setup_pyramid_scene( // pillars for (x, z) in &[(-1.5, -1.5), (1.5, -1.5), (1.5, 1.5), (-1.5, 1.5)] { commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Box { + mesh: meshes.add(shape::Box { min_x: -0.5, max_x: 0.5, min_z: -0.5, max_z: 0.5, min_y: 0.0, max_y: 3.0, - })), + }), material: stone.clone(), transform: Transform::from_xyz(*x, 0.0, *z), ..default() @@ -97,14 +97,14 @@ fn setup_pyramid_scene( let size = i as f32 / 2.0 + 3.0; let y = -i as f32 / 2.0; commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Box { + mesh: meshes.add(shape::Box { min_x: -size, max_x: size, min_z: -size, max_z: size, min_y: 0.0, max_y: 0.5, - })), + }), material: stone.clone(), transform: Transform::from_xyz(0.0, y, 0.0), ..default() @@ -113,7 +113,7 @@ fn setup_pyramid_scene( // sky commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Box::default())), + mesh: meshes.add(shape::Box::default()), material: materials.add(StandardMaterial { base_color: Color::hex("888888").unwrap(), unlit: true, diff --git a/examples/3d/lighting.rs b/examples/3d/lighting.rs index e82e50145a..5e4069ab66 100644 --- a/examples/3d/lighting.rs +++ b/examples/3d/lighting.rs @@ -25,7 +25,7 @@ fn setup( ) { // ground plane commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(10.0).into()), + mesh: meshes.add(shape::Plane::from_size(10.0)), material: materials.add(StandardMaterial { base_color: Color::WHITE, perceptual_roughness: 1.0, @@ -38,7 +38,7 @@ fn setup( let mut transform = Transform::from_xyz(2.5, 2.5, 0.0); transform.rotate_z(PI / 2.); commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Box::new(5.0, 0.15, 5.0))), + mesh: meshes.add(shape::Box::new(5.0, 0.15, 5.0)), transform, material: materials.add(StandardMaterial { base_color: Color::INDIGO, @@ -51,7 +51,7 @@ fn setup( let mut transform = Transform::from_xyz(0.0, 2.5, -2.5); transform.rotate_x(PI / 2.); commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Box::new(5.0, 0.15, 5.0))), + mesh: meshes.add(shape::Box::new(5.0, 0.15, 5.0)), transform, material: materials.add(StandardMaterial { base_color: Color::INDIGO, @@ -66,7 +66,7 @@ fn setup( transform.rotate_y(PI / 8.); commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::Quad::new(Vec2::new(2.0, 0.5)))), + mesh: meshes.add(shape::Quad::new(Vec2::new(2.0, 0.5))), transform, material: materials.add(StandardMaterial { base_color_texture: Some(asset_server.load("branding/bevy_logo_light.png")), @@ -83,7 +83,7 @@ fn setup( // cube commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + mesh: meshes.add(shape::Cube { size: 1.0 }), material: materials.add(StandardMaterial { base_color: Color::PINK, ..default() @@ -96,10 +96,10 @@ fn setup( // sphere commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::UVSphere { + mesh: meshes.add(shape::UVSphere { radius: 0.5, ..default() - })), + }), material: materials.add(StandardMaterial { base_color: Color::LIME_GREEN, ..default() @@ -131,10 +131,10 @@ fn setup( }) .with_children(|builder| { builder.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::UVSphere { + mesh: meshes.add(shape::UVSphere { radius: 0.1, ..default() - })), + }), material: materials.add(StandardMaterial { base_color: Color::RED, emissive: Color::rgba_linear(7.13, 0.0, 0.0, 0.0), @@ -162,11 +162,11 @@ fn setup( .with_children(|builder| { builder.spawn(PbrBundle { transform: Transform::from_rotation(Quat::from_rotation_x(PI / 2.0)), - mesh: meshes.add(Mesh::from(shape::Capsule { + mesh: meshes.add(shape::Capsule { depth: 0.125, radius: 0.1, ..default() - })), + }), material: materials.add(StandardMaterial { base_color: Color::GREEN, emissive: Color::rgba_linear(0.0, 7.13, 0.0, 0.0), @@ -191,10 +191,10 @@ fn setup( }) .with_children(|builder| { builder.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::UVSphere { + mesh: meshes.add(shape::UVSphere { radius: 0.1, ..default() - })), + }), material: materials.add(StandardMaterial { base_color: Color::BLUE, emissive: Color::rgba_linear(0.0, 0.0, 7.13, 0.0), diff --git a/examples/3d/lines.rs b/examples/3d/lines.rs index e12202c8ad..86acc9e7cf 100644 --- a/examples/3d/lines.rs +++ b/examples/3d/lines.rs @@ -28,12 +28,12 @@ fn setup( ) { // Spawn a list of lines with start and end points for each lines commands.spawn(MaterialMeshBundle { - mesh: meshes.add(Mesh::from(LineList { + mesh: meshes.add(LineList { lines: vec![ (Vec3::ZERO, Vec3::new(1.0, 1.0, 0.0)), (Vec3::new(1.0, 1.0, 0.0), Vec3::new(1.0, 0.0, 0.0)), ], - })), + }), transform: Transform::from_xyz(-1.5, 0.0, 0.0), material: materials.add(LineMaterial { color: Color::GREEN, @@ -43,13 +43,13 @@ fn setup( // Spawn a line strip that goes from point to point commands.spawn(MaterialMeshBundle { - mesh: meshes.add(Mesh::from(LineStrip { + mesh: meshes.add(LineStrip { points: vec![ Vec3::ZERO, Vec3::new(1.0, 1.0, 0.0), Vec3::new(1.0, 0.0, 0.0), ], - })), + }), transform: Transform::from_xyz(0.5, 0.0, 0.0), material: materials.add(LineMaterial { color: Color::BLUE }), ..default() diff --git a/examples/3d/orthographic.rs b/examples/3d/orthographic.rs index 32447fd6a8..0f85c1d0fd 100644 --- a/examples/3d/orthographic.rs +++ b/examples/3d/orthographic.rs @@ -29,32 +29,32 @@ fn setup( // plane commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(5.0).into()), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + mesh: meshes.add(shape::Plane::from_size(5.0)), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }); // cubes commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(1.5, 0.5, 1.5), ..default() }); commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(1.5, 0.5, -1.5), ..default() }); commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(-1.5, 0.5, 1.5), ..default() }); commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(-1.5, 0.5, -1.5), ..default() }); diff --git a/examples/3d/parallax_mapping.rs b/examples/3d/parallax_mapping.rs index dfdca7d2e2..0e1ab2be02 100644 --- a/examples/3d/parallax_mapping.rs +++ b/examples/3d/parallax_mapping.rs @@ -234,11 +234,10 @@ fn setup( .with_children(|commands| { // represent the light source as a sphere let mesh = meshes.add( - shape::Icosphere { + Mesh::try_from(shape::Icosphere { radius: 0.05, subdivisions: 3, - } - .try_into() + }) .unwrap(), ); commands.spawn(PbrBundle { mesh, ..default() }); @@ -246,13 +245,10 @@ fn setup( // Plane commands.spawn(PbrBundle { - mesh: meshes.add( - shape::Plane { - size: 10.0, - subdivisions: 0, - } - .into(), - ), + mesh: meshes.add(shape::Plane { + size: 10.0, + subdivisions: 0, + }), material: materials.add(StandardMaterial { // standard material derived from dark green, but // with roughness and reflectance set. diff --git a/examples/3d/parenting.rs b/examples/3d/parenting.rs index 827d8ffbec..877cabc02e 100644 --- a/examples/3d/parenting.rs +++ b/examples/3d/parenting.rs @@ -28,7 +28,7 @@ fn setup( mut meshes: ResMut>, mut materials: ResMut>, ) { - let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 2.0 })); + let cube_handle = meshes.add(shape::Cube { size: 2.0 }); let cube_material_handle = materials.add(StandardMaterial { base_color: Color::rgb(0.8, 0.7, 0.6), ..default() diff --git a/examples/3d/render_to_texture.rs b/examples/3d/render_to_texture.rs index eeda0f30a5..2191760dd2 100644 --- a/examples/3d/render_to_texture.rs +++ b/examples/3d/render_to_texture.rs @@ -62,7 +62,7 @@ fn setup( let image_handle = images.add(image); - let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 4.0 })); + let cube_handle = meshes.add(shape::Cube { size: 4.0 }); let cube_material_handle = materials.add(StandardMaterial { base_color: Color::rgb(0.8, 0.7, 0.6), reflectance: 0.02, @@ -114,7 +114,7 @@ fn setup( )); let cube_size = 4.0; - let cube_handle = meshes.add(Mesh::from(shape::Box::new(cube_size, cube_size, cube_size))); + let cube_handle = meshes.add(shape::Box::new(cube_size, cube_size, cube_size)); // This material has the texture that has been rendered. let material_handle = materials.add(StandardMaterial { diff --git a/examples/3d/shadow_biases.rs b/examples/3d/shadow_biases.rs index 49ee6a2492..c3d3db32ff 100644 --- a/examples/3d/shadow_biases.rs +++ b/examples/3d/shadow_biases.rs @@ -112,7 +112,7 @@ fn setup( // ground plane commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(2.0 * spawn_plane_depth).into()), + mesh: meshes.add(shape::Plane::from_size(2.0 * spawn_plane_depth)), material: white_handle, ..default() }); diff --git a/examples/3d/shadow_caster_receiver.rs b/examples/3d/shadow_caster_receiver.rs index cf19333832..b0fde2c3aa 100644 --- a/examples/3d/shadow_caster_receiver.rs +++ b/examples/3d/shadow_caster_receiver.rs @@ -47,7 +47,7 @@ fn setup( // sphere - initially a caster commands.spawn(PbrBundle { mesh: sphere_handle.clone(), - material: materials.add(Color::RED.into()), + material: materials.add(Color::RED), transform: Transform::from_xyz(-1.0, spawn_height, 0.0), ..default() }); @@ -56,7 +56,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: sphere_handle, - material: materials.add(Color::BLUE.into()), + material: materials.add(Color::BLUE), transform: Transform::from_xyz(1.0, spawn_height, 0.0), ..default() }, @@ -66,8 +66,8 @@ fn setup( // floating plane - initially not a shadow receiver and not a caster commands.spawn(( PbrBundle { - mesh: meshes.add(shape::Plane::from_size(20.0).into()), - material: materials.add(Color::GREEN.into()), + mesh: meshes.add(shape::Plane::from_size(20.0)), + material: materials.add(Color::GREEN), transform: Transform::from_xyz(0.0, 1.0, -10.0), ..default() }, @@ -77,7 +77,7 @@ fn setup( // lower ground plane - initially a shadow receiver commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(20.0).into()), + mesh: meshes.add(shape::Plane::from_size(20.0)), material: white_handle, ..default() }); diff --git a/examples/3d/spherical_area_lights.rs b/examples/3d/spherical_area_lights.rs index 99dfc14d09..4b7b57ba1d 100644 --- a/examples/3d/spherical_area_lights.rs +++ b/examples/3d/spherical_area_lights.rs @@ -22,7 +22,7 @@ fn setup( // plane commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(100.0).into()), + mesh: meshes.add(shape::Plane::from_size(100.0)), material: materials.add(StandardMaterial { base_color: Color::rgb(0.2, 0.2, 0.2), perceptual_roughness: 0.08, @@ -36,11 +36,11 @@ fn setup( let radius_range = 0.0..0.8; let pos_len = position_range.end - position_range.start; let radius_len = radius_range.end - radius_range.start; - let mesh = meshes.add(Mesh::from(shape::UVSphere { + let mesh = meshes.add(shape::UVSphere { sectors: 128, stacks: 64, ..default() - })); + }); for i in 0..COUNT { let percent = i as f32 / COUNT as f32; diff --git a/examples/3d/split_screen.rs b/examples/3d/split_screen.rs index 23c5e45535..8669e811f2 100644 --- a/examples/3d/split_screen.rs +++ b/examples/3d/split_screen.rs @@ -23,8 +23,8 @@ fn setup( ) { // plane commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(100.0).into()), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + mesh: meshes.add(shape::Plane::from_size(100.0)), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }); diff --git a/examples/3d/spotlight.rs b/examples/3d/spotlight.rs index 9331f01635..e3119d90a2 100644 --- a/examples/3d/spotlight.rs +++ b/examples/3d/spotlight.rs @@ -35,15 +35,15 @@ fn setup( ) { // ground plane commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(100.0).into()), - material: materials.add(Color::WHITE.into()), + mesh: meshes.add(shape::Plane::from_size(100.0)), + material: materials.add(Color::WHITE), ..default() }); // cubes let mut rng = StdRng::seed_from_u64(19878367467713); - let cube_mesh = meshes.add(Mesh::from(shape::Cube { size: 0.5 })); - let blue = materials.add(Color::rgb_u8(124, 144, 255).into()); + let cube_mesh = meshes.add(shape::Cube { size: 0.5 }); + let blue = materials.add(Color::rgb_u8(124, 144, 255)); for _ in 0..40 { let x = rng.gen_range(-5.0..5.0); let y = rng.gen_range(0.0..3.0); @@ -59,14 +59,14 @@ fn setup( )); } - let sphere_mesh = meshes.add(Mesh::from(shape::UVSphere { + let sphere_mesh = meshes.add(shape::UVSphere { radius: 0.05, ..default() - })); - let sphere_mesh_direction = meshes.add(Mesh::from(shape::UVSphere { + }); + let sphere_mesh_direction = meshes.add(shape::UVSphere { radius: 0.1, ..default() - })); + }); let red_emissive = materials.add(StandardMaterial { base_color: Color::RED, emissive: Color::rgba_linear(1.0, 0.0, 0.0, 0.0), diff --git a/examples/3d/ssao.rs b/examples/3d/ssao.rs index 001d3c9266..f8cbeae284 100644 --- a/examples/3d/ssao.rs +++ b/examples/3d/ssao.rs @@ -48,30 +48,30 @@ fn setup( ..default() }); commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + mesh: meshes.add(shape::Cube { size: 1.0 }), material: material.clone(), transform: Transform::from_xyz(0.0, 0.0, 1.0), ..default() }); commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + mesh: meshes.add(shape::Cube { size: 1.0 }), material: material.clone(), transform: Transform::from_xyz(0.0, -1.0, 0.0), ..default() }); commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + mesh: meshes.add(shape::Cube { size: 1.0 }), material, transform: Transform::from_xyz(1.0, 0.0, 0.0), ..default() }); commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::UVSphere { + mesh: meshes.add(shape::UVSphere { radius: 0.4, sectors: 72, stacks: 36, - })), + }), material: materials.add(StandardMaterial { base_color: Color::rgb(0.4, 0.4, 0.4), perceptual_roughness: 1.0, diff --git a/examples/3d/texture.rs b/examples/3d/texture.rs index b0036abb48..820ec05caa 100644 --- a/examples/3d/texture.rs +++ b/examples/3d/texture.rs @@ -24,10 +24,7 @@ fn setup( // create a new quad mesh. this is what we will apply the texture to let quad_width = 8.0; - let quad_handle = meshes.add(Mesh::from(shape::Quad::new(Vec2::new( - quad_width, - quad_width * aspect, - )))); + let quad_handle = meshes.add(shape::Quad::new(Vec2::new(quad_width, quad_width * aspect))); // this material renders the texture normally let material_handle = materials.add(StandardMaterial { diff --git a/examples/3d/tonemapping.rs b/examples/3d/tonemapping.rs index 530d07a9da..b77f4b4bb7 100644 --- a/examples/3d/tonemapping.rs +++ b/examples/3d/tonemapping.rs @@ -107,8 +107,8 @@ fn setup_basic_scene( // plane commands.spawn(( PbrBundle { - mesh: meshes.add(shape::Plane::from_size(50.0).into()), - material: materials.add(Color::rgb(0.1, 0.2, 0.1).into()), + mesh: meshes.add(shape::Plane::from_size(50.0)), + material: materials.add(Color::rgb(0.1, 0.2, 0.1)), ..default() }, SceneNumber(1), @@ -120,7 +120,7 @@ fn setup_basic_scene( ..default() }); - let cube_mesh = meshes.add(Mesh::from(shape::Cube { size: 0.25 })); + let cube_mesh = meshes.add(shape::Cube { size: 0.25 }); for i in 0..5 { commands.spawn(( PbrBundle { @@ -134,10 +134,10 @@ fn setup_basic_scene( } // spheres - let sphere_mesh = meshes.add(Mesh::from(shape::UVSphere { + let sphere_mesh = meshes.add(shape::UVSphere { radius: 0.125, ..default() - })); + }); for i in 0..6 { let j = i % 3; let s_val = if i < 3 { 0.0 } else { 0.2 }; @@ -226,10 +226,10 @@ fn setup_color_gradient_scene( commands.spawn(( MaterialMeshBundle { - mesh: meshes.add(Mesh::from(shape::Quad { + mesh: meshes.add(shape::Quad { size: vec2(1.0, 1.0) * 0.7, flip: false, - })), + }), material: materials.add(ColorGradientMaterial {}), transform, visibility: Visibility::Hidden, @@ -251,10 +251,10 @@ fn setup_image_viewer_scene( // exr/hdr viewer (exr requires enabling bevy feature) commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::Quad { + mesh: meshes.add(shape::Quad { size: vec2(1.0, 1.0), flip: false, - })), + }), material: materials.add(StandardMaterial { base_color_texture: None, unlit: true, diff --git a/examples/3d/transmission.rs b/examples/3d/transmission.rs index 34a9ae99ae..8c780fbbab 100644 --- a/examples/3d/transmission.rs +++ b/examples/3d/transmission.rs @@ -76,9 +76,9 @@ fn setup( .unwrap(), ); - let cube_mesh = meshes.add(Mesh::from(shape::Cube { size: 0.7 })); + let cube_mesh = meshes.add(shape::Cube { size: 0.7 }); - let plane_mesh = meshes.add(shape::Plane::from_size(2.0).into()); + let plane_mesh = meshes.add(shape::Plane::from_size(2.0)); let cylinder_mesh = meshes.add(Mesh::from(shape::Cylinder { radius: 0.5, @@ -91,7 +91,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: cube_mesh.clone(), - material: materials.add(StandardMaterial { ..default() }), + material: materials.add(StandardMaterial::default()), transform: Transform::from_xyz(0.25, 0.5, -2.0).with_rotation(Quat::from_euler( EulerRot::XYZ, 1.4, @@ -111,7 +111,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: cube_mesh, - material: materials.add(StandardMaterial { ..default() }), + material: materials.add(StandardMaterial::default()), transform: Transform::from_xyz(-0.75, 0.7, -2.0).with_rotation(Quat::from_euler( EulerRot::XYZ, 0.4, diff --git a/examples/3d/transparency_3d.rs b/examples/3d/transparency_3d.rs index f048f95942..c8915d424e 100644 --- a/examples/3d/transparency_3d.rs +++ b/examples/3d/transparency_3d.rs @@ -20,8 +20,8 @@ fn setup( ) { // opaque plane, uses `alpha_mode: Opaque` by default commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(6.0).into()), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + mesh: meshes.add(shape::Plane::from_size(6.0)), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }); // transparent sphere, uses `alpha_mode: Mask(f32)` @@ -67,11 +67,11 @@ fn setup( }); // transparent cube, uses `alpha_mode: Blend` commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + mesh: meshes.add(shape::Cube { size: 1.0 }), // Notice how there is no need to set the `alpha_mode` explicitly here. // When converting a color to a material using `into()`, the alpha mode is // automatically set to `Blend` if the alpha channel is anything lower than 1.0. - material: materials.add(Color::rgba(0.5, 0.5, 1.0, 0.0).into()), + material: materials.add(Color::rgba(0.5, 0.5, 1.0, 0.0)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }); @@ -84,7 +84,7 @@ fn setup( }) .unwrap(), ), - material: materials.add(Color::rgb(0.7, 0.2, 0.1).into()), + material: materials.add(Color::rgb(0.7, 0.2, 0.1)), transform: Transform::from_xyz(0.0, 0.5, -1.5), ..default() }); diff --git a/examples/3d/two_passes.rs b/examples/3d/two_passes.rs index 8ded87396e..2a72287d50 100644 --- a/examples/3d/two_passes.rs +++ b/examples/3d/two_passes.rs @@ -17,14 +17,14 @@ fn setup( ) { // plane commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(5.0).into()), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + mesh: meshes.add(shape::Plane::from_size(5.0)), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }); // cube commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }); diff --git a/examples/3d/vertex_colors.rs b/examples/3d/vertex_colors.rs index 93d05882b7..d98aca9feb 100644 --- a/examples/3d/vertex_colors.rs +++ b/examples/3d/vertex_colors.rs @@ -17,8 +17,8 @@ fn setup( ) { // plane commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(5.0).into()), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + mesh: meshes.add(shape::Plane::from_size(5.0)), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }); // cube @@ -38,7 +38,7 @@ fn setup( // This is the default color, but note that vertex colors are // multiplied by the base color, so you'll likely want this to be // white if using vertex colors. - material: materials.add(Color::rgb(1., 1., 1.).into()), + material: materials.add(Color::rgb(1., 1., 1.)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }); diff --git a/examples/3d/wireframe.rs b/examples/3d/wireframe.rs index ab875c0e30..cc7b110dbb 100644 --- a/examples/3d/wireframe.rs +++ b/examples/3d/wireframe.rs @@ -54,16 +54,16 @@ fn setup( ) { // plane commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))), - material: materials.add(Color::BLUE.into()), + mesh: meshes.add(shape::Plane::from_size(5.0)), + material: materials.add(Color::BLUE), ..default() }); // Red cube: Never renders a wireframe commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::RED.into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::RED), transform: Transform::from_xyz(-1.0, 0.5, -1.0), ..default() }, @@ -71,16 +71,16 @@ fn setup( )); // Orange cube: Follows global wireframe setting commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::ORANGE.into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::ORANGE), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }); // Green cube: Always renders a wireframe commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::GREEN.into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::GREEN), transform: Transform::from_xyz(1.0, 0.5, 1.0), ..default() }, diff --git a/examples/animation/animated_fox.rs b/examples/animation/animated_fox.rs index 1193877e9f..402049aba2 100644 --- a/examples/animation/animated_fox.rs +++ b/examples/animation/animated_fox.rs @@ -45,8 +45,8 @@ fn setup( // Plane commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(500000.0).into()), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + mesh: meshes.add(shape::Plane::from_size(500000.0)), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }); diff --git a/examples/animation/animated_transform.rs b/examples/animation/animated_transform.rs index b596e97c58..a77ea51735 100644 --- a/examples/animation/animated_transform.rs +++ b/examples/animation/animated_transform.rs @@ -123,7 +123,7 @@ fn setup( .spawn(( PbrBundle { mesh: meshes.add(Mesh::try_from(shape::Icosphere::default()).unwrap()), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), ..default() }, // Add the Name component, and the animation player @@ -142,8 +142,8 @@ fn setup( p.spawn(( PbrBundle { transform: Transform::from_xyz(1.5, 0.0, 0.0), - mesh: meshes.add(Mesh::from(shape::Cube { size: 0.5 })), - material: materials.add(Color::rgb(0.3, 0.9, 0.3).into()), + mesh: meshes.add(shape::Cube { size: 0.5 }), + material: materials.add(Color::rgb(0.3, 0.9, 0.3)), ..default() }, // Add the Name component diff --git a/examples/animation/cubic_curve.rs b/examples/animation/cubic_curve.rs index 92a003edaa..3ac890d68b 100644 --- a/examples/animation/cubic_curve.rs +++ b/examples/animation/cubic_curve.rs @@ -38,8 +38,8 @@ fn setup( // Spawning a cube to experiment on commands.spawn(( PbrBundle { - mesh: meshes.add(shape::Cube::default().into()), - material: materials.add(Color::ORANGE.into()), + mesh: meshes.add(shape::Cube::default()), + material: materials.add(Color::ORANGE), transform: Transform::from_translation(points[0][0]), ..default() }, @@ -60,8 +60,8 @@ fn setup( // ground plane commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(50.).into()), - material: materials.add(Color::SILVER.into()), + mesh: meshes.add(shape::Plane::from_size(50.)), + material: materials.add(Color::SILVER), ..default() }); diff --git a/examples/animation/custom_skinned_mesh.rs b/examples/animation/custom_skinned_mesh.rs index a5c23af8db..4973eee280 100644 --- a/examples/animation/custom_skinned_mesh.rs +++ b/examples/animation/custom_skinned_mesh.rs @@ -48,11 +48,10 @@ fn setup( }); // Create inverse bindpose matrices for a skeleton consists of 2 joints - let inverse_bindposes = - skinned_mesh_inverse_bindposes_assets.add(SkinnedMeshInverseBindposes::from(vec![ - Mat4::from_translation(Vec3::new(-0.5, -1.0, 0.0)), - Mat4::from_translation(Vec3::new(-0.5, -1.0, 0.0)), - ])); + let inverse_bindposes = skinned_mesh_inverse_bindposes_assets.add(vec![ + Mat4::from_translation(Vec3::new(-0.5, -1.0, 0.0)), + Mat4::from_translation(Vec3::new(-0.5, -1.0, 0.0)), + ]); // Create a mesh let mesh = Mesh::new( @@ -148,14 +147,11 @@ fn setup( commands.spawn(( PbrBundle { mesh: mesh.clone(), - material: materials.add( - Color::rgb( - rng.gen_range(0.0..1.0), - rng.gen_range(0.0..1.0), - rng.gen_range(0.0..1.0), - ) - .into(), - ), + material: materials.add(Color::rgb( + rng.gen_range(0.0..1.0), + rng.gen_range(0.0..1.0), + rng.gen_range(0.0..1.0), + )), ..default() }, SkinnedMesh { diff --git a/examples/async_tasks/async_compute.rs b/examples/async_tasks/async_compute.rs index ebf4eaa986..e162e3fe4a 100644 --- a/examples/async_tasks/async_compute.rs +++ b/examples/async_tasks/async_compute.rs @@ -35,10 +35,10 @@ fn add_assets( mut meshes: ResMut>, mut materials: ResMut>, ) { - let box_mesh_handle = meshes.add(Mesh::from(shape::Cube { size: 0.25 })); + let box_mesh_handle = meshes.add(shape::Cube { size: 0.25 }); commands.insert_resource(BoxMeshHandle(box_mesh_handle)); - let box_material_handle = materials.add(Color::rgb(1.0, 0.2, 0.3).into()); + let box_material_handle = materials.add(Color::rgb(1.0, 0.2, 0.3)); commands.insert_resource(BoxMaterialHandle(box_material_handle)); } diff --git a/examples/audio/spatial_audio_2d.rs b/examples/audio/spatial_audio_2d.rs index 5a61f6bfdb..f911bb59e8 100644 --- a/examples/audio/spatial_audio_2d.rs +++ b/examples/audio/spatial_audio_2d.rs @@ -34,8 +34,8 @@ fn setup( // sound emitter commands.spawn(( MaterialMesh2dBundle { - mesh: meshes.add(shape::Circle::new(15.0).into()).into(), - material: materials.add(ColorMaterial::from(Color::BLUE)), + mesh: meshes.add(shape::Circle::new(15.0)).into(), + material: materials.add(Color::BLUE), transform: Transform::from_translation(Vec3::new(0.0, 50.0, 0.0)), ..default() }, diff --git a/examples/audio/spatial_audio_3d.rs b/examples/audio/spatial_audio_3d.rs index 1b35e64935..3fb477752e 100644 --- a/examples/audio/spatial_audio_3d.rs +++ b/examples/audio/spatial_audio_3d.rs @@ -22,11 +22,11 @@ fn setup( // sound emitter commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::UVSphere { + mesh: meshes.add(shape::UVSphere { radius: 0.2, ..default() - })), - material: materials.add(Color::BLUE.into()), + }), + material: materials.add(Color::BLUE), transform: Transform::from_xyz(0.0, 0.0, 0.0), ..default() }, @@ -43,16 +43,16 @@ fn setup( .with_children(|parent| { // left ear indicator parent.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 0.2 })), - material: materials.add(Color::RED.into()), + mesh: meshes.add(shape::Cube { size: 0.2 }), + material: materials.add(Color::RED), transform: Transform::from_translation(listener.left_ear_offset), ..default() }); // right ear indicator parent.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 0.2 })), - material: materials.add(Color::GREEN.into()), + mesh: meshes.add(shape::Cube { size: 0.2 }), + material: materials.add(Color::GREEN), transform: Transform::from_translation(listener.right_ear_offset), ..default() }); diff --git a/examples/ecs/iter_combinations.rs b/examples/ecs/iter_combinations.rs index 5f63cd52bf..c6154f7d38 100644 --- a/examples/ecs/iter_combinations.rs +++ b/examples/ecs/iter_combinations.rs @@ -76,14 +76,11 @@ fn generate_bodies( ..default() }, mesh: mesh.clone(), - material: materials.add( - Color::rgb( - rng.gen_range(color_range.clone()), - rng.gen_range(color_range.clone()), - rng.gen_range(color_range.clone()), - ) - .into(), - ), + material: materials.add(Color::rgb( + rng.gen_range(color_range.clone()), + rng.gen_range(color_range.clone()), + rng.gen_range(color_range.clone()), + )), ..default() }, mass: Mass(mass_value), diff --git a/examples/games/breakout.rs b/examples/games/breakout.rs index 8c6a37e865..c5b103e97a 100644 --- a/examples/games/breakout.rs +++ b/examples/games/breakout.rs @@ -207,8 +207,8 @@ fn setup( // Ball commands.spawn(( MaterialMesh2dBundle { - mesh: meshes.add(shape::Circle::default().into()).into(), - material: materials.add(ColorMaterial::from(BALL_COLOR)), + mesh: meshes.add(shape::Circle::default()).into(), + material: materials.add(BALL_COLOR), transform: Transform::from_translation(BALL_STARTING_POSITION).with_scale(BALL_SIZE), ..default() }, diff --git a/examples/mobile/src/lib.rs b/examples/mobile/src/lib.rs index d0ce7c2f9b..41190b081b 100644 --- a/examples/mobile/src/lib.rs +++ b/examples/mobile/src/lib.rs @@ -62,14 +62,14 @@ fn setup_scene( ) { // plane commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(5.0).into()), - material: materials.add(Color::rgb(0.1, 0.2, 0.1).into()), + mesh: meshes.add(shape::Plane::from_size(5.0)), + material: materials.add(Color::rgb(0.1, 0.2, 0.1)), ..default() }); // cube commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.5, 0.4, 0.3).into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::rgb(0.5, 0.4, 0.3)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }); @@ -82,7 +82,7 @@ fn setup_scene( }) .unwrap(), ), - material: materials.add(Color::rgb(0.1, 0.4, 0.8).into()), + material: materials.add(Color::rgb(0.1, 0.4, 0.8)), transform: Transform::from_xyz(1.5, 1.5, 1.5), ..default() }); diff --git a/examples/shader/animate_shader.rs b/examples/shader/animate_shader.rs index a828420387..5d37c9aca5 100644 --- a/examples/shader/animate_shader.rs +++ b/examples/shader/animate_shader.rs @@ -21,7 +21,7 @@ fn setup( ) { // cube commands.spawn(MaterialMeshBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + mesh: meshes.add(shape::Cube { size: 1.0 }), transform: Transform::from_xyz(0.0, 0.5, 0.0), material: materials.add(CustomMaterial {}), ..default() diff --git a/examples/shader/array_texture.rs b/examples/shader/array_texture.rs index 478119cfa9..da17ce6347 100644 --- a/examples/shader/array_texture.rs +++ b/examples/shader/array_texture.rs @@ -77,7 +77,7 @@ fn create_array_texture( image.reinterpret_stacked_2d_as_array(array_layers); // Spawn some cubes using the array texture - let mesh_handle = meshes.add(Mesh::from(shape::Cube { size: 1.0 })); + let mesh_handle = meshes.add(shape::Cube { size: 1.0 }); let material_handle = materials.add(ArrayTextureMaterial { array_texture: loading_texture.handle.clone(), }); diff --git a/examples/shader/fallback_image.rs b/examples/shader/fallback_image.rs index b799b56d27..8a0117fc54 100644 --- a/examples/shader/fallback_image.rs +++ b/examples/shader/fallback_image.rs @@ -27,7 +27,7 @@ fn setup( mut materials: ResMut>, ) { commands.spawn(MaterialMeshBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + mesh: meshes.add(shape::Cube { size: 1.0 }), material: materials.add(FallbackTestMaterial { image_1d: None, image_2d: None, @@ -36,11 +36,11 @@ fn setup( image_cube_array: None, image_3d: None, }), - ..Default::default() + ..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::default() + ..default() }); } diff --git a/examples/shader/post_processing.rs b/examples/shader/post_processing.rs index cb5168c4f5..d9465f902e 100644 --- a/examples/shader/post_processing.rs +++ b/examples/shader/post_processing.rs @@ -322,8 +322,8 @@ fn setup( // cube commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }, diff --git a/examples/shader/shader_defs.rs b/examples/shader/shader_defs.rs index a638c3569a..e5b61466d7 100644 --- a/examples/shader/shader_defs.rs +++ b/examples/shader/shader_defs.rs @@ -27,7 +27,7 @@ fn setup( ) { // blue cube commands.spawn(MaterialMeshBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + mesh: meshes.add(shape::Cube { size: 1.0 }), transform: Transform::from_xyz(-1.0, 0.5, 0.0), material: materials.add(CustomMaterial { color: Color::BLUE, @@ -38,7 +38,7 @@ fn setup( // red cube (with green color overridden by the IS_RED "shader def") commands.spawn(MaterialMeshBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + mesh: meshes.add(shape::Cube { size: 1.0 }), transform: Transform::from_xyz(1.0, 0.5, 0.0), material: materials.add(CustomMaterial { color: Color::GREEN, diff --git a/examples/shader/shader_instancing.rs b/examples/shader/shader_instancing.rs index a0b4c7db79..3a40d7fa69 100644 --- a/examples/shader/shader_instancing.rs +++ b/examples/shader/shader_instancing.rs @@ -35,7 +35,7 @@ fn main() { fn setup(mut commands: Commands, mut meshes: ResMut>) { commands.spawn(( - meshes.add(Mesh::from(shape::Cube { size: 0.5 })), + meshes.add(shape::Cube { size: 0.5 }), SpatialBundle::INHERITED_IDENTITY, InstanceMaterialData( (1..=10) diff --git a/examples/shader/shader_material.rs b/examples/shader/shader_material.rs index eb20a77566..2ea67128d5 100644 --- a/examples/shader/shader_material.rs +++ b/examples/shader/shader_material.rs @@ -22,7 +22,7 @@ fn setup( ) { // cube commands.spawn(MaterialMeshBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + mesh: meshes.add(shape::Cube { size: 1.0 }), transform: Transform::from_xyz(0.0, 0.5, 0.0), material: materials.add(CustomMaterial { color: Color::BLUE, diff --git a/examples/shader/shader_material_2d.rs b/examples/shader/shader_material_2d.rs index 351b5c5c8b..8fa03aa5a8 100644 --- a/examples/shader/shader_material_2d.rs +++ b/examples/shader/shader_material_2d.rs @@ -29,7 +29,7 @@ fn setup( // quad commands.spawn(MaterialMesh2dBundle { - mesh: meshes.add(Mesh::from(shape::Quad::default())).into(), + mesh: meshes.add(shape::Quad::default()).into(), transform: Transform::default().with_scale(Vec3::splat(128.)), material: materials.add(CustomMaterial { color: Color::BLUE, diff --git a/examples/shader/shader_material_glsl.rs b/examples/shader/shader_material_glsl.rs index f24cfa5070..52bf59c749 100644 --- a/examples/shader/shader_material_glsl.rs +++ b/examples/shader/shader_material_glsl.rs @@ -28,7 +28,7 @@ fn setup( ) { // cube commands.spawn(MaterialMeshBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + mesh: meshes.add(shape::Cube { size: 1.0 }), transform: Transform::from_xyz(0.0, 0.5, 0.0), material: materials.add(CustomMaterial { color: Color::BLUE, diff --git a/examples/shader/shader_material_screenspace_texture.rs b/examples/shader/shader_material_screenspace_texture.rs index ddee9a6809..c8083c4ae1 100644 --- a/examples/shader/shader_material_screenspace_texture.rs +++ b/examples/shader/shader_material_screenspace_texture.rs @@ -25,8 +25,8 @@ fn setup( mut standard_materials: ResMut>, ) { commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(5.0).into()), - material: standard_materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + mesh: meshes.add(shape::Plane::from_size(5.0)), + material: standard_materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }); commands.spawn(PointLightBundle { @@ -35,7 +35,7 @@ fn setup( }); commands.spawn(MaterialMeshBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + mesh: meshes.add(shape::Cube { size: 1.0 }), transform: Transform::from_xyz(0.0, 0.5, 0.0), material: custom_materials.add(CustomMaterial { texture: asset_server.load( diff --git a/examples/shader/shader_prepass.rs b/examples/shader/shader_prepass.rs index de17d4341f..4737b38139 100644 --- a/examples/shader/shader_prepass.rs +++ b/examples/shader/shader_prepass.rs @@ -61,8 +61,8 @@ fn setup( // plane commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(5.0).into()), - material: std_materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + mesh: meshes.add(shape::Plane::from_size(5.0)), + material: std_materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }); @@ -71,7 +71,7 @@ fn setup( // For a real application, this isn't ideal. commands.spawn(( MaterialMeshBundle { - mesh: meshes.add(shape::Quad::new(Vec2::new(20.0, 20.0)).into()), + mesh: meshes.add(shape::Quad::new(Vec2::new(20.0, 20.0))), material: depth_materials.add(PrepassOutputMaterial { settings: ShowPrepassSettings::default(), }), @@ -85,7 +85,7 @@ fn setup( // Opaque cube commands.spawn(( MaterialMeshBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + mesh: meshes.add(shape::Cube { size: 1.0 }), material: materials.add(CustomMaterial { color: Color::WHITE, color_texture: Some(asset_server.load("branding/icon.png")), @@ -99,7 +99,7 @@ fn setup( // Cube with alpha mask commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + mesh: meshes.add(shape::Cube { size: 1.0 }), material: std_materials.add(StandardMaterial { alpha_mode: AlphaMode::Mask(1.0), base_color_texture: Some(asset_server.load("branding/icon.png")), @@ -112,7 +112,7 @@ fn setup( // Cube with alpha blending. // Transparent materials are ignored by the prepass commands.spawn(MaterialMeshBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + mesh: meshes.add(shape::Cube { size: 1.0 }), material: materials.add(CustomMaterial { color: Color::WHITE, color_texture: Some(asset_server.load("branding/icon.png")), diff --git a/examples/shader/texture_binding_array.rs b/examples/shader/texture_binding_array.rs index 91c23479c6..5e01de4007 100644 --- a/examples/shader/texture_binding_array.rs +++ b/examples/shader/texture_binding_array.rs @@ -63,7 +63,7 @@ fn setup( ) { commands.spawn(Camera3dBundle { transform: Transform::from_xyz(2.0, 2.0, 2.0).looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y), - ..Default::default() + ..default() }); // load 16 textures @@ -74,9 +74,9 @@ fn setup( // a cube with multiple textures commands.spawn(MaterialMeshBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + mesh: meshes.add(shape::Cube { size: 1.0 }), material: materials.add(BindlessMaterial { textures }), - ..Default::default() + ..default() }); } diff --git a/examples/stress_tests/bevymark.rs b/examples/stress_tests/bevymark.rs index 811be1b403..c59f2047e0 100644 --- a/examples/stress_tests/bevymark.rs +++ b/examples/stress_tests/bevymark.rs @@ -209,9 +209,7 @@ fn setup( textures, materials, quad: meshes - .add(Mesh::from(shape::Quad::new(Vec2::splat( - BIRD_TEXTURE_SIZE as f32, - )))) + .add(shape::Quad::new(Vec2::splat(BIRD_TEXTURE_SIZE as f32))) .into(), color_rng: StdRng::seed_from_u64(42), material_rng: StdRng::seed_from_u64(42), diff --git a/examples/stress_tests/many_cubes.rs b/examples/stress_tests/many_cubes.rs index 3f45521fa9..1da8e18bbe 100644 --- a/examples/stress_tests/many_cubes.rs +++ b/examples/stress_tests/many_cubes.rs @@ -104,7 +104,7 @@ fn setup( let images = images.into_inner(); let material_assets = material_assets.into_inner(); - let mesh = meshes.add(Mesh::from(shape::Cube { size: 1.0 })); + let mesh = meshes.add(shape::Cube { size: 1.0 }); let material_textures = init_textures(args, images); let materials = init_materials(args, &material_textures, material_assets); diff --git a/examples/stress_tests/many_foxes.rs b/examples/stress_tests/many_foxes.rs index 1c75de1bc9..f4890dc079 100644 --- a/examples/stress_tests/many_foxes.rs +++ b/examples/stress_tests/many_foxes.rs @@ -185,8 +185,8 @@ fn setup( // Plane commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(5000.0).into()), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + mesh: meshes.add(shape::Plane::from_size(5000.0)), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }); diff --git a/examples/stress_tests/many_lights.rs b/examples/stress_tests/many_lights.rs index c36a04920c..2345213ebb 100644 --- a/examples/stress_tests/many_lights.rs +++ b/examples/stress_tests/many_lights.rs @@ -55,12 +55,12 @@ fn setup( }) .unwrap(), ), - material: materials.add(StandardMaterial::from(Color::WHITE)), + material: materials.add(Color::WHITE), transform: Transform::from_scale(Vec3::NEG_ONE), ..default() }); - let mesh = meshes.add(Mesh::from(shape::Cube { size: 1.0 })); + let mesh = meshes.add(shape::Cube { size: 1.0 }); let material = materials.add(StandardMaterial { base_color: Color::PINK, ..default() diff --git a/examples/tools/gamepad_viewer.rs b/examples/tools/gamepad_viewer.rs index 29ef2c5af2..359dbcff22 100644 --- a/examples/tools/gamepad_viewer.rs +++ b/examples/tools/gamepad_viewer.rs @@ -56,8 +56,8 @@ impl FromWorld for ButtonMaterials { fn from_world(world: &mut World) -> Self { let mut materials = world.resource_mut::>(); Self { - normal: materials.add(ColorMaterial::from(NORMAL_BUTTON_COLOR)), - active: materials.add(ColorMaterial::from(ACTIVE_BUTTON_COLOR)), + normal: materials.add(NORMAL_BUTTON_COLOR), + active: materials.add(ACTIVE_BUTTON_COLOR), } } } @@ -72,12 +72,12 @@ impl FromWorld for ButtonMeshes { fn from_world(world: &mut World) -> Self { let mut meshes = world.resource_mut::>(); Self { - circle: meshes.add(shape::Circle::new(BUTTON_RADIUS).into()).into(), + circle: meshes.add(shape::Circle::new(BUTTON_RADIUS)).into(), triangle: meshes - .add(shape::RegularPolygon::new(BUTTON_RADIUS, 3).into()) + .add(shape::RegularPolygon::new(BUTTON_RADIUS, 3)) .into(), - start_pause: meshes.add(shape::Quad::new(START_SIZE).into()).into(), - trigger: meshes.add(shape::Quad::new(TRIGGER_SIZE).into()).into(), + start_pause: meshes.add(shape::Quad::new(START_SIZE)).into(), + trigger: meshes.add(shape::Quad::new(TRIGGER_SIZE)).into(), } } } diff --git a/examples/transforms/3d_rotation.rs b/examples/transforms/3d_rotation.rs index ddedbbae85..62ff7834c2 100644 --- a/examples/transforms/3d_rotation.rs +++ b/examples/transforms/3d_rotation.rs @@ -26,8 +26,8 @@ fn setup( // Spawn a cube to rotate. commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::WHITE.into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::WHITE), transform: Transform::from_translation(Vec3::ZERO), ..default() }, diff --git a/examples/transforms/scale.rs b/examples/transforms/scale.rs index bbae8b71b9..44ce68eb16 100644 --- a/examples/transforms/scale.rs +++ b/examples/transforms/scale.rs @@ -42,8 +42,8 @@ fn setup( // Spawn a cube to scale. commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::WHITE.into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::WHITE), transform: Transform::from_rotation(Quat::from_rotation_y(PI / 4.0)), ..default() }, diff --git a/examples/transforms/transform.rs b/examples/transforms/transform.rs index 38bad31c4f..b07522633b 100644 --- a/examples/transforms/transform.rs +++ b/examples/transforms/transform.rs @@ -53,7 +53,7 @@ fn setup( }) .unwrap(), ), - material: materials.add(Color::YELLOW.into()), + material: materials.add(Color::YELLOW), transform: Transform::from_translation(Vec3::ZERO), ..default() }, @@ -73,8 +73,8 @@ fn setup( Transform::from_translation(Vec3::Z * -10.0).with_rotation(Quat::from_rotation_y(PI / 2.)); commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::WHITE.into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::WHITE), transform: cube_spawn, ..default() }, diff --git a/examples/transforms/translation.rs b/examples/transforms/translation.rs index e8aaef4edf..d916416aac 100644 --- a/examples/transforms/translation.rs +++ b/examples/transforms/translation.rs @@ -40,8 +40,8 @@ fn setup( let entity_spawn = Vec3::ZERO; commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::WHITE.into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::WHITE), transform: Transform::from_translation(entity_spawn), ..default() }, diff --git a/examples/window/low_power.rs b/examples/window/low_power.rs index 00a211cf06..37c8dcc646 100644 --- a/examples/window/low_power.rs +++ b/examples/window/low_power.rs @@ -150,8 +150,8 @@ pub(crate) mod test_setup { ) { commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 0.5 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + mesh: meshes.add(shape::Cube { size: 0.5 }), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), ..default() }, Rotator, diff --git a/examples/window/screenshot.rs b/examples/window/screenshot.rs index 8ebfdaba5e..22cd1c5861 100644 --- a/examples/window/screenshot.rs +++ b/examples/window/screenshot.rs @@ -35,14 +35,14 @@ fn setup( ) { // plane commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(5.0).into()), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + mesh: meshes.add(shape::Plane::from_size(5.0)), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }); // cube commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }); diff --git a/tests/window/minimising.rs b/tests/window/minimising.rs index b60829cb08..3e4ff57754 100644 --- a/tests/window/minimising.rs +++ b/tests/window/minimising.rs @@ -35,17 +35,17 @@ fn setup_3d( ) { // plane commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Plane { + mesh: meshes.add(shape::Plane { size: 5.0, subdivisions: 0, - })), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + }), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }); // cube commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }); diff --git a/tests/window/resizing.rs b/tests/window/resizing.rs index a6da0450dd..003028b2bd 100644 --- a/tests/window/resizing.rs +++ b/tests/window/resizing.rs @@ -118,17 +118,17 @@ fn setup_3d( ) { // plane commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Plane { + mesh: meshes.add(shape::Plane { size: 5.0, subdivisions: 0, - })), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + }), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }); // cube commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + mesh: meshes.add(shape::Cube { size: 1.0 }), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() });