bevy/crates/bevy_render/src
Joona Aalto f1f83bf5bc
Add Mesh::merge (#11456)
# Objective

It can sometimes be useful to combine several meshes into one. This
allows constructing more complex meshes out of simple primitives without
needing to use a 3D modeling program or entity hierarchies.

This could also be used internally to increase code reuse by using
existing mesh generation logic for e.g. circles and using that in
cylinder mesh generation logic to add the top and bottom of the
cylinder.

**Note**: This is *not* implementing CSGs (Constructive Solid Geometry)
or any boolean operations, as that is much more complex. This is simply
adding the mesh data of another mesh to a mesh.

## Solution

Add a `merge` method to `Mesh`. It appends the vertex attributes and
indices of `other` to `self`, resulting in a `Mesh` that is the
combination of the two.

For example, you could do this:

```rust
let mut cuboid = Mesh::from(shape::Box::default());
let mut cylinder = Mesh::from(shape::Cylinder::default());
let mut torus = Mesh::from(shape::Torus::default());

cuboid.merge(cylinder);
cuboid.merge(torus);
```

This would result in `cuboid` being a `Mesh` that also has the cylinder
mesh and torus mesh. In this case, they would just be placed on top of
each other, but by utilizing #11454 we can transform the cylinder and
torus to get a result like this:


https://github.com/bevyengine/bevy/assets/57632562/557402c6-b896-4aba-bd95-312e7d1b5238

This is just a single entity and a single mesh.
2024-02-12 22:04:33 +00:00
..
batching optimize batch_and_prepare_render_phase (#11323) 2024-01-20 09:30:44 +00:00
camera CameraProjection::compute_frustum (#11139) 2024-02-04 01:21:07 +00:00
color Replace deprecated elements (#10991) 2023-12-16 02:25:12 +00:00
mesh Add Mesh::merge (#11456) 2024-02-12 22:04:33 +00:00
primitives Move EntityHash related types into bevy_ecs (#11498) 2024-02-12 15:02:24 +00:00
render_graph Multithreaded render command encoding (#9172) 2024-02-09 07:35:35 +00:00
render_phase Stop extracting mesh entities to the render world. (#11803) 2024-02-10 10:46:10 +00:00
render_resource Async pipeline compilation (#10812) 2024-02-05 13:50:50 +00:00
renderer Multithreaded render command encoding (#9172) 2024-02-09 07:35:35 +00:00
texture mipmap levels can be 0 and they should be interpreted as 1 (#11767) 2024-02-11 22:00:07 +00:00
view Move EntityHash related types into bevy_ecs (#11498) 2024-02-12 15:02:24 +00:00
deterministic.rs Option to enable deterministic rendering (#11248) 2024-01-09 00:46:01 +00:00
extract_component.rs Revert rendering-related associated type name changes (#11027) 2024-01-22 15:01:55 +00:00
extract_instances.rs Move EntityHash related types into bevy_ecs (#11498) 2024-02-12 15:02:24 +00:00
extract_param.rs Enable the unsafe_op_in_unsafe_fn lint (#11591) 2024-01-28 23:18:11 +00:00
extract_resource.rs Use warn_once where relevant instead of manually implementing a single warn check (#11693) 2024-02-05 21:05:43 +00:00
globals.rs Update to wgpu 0.19 and raw-window-handle 0.6 (#11280) 2024-01-26 18:14:21 +00:00
globals.wgsl Refactor Globals and View structs into separate shaders (#7512) 2023-02-11 17:55:18 +00:00
gpu_component_array_buffer.rs Reorder render sets, refactor bevy_sprite to take advantage (#9236) 2023-08-27 14:33:49 +00:00
lib.rs Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
maths.wgsl Use instancing for sprites (#9597) 2023-09-02 18:03:19 +00:00
pipelined_rendering.rs wait for render app when main world is dropped (#11737) 2024-02-08 14:09:17 +00:00
render_asset.rs Add ReflectKind (#11664) 2024-02-07 00:36:23 +00:00
settings.rs Update to wgpu 0.19 and raw-window-handle 0.6 (#11280) 2024-01-26 18:14:21 +00:00
spatial_bundle.rs Implement Clone for VisibilityBundle and SpatialBundle (#10394) 2023-11-07 21:25:00 +00:00