├── .gitignore ├── Cargo.toml ├── LICENSE ├── README.md ├── .github └── workflows │ └── rust.yml ├── examples └── demo.rs └── src ├── lib.rs ├── sphere.rs ├── aabb.rs ├── obb.rs └── debug.rs /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | Cargo.lock 3 | .cargo/config 4 | .cargo/config.toml 5 | .vscode 6 | .cargo/credentials.toml 7 | .cargo/config_fast_compile 8 | **/trace-*.json -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "bevy_mod_bounding" 3 | version = "0.1.2-alpha.0" 4 | authors = ["Aevyrie Roessler "] 5 | edition = "2018" 6 | license = "MIT" 7 | description = "Bounding box generation for the Bevy Engine." 8 | repository = "https://github.com/aevyrie/bevy_mod_bounding/" 9 | keywords = ["gamedev", "graphics", "bevy", "3d", "bounding"] 10 | categories = ["game-engines", "rendering"] 11 | resolver = "2" 12 | 13 | [dependencies] 14 | bevy = { git = "https://github.com/bevyengine/bevy", branch = "main", version = "0.5" } 15 | 16 | [[example]] 17 | name = "demo" 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Aevyrie 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bounding Box Generation for Bevy 2 | 3 | [![CI](https://github.com/aevyrie/bevy_mod_bounding/workflows/CI/badge.svg?branch=master)](https://github.com/aevyrie/bevy_mod_bounding/actions?query=workflow%3A%22CI%22+branch%3Amaster) 4 | [![crates.io](https://img.shields.io/crates/v/bevy_mod_bounding)](https://crates.io/crates/bevy_mod_bounding) 5 | [![docs.rs](https://docs.rs/bevy_mod_bounding/badge.svg)](https://docs.rs/bevy_mod_bounding) 6 | [![Bevy tracking](https://img.shields.io/badge/Bevy%20tracking-main-lightblue)](https://github.com/bevyengine/bevy/blob/main/docs/plugins_guidelines.md#main-branch-tracking) 7 | 8 | Unofficial plugin for generating bounding volumes. 9 | 10 | ![demo](https://user-images.githubusercontent.com/2632925/114147530-a4785800-98cd-11eb-9395-7a0522e117a2.gif) 11 | 12 | ## Status 13 | 14 | | Status | Bounding Volume | 15 | |:-:|----------------------------| 16 | | ✅ | Bounding Sphere | 17 | | ✅ | Axis Aligned Bounding Box | 18 | | ✅ | Oriented Bounding Box | 19 | 20 | ## Example 21 | 22 | Run the demo with: 23 | 24 | ```shell 25 | cargo run --features ex --example demo 26 | ``` 27 | 28 | ## Bevy Version Support 29 | 30 | I intend to track the `main` branch of Bevy. PRs supporting this are welcome! 31 | 32 | |bevy|bevy_mod_bounding| 33 | |---|---| 34 | |0.5|0.1| 35 | 36 | # License 37 | 38 | This project is licensed under the [MIT license](https://github.com/aevyrie/bevy_mod_bounding/blob/master/LICENSE). 39 | 40 | ## Contribution 41 | 42 | Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in bevy_mod_bounding by you, shall be licensed as MIT, without any additional terms or conditions. 43 | -------------------------------------------------------------------------------- /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | on: 2 | pull_request: 3 | push: 4 | branches: 5 | - master 6 | 7 | name: CI 8 | 9 | jobs: 10 | check: 11 | name: Check 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Install alsa 15 | run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev 16 | if: ${{ runner.os == 'Linux' }} 17 | 18 | - name: Install udev 19 | run: sudo apt-get update; sudo apt-get install --no-install-recommends libudev-dev 20 | if: ${{ runner.os == 'Linux' }} 21 | 22 | - uses: actions/checkout@v2 23 | - uses: actions-rs/toolchain@v1 24 | with: 25 | profile: minimal 26 | toolchain: stable 27 | override: true 28 | - uses: actions-rs/cargo@v1 29 | with: 30 | command: check 31 | 32 | test: 33 | name: Test Suite 34 | runs-on: ubuntu-latest 35 | steps: 36 | - name: Install alsa 37 | run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev 38 | if: ${{ runner.os == 'Linux' }} 39 | 40 | - name: Install udev 41 | run: sudo apt-get update; sudo apt-get install --no-install-recommends libudev-dev 42 | if: ${{ runner.os == 'Linux' }} 43 | 44 | - uses: actions/checkout@v2 45 | - uses: actions-rs/toolchain@v1 46 | with: 47 | profile: minimal 48 | toolchain: stable 49 | override: true 50 | - uses: actions-rs/cargo@v1 51 | with: 52 | command: test 53 | 54 | fmt: 55 | name: Rustfmt 56 | runs-on: ubuntu-latest 57 | steps: 58 | - name: Install alsa 59 | run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev 60 | if: ${{ runner.os == 'Linux' }} 61 | 62 | - name: Install udev 63 | run: sudo apt-get update; sudo apt-get install --no-install-recommends libudev-dev 64 | if: ${{ runner.os == 'Linux' }} 65 | 66 | - uses: actions/checkout@v2 67 | - uses: actions-rs/toolchain@v1 68 | with: 69 | profile: minimal 70 | toolchain: stable 71 | override: true 72 | - run: rustup component add rustfmt 73 | - uses: actions-rs/cargo@v1 74 | with: 75 | command: fmt 76 | args: --all -- --check 77 | 78 | clippy: 79 | name: Clippy 80 | runs-on: ubuntu-latest 81 | steps: 82 | - name: Install alsa 83 | run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev 84 | if: ${{ runner.os == 'Linux' }} 85 | 86 | - name: Install udev 87 | run: sudo apt-get update; sudo apt-get install --no-install-recommends libudev-dev 88 | if: ${{ runner.os == 'Linux' }} 89 | 90 | - uses: actions/checkout@v2 91 | - uses: actions-rs/toolchain@v1 92 | with: 93 | profile: minimal 94 | toolchain: stable 95 | override: true 96 | - run: rustup component add clippy 97 | - uses: actions-rs/cargo@v1 98 | with: 99 | command: clippy 100 | args: -- -D warnings 101 | -------------------------------------------------------------------------------- /examples/demo.rs: -------------------------------------------------------------------------------- 1 | use bevy::prelude::*; 2 | use bevy_mod_bounding::{aabb, debug, obb, *}; 3 | 4 | fn main() { 5 | App::new() 6 | .insert_resource(Msaa { samples: 2 }) 7 | .add_plugins(DefaultPlugins) 8 | .add_plugin(BoundingVolumePlugin::::default()) 9 | .add_plugin(BoundingVolumePlugin::::default()) 10 | .add_plugin(BoundingVolumePlugin::::default()) 11 | .add_startup_system(setup.system()) 12 | .add_system(rotation_system.system()) 13 | .run(); 14 | } 15 | 16 | #[derive(Component)] 17 | struct Rotator; 18 | 19 | fn setup( 20 | mut commands: Commands, 21 | mut meshes: ResMut>, 22 | mut materials: ResMut>, 23 | ) { 24 | let mut ortho_cam = OrthographicCameraBundle::new_3d(); 25 | ortho_cam.transform = Transform::from_matrix(Mat4::face_toward( 26 | Vec3::new(0.1, 0.1, 1.0), 27 | Vec3::ZERO, 28 | Vec3::Y, 29 | )); 30 | commands.spawn_bundle(ortho_cam); 31 | // AABB 32 | commands 33 | .spawn_bundle(PbrBundle { 34 | mesh: meshes.add(Mesh::from(shape::Cube::default())), 35 | material: materials.add(Color::rgb(1.0, 1.0, 1.0).into()), 36 | transform: Transform::from_translation(Vec3::new(-1.0, 0.0, 0.0)), 37 | ..Default::default() 38 | }) 39 | .insert(Bounded::::default()) 40 | .insert(debug::DebugBounds) 41 | .insert(Rotator); 42 | // OBB 43 | commands 44 | .spawn_bundle(PbrBundle { 45 | mesh: meshes.add(Mesh::from(shape::Cube::default())), 46 | material: materials.add(Color::rgb(1.0, 1.0, 1.0).into()), 47 | transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)), 48 | ..Default::default() 49 | }) 50 | .insert(Bounded::::default()) 51 | .insert(debug::DebugBounds) 52 | .insert(Rotator); 53 | // Sphere 54 | commands 55 | .spawn_bundle(PbrBundle { 56 | mesh: meshes.add(Mesh::from(shape::Cube::default())), 57 | material: materials.add(Color::rgb(1.0, 1.0, 1.0).into()), 58 | transform: Transform::from_translation(Vec3::new(1.0, 0.0, 0.0)), 59 | ..Default::default() 60 | }) 61 | .insert(Bounded::::default()) 62 | .insert(debug::DebugBounds) 63 | .insert(Rotator); 64 | // Light 65 | commands.spawn_bundle(PointLightBundle { 66 | transform: Transform::from_translation(Vec3::new(4.0, 8.0, 4.0)), 67 | ..Default::default() 68 | }); 69 | } 70 | 71 | /// Rotate the meshes to demonstrate how the bounding volumes update 72 | fn rotation_system(time: Res