Use impl Into<A> 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<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    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<A>` instead of `A`.

## Solution

`Assets::add` now takes an `impl Into<A>` 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<A>` 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.
This commit is contained in:
Joona Aalto 2024-01-09 00:14:43 +02:00 committed by GitHub
parent 54a943d232
commit a795de30b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
69 changed files with 247 additions and 268 deletions

View file

@ -361,9 +361,9 @@ impl<A: Asset> Assets<A> {
/// Adds the given `asset` and allocates a new strong [`Handle`] for it. /// Adds the given `asset` and allocates a new strong [`Handle`] for it.
#[inline] #[inline]
pub fn add(&mut self, asset: A) -> Handle<A> { pub fn add(&mut self, asset: impl Into<A>) -> Handle<A> {
let index = self.dense_storage.allocator.reserve(); let index = self.dense_storage.allocator.reserve();
self.insert_with_index(index, asset).unwrap(); self.insert_with_index(index, asset.into()).unwrap();
Handle::Strong( Handle::Strong(
self.handle_provider self.handle_provider
.get_handle(index.into(), false, None, None), .get_handle(index.into(), false, None, None),

View file

@ -33,8 +33,8 @@ fn setup_cube(
.with_children(|parent| { .with_children(|parent| {
// cube // cube
parent.spawn(PbrBundle { parent.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0), transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default() ..default()
}); });
@ -80,8 +80,8 @@ fn setup_cube(
.with_children(|parent| { .with_children(|parent| {
// cube // cube
parent.spawn(PbrBundle { parent.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0), transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default() ..default()
}); });

View file

@ -18,7 +18,7 @@ fn setup(
// Circle // Circle
commands.spawn(MaterialMesh2dBundle { 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)), material: materials.add(ColorMaterial::from(Color::PURPLE)),
transform: Transform::from_translation(Vec3::new(-150., 0., 0.)), transform: Transform::from_translation(Vec3::new(-150., 0., 0.)),
..default() ..default()
@ -37,9 +37,7 @@ fn setup(
// Quad // Quad
commands.spawn(MaterialMesh2dBundle { commands.spawn(MaterialMesh2dBundle {
mesh: meshes mesh: meshes.add(shape::Quad::new(Vec2::new(50., 100.))).into(),
.add(shape::Quad::new(Vec2::new(50., 100.)).into())
.into(),
material: materials.add(ColorMaterial::from(Color::LIME_GREEN)), material: materials.add(ColorMaterial::from(Color::LIME_GREEN)),
transform: Transform::from_translation(Vec3::new(50., 0., 0.)), transform: Transform::from_translation(Vec3::new(50., 0., 0.)),
..default() ..default()
@ -47,7 +45,7 @@ fn setup(
// Hexagon // Hexagon
commands.spawn(MaterialMesh2dBundle { 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)), material: materials.add(ColorMaterial::from(Color::TURQUOISE)),
transform: Transform::from_translation(Vec3::new(150., 0., 0.)), transform: Transform::from_translation(Vec3::new(150., 0., 0.)),
..default() ..default()

View file

@ -48,7 +48,7 @@ fn setup(
// Circle mesh // Circle mesh
commands.spawn(MaterialMesh2dBundle { 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 // 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))), material: materials.add(ColorMaterial::from(Color::rgb(7.5, 0.0, 7.5))),
transform: Transform::from_translation(Vec3::new(-200., 0., 0.)), transform: Transform::from_translation(Vec3::new(-200., 0., 0.)),
@ -57,9 +57,7 @@ fn setup(
// Hexagon mesh // Hexagon mesh
commands.spawn(MaterialMesh2dBundle { commands.spawn(MaterialMesh2dBundle {
mesh: meshes mesh: meshes.add(shape::RegularPolygon::new(100., 6)).into(),
.add(shape::RegularPolygon::new(100., 6).into())
.into(),
// 4. Put something bright in a dark environment to see the effect // 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))), material: materials.add(ColorMaterial::from(Color::rgb(6.25, 9.4, 9.1))),
transform: Transform::from_translation(Vec3::new(200., 0., 0.)), transform: Transform::from_translation(Vec3::new(200., 0., 0.)),

View file

@ -18,7 +18,7 @@ fn setup(
) { ) {
commands.spawn(Camera2dBundle::default()); commands.spawn(Camera2dBundle::default());
commands.spawn(MaterialMesh2dBundle { 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.)), transform: Transform::default().with_scale(Vec3::splat(128.)),
material: materials.add(ColorMaterial::from(Color::PURPLE)), material: materials.add(ColorMaterial::from(Color::PURPLE)),
..default() ..default()

View file

@ -23,14 +23,14 @@ fn setup(
}); });
// plane // plane
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))), mesh: meshes.add(shape::Plane::from_size(5.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() ..default()
}); });
// cube // cube
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0), transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default() ..default()
}); });

View file

@ -17,15 +17,15 @@ fn setup(
) { ) {
// circular base // circular base
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(shape::Circle::new(4.0).into()), mesh: meshes.add(shape::Circle::new(4.0)),
material: materials.add(Color::WHITE.into()), material: materials.add(Color::WHITE),
transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)), transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
..default() ..default()
}); });
// cube // cube
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::rgb_u8(124, 144, 255).into()), material: materials.add(Color::rgb_u8(124, 144, 255)),
transform: Transform::from_xyz(0.0, 0.5, 0.0), transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default() ..default()
}); });

View file

@ -37,13 +37,13 @@ fn setup(
}); });
let shapes = [ let shapes = [
meshes.add(shape::Cube::default().into()), meshes.add(shape::Cube::default()),
meshes.add(shape::Box::default().into()), meshes.add(shape::Box::default()),
meshes.add(shape::Capsule::default().into()), meshes.add(shape::Capsule::default()),
meshes.add(shape::Torus::default().into()), meshes.add(shape::Torus::default()),
meshes.add(shape::Cylinder::default().into()), meshes.add(shape::Cylinder::default()),
meshes.add(shape::Icosphere::default().try_into().unwrap()), meshes.add(Mesh::try_from(shape::Icosphere::default()).unwrap()),
meshes.add(shape::UVSphere::default().into()), meshes.add(shape::UVSphere::default()),
]; ];
let num_shapes = shapes.len(); let num_shapes = shapes.len();
@ -78,8 +78,8 @@ fn setup(
// ground plane // ground plane
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(50.0).into()), mesh: meshes.add(shape::Plane::from_size(50.0)),
material: materials.add(Color::SILVER.into()), material: materials.add(Color::SILVER),
..default() ..default()
}); });

View file

@ -51,8 +51,8 @@ fn setup(
// plane // plane
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(shape::Plane::from_size(20.).into()), mesh: meshes.add(shape::Plane::from_size(20.)),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), material: materials.add(Color::rgb(0.3, 0.5, 0.3)),
..default() ..default()
}, },
Ground, Ground,

View file

@ -260,8 +260,8 @@ fn setup(
) { ) {
// Plane // Plane
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(50.0).into()), mesh: meshes.add(shape::Plane::from_size(50.0)),
material: materials.add(Color::rgb(0.1, 0.2, 0.1).into()), material: materials.add(Color::rgb(0.1, 0.2, 0.1)),
..default() ..default()
}); });
@ -273,7 +273,7 @@ fn setup(
// Cubes // Cubes
for i in 0..5 { for i in 0..5 {
commands.spawn(PbrBundle { 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(), material: cube_material.clone(),
transform: Transform::from_xyz(i as f32 * 0.25 - 1.0, 0.125, -i as f32 * 0.5), transform: Transform::from_xyz(i as f32 * 0.25 - 1.0, 0.125, -i as f32 * 0.5),
..default() ..default()

View file

@ -79,7 +79,7 @@ fn setup_terrain_scene(
// Sky // Sky
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(Mesh::from(shape::Box::default())), mesh: meshes.add(shape::Box::default()),
material: materials.add(StandardMaterial { material: materials.add(StandardMaterial {
base_color: Color::hex("888888").unwrap(), base_color: Color::hex("888888").unwrap(),
unlit: true, unlit: true,

View file

@ -146,10 +146,10 @@ fn setup(
.id(); .id();
// Chessboard Plane // Chessboard Plane
let black_material = materials.add(Color::BLACK.into()); let black_material = materials.add(Color::BLACK);
let white_material = materials.add(Color::WHITE.into()); 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 x in -3..4 {
for z in -3..4 { for z in -3..4 {

View file

@ -56,11 +56,10 @@ fn setup_scene(
}); });
let mesh = meshes.add( let mesh = meshes.add(
shape::Icosphere { Mesh::try_from(shape::Icosphere {
radius: 0.5, radius: 0.5,
subdivisions: 5, subdivisions: 5,
} })
.try_into()
.unwrap(), .unwrap(),
); );

View file

@ -103,16 +103,16 @@ fn setup(
// Plane // Plane
commands.spawn(PbrBundle { 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(), material: forward_mat_h.clone(),
..default() ..default()
}); });
let cube_h = meshes.add(Mesh::from(shape::Cube { size: 0.1 })); let cube_h = meshes.add(shape::Cube { size: 0.1 });
let sphere_h = meshes.add(Mesh::from(shape::UVSphere { let sphere_h = meshes.add(shape::UVSphere {
radius: 0.125, radius: 0.125,
..default() ..default()
})); });
// Cubes // Cubes
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
@ -196,7 +196,7 @@ fn setup(
// sky // sky
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(Mesh::from(shape::Box::default())), mesh: meshes.add(shape::Box::default()),
material: materials.add(StandardMaterial { material: materials.add(StandardMaterial {
base_color: Color::hex("888888").unwrap(), base_color: Color::hex("888888").unwrap(),
unlit: true, unlit: true,

View file

@ -58,14 +58,14 @@ fn setup_pyramid_scene(
// pillars // pillars
for (x, z) in &[(-1.5, -1.5), (1.5, -1.5), (1.5, 1.5), (-1.5, 1.5)] { for (x, z) in &[(-1.5, -1.5), (1.5, -1.5), (1.5, 1.5), (-1.5, 1.5)] {
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Box { mesh: meshes.add(shape::Box {
min_x: -0.5, min_x: -0.5,
max_x: 0.5, max_x: 0.5,
min_z: -0.5, min_z: -0.5,
max_z: 0.5, max_z: 0.5,
min_y: 0.0, min_y: 0.0,
max_y: 3.0, max_y: 3.0,
})), }),
material: stone.clone(), material: stone.clone(),
transform: Transform::from_xyz(*x, 0.0, *z), transform: Transform::from_xyz(*x, 0.0, *z),
..default() ..default()
@ -97,14 +97,14 @@ fn setup_pyramid_scene(
let size = i as f32 / 2.0 + 3.0; let size = i as f32 / 2.0 + 3.0;
let y = -i as f32 / 2.0; let y = -i as f32 / 2.0;
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Box { mesh: meshes.add(shape::Box {
min_x: -size, min_x: -size,
max_x: size, max_x: size,
min_z: -size, min_z: -size,
max_z: size, max_z: size,
min_y: 0.0, min_y: 0.0,
max_y: 0.5, max_y: 0.5,
})), }),
material: stone.clone(), material: stone.clone(),
transform: Transform::from_xyz(0.0, y, 0.0), transform: Transform::from_xyz(0.0, y, 0.0),
..default() ..default()
@ -113,7 +113,7 @@ fn setup_pyramid_scene(
// sky // sky
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Box::default())), mesh: meshes.add(shape::Box::default()),
material: materials.add(StandardMaterial { material: materials.add(StandardMaterial {
base_color: Color::hex("888888").unwrap(), base_color: Color::hex("888888").unwrap(),
unlit: true, unlit: true,

View file

@ -25,7 +25,7 @@ fn setup(
) { ) {
// ground plane // ground plane
commands.spawn(PbrBundle { 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 { material: materials.add(StandardMaterial {
base_color: Color::WHITE, base_color: Color::WHITE,
perceptual_roughness: 1.0, perceptual_roughness: 1.0,
@ -38,7 +38,7 @@ fn setup(
let mut transform = Transform::from_xyz(2.5, 2.5, 0.0); let mut transform = Transform::from_xyz(2.5, 2.5, 0.0);
transform.rotate_z(PI / 2.); transform.rotate_z(PI / 2.);
commands.spawn(PbrBundle { 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, transform,
material: materials.add(StandardMaterial { material: materials.add(StandardMaterial {
base_color: Color::INDIGO, base_color: Color::INDIGO,
@ -51,7 +51,7 @@ fn setup(
let mut transform = Transform::from_xyz(0.0, 2.5, -2.5); let mut transform = Transform::from_xyz(0.0, 2.5, -2.5);
transform.rotate_x(PI / 2.); transform.rotate_x(PI / 2.);
commands.spawn(PbrBundle { 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, transform,
material: materials.add(StandardMaterial { material: materials.add(StandardMaterial {
base_color: Color::INDIGO, base_color: Color::INDIGO,
@ -66,7 +66,7 @@ fn setup(
transform.rotate_y(PI / 8.); transform.rotate_y(PI / 8.);
commands.spawn(( commands.spawn((
PbrBundle { 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, transform,
material: materials.add(StandardMaterial { material: materials.add(StandardMaterial {
base_color_texture: Some(asset_server.load("branding/bevy_logo_light.png")), base_color_texture: Some(asset_server.load("branding/bevy_logo_light.png")),
@ -83,7 +83,7 @@ fn setup(
// cube // cube
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(StandardMaterial { material: materials.add(StandardMaterial {
base_color: Color::PINK, base_color: Color::PINK,
..default() ..default()
@ -96,10 +96,10 @@ fn setup(
// sphere // sphere
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(Mesh::from(shape::UVSphere { mesh: meshes.add(shape::UVSphere {
radius: 0.5, radius: 0.5,
..default() ..default()
})), }),
material: materials.add(StandardMaterial { material: materials.add(StandardMaterial {
base_color: Color::LIME_GREEN, base_color: Color::LIME_GREEN,
..default() ..default()
@ -131,10 +131,10 @@ fn setup(
}) })
.with_children(|builder| { .with_children(|builder| {
builder.spawn(PbrBundle { builder.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::UVSphere { mesh: meshes.add(shape::UVSphere {
radius: 0.1, radius: 0.1,
..default() ..default()
})), }),
material: materials.add(StandardMaterial { material: materials.add(StandardMaterial {
base_color: Color::RED, base_color: Color::RED,
emissive: Color::rgba_linear(7.13, 0.0, 0.0, 0.0), emissive: Color::rgba_linear(7.13, 0.0, 0.0, 0.0),
@ -162,11 +162,11 @@ fn setup(
.with_children(|builder| { .with_children(|builder| {
builder.spawn(PbrBundle { builder.spawn(PbrBundle {
transform: Transform::from_rotation(Quat::from_rotation_x(PI / 2.0)), 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, depth: 0.125,
radius: 0.1, radius: 0.1,
..default() ..default()
})), }),
material: materials.add(StandardMaterial { material: materials.add(StandardMaterial {
base_color: Color::GREEN, base_color: Color::GREEN,
emissive: Color::rgba_linear(0.0, 7.13, 0.0, 0.0), emissive: Color::rgba_linear(0.0, 7.13, 0.0, 0.0),
@ -191,10 +191,10 @@ fn setup(
}) })
.with_children(|builder| { .with_children(|builder| {
builder.spawn(PbrBundle { builder.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::UVSphere { mesh: meshes.add(shape::UVSphere {
radius: 0.1, radius: 0.1,
..default() ..default()
})), }),
material: materials.add(StandardMaterial { material: materials.add(StandardMaterial {
base_color: Color::BLUE, base_color: Color::BLUE,
emissive: Color::rgba_linear(0.0, 0.0, 7.13, 0.0), emissive: Color::rgba_linear(0.0, 0.0, 7.13, 0.0),

View file

@ -28,12 +28,12 @@ fn setup(
) { ) {
// Spawn a list of lines with start and end points for each lines // Spawn a list of lines with start and end points for each lines
commands.spawn(MaterialMeshBundle { commands.spawn(MaterialMeshBundle {
mesh: meshes.add(Mesh::from(LineList { mesh: meshes.add(LineList {
lines: vec![ lines: vec![
(Vec3::ZERO, Vec3::new(1.0, 1.0, 0.0)), (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)), (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), transform: Transform::from_xyz(-1.5, 0.0, 0.0),
material: materials.add(LineMaterial { material: materials.add(LineMaterial {
color: Color::GREEN, color: Color::GREEN,
@ -43,13 +43,13 @@ fn setup(
// Spawn a line strip that goes from point to point // Spawn a line strip that goes from point to point
commands.spawn(MaterialMeshBundle { commands.spawn(MaterialMeshBundle {
mesh: meshes.add(Mesh::from(LineStrip { mesh: meshes.add(LineStrip {
points: vec![ points: vec![
Vec3::ZERO, 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), Vec3::new(1.0, 0.0, 0.0),
], ],
})), }),
transform: Transform::from_xyz(0.5, 0.0, 0.0), transform: Transform::from_xyz(0.5, 0.0, 0.0),
material: materials.add(LineMaterial { color: Color::BLUE }), material: materials.add(LineMaterial { color: Color::BLUE }),
..default() ..default()

View file

@ -29,32 +29,32 @@ fn setup(
// plane // plane
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(5.0).into()), mesh: meshes.add(shape::Plane::from_size(5.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() ..default()
}); });
// cubes // cubes
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(1.5, 0.5, 1.5), transform: Transform::from_xyz(1.5, 0.5, 1.5),
..default() ..default()
}); });
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(1.5, 0.5, -1.5), transform: Transform::from_xyz(1.5, 0.5, -1.5),
..default() ..default()
}); });
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(-1.5, 0.5, 1.5), transform: Transform::from_xyz(-1.5, 0.5, 1.5),
..default() ..default()
}); });
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(-1.5, 0.5, -1.5), transform: Transform::from_xyz(-1.5, 0.5, -1.5),
..default() ..default()
}); });

View file

@ -234,11 +234,10 @@ fn setup(
.with_children(|commands| { .with_children(|commands| {
// represent the light source as a sphere // represent the light source as a sphere
let mesh = meshes.add( let mesh = meshes.add(
shape::Icosphere { Mesh::try_from(shape::Icosphere {
radius: 0.05, radius: 0.05,
subdivisions: 3, subdivisions: 3,
} })
.try_into()
.unwrap(), .unwrap(),
); );
commands.spawn(PbrBundle { mesh, ..default() }); commands.spawn(PbrBundle { mesh, ..default() });
@ -246,13 +245,10 @@ fn setup(
// Plane // Plane
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add( mesh: meshes.add(shape::Plane {
shape::Plane {
size: 10.0, size: 10.0,
subdivisions: 0, subdivisions: 0,
} }),
.into(),
),
material: materials.add(StandardMaterial { material: materials.add(StandardMaterial {
// standard material derived from dark green, but // standard material derived from dark green, but
// with roughness and reflectance set. // with roughness and reflectance set.

View file

@ -28,7 +28,7 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
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 { let cube_material_handle = materials.add(StandardMaterial {
base_color: Color::rgb(0.8, 0.7, 0.6), base_color: Color::rgb(0.8, 0.7, 0.6),
..default() ..default()

View file

@ -62,7 +62,7 @@ fn setup(
let image_handle = images.add(image); 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 { let cube_material_handle = materials.add(StandardMaterial {
base_color: Color::rgb(0.8, 0.7, 0.6), base_color: Color::rgb(0.8, 0.7, 0.6),
reflectance: 0.02, reflectance: 0.02,
@ -114,7 +114,7 @@ fn setup(
)); ));
let cube_size = 4.0; 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. // This material has the texture that has been rendered.
let material_handle = materials.add(StandardMaterial { let material_handle = materials.add(StandardMaterial {

View file

@ -112,7 +112,7 @@ fn setup(
// ground plane // ground plane
commands.spawn(PbrBundle { 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, material: white_handle,
..default() ..default()
}); });

View file

@ -47,7 +47,7 @@ fn setup(
// sphere - initially a caster // sphere - initially a caster
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: sphere_handle.clone(), 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), transform: Transform::from_xyz(-1.0, spawn_height, 0.0),
..default() ..default()
}); });
@ -56,7 +56,7 @@ fn setup(
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: sphere_handle, mesh: sphere_handle,
material: materials.add(Color::BLUE.into()), material: materials.add(Color::BLUE),
transform: Transform::from_xyz(1.0, spawn_height, 0.0), transform: Transform::from_xyz(1.0, spawn_height, 0.0),
..default() ..default()
}, },
@ -66,8 +66,8 @@ fn setup(
// floating plane - initially not a shadow receiver and not a caster // floating plane - initially not a shadow receiver and not a caster
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(shape::Plane::from_size(20.0).into()), mesh: meshes.add(shape::Plane::from_size(20.0)),
material: materials.add(Color::GREEN.into()), material: materials.add(Color::GREEN),
transform: Transform::from_xyz(0.0, 1.0, -10.0), transform: Transform::from_xyz(0.0, 1.0, -10.0),
..default() ..default()
}, },
@ -77,7 +77,7 @@ fn setup(
// lower ground plane - initially a shadow receiver // lower ground plane - initially a shadow receiver
commands.spawn(PbrBundle { 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, material: white_handle,
..default() ..default()
}); });

View file

@ -22,7 +22,7 @@ fn setup(
// plane // plane
commands.spawn(PbrBundle { 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 { material: materials.add(StandardMaterial {
base_color: Color::rgb(0.2, 0.2, 0.2), base_color: Color::rgb(0.2, 0.2, 0.2),
perceptual_roughness: 0.08, perceptual_roughness: 0.08,
@ -36,11 +36,11 @@ fn setup(
let radius_range = 0.0..0.8; let radius_range = 0.0..0.8;
let pos_len = position_range.end - position_range.start; let pos_len = position_range.end - position_range.start;
let radius_len = radius_range.end - radius_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, sectors: 128,
stacks: 64, stacks: 64,
..default() ..default()
})); });
for i in 0..COUNT { for i in 0..COUNT {
let percent = i as f32 / COUNT as f32; let percent = i as f32 / COUNT as f32;

View file

@ -23,8 +23,8 @@ fn setup(
) { ) {
// plane // plane
commands.spawn(PbrBundle { 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(Color::rgb(0.3, 0.5, 0.3).into()), material: materials.add(Color::rgb(0.3, 0.5, 0.3)),
..default() ..default()
}); });

View file

@ -35,15 +35,15 @@ fn setup(
) { ) {
// ground plane // ground plane
commands.spawn(PbrBundle { 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(Color::WHITE.into()), material: materials.add(Color::WHITE),
..default() ..default()
}); });
// cubes // cubes
let mut rng = StdRng::seed_from_u64(19878367467713); let mut rng = StdRng::seed_from_u64(19878367467713);
let cube_mesh = meshes.add(Mesh::from(shape::Cube { size: 0.5 })); let cube_mesh = meshes.add(shape::Cube { size: 0.5 });
let blue = materials.add(Color::rgb_u8(124, 144, 255).into()); let blue = materials.add(Color::rgb_u8(124, 144, 255));
for _ in 0..40 { for _ in 0..40 {
let x = rng.gen_range(-5.0..5.0); let x = rng.gen_range(-5.0..5.0);
let y = rng.gen_range(0.0..3.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, radius: 0.05,
..default() ..default()
})); });
let sphere_mesh_direction = meshes.add(Mesh::from(shape::UVSphere { let sphere_mesh_direction = meshes.add(shape::UVSphere {
radius: 0.1, radius: 0.1,
..default() ..default()
})); });
let red_emissive = materials.add(StandardMaterial { let red_emissive = materials.add(StandardMaterial {
base_color: Color::RED, base_color: Color::RED,
emissive: Color::rgba_linear(1.0, 0.0, 0.0, 0.0), emissive: Color::rgba_linear(1.0, 0.0, 0.0, 0.0),

View file

@ -48,30 +48,30 @@ fn setup(
..default() ..default()
}); });
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: material.clone(), material: material.clone(),
transform: Transform::from_xyz(0.0, 0.0, 1.0), transform: Transform::from_xyz(0.0, 0.0, 1.0),
..default() ..default()
}); });
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: material.clone(), material: material.clone(),
transform: Transform::from_xyz(0.0, -1.0, 0.0), transform: Transform::from_xyz(0.0, -1.0, 0.0),
..default() ..default()
}); });
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material, material,
transform: Transform::from_xyz(1.0, 0.0, 0.0), transform: Transform::from_xyz(1.0, 0.0, 0.0),
..default() ..default()
}); });
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(Mesh::from(shape::UVSphere { mesh: meshes.add(shape::UVSphere {
radius: 0.4, radius: 0.4,
sectors: 72, sectors: 72,
stacks: 36, stacks: 36,
})), }),
material: materials.add(StandardMaterial { material: materials.add(StandardMaterial {
base_color: Color::rgb(0.4, 0.4, 0.4), base_color: Color::rgb(0.4, 0.4, 0.4),
perceptual_roughness: 1.0, perceptual_roughness: 1.0,

View file

@ -24,10 +24,7 @@ fn setup(
// create a new quad mesh. this is what we will apply the texture to // create a new quad mesh. this is what we will apply the texture to
let quad_width = 8.0; let quad_width = 8.0;
let quad_handle = meshes.add(Mesh::from(shape::Quad::new(Vec2::new( let quad_handle = meshes.add(shape::Quad::new(Vec2::new(quad_width, quad_width * aspect)));
quad_width,
quad_width * aspect,
))));
// this material renders the texture normally // this material renders the texture normally
let material_handle = materials.add(StandardMaterial { let material_handle = materials.add(StandardMaterial {

View file

@ -107,8 +107,8 @@ fn setup_basic_scene(
// plane // plane
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(shape::Plane::from_size(50.0).into()), mesh: meshes.add(shape::Plane::from_size(50.0)),
material: materials.add(Color::rgb(0.1, 0.2, 0.1).into()), material: materials.add(Color::rgb(0.1, 0.2, 0.1)),
..default() ..default()
}, },
SceneNumber(1), SceneNumber(1),
@ -120,7 +120,7 @@ fn setup_basic_scene(
..default() ..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 { for i in 0..5 {
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
@ -134,10 +134,10 @@ fn setup_basic_scene(
} }
// spheres // spheres
let sphere_mesh = meshes.add(Mesh::from(shape::UVSphere { let sphere_mesh = meshes.add(shape::UVSphere {
radius: 0.125, radius: 0.125,
..default() ..default()
})); });
for i in 0..6 { for i in 0..6 {
let j = i % 3; let j = i % 3;
let s_val = if i < 3 { 0.0 } else { 0.2 }; let s_val = if i < 3 { 0.0 } else { 0.2 };
@ -226,10 +226,10 @@ fn setup_color_gradient_scene(
commands.spawn(( commands.spawn((
MaterialMeshBundle { MaterialMeshBundle {
mesh: meshes.add(Mesh::from(shape::Quad { mesh: meshes.add(shape::Quad {
size: vec2(1.0, 1.0) * 0.7, size: vec2(1.0, 1.0) * 0.7,
flip: false, flip: false,
})), }),
material: materials.add(ColorGradientMaterial {}), material: materials.add(ColorGradientMaterial {}),
transform, transform,
visibility: Visibility::Hidden, visibility: Visibility::Hidden,
@ -251,10 +251,10 @@ fn setup_image_viewer_scene(
// exr/hdr viewer (exr requires enabling bevy feature) // exr/hdr viewer (exr requires enabling bevy feature)
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(Mesh::from(shape::Quad { mesh: meshes.add(shape::Quad {
size: vec2(1.0, 1.0), size: vec2(1.0, 1.0),
flip: false, flip: false,
})), }),
material: materials.add(StandardMaterial { material: materials.add(StandardMaterial {
base_color_texture: None, base_color_texture: None,
unlit: true, unlit: true,

View file

@ -76,9 +76,9 @@ fn setup(
.unwrap(), .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 { let cylinder_mesh = meshes.add(Mesh::from(shape::Cylinder {
radius: 0.5, radius: 0.5,
@ -91,7 +91,7 @@ fn setup(
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: cube_mesh.clone(), 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( transform: Transform::from_xyz(0.25, 0.5, -2.0).with_rotation(Quat::from_euler(
EulerRot::XYZ, EulerRot::XYZ,
1.4, 1.4,
@ -111,7 +111,7 @@ fn setup(
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: cube_mesh, 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( transform: Transform::from_xyz(-0.75, 0.7, -2.0).with_rotation(Quat::from_euler(
EulerRot::XYZ, EulerRot::XYZ,
0.4, 0.4,

View file

@ -20,8 +20,8 @@ fn setup(
) { ) {
// opaque plane, uses `alpha_mode: Opaque` by default // opaque plane, uses `alpha_mode: Opaque` by default
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(6.0).into()), mesh: meshes.add(shape::Plane::from_size(6.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() ..default()
}); });
// transparent sphere, uses `alpha_mode: Mask(f32)` // transparent sphere, uses `alpha_mode: Mask(f32)`
@ -67,11 +67,11 @@ fn setup(
}); });
// transparent cube, uses `alpha_mode: Blend` // transparent cube, uses `alpha_mode: Blend`
commands.spawn(PbrBundle { 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. // 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 // 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. // 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), transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default() ..default()
}); });
@ -84,7 +84,7 @@ fn setup(
}) })
.unwrap(), .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), transform: Transform::from_xyz(0.0, 0.5, -1.5),
..default() ..default()
}); });

View file

@ -17,14 +17,14 @@ fn setup(
) { ) {
// plane // plane
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(5.0).into()), mesh: meshes.add(shape::Plane::from_size(5.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() ..default()
}); });
// cube // cube
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0), transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default() ..default()
}); });

View file

@ -17,8 +17,8 @@ fn setup(
) { ) {
// plane // plane
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(5.0).into()), mesh: meshes.add(shape::Plane::from_size(5.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() ..default()
}); });
// cube // cube
@ -38,7 +38,7 @@ fn setup(
// This is the default color, but note that vertex colors are // This is the default color, but note that vertex colors are
// multiplied by the base color, so you'll likely want this to be // multiplied by the base color, so you'll likely want this to be
// white if using vertex colors. // 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), transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default() ..default()
}); });

View file

@ -54,16 +54,16 @@ fn setup(
) { ) {
// plane // plane
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))), mesh: meshes.add(shape::Plane::from_size(5.0)),
material: materials.add(Color::BLUE.into()), material: materials.add(Color::BLUE),
..default() ..default()
}); });
// Red cube: Never renders a wireframe // Red cube: Never renders a wireframe
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::RED.into()), material: materials.add(Color::RED),
transform: Transform::from_xyz(-1.0, 0.5, -1.0), transform: Transform::from_xyz(-1.0, 0.5, -1.0),
..default() ..default()
}, },
@ -71,16 +71,16 @@ fn setup(
)); ));
// Orange cube: Follows global wireframe setting // Orange cube: Follows global wireframe setting
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::ORANGE.into()), material: materials.add(Color::ORANGE),
transform: Transform::from_xyz(0.0, 0.5, 0.0), transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default() ..default()
}); });
// Green cube: Always renders a wireframe // Green cube: Always renders a wireframe
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::GREEN.into()), material: materials.add(Color::GREEN),
transform: Transform::from_xyz(1.0, 0.5, 1.0), transform: Transform::from_xyz(1.0, 0.5, 1.0),
..default() ..default()
}, },

View file

@ -45,8 +45,8 @@ fn setup(
// Plane // Plane
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(500000.0).into()), mesh: meshes.add(shape::Plane::from_size(500000.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() ..default()
}); });

View file

@ -123,7 +123,7 @@ fn setup(
.spawn(( .spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(Mesh::try_from(shape::Icosphere::default()).unwrap()), 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() ..default()
}, },
// Add the Name component, and the animation player // Add the Name component, and the animation player
@ -142,8 +142,8 @@ fn setup(
p.spawn(( p.spawn((
PbrBundle { PbrBundle {
transform: Transform::from_xyz(1.5, 0.0, 0.0), transform: Transform::from_xyz(1.5, 0.0, 0.0),
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.5 })), mesh: meshes.add(shape::Cube { size: 0.5 }),
material: materials.add(Color::rgb(0.3, 0.9, 0.3).into()), material: materials.add(Color::rgb(0.3, 0.9, 0.3)),
..default() ..default()
}, },
// Add the Name component // Add the Name component

View file

@ -38,8 +38,8 @@ fn setup(
// Spawning a cube to experiment on // Spawning a cube to experiment on
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(shape::Cube::default().into()), mesh: meshes.add(shape::Cube::default()),
material: materials.add(Color::ORANGE.into()), material: materials.add(Color::ORANGE),
transform: Transform::from_translation(points[0][0]), transform: Transform::from_translation(points[0][0]),
..default() ..default()
}, },
@ -60,8 +60,8 @@ fn setup(
// ground plane // ground plane
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(50.).into()), mesh: meshes.add(shape::Plane::from_size(50.)),
material: materials.add(Color::SILVER.into()), material: materials.add(Color::SILVER),
..default() ..default()
}); });

View file

@ -48,11 +48,10 @@ fn setup(
}); });
// Create inverse bindpose matrices for a skeleton consists of 2 joints // Create inverse bindpose matrices for a skeleton consists of 2 joints
let inverse_bindposes = let inverse_bindposes = skinned_mesh_inverse_bindposes_assets.add(vec![
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)),
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 // Create a mesh
let mesh = Mesh::new( let mesh = Mesh::new(
@ -148,14 +147,11 @@ fn setup(
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: mesh.clone(), mesh: mesh.clone(),
material: materials.add( material: materials.add(Color::rgb(
Color::rgb(
rng.gen_range(0.0..1.0), rng.gen_range(0.0..1.0),
rng.gen_range(0.0..1.0), rng.gen_range(0.0..1.0),
rng.gen_range(0.0..1.0), rng.gen_range(0.0..1.0),
) )),
.into(),
),
..default() ..default()
}, },
SkinnedMesh { SkinnedMesh {

View file

@ -35,10 +35,10 @@ fn add_assets(
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
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)); 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)); commands.insert_resource(BoxMaterialHandle(box_material_handle));
} }

View file

@ -34,8 +34,8 @@ fn setup(
// sound emitter // sound emitter
commands.spawn(( commands.spawn((
MaterialMesh2dBundle { MaterialMesh2dBundle {
mesh: meshes.add(shape::Circle::new(15.0).into()).into(), mesh: meshes.add(shape::Circle::new(15.0)).into(),
material: materials.add(ColorMaterial::from(Color::BLUE)), material: materials.add(Color::BLUE),
transform: Transform::from_translation(Vec3::new(0.0, 50.0, 0.0)), transform: Transform::from_translation(Vec3::new(0.0, 50.0, 0.0)),
..default() ..default()
}, },

View file

@ -22,11 +22,11 @@ fn setup(
// sound emitter // sound emitter
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(Mesh::from(shape::UVSphere { mesh: meshes.add(shape::UVSphere {
radius: 0.2, radius: 0.2,
..default() ..default()
})), }),
material: materials.add(Color::BLUE.into()), material: materials.add(Color::BLUE),
transform: Transform::from_xyz(0.0, 0.0, 0.0), transform: Transform::from_xyz(0.0, 0.0, 0.0),
..default() ..default()
}, },
@ -43,16 +43,16 @@ fn setup(
.with_children(|parent| { .with_children(|parent| {
// left ear indicator // left ear indicator
parent.spawn(PbrBundle { parent.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.2 })), mesh: meshes.add(shape::Cube { size: 0.2 }),
material: materials.add(Color::RED.into()), material: materials.add(Color::RED),
transform: Transform::from_translation(listener.left_ear_offset), transform: Transform::from_translation(listener.left_ear_offset),
..default() ..default()
}); });
// right ear indicator // right ear indicator
parent.spawn(PbrBundle { parent.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.2 })), mesh: meshes.add(shape::Cube { size: 0.2 }),
material: materials.add(Color::GREEN.into()), material: materials.add(Color::GREEN),
transform: Transform::from_translation(listener.right_ear_offset), transform: Transform::from_translation(listener.right_ear_offset),
..default() ..default()
}); });

View file

@ -76,14 +76,11 @@ fn generate_bodies(
..default() ..default()
}, },
mesh: mesh.clone(), mesh: mesh.clone(),
material: materials.add( material: materials.add(Color::rgb(
Color::rgb(
rng.gen_range(color_range.clone()), rng.gen_range(color_range.clone()),
rng.gen_range(color_range.clone()), rng.gen_range(color_range.clone()),
rng.gen_range(color_range.clone()), rng.gen_range(color_range.clone()),
) )),
.into(),
),
..default() ..default()
}, },
mass: Mass(mass_value), mass: Mass(mass_value),

View file

@ -207,8 +207,8 @@ fn setup(
// Ball // Ball
commands.spawn(( commands.spawn((
MaterialMesh2dBundle { MaterialMesh2dBundle {
mesh: meshes.add(shape::Circle::default().into()).into(), mesh: meshes.add(shape::Circle::default()).into(),
material: materials.add(ColorMaterial::from(BALL_COLOR)), material: materials.add(BALL_COLOR),
transform: Transform::from_translation(BALL_STARTING_POSITION).with_scale(BALL_SIZE), transform: Transform::from_translation(BALL_STARTING_POSITION).with_scale(BALL_SIZE),
..default() ..default()
}, },

View file

@ -62,14 +62,14 @@ fn setup_scene(
) { ) {
// plane // plane
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(5.0).into()), mesh: meshes.add(shape::Plane::from_size(5.0)),
material: materials.add(Color::rgb(0.1, 0.2, 0.1).into()), material: materials.add(Color::rgb(0.1, 0.2, 0.1)),
..default() ..default()
}); });
// cube // cube
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::rgb(0.5, 0.4, 0.3).into()), material: materials.add(Color::rgb(0.5, 0.4, 0.3)),
transform: Transform::from_xyz(0.0, 0.5, 0.0), transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default() ..default()
}); });
@ -82,7 +82,7 @@ fn setup_scene(
}) })
.unwrap(), .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), transform: Transform::from_xyz(1.5, 1.5, 1.5),
..default() ..default()
}); });

View file

@ -21,7 +21,7 @@ fn setup(
) { ) {
// cube // cube
commands.spawn(MaterialMeshBundle { 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), transform: Transform::from_xyz(0.0, 0.5, 0.0),
material: materials.add(CustomMaterial {}), material: materials.add(CustomMaterial {}),
..default() ..default()

View file

@ -77,7 +77,7 @@ fn create_array_texture(
image.reinterpret_stacked_2d_as_array(array_layers); image.reinterpret_stacked_2d_as_array(array_layers);
// Spawn some cubes using the array texture // 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 { let material_handle = materials.add(ArrayTextureMaterial {
array_texture: loading_texture.handle.clone(), array_texture: loading_texture.handle.clone(),
}); });

View file

@ -27,7 +27,7 @@ fn setup(
mut materials: ResMut<Assets<FallbackTestMaterial>>, mut materials: ResMut<Assets<FallbackTestMaterial>>,
) { ) {
commands.spawn(MaterialMeshBundle { 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 { material: materials.add(FallbackTestMaterial {
image_1d: None, image_1d: None,
image_2d: None, image_2d: None,
@ -36,11 +36,11 @@ fn setup(
image_cube_array: None, image_cube_array: None,
image_3d: None, image_3d: None,
}), }),
..Default::default() ..default()
}); });
commands.spawn(Camera3dBundle { 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), 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()
}); });
} }

View file

@ -322,8 +322,8 @@ fn setup(
// cube // cube
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0), transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default() ..default()
}, },

View file

@ -27,7 +27,7 @@ fn setup(
) { ) {
// blue cube // blue cube
commands.spawn(MaterialMeshBundle { 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), transform: Transform::from_xyz(-1.0, 0.5, 0.0),
material: materials.add(CustomMaterial { material: materials.add(CustomMaterial {
color: Color::BLUE, color: Color::BLUE,
@ -38,7 +38,7 @@ fn setup(
// red cube (with green color overridden by the IS_RED "shader def") // red cube (with green color overridden by the IS_RED "shader def")
commands.spawn(MaterialMeshBundle { 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), transform: Transform::from_xyz(1.0, 0.5, 0.0),
material: materials.add(CustomMaterial { material: materials.add(CustomMaterial {
color: Color::GREEN, color: Color::GREEN,

View file

@ -35,7 +35,7 @@ fn main() {
fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) { fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
commands.spawn(( commands.spawn((
meshes.add(Mesh::from(shape::Cube { size: 0.5 })), meshes.add(shape::Cube { size: 0.5 }),
SpatialBundle::INHERITED_IDENTITY, SpatialBundle::INHERITED_IDENTITY,
InstanceMaterialData( InstanceMaterialData(
(1..=10) (1..=10)

View file

@ -22,7 +22,7 @@ fn setup(
) { ) {
// cube // cube
commands.spawn(MaterialMeshBundle { 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), transform: Transform::from_xyz(0.0, 0.5, 0.0),
material: materials.add(CustomMaterial { material: materials.add(CustomMaterial {
color: Color::BLUE, color: Color::BLUE,

View file

@ -29,7 +29,7 @@ fn setup(
// quad // quad
commands.spawn(MaterialMesh2dBundle { 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.)), transform: Transform::default().with_scale(Vec3::splat(128.)),
material: materials.add(CustomMaterial { material: materials.add(CustomMaterial {
color: Color::BLUE, color: Color::BLUE,

View file

@ -28,7 +28,7 @@ fn setup(
) { ) {
// cube // cube
commands.spawn(MaterialMeshBundle { 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), transform: Transform::from_xyz(0.0, 0.5, 0.0),
material: materials.add(CustomMaterial { material: materials.add(CustomMaterial {
color: Color::BLUE, color: Color::BLUE,

View file

@ -25,8 +25,8 @@ fn setup(
mut standard_materials: ResMut<Assets<StandardMaterial>>, mut standard_materials: ResMut<Assets<StandardMaterial>>,
) { ) {
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(5.0).into()), mesh: meshes.add(shape::Plane::from_size(5.0)),
material: standard_materials.add(Color::rgb(0.3, 0.5, 0.3).into()), material: standard_materials.add(Color::rgb(0.3, 0.5, 0.3)),
..default() ..default()
}); });
commands.spawn(PointLightBundle { commands.spawn(PointLightBundle {
@ -35,7 +35,7 @@ fn setup(
}); });
commands.spawn(MaterialMeshBundle { 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), transform: Transform::from_xyz(0.0, 0.5, 0.0),
material: custom_materials.add(CustomMaterial { material: custom_materials.add(CustomMaterial {
texture: asset_server.load( texture: asset_server.load(

View file

@ -61,8 +61,8 @@ fn setup(
// plane // plane
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(5.0).into()), mesh: meshes.add(shape::Plane::from_size(5.0)),
material: std_materials.add(Color::rgb(0.3, 0.5, 0.3).into()), material: std_materials.add(Color::rgb(0.3, 0.5, 0.3)),
..default() ..default()
}); });
@ -71,7 +71,7 @@ fn setup(
// For a real application, this isn't ideal. // For a real application, this isn't ideal.
commands.spawn(( commands.spawn((
MaterialMeshBundle { 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 { material: depth_materials.add(PrepassOutputMaterial {
settings: ShowPrepassSettings::default(), settings: ShowPrepassSettings::default(),
}), }),
@ -85,7 +85,7 @@ fn setup(
// Opaque cube // Opaque cube
commands.spawn(( commands.spawn((
MaterialMeshBundle { MaterialMeshBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(CustomMaterial { material: materials.add(CustomMaterial {
color: Color::WHITE, color: Color::WHITE,
color_texture: Some(asset_server.load("branding/icon.png")), color_texture: Some(asset_server.load("branding/icon.png")),
@ -99,7 +99,7 @@ fn setup(
// Cube with alpha mask // Cube with alpha mask
commands.spawn(PbrBundle { 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 { material: std_materials.add(StandardMaterial {
alpha_mode: AlphaMode::Mask(1.0), alpha_mode: AlphaMode::Mask(1.0),
base_color_texture: Some(asset_server.load("branding/icon.png")), base_color_texture: Some(asset_server.load("branding/icon.png")),
@ -112,7 +112,7 @@ fn setup(
// Cube with alpha blending. // Cube with alpha blending.
// Transparent materials are ignored by the prepass // Transparent materials are ignored by the prepass
commands.spawn(MaterialMeshBundle { 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 { material: materials.add(CustomMaterial {
color: Color::WHITE, color: Color::WHITE,
color_texture: Some(asset_server.load("branding/icon.png")), color_texture: Some(asset_server.load("branding/icon.png")),

View file

@ -63,7 +63,7 @@ fn setup(
) { ) {
commands.spawn(Camera3dBundle { 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), 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 // load 16 textures
@ -74,9 +74,9 @@ fn setup(
// a cube with multiple textures // a cube with multiple textures
commands.spawn(MaterialMeshBundle { 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 }), material: materials.add(BindlessMaterial { textures }),
..Default::default() ..default()
}); });
} }

View file

@ -209,9 +209,7 @@ fn setup(
textures, textures,
materials, materials,
quad: meshes quad: meshes
.add(Mesh::from(shape::Quad::new(Vec2::splat( .add(shape::Quad::new(Vec2::splat(BIRD_TEXTURE_SIZE as f32)))
BIRD_TEXTURE_SIZE as f32,
))))
.into(), .into(),
color_rng: StdRng::seed_from_u64(42), color_rng: StdRng::seed_from_u64(42),
material_rng: StdRng::seed_from_u64(42), material_rng: StdRng::seed_from_u64(42),

View file

@ -104,7 +104,7 @@ fn setup(
let images = images.into_inner(); let images = images.into_inner();
let material_assets = material_assets.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 material_textures = init_textures(args, images);
let materials = init_materials(args, &material_textures, material_assets); let materials = init_materials(args, &material_textures, material_assets);

View file

@ -185,8 +185,8 @@ fn setup(
// Plane // Plane
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(5000.0).into()), mesh: meshes.add(shape::Plane::from_size(5000.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() ..default()
}); });

View file

@ -55,12 +55,12 @@ fn setup(
}) })
.unwrap(), .unwrap(),
), ),
material: materials.add(StandardMaterial::from(Color::WHITE)), material: materials.add(Color::WHITE),
transform: Transform::from_scale(Vec3::NEG_ONE), transform: Transform::from_scale(Vec3::NEG_ONE),
..default() ..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 { let material = materials.add(StandardMaterial {
base_color: Color::PINK, base_color: Color::PINK,
..default() ..default()

View file

@ -56,8 +56,8 @@ impl FromWorld for ButtonMaterials {
fn from_world(world: &mut World) -> Self { fn from_world(world: &mut World) -> Self {
let mut materials = world.resource_mut::<Assets<ColorMaterial>>(); let mut materials = world.resource_mut::<Assets<ColorMaterial>>();
Self { Self {
normal: materials.add(ColorMaterial::from(NORMAL_BUTTON_COLOR)), normal: materials.add(NORMAL_BUTTON_COLOR),
active: materials.add(ColorMaterial::from(ACTIVE_BUTTON_COLOR)), active: materials.add(ACTIVE_BUTTON_COLOR),
} }
} }
} }
@ -72,12 +72,12 @@ impl FromWorld for ButtonMeshes {
fn from_world(world: &mut World) -> Self { fn from_world(world: &mut World) -> Self {
let mut meshes = world.resource_mut::<Assets<Mesh>>(); let mut meshes = world.resource_mut::<Assets<Mesh>>();
Self { Self {
circle: meshes.add(shape::Circle::new(BUTTON_RADIUS).into()).into(), circle: meshes.add(shape::Circle::new(BUTTON_RADIUS)).into(),
triangle: meshes triangle: meshes
.add(shape::RegularPolygon::new(BUTTON_RADIUS, 3).into()) .add(shape::RegularPolygon::new(BUTTON_RADIUS, 3))
.into(), .into(),
start_pause: meshes.add(shape::Quad::new(START_SIZE).into()).into(), start_pause: meshes.add(shape::Quad::new(START_SIZE)).into(),
trigger: meshes.add(shape::Quad::new(TRIGGER_SIZE).into()).into(), trigger: meshes.add(shape::Quad::new(TRIGGER_SIZE)).into(),
} }
} }
} }

View file

@ -26,8 +26,8 @@ fn setup(
// Spawn a cube to rotate. // Spawn a cube to rotate.
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::WHITE.into()), material: materials.add(Color::WHITE),
transform: Transform::from_translation(Vec3::ZERO), transform: Transform::from_translation(Vec3::ZERO),
..default() ..default()
}, },

View file

@ -42,8 +42,8 @@ fn setup(
// Spawn a cube to scale. // Spawn a cube to scale.
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::WHITE.into()), material: materials.add(Color::WHITE),
transform: Transform::from_rotation(Quat::from_rotation_y(PI / 4.0)), transform: Transform::from_rotation(Quat::from_rotation_y(PI / 4.0)),
..default() ..default()
}, },

View file

@ -53,7 +53,7 @@ fn setup(
}) })
.unwrap(), .unwrap(),
), ),
material: materials.add(Color::YELLOW.into()), material: materials.add(Color::YELLOW),
transform: Transform::from_translation(Vec3::ZERO), transform: Transform::from_translation(Vec3::ZERO),
..default() ..default()
}, },
@ -73,8 +73,8 @@ fn setup(
Transform::from_translation(Vec3::Z * -10.0).with_rotation(Quat::from_rotation_y(PI / 2.)); Transform::from_translation(Vec3::Z * -10.0).with_rotation(Quat::from_rotation_y(PI / 2.));
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::WHITE.into()), material: materials.add(Color::WHITE),
transform: cube_spawn, transform: cube_spawn,
..default() ..default()
}, },

View file

@ -40,8 +40,8 @@ fn setup(
let entity_spawn = Vec3::ZERO; let entity_spawn = Vec3::ZERO;
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::WHITE.into()), material: materials.add(Color::WHITE),
transform: Transform::from_translation(entity_spawn), transform: Transform::from_translation(entity_spawn),
..default() ..default()
}, },

View file

@ -150,8 +150,8 @@ pub(crate) mod test_setup {
) { ) {
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.5 })), mesh: meshes.add(shape::Cube { size: 0.5 }),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
..default() ..default()
}, },
Rotator, Rotator,

View file

@ -35,14 +35,14 @@ fn setup(
) { ) {
// plane // plane
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(5.0).into()), mesh: meshes.add(shape::Plane::from_size(5.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() ..default()
}); });
// cube // cube
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0), transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default() ..default()
}); });

View file

@ -35,17 +35,17 @@ fn setup_3d(
) { ) {
// plane // plane
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane { mesh: meshes.add(shape::Plane {
size: 5.0, size: 5.0,
subdivisions: 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() ..default()
}); });
// cube // cube
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0), transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default() ..default()
}); });

View file

@ -118,17 +118,17 @@ fn setup_3d(
) { ) {
// plane // plane
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane { mesh: meshes.add(shape::Plane {
size: 5.0, size: 5.0,
subdivisions: 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() ..default()
}); });
// cube // cube
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0), transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default() ..default()
}); });