Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add collider-from-mesh feature and make bevy_render optional #55

Merged
merged 2 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain stable
- name: Run cargo test
run: cargo test --no-default-features --features enhanced-determinism,bevy_xpbd_2d/2d,bevy_xpbd_3d/3d,bevy_xpbd_2d/f64,bevy_xpbd_3d/f64
run: cargo test --no-default-features --features enhanced-determinism,collider-from-mesh,bevy_xpbd_2d/2d,bevy_xpbd_3d/3d,bevy_xpbd_2d/f64,bevy_xpbd_3d/f64

lints:
name: Lints
Expand Down
5 changes: 3 additions & 2 deletions crates/bevy_xpbd_2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ keywords = [ "gamedev", "physics", "simulation", "xpbd", "bevy" ]
categories = [ "game-development", "science", "simulation" ]

[features]
default = [ "2d", "f32" ]
default = [ "2d", "f32", "collider-from-mesh" ]
2d = []
f32 = [ "dep:parry2d" ]
f64 = [ "dep:parry2d-f64" ]
debug-plugin = [ "dep:bevy_prototype_debug_lines", "examples_common_2d/debug-plugin" ]
simd = [ "parry2d?/simd-stable", "parry2d-f64?/simd-stable" ]
enhanced-determinism = [ "parry2d?/enhanced-determinism", "parry2d-f64?/enhanced-determinism" ]
collider-from-mesh = [ "bevy/bevy_render" ]

[lib]
name = "bevy_xpbd_2d"
Expand All @@ -27,7 +28,7 @@ required-features = [ "2d" ]

[dependencies]
bevy_xpbd_derive = { path = "../bevy_xpbd_derive", version = "0.1" }
bevy = { version = "0.10.1", default-features = false, features = [ "bevy_render" ] }
bevy = { version = "0.10.1", default-features = false }
bevy_prototype_debug_lines = { version = "0.10.1", optional = true }
parry2d = { version = "0.13.1", optional = true }
parry2d-f64 = { version = "0.13.1", optional = true }
Expand Down
5 changes: 3 additions & 2 deletions crates/bevy_xpbd_3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ keywords = [ "gamedev", "physics", "simulation", "xpbd", "bevy" ]
categories = [ "game-development", "science", "simulation" ]

[features]
default = [ "3d", "f32" ]
default = [ "3d", "f32", "collider-from-mesh" ]
3d = []
f32 = [ "dep:parry3d" ]
f64 = [ "dep:parry3d-f64" ]
debug-plugin = [ "dep:bevy_prototype_debug_lines", "examples_common_3d/debug-plugin" ]
simd = [ "parry3d?/simd-stable", "parry3d-f64?/simd-stable" ]
enhanced-determinism = [ "parry3d?/enhanced-determinism", "parry3d-f64?/enhanced-determinism" ]
collider-from-mesh = [ "bevy/bevy_render" ]

[lib]
name = "bevy_xpbd_3d"
Expand All @@ -27,7 +28,7 @@ required-features = [ "3d" ]

[dependencies]
bevy_xpbd_derive = { path = "../bevy_xpbd_derive", version = "0.1" }
bevy = { version = "0.10.1", default-features = false, features = [ "bevy_render" ] }
bevy = { version = "0.10.1", default-features = false }
bevy_prototype_debug_lines = { version = "0.10.1", optional = true, features = [ "3d" ] }
parry3d = { version = "0.13.1", optional = true }
parry3d-f64 = { version = "0.13.1", optional = true }
Expand Down
8 changes: 4 additions & 4 deletions src/components/collider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl Collider {
}

/// Creates a collider with a triangle mesh shape built from a given Bevy `Mesh`.
#[cfg(feature = "3d")]
#[cfg(all(feature = "3d", feature = "collider-from-mesh"))]
pub fn trimesh_from_bevy_mesh(mesh: &Mesh) -> Option<Self> {
use parry::shape::TriMeshFlags;

Expand All @@ -216,7 +216,7 @@ impl Collider {

/// Creates a collider with a compound shape obtained from the decomposition of a triangle mesh
/// built from a given Bevy `Mesh`.
#[cfg(feature = "3d")]
#[cfg(all(feature = "3d", feature = "collider-from-mesh"))]
pub fn convex_decomposition_from_bevy_mesh(mesh: &Mesh) -> Option<Self> {
let vertices_indices = extract_mesh_vertices_indices(mesh);
vertices_indices.map(|(v, i)| SharedShape::convex_decomposition(&v, &i).into())
Expand Down Expand Up @@ -291,10 +291,10 @@ impl Collider {
}
}

#[cfg(feature = "3d")]
#[cfg(all(feature = "3d", feature = "collider-from-mesh"))]
type VerticesIndices = (Vec<nalgebra::Point3<Scalar>>, Vec<[u32; 3]>);

#[cfg(feature = "3d")]
#[cfg(all(feature = "3d", feature = "collider-from-mesh"))]
fn extract_mesh_vertices_indices(mesh: &Mesh) -> Option<VerticesIndices> {
let vertices = mesh.attribute(Mesh::ATTRIBUTE_POSITION)?;
let indices = mesh.indices()?;
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@
//!
//! ### Feature flags
//!
//! Default features: `2d`/`3d`, `f32` and `collider-from-mesh`
//!
//! - `2d` enables simulation on the `x` and `y` axes. Enabled by default for `bevy_xpbd_2d`. Incompatible with `3d`.
//! - `3d` enables simulation on the `x`, `y` and `z` axes. Enabled by default for `bevy_xpbd_3d`. Incompatible with `2d`.
//! - `f32` enables using `f32` numbers. Incompatible with `f64`.
//! - `f64` enables using `f64` numbers. Recommended when encountering stability problems, especially with
//! small timesteps. Incompatible with `f32`.
//! - `debug-plugin` enables the `PhysicsDebugPlugin` used for rendering physics objects and events like [AABBs](ColliderAabb)
//! and [contacts](Contact).
//! - `collider-from-mesh` allows you to create [colliders](Collider) from Bevy meshes. Enables `bevy_render`.
//! - `simd` enables [SIMD](https://en.wikipedia.org/wiki/Single_instruction,_multiple_data) optimizations.
//! - `enhanced-determinism` enables increased determinism. (Note: cross-platform determinism doesn't work yet, even
//! with this feature enabled)
Expand Down
Loading