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

Fix wavefront tests + new test for different pos + add them in ci #268

Merged
merged 7 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 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 Down Expand Up @@ -40,7 +40,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 +74,6 @@ 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
48 changes: 37 additions & 11 deletions src/transformation/mesh_intersection/mesh_intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use crate::query::{visitors::BoundingVolumeIntersectionsSimultaneousVisitor, Poi
use crate::shape::{TriMesh, Triangle};
use crate::utils;
use na::{Point3, Vector3};
#[cfg(feature = "wavefront")]
use obj::{Group, IndexTuple, ObjData, Object, SimplePolygon};
use rstar::RTree;
use spade::{ConstrainedDelaunayTriangulation, InsertionError, Triangulation as _};
use std::collections::BTreeMap;
Expand Down Expand Up @@ -668,9 +666,10 @@ fn merge_triangle_sets(
#[cfg(test)]
mod tests {
use super::*;
use crate::shape::TriMeshFlags;
use crate::transformation::wavefront::*;
use crate::bounding_volume::{bounding_sphere, BoundingSphere};
use crate::shape::{Ball, Cuboid, TriMeshFlags};
use obj::Obj;
use obj::ObjData;

#[test]
fn test_same_mesh_intersection() {
Expand All @@ -684,7 +683,7 @@ mod tests {
let mesh = TriMesh::with_flags(
position
.iter()
.map(|v| Point3::new(v[0] as f64, v[1] as f64, v[2] as f64))
.map(|v| Point3::new(v[0] as Real, v[1] as Real, v[2] as Real))
.collect::<Vec<_>>(),
objects[0].groups[0]
.polys
Expand All @@ -708,6 +707,33 @@ mod tests {
mesh.to_obj_file(&PathBuf::from("same_test.obj"));
}

#[test]
fn test_non_origin_pos1_pos2_intersection() {
let ball = Ball::new(2f32 as Real).to_trimesh(10, 10);
let cuboid = Cuboid::new(Vector3::new(2.0, 1.0, 1.0)).to_trimesh();
let mut sphere_mesh = TriMesh::new(ball.0, ball.1);
sphere_mesh.set_flags(TriMeshFlags::all()).unwrap();
let mut cuboid_mesh = TriMesh::new(cuboid.0, cuboid.1);
cuboid_mesh.set_flags(TriMeshFlags::all()).unwrap();

let res = intersect_meshes(
&Isometry::translation(1.0, 0.0, 0.0),
&cuboid_mesh,
false,
&Isometry::translation(2.0, 0.0, 0.0),
&sphere_mesh, //.clone().scaled(&Vector3::new(1.001, 1.001, 1.001)),
Copy link
Contributor Author

@Vrixyz Vrixyz Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That comment will have to be removed, but I added that because setting both positions to 200;0;0 resulted in a lot of holes in the resulting intersection. I can imagine this is floating point imprecision but it was surprising.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I think it’s worth opening an issue with the example that generates holes.

Copy link
Contributor Author

@Vrixyz Vrixyz Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #270 ; it can even be reproduced in a position of 2;0;0

false,
)
.unwrap()
.unwrap();

let _ = res.to_obj_file(&PathBuf::from("test_non_origin_pos1_pos2_intersection.obj"));

let bounding_sphere = res.local_bounding_sphere();
assert!(bounding_sphere.center == Point3::new(1.5, 0.0, 0.0));
assert_relative_eq!(2.0615528, bounding_sphere.radius, epsilon = 1.0e-5);
}

#[test]
fn test_offset_cylinder_intersection() {
let Obj {
Expand All @@ -720,7 +746,7 @@ mod tests {
let offset_mesh = TriMesh::with_flags(
position
.iter()
.map(|v| Point3::new(v[0] as f64, v[1] as f64, v[2] as f64))
.map(|v| Point3::new(v[0] as Real, v[1] as Real, v[2] as Real))
.collect::<Vec<_>>(),
objects[0].groups[0]
.polys
Expand All @@ -740,7 +766,7 @@ mod tests {
let center_mesh = TriMesh::with_flags(
position
.iter()
.map(|v| Point3::new(v[0] as f64, v[1] as f64, v[2] as f64))
.map(|v| Point3::new(v[0] as Real, v[1] as Real, v[2] as Real))
.collect::<Vec<_>>(),
objects[0].groups[0]
.polys
Expand Down Expand Up @@ -776,7 +802,7 @@ mod tests {
let stair_mesh = TriMesh::with_flags(
position
.iter()
.map(|v| Point3::new(v[0] as f64, v[1] as f64, v[2] as f64))
.map(|v| Point3::new(v[0] as Real, v[1] as Real, v[2] as Real))
.collect::<Vec<_>>(),
objects[0].groups[0]
.polys
Expand All @@ -796,7 +822,7 @@ mod tests {
let bar_mesh = TriMesh::with_flags(
position
.iter()
.map(|v| Point3::new(v[0] as f64, v[1] as f64, v[2] as f64))
.map(|v| Point3::new(v[0] as Real, v[1] as Real, v[2] as Real))
.collect::<Vec<_>>(),
objects[0].groups[0]
.polys
Expand Down Expand Up @@ -832,7 +858,7 @@ mod tests {
let bunny_mesh = TriMesh::with_flags(
position
.iter()
.map(|v| Point3::new(v[0] as f64, v[1] as f64, v[2] as f64))
.map(|v| Point3::new(v[0] as Real, v[1] as Real, v[2] as Real))
.collect::<Vec<_>>(),
objects[0].groups[0]
.polys
Expand All @@ -852,7 +878,7 @@ mod tests {
let cylinder_mesh = TriMesh::with_flags(
position
.iter()
.map(|v| Point3::new(v[0] as f64, v[1] as f64, v[2] as f64))
.map(|v| Point3::new(v[0] as Real, v[1] as Real, v[2] as Real))
.collect::<Vec<_>>(),
objects[0].groups[0]
.polys
Expand Down
Loading