Skip to content

Commit

Permalink
Merge branch 'master' into example_bounding_sphere
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrixyz committed Sep 20, 2024
2 parents cfd62f4 + c385c9b commit abf04f3
Show file tree
Hide file tree
Showing 45 changed files with 386 additions and 252 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/parry-ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: parry CI build

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

env:
CARGO_TERM_COLOR: always
Expand All @@ -18,6 +18,8 @@ jobs:
run: cargo fmt -- --check
clippy:
runs-on: ubuntu-latest
env:
RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@v4
- name: Clippy
Expand All @@ -40,7 +42,7 @@ jobs:
- name: Check serialization
run: cargo check --features bytemuck-serialize,serde-serialize,rkyv-serialize;
- name: Run tests
run: cargo test
run: cargo test --features wavefront
build-wasm:
runs-on: ubuntu-latest
env:
Expand Down Expand Up @@ -74,6 +76,16 @@ jobs:
- name: install stable Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
toolchain: stable
- name: cargo doc
run: cargo doc --workspace --features bytemuck-serialize,serde-serialize,rkyv-serialize,parallel --no-deps --document-private-items
check-benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install nightly Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
- name: check benchmarks
run: cargo +nightly check --benches
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,25 @@

## Unreleased

### Added

- Implement `::to_trimesh` in 2d for `Cuboid` and `Aabb`.
- Implement `Shape::feature_normal_at_point` for `TriMesh` to retrieve the normal of a face, when passing a `FeatureId::Face`.

### Modified

- Propagate error information while creating a mesh and using functions making use of it (See #262):
- `TriMesh::new`
- `TriMesh::intersection_with_aabb`
- `SharedShape::trimesh`
- `SharedShape::trimesh_with_flags`

## v0.17.1

### Modified

- Improve convergence of epa algorithm in degenerate configurations.
- Fix bug in the mesh/mesh intersection algorithm that didn’t properly take mesh transforms into account.

## v0.17.0

Expand Down
2 changes: 1 addition & 1 deletion crates/parry2d-f64/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "parry2d-f64"
version = "0.17.0"
version = "0.17.1"
authors = ["Sébastien Crozet <[email protected]>"]

description = "2 dimensional collision detection library in Rust. 64-bit precision version."
Expand Down
2 changes: 1 addition & 1 deletion crates/parry2d/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "parry2d"
version = "0.17.0"
version = "0.17.1"
authors = ["Sébastien Crozet <[email protected]>"]

description = "2 dimensional collision detection library in Rust."
Expand Down
4 changes: 2 additions & 2 deletions crates/parry2d/examples/aabb2d.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod common_macroquad;
mod common_macroquad2d;

extern crate nalgebra as na;

use common_macroquad::{draw_polyline, lissajous_2d, mquad_from_na, na_from_mquad};
use common_macroquad2d::{draw_polyline, lissajous_2d, mquad_from_na, na_from_mquad};
use macroquad::prelude::*;
use na::Isometry2;
use parry2d::bounding_volume::{Aabb, BoundingVolume};
Expand Down
5 changes: 2 additions & 3 deletions crates/parry2d/examples/bounding_sphere2d.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
mod common_macroquad;
mod common_macroquad2d;

extern crate nalgebra as na;

use common_macroquad::{draw_polyline, lissajous_2d, mquad_from_na, na_from_mquad};
use common_macroquad2d::{draw_polyline, lissajous_2d, mquad_from_na, na_from_mquad};
use macroquad::prelude::*;
use na::{Isometry2, Vector2};
use parry2d::bounding_volume::{Aabb, BoundingVolume};
use parry2d::shape::Ball;
use parry2d::shape::Cuboid;

const RENDER_SCALE: f32 = 30.0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#[allow(unused, dead_code)]
use std::f32::consts::{FRAC_PI_2, FRAC_PI_4, FRAC_PI_6};
use std::f32::consts::{FRAC_PI_2, FRAC_PI_4};

use macroquad::prelude::*;
use macroquad::{
Expand All @@ -11,21 +10,29 @@ use nalgebra::Point2;
use parry2d::math::Real;
use parry2d::shape::TriMesh;

/// As this file is used as a module from other examples,
/// rustc warns about dead code:
/// - `main()` is needed for this file to be included in examples
/// - For other functions, they may be "dead code" for an example, but not for others.
#[allow(dead_code)]
fn main() {
println!(
"This module contains helper functions to use macroquad,
isolated from the rest of the examples for the sake of simplicity."
);
}

#[allow(dead_code)]
pub fn mquad_from_na(a: Point2<Real>) -> Vec2 {
Vec2::new(a.x, a.y)
}

#[allow(dead_code)]
pub fn na_from_mquad(a: Vec2) -> Point2<Real> {
Point2::new(a.x, a.y)
}

#[allow(dead_code)]
pub fn draw_polyline(polygon: Vec<(Vec2, Vec2)>, color: Color) {
for i in 0..polygon.len() {
let a = polygon[i].0;
Expand All @@ -34,14 +41,18 @@ pub fn draw_polyline(polygon: Vec<(Vec2, Vec2)>, color: Color) {
}
}

#[allow(dead_code)]
pub fn easy_draw_text(text: &str) {
macroquad::text::draw_text(text, 10.0, 48.0 + 18.0, 30.0, WHITE);
}

#[allow(dead_code)]
pub fn lissajous_2d(t: f32) -> Vec2 {
// Some hardcoded parameters to have a pleasing lissajous trajectory.
lissajous_2d_with_params(t, 3.0, 2.0, FRAC_PI_2, FRAC_PI_4)
}

#[allow(dead_code)]
pub fn lissajous_2d_with_params(t: f32, a: f32, b: f32, delta_x: f32, delta_y: f32) -> Vec2 {
// Some hardcoded parameters to have a pleasing lissajous trajectory.

Expand All @@ -50,10 +61,12 @@ pub fn lissajous_2d_with_params(t: f32, a: f32, b: f32, delta_x: f32, delta_y: f
Vec2::new(x, y) * 0.75f32
}

#[allow(dead_code)]
pub fn draw_line_2d(a: Vec2, b: Vec2, color: Color) {
draw_line(a.x, a.y, b.x, b.y, 2f32, color);
}

#[allow(dead_code)]
pub fn draw_trimesh2(trimesh: &TriMesh, offset: Vec2) {
let vertices = trimesh.vertices();
for v in trimesh.indices() {
Expand All @@ -67,6 +80,7 @@ pub fn draw_trimesh2(trimesh: &TriMesh, offset: Vec2) {
}
}

#[allow(dead_code)]
pub fn draw_polygon(polygon: &[Point2<f32>], scale: f32, shift: Point2<f32>, color: Color) {
for i in 0..polygon.len() {
let a = polygon[i];
Expand All @@ -82,6 +96,7 @@ pub fn draw_polygon(polygon: &[Point2<f32>], scale: f32, shift: Point2<f32>, col
}
}

#[allow(dead_code)]
pub fn draw_point(point: Point2<f32>, scale: f32, shift: Point2<f32>, color: Color) {
let edge_len = 0.15;
draw_line(
Expand Down
7 changes: 3 additions & 4 deletions crates/parry2d/examples/convex_hull2d.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
mod common_macroquad;
mod common_macroquad2d;

use std::f32::consts::{FRAC_PI_2, FRAC_PI_4};

use common_macroquad::{draw_point, draw_polygon, lissajous_2d_with_params, na_from_mquad};
use common_macroquad2d::{draw_point, draw_polygon, lissajous_2d_with_params, na_from_mquad};
use macroquad::prelude::*;
use nalgebra::Point2;
use parry2d::transformation;
use std::f32::consts::{FRAC_PI_2, FRAC_PI_4};

const RENDER_SCALE: f32 = 30.0;

Expand Down
4 changes: 2 additions & 2 deletions crates/parry2d/examples/point_in_poly2d.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod common_macroquad;
mod common_macroquad2d;

use common_macroquad::{draw_point, draw_polygon};
use common_macroquad2d::{draw_point, draw_polygon};
use macroquad::prelude::*;
use nalgebra::{Point2, UnitComplex, Vector2};
use parry2d::utils::point_in_poly2d;
Expand Down
4 changes: 2 additions & 2 deletions crates/parry2d/examples/polygons_intersection2d.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod common_macroquad;
mod common_macroquad2d;

use common_macroquad::draw_polygon;
use common_macroquad2d::draw_polygon;
use macroquad::prelude::*;
use nalgebra::{Point2, UnitComplex, Vector2};
use parry2d::shape::Ball;
Expand Down
6 changes: 3 additions & 3 deletions crates/parry2d/examples/project_point2d.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod common_macroquad;
mod common_macroquad2d;

use common_macroquad::{draw_line_2d, draw_trimesh2, lissajous_2d, mquad_from_na, na_from_mquad};
use common_macroquad2d::{draw_line_2d, draw_trimesh2, lissajous_2d, mquad_from_na, na_from_mquad};
use macroquad::prelude::*;
use nalgebra::{Point3, UnitComplex, Vector2};
use parry2d::math::{Isometry, Translation};
Expand All @@ -22,7 +22,7 @@ async fn main() {
let scale = 200f32;
let (points, indices) = Cuboid::new(Vector2::new(0.2 * scale, 0.5 * scale)).to_trimesh();

let trimesh = TriMesh::with_flags(points, indices, TriMeshFlags::ORIENTED);
let trimesh = TriMesh::with_flags(points, indices, TriMeshFlags::ORIENTED).unwrap();
for _i in 1.. {
clear_background(BLACK);

Expand Down
4 changes: 2 additions & 2 deletions crates/parry2d/examples/raycasts_animated.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod common_macroquad;
mod common_macroquad2d;

use common_macroquad::draw_point;
use common_macroquad2d::draw_point;
use macroquad::prelude::*;
use nalgebra::{Isometry2, Point2, UnitComplex, Vector2};
use parry2d::math::Isometry;
Expand Down
4 changes: 2 additions & 2 deletions crates/parry2d/tests/query/point_composite_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn project_local_point_and_get_feature_gets_the_enclosing_triangle() {
Point2::new(1.0, 1.0),
];

let mesh = TriMesh::new(vertices, vec![[0, 1, 2], [3, 0, 2]]);
let mesh = TriMesh::new(vertices, vec![[0, 1, 2], [3, 0, 2]]).unwrap();
let query_pt = Point2::new(0.6, 0.6); // Inside the top-right triangle (index 1)

let (proj, feat) = mesh.project_local_point_and_get_feature(&query_pt);
Expand All @@ -34,7 +34,7 @@ fn project_local_point_and_get_feature_projects_correctly_from_outside() {
Point2::new(1.0, 1.0),
];

let mesh = TriMesh::new(vertices, vec![[0, 1, 2], [3, 0, 2]]);
let mesh = TriMesh::new(vertices, vec![[0, 1, 2], [3, 0, 2]]).unwrap();

{
let query_pt = Point2::new(-1.0, 0.0); // Left from the bottom-left triangle (index 0)
Expand Down
7 changes: 6 additions & 1 deletion crates/parry3d-f64/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "parry3d-f64"
version = "0.17.0"
version = "0.17.1"
authors = ["Sébastien Crozet <[email protected]>"]

description = "3 dimensional collision detection library in Rust. 64-bits precision version."
Expand Down Expand Up @@ -44,6 +44,7 @@ simd-stable = ["simba/wide", "simd-is-enabled"]
simd-nightly = ["simba/portable_simd", "simd-is-enabled"]
enhanced-determinism = ["simba/libm_force", "indexmap"]
parallel = ["rayon"]
# Adds `TriMesh:to_obj_file` function.
wavefront = ["obj"]
alloc = []
improved_fixed_point_support = []
Expand Down Expand Up @@ -88,3 +89,7 @@ thiserror = { version = "1", optional = true }
oorandom = "11"
ptree = "0.4.0"
rand = { version = "0.8" }

[package.metadata.docs.rs]
rustdoc-args = ["-Zunstable-options", "--generate-link-to-definition"]
features = ["wavefront"]
6 changes: 5 additions & 1 deletion crates/parry3d/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "parry3d"
version = "0.17.0"
version = "0.17.1"
authors = ["Sébastien Crozet <[email protected]>"]

description = "3 dimensional collision detection library in Rust."
Expand Down Expand Up @@ -45,6 +45,7 @@ simd-stable = ["simba/wide", "simd-is-enabled"]
simd-nightly = ["simba/portable_simd", "simd-is-enabled"]
enhanced-determinism = ["simba/libm_force", "indexmap"]
parallel = ["rayon"]
# Adds `TriMesh:to_obj_file` function.
wavefront = ["obj"]
alloc = []
improved_fixed_point_support = []
Expand Down Expand Up @@ -89,10 +90,13 @@ oorandom = "11"
ptree = "0.4.0"
rand = { version = "0.8" }
macroquad = "0.4.12"
nalgebra = { version = "0.33", default-features = false, features = ["rand"] }
rand_isaac = "0.3"

[package.metadata.docs.rs]
rustdoc-args = ["-Zunstable-options", "--generate-link-to-definition"]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
features = ["wavefront"]

# The following listing is to allow for examples to be scraped,
# see https://doc.rust-lang.org/rustdoc/scraped-examples.html#scraped-examples for details.
Expand Down
6 changes: 3 additions & 3 deletions crates/parry3d/benches/bounding_volume/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use na::Isometry3;
use parry3d::bounding_volume::BoundingVolume;
use parry3d::bounding_volume::{Aabb, BoundingSphere};
use parry3d::shape::{
Ball, Capsule, Cone, ConvexHull, Cuboid, Cylinder, Segment, TriMesh, Triangle,
Ball, Capsule, Cone, ConvexPolyhedron, Cuboid, Cylinder, Segment, TriMesh, Triangle,
};
use rand::SeedableRng;
use rand_isaac::IsaacRng;
Expand Down Expand Up @@ -135,13 +135,13 @@ bench_method!(
bench_method!(
bench_convex_aabb,
aabb: Aabb,
c: ConvexHull,
c: ConvexPolyhedron,
m: Isometry3<f32>
);
bench_method!(
bench_convex_bounding_sphere,
bounding_sphere: BoundingSphere,
c: ConvexHull,
c: ConvexPolyhedron,
m: Isometry3<f32>
);

Expand Down
Loading

0 comments on commit abf04f3

Please sign in to comment.