Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# 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 bevyengine#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.
- Loading branch information