bevy/examples/3d
Marco Buono 12a2f83edd
Add consuming builder methods for more ergonomic Mesh creation (#10056)
# Objective

- This PR aims to make creating meshes a little bit more ergonomic,
specifically by removing the need for intermediate mutable variables.

## Solution

- We add methods that consume the `Mesh` and return a mesh with the
specified changes, so that meshes can be entirely constructed via
builder-style calls, without intermediate variables;
- Methods are flagged with `#[must_use]` to ensure proper use;
- Examples are updated to use the new methods where applicable. Some
examples are kept with the mutating methods so that users can still
easily discover them, and also where the new methods wouldn't really be
an improvement.

## Examples

Before:

```rust
let mut mesh = Mesh::new(PrimitiveTopology::TriangleList);
mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, vs);
mesh.insert_attribute(Mesh::ATTRIBUTE_NORMAL, vns);
mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, vts);
mesh.set_indices(Some(Indices::U32(tris)));
mesh
```

After:

```rust
Mesh::new(PrimitiveTopology::TriangleList)
    .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, vs)
    .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, vns)
    .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, vts)
    .with_indices(Some(Indices::U32(tris)))
```

Before:

```rust
let mut cube = Mesh::from(shape::Cube { size: 1.0 });

cube.generate_tangents().unwrap();

PbrBundle {
    mesh: meshes.add(cube),
    ..default()
}
```

After:

```rust
PbrBundle {
    mesh: meshes.add(
        Mesh::from(shape::Cube { size: 1.0 })
            .with_generated_tangents()
            .unwrap(),
    ),
    ..default()
}
```

---

## Changelog

- Added consuming builder methods for more ergonomic `Mesh` creation:
`with_inserted_attribute()`, `with_removed_attribute()`,
`with_indices()`, `with_duplicated_vertices()`,
`with_computed_flat_normals()`, `with_generated_tangents()`,
`with_morph_targets()`, `with_morph_target_names()`.
2023-10-09 19:47:41 +00:00
..
3d_gizmos.rs Instanced line rendering for gizmos based on bevy_polyline (#8427) 2023-06-13 06:49:47 +00:00
3d_scene.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
3d_shapes.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
3d_viewport_to_world.rs Add example for Camera::viewport_to_world (#7179) 2023-09-11 18:52:11 +00:00
anti_aliasing.rs Allow clippy::type_complexity in more places. (#9796) 2023-10-02 21:55:16 +00:00
atmospheric_fog.rs Remove useless single tuples and trailing commas (#9720) 2023-09-08 21:46:54 +00:00
blend_modes.rs Added Val::ZERO Constant (#9566) 2023-08-26 14:00:53 +00:00
bloom_3d.rs Fix CI for Rust 1.72 (#9562) 2023-08-25 12:34:24 +00:00
fog.rs Rename keys like LAlt to AltLeft (#8792) 2023-06-15 01:37:04 +00:00
generate_custom_mesh.rs Add consuming builder methods for more ergonomic Mesh creation (#10056) 2023-10-09 19:47:41 +00:00
lighting.rs standardize instructions in examples (#8478) 2023-04-26 19:52:31 +00:00
lines.rs Add consuming builder methods for more ergonomic Mesh creation (#10056) 2023-10-09 19:47:41 +00:00
load_gltf.rs Bevy Asset V2 (#8624) 2023-09-07 02:07:27 +00:00
orthographic.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
parallax_mapping.rs Add consuming builder methods for more ergonomic Mesh creation (#10056) 2023-10-09 19:47:41 +00:00
parenting.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
pbr.rs Bevy Asset V2 (#8624) 2023-09-07 02:07:27 +00:00
render_to_texture.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
shadow_biases.rs Refactor EventReader::iter to read (#9631) 2023-08-30 14:20:03 +00:00
shadow_caster_receiver.rs Allow clippy::type_complexity in more places. (#9796) 2023-10-02 21:55:16 +00:00
skybox.rs Bevy Asset V2 (#8624) 2023-09-07 02:07:27 +00:00
spherical_area_lights.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
split_screen.rs Refactor EventReader::iter to read (#9631) 2023-08-30 14:20:03 +00:00
spotlight.rs Improve execution of examples in CI (#9331) 2023-08-03 12:45:28 +00:00
ssao.rs Allow clippy::type_complexity in more places. (#9796) 2023-10-02 21:55:16 +00:00
texture.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
tonemapping.rs Bevy Asset V2 (#8624) 2023-09-07 02:07:27 +00:00
transparency_3d.rs Fixed several missing links in docs. (#8117) 2023-04-23 17:28:36 +00:00
two_passes.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
update_gltf_scene.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
vertex_colors.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
wireframe.rs Alternate wireframe override api (#10023) 2023-10-05 12:12:08 +00:00