mirror of
https://github.com/bevyengine/bevy
synced 2024-12-03 09:59:15 +00:00
948ea3137a
# Objective Give easy methods for uniform point sampling in a variety of primitive shapes (particularly useful for circles and spheres) because in a lot of cases its quite easy to get wrong (non-uniform). ## Solution Added the `ShapeSample` trait to `bevy_math` and implemented it for `Circle`, `Sphere`, `Rectangle`, `Cuboid`, `Cylinder`, `Capsule2d` and `Capsule3d`. There are a few other shapes it would be reasonable to implement for like `Triangle`, `Ellipse` and `Torus` but I'm not immediately sure how these would be implemented (other than rejection which could be the best method, and could be more performant than some of the solutions in this pr I'm not sure). This exposes the `sample_volume` and `sample_surface` methods to get both a random point from its interior or its surface. EDIT: Renamed `sample_volume` to `sample_interior` and `sample_surface` to `sample_boundary` This brings in `rand` as a default optional dependency (without default features), and the methods take `&mut impl Rng` which allows them to use any random source implementing `RngCore`. --- ## Changelog ### Added Added the methods `sample_interior` and `sample_boundary` to a variety of primitive shapes providing easy uniform point sampling. |
||
---|---|---|
.. | ||
bevy_a11y | ||
bevy_animation | ||
bevy_app | ||
bevy_asset | ||
bevy_audio | ||
bevy_color | ||
bevy_core | ||
bevy_core_pipeline | ||
bevy_derive | ||
bevy_dev_tools | ||
bevy_diagnostic | ||
bevy_dylib | ||
bevy_dynamic_plugin | ||
bevy_ecs | ||
bevy_ecs_compile_fail_tests | ||
bevy_encase_derive | ||
bevy_gilrs | ||
bevy_gizmos | ||
bevy_gltf | ||
bevy_hierarchy | ||
bevy_input | ||
bevy_internal | ||
bevy_log | ||
bevy_macro_utils | ||
bevy_macros_compile_fail_tests | ||
bevy_math | ||
bevy_mikktspace | ||
bevy_pbr | ||
bevy_ptr | ||
bevy_reflect | ||
bevy_reflect_compile_fail_tests | ||
bevy_render | ||
bevy_scene | ||
bevy_sprite | ||
bevy_tasks | ||
bevy_text | ||
bevy_time | ||
bevy_transform | ||
bevy_ui | ||
bevy_utils | ||
bevy_window | ||
bevy_winit |