From 6e1769c30ecb5b568d49c9310ac6b59bb408722d Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Thu, 12 Sep 2024 10:12:34 +0200 Subject: [PATCH 1/4] fix wavefront tests + new test for different pos + add them in ci --- .github/workflows/parry-ci-build.yml | 8 ++-- .../mesh_intersection/mesh_intersection.rs | 48 ++++++++++++++----- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/.github/workflows/parry-ci-build.yml b/.github/workflows/parry-ci-build.yml index ecf8470a..9de91ddc 100644 --- a/.github/workflows/parry-ci-build.yml +++ b/.github/workflows/parry-ci-build.yml @@ -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 @@ -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: @@ -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 diff --git a/src/transformation/mesh_intersection/mesh_intersection.rs b/src/transformation/mesh_intersection/mesh_intersection.rs index ae016f0b..5cf1b1ac 100644 --- a/src/transformation/mesh_intersection/mesh_intersection.rs +++ b/src/transformation/mesh_intersection/mesh_intersection.rs @@ -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; @@ -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() { @@ -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::>(), objects[0].groups[0] .polys @@ -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)), + 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 { @@ -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::>(), objects[0].groups[0] .polys @@ -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::>(), objects[0].groups[0] .polys @@ -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::>(), objects[0].groups[0] .polys @@ -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::>(), objects[0].groups[0] .polys @@ -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::>(), objects[0].groups[0] .polys @@ -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::>(), objects[0].groups[0] .polys From c4040d8f0cea16cf1155f8f6250eee291881f40f Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Fri, 13 Sep 2024 14:58:43 +0200 Subject: [PATCH 2/4] removed comment about bug investigation --- src/transformation/mesh_intersection/mesh_intersection.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transformation/mesh_intersection/mesh_intersection.rs b/src/transformation/mesh_intersection/mesh_intersection.rs index 5cf1b1ac..a09138d3 100644 --- a/src/transformation/mesh_intersection/mesh_intersection.rs +++ b/src/transformation/mesh_intersection/mesh_intersection.rs @@ -721,7 +721,7 @@ mod tests { &cuboid_mesh, false, &Isometry::translation(2.0, 0.0, 0.0), - &sphere_mesh, //.clone().scaled(&Vector3::new(1.001, 1.001, 1.001)), + &sphere_mesh, false, ) .unwrap() From 3971d15b99ceada6382cc55c71954c95a57bb594 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Fri, 13 Sep 2024 14:58:01 +0200 Subject: [PATCH 3/4] add failing test for intersection with a similar mesh: missing triangles are observed --- .../mesh_intersection/mesh_intersection.rs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/transformation/mesh_intersection/mesh_intersection.rs b/src/transformation/mesh_intersection/mesh_intersection.rs index a09138d3..9d104d7d 100644 --- a/src/transformation/mesh_intersection/mesh_intersection.rs +++ b/src/transformation/mesh_intersection/mesh_intersection.rs @@ -707,6 +707,51 @@ mod tests { mesh.to_obj_file(&PathBuf::from("same_test.obj")); } + #[test] + fn test_same_mesh_same_position_far_from_origin() { + let Obj { + data: ObjData { + position, objects, .. + }, + .. + } = Obj::load("../../assets/tests/low_poly_bunny.obj").unwrap(); + + let mesh = TriMesh::with_flags( + position + .iter() + .map(|v| Point3::new(v[0] as Real, v[1] as Real, v[2] as Real)) + .collect::>(), + objects[0].groups[0] + .polys + .iter() + .map(|p| [p.0[0].0 as u32, p.0[1].0 as u32, p.0[2].0 as u32]) + .collect::>(), + TriMeshFlags::all(), + ); + + let res = intersect_meshes( + &Isometry::translation(2.0, 0.0, 0.0), + &mesh, + false, + &Isometry::translation(2.0, 0.0, 0.0), + &mesh, // To Fix: + // .clone().scaled(&Vector3::new(1.001, 1.001, 1.001)) + false, + ) + .unwrap() + .unwrap(); + + let _ = res.to_obj_file(&PathBuf::from( + "test_same_mesh_same_position_far_from_origin.obj", + )); + + // Not sure how to test, maybe amount of triangles ? verify the mesh is manifold? + assert!( + false, + "This test is failing, for now needs manual verification." + ) + } + #[test] fn test_non_origin_pos1_pos2_intersection() { let ball = Ball::new(2f32 as Real).to_trimesh(10, 10); From f9c0145ee9ad19eafff5e0a53c1217c2d8a34d6c Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Mon, 16 Sep 2024 15:43:07 +0200 Subject: [PATCH 4/4] test for manifold mesh --- ...ame_mesh_same_position_far_from_origin.obj | 990 ++++++++++++++++++ .../mesh_intersection/mesh_intersection.rs | 33 +- 2 files changed, 1017 insertions(+), 6 deletions(-) create mode 100644 crates/parry3d/test_same_mesh_same_position_far_from_origin.obj diff --git a/crates/parry3d/test_same_mesh_same_position_far_from_origin.obj b/crates/parry3d/test_same_mesh_same_position_far_from_origin.obj new file mode 100644 index 00000000..76792b66 --- /dev/null +++ b/crates/parry3d/test_same_mesh_same_position_far_from_origin.obj @@ -0,0 +1,990 @@ +# Generated by the obj Rust library (https://crates.io/crates/obj). +v 2.940102 0.470482 0.314923 +v 3.1417189 0.423271 0.086702 +v 2.937182 0.42821 0.078141 +v 0.28306496 1.490338 -0.07495 +v 0.61845195 1.578558 -0.185131 +v 0.523167 1.282447 -0.142186 +v 0.746241 -0.300415 0.896741 +v 0.74345005 -0.077663 0.741935 +v 0.654863 -0.29497 0.613325 +v 1.0441461 1.14383 -0.392172 +v 1.0339761 1.413036 -0.267413 +v 1.18927 1.496291 -0.188235 +v 0.54135096 2.333704 -0.87345 +v 0.45192504 2.587439 -1.020768 +v 0.658324 2.560165 -1.199939 +v 2.406291 -0.293454 -0.046927 +v 2.6372929 -0.006644 -0.160961 +v 2.742359 -0.206825 -0.021296 +v 2.42826 0.093019 -0.543882 +v 2.550221 -0.014567 -0.376243 +v 2.434215 -0.085258 -0.413636 +v 0.74967396 0.443967 -0.331626 +v 0.45626605 0.457225 -0.109284 +v 0.52054 0.663107 -0.305621 +v 0.175313 1.996111 0.277494 +v 0.19388998 1.916116 0.569366 +v 0.31122005 2.021224 0.632541 +v 0.95989394 -0.320691 0.505978 +v 1.08042 -0.328048 0.107806 +v 1.281252 -0.317132 0.206641 +v 0.47522402 2.305617 -0.417891 +v 0.46167696 2.078191 -0.001137 +v 0.60133004 2.112914 0.038787 +v 0.69155896 2.218786 -1.174929 +v 0.789191 2.417327 -1.24196 +v 1.492051 -0.241648 0.236043 +v 1.3553641 -0.326972 0.400391 +v 1.669186 0.231838 1.053564 +v 1.56038 0.025928 0.886406 +v 1.749822 -0.046735 0.968372 +v 0.13451695 1.396082 0.595172 +v 0.26888704 1.183966 0.317156 +v 0.367069 1.191555 0.573243 +v 0.324023 1.201319 0.040754 +v 0.13441002 1.292859 0.256558 +v 0.95300996 -0.019141 0.507989 +v 1.008386 0.085067 0.318619 +v 0.988132 -0.07233 0.344236 +v 0.436566 2.122153 0.411995 +v 0.77511 2.104145 0.070637 +v 1.7885439 -0.217407 0.75192 +v 2.137022 -0.214321 0.616751 +v 2.154657 -0.313672 0.815652 +v 0.87757194 -0.058767 -0.095476 +v 0.657048 -0.223018 -0.128304 +v 0.62540495 -0.094946 0.107979 +v 2.4933891 0.901867 0.927212 +v 2.39881 0.591481 1.038245 +v 2.601453 0.574139 0.888465 +v 3.017473 0.20248 -0.094421 +v 1.258885 2.246469 -0.276917 +v 0.959916 1.855343 0.020213 +v 0.915208 2.018689 -0.051406 +v 0.57463 1.2348 0.977332 +v 0.49976504 1.146758 0.718896 +v 0.68258595 1.21181 0.747668 +v 1.3024111 0.903487 0.895772 +v 1.243098 0.64474 0.876448 +v 1.37104 0.667973 0.841685 +v 0.33644998 0.63551 0.589829 +v 0.20509303 0.805548 0.393436 +v 0.26123405 0.651866 0.192682 +v 1.5052791 0.660059 1.094944 +v 1.4889619 0.890224 0.898911 +v 0.71914995 -0.163914 0.539172 +v 0.81211996 -0.206945 0.398413 +v 0.75064695 -0.313633 0.394476 +v 0.89687395 2.070624 0.559535 +v 1.017719 1.879877 0.151544 +v 0.97948694 2.030979 0.251655 +v 0.908329 0.94365 -0.446658 +v 0.72243094 0.93786 -0.357568 +v 1.434154 2.088861 -0.077108 +v 3.131363 0.447779 0.402172 +v 3.234315 0.254007 0.176538 +v 0.71449196 0.245704 -0.05583 +v 0.49390304 0.355873 0.058008 +v 1.045418 1.133881 0.803952 +v 0.86166704 1.017194 0.857497 +v 1.021697 0.925187 0.884035 +v 1.797286 -0.310556 0.887632 +v 2.053858 -0.319867 0.086221 +v 2.127122 -0.21412 -0.225272 +v 2.231792 -0.311216 -0.263775 +v 1.130738 0.824713 -0.444856 +v 1.279177 0.576003 -0.404734 +v 1.0693331 0.534924 -0.369422 +v 0.919371 1.779159 0.582179 +v 0.81978905 0.61293 -0.416339 +v 0.45172703 1.898256 0.895887 +v 0.729182 2.026028 0.739459 +v 0.56118405 2.126505 0.550931 +v 2.771131 0.726767 -0.311357 +v 2.814158 0.980996 -0.083952 +v 2.91986 0.806306 0.05763 +v 0.757324 1.743577 0.713482 +v 0.80687 1.964145 0.734747 +v 0.23582602 1.241225 0.871106 +v 0.39268696 1.392937 1.003375 +v 1.573506 2.265286 -0.326361 +v 1.698658 2.214073 -0.248339 +v 1.905366 -0.230486 0.200918 +v 0.874341 0.244187 -0.12844 +v 0.847726 0.15231 0.109967 +v 0.571584 1.826239 -0.158769 +v 0.49850702 1.992898 -0.532615 +v 0.71195304 1.929522 -0.425011 +v 1.8262761 2.371577 -0.487548 +v 0.922632 0.171055 0.477747 +v 1.446885 0.26596 0.743723 +v 1.423813 0.086198 0.723778 +v 3.0871758 -0.001257 0.029786 +v 1.4570999 0.218017 -0.587722 +v 1.366005 0.530108 -0.640556 +v 1.541939 0.429134 -0.766367 +v 0.58065903 2.034858 -0.926695 +v 0.42637205 0.825916 0.736794 +v 0.58665097 0.920041 0.836655 +v 0.18306899 1.730446 0.332613 +v 0.22242999 1.746828 0.528811 +v 2.899016 0.612787 -0.015984 +v 2.777422 0.297245 -0.219951 +v 2.608082 0.484621 -0.418798 +v 3.099452 -0.069639 0.291576 +v 2.68117 -0.289601 0.228171 +v 0.857363 1.746613 -0.105149 +v 0.73295 1.841575 -0.136076 +v 1.130197 -0.04161 -0.212523 +v 1.034112 -0.328775 -0.264877 +v 0.81640804 -0.331282 -0.208945 +v 0.40363896 2.397274 -0.800259 +v 1.299546 0.446739 0.836718 +v 2.437403 -0.303291 0.447249 +v 2.504131 -0.154731 0.757366 +v 2.358495 -0.274806 0.859045 +v 0.69341004 2.631176 -1.173387 +v 1.288321 1.104614 -0.412796 +v 0.513126 2.096864 -0.439157 +v 0.43538797 2.166453 -0.413847 +v 1.2478831 1.41669 0.597296 +v 1.03223 1.370468 0.610515 +v 1.134162 0.052745 0.790804 +v 1.0912011 0.42979 0.834956 +v 1.736265 0.858539 1.123588 +v 1.638526 0.918233 1.043957 +v 1.301085 -0.324743 -0.62112 +v 1.094212 -0.262625 -0.475934 +v 0.73453104 2.162605 -0.889537 +v 0.65466905 2.044793 -0.961809 +v 1.547917 0.862621 -0.687707 +v 1.332665 0.7304 -0.503039 +v 1.459799 0.908352 -0.491425 +v 1.463701 1.112677 -0.457167 +v 1.589089 1.302278 -0.331441 +v 1.681294 1.189421 -0.413767 +v 1.0246091 1.573702 -0.067315 +v 0.78926694 1.437931 0.859106 +v 0.553372 -0.324673 -0.014624 +v 0.535879 -0.279284 0.155621 +v 0.74582005 2.352787 -0.934974 +v 0.66032195 2.460943 -0.891817 +v 0.95079696 0.010663 -0.139785 +v 1.289742 -0.305473 0.775053 +v 1.391722 -0.226524 0.718841 +v 1.220679 -0.300516 0.85812 +v 2.248308 0.323535 1.074198 +v 2.165365 0.56168 1.120613 +v 2.004969 0.372179 1.129627 +v 2.643705 1.365763 0.110519 +v 2.440645 1.512562 0.443111 +v 2.614266 1.331982 0.573045 +v 0.18892002 1.649729 0.105226 +v 0.29692805 1.876421 0.128359 +v 0.38806903 1.76143 -0.064956 +v 2.968271 0.21125 0.628987 +v 2.704164 0.029651 0.639615 +v 2.845702 -0.038298 0.654686 +v 1.816983 2.542578 -0.614849 +v 1.524598 2.527752 -0.41869 +v 1.309266 -0.322259 -0.419404 +v 1.884866 -0.319651 -0.47837 +v 1.794947 -0.314581 -0.368238 +v 2.342511 0.329771 -0.591951 +v 2.097765 0.096534 -0.616585 +v 1.977557 0.245175 -0.693814 +v 1.348683 1.29751 -0.323072 +v 1.483913 -0.228438 1.105902 +v 1.327014 -0.155706 0.98604 +v 0.98848295 0.021087 0.698274 +v 0.88679004 -0.108873 0.906066 +v 2.888214 -0.015508 -0.118325 +v 2.7322779 0.083778 -0.132954 +v 0.38257504 1.577763 1.071003 +v 0.23471403 1.762439 0.83031 +v 0.40683103 0.428926 0.368551 +v 0.35447395 0.502254 0.046539 +v 1.088002 0.294079 -0.290498 +v 1.331042 0.184383 -0.231929 +v 0.52729 2.505241 -0.83704 +v 2.711103 0.237502 0.7682 +v 2.534702 0.396707 0.864832 +v 1.642717 0.635818 1.149879 +v 0.47184205 0.911803 -0.264668 +v 0.83785295 1.151608 -0.375568 +v 0.836267 -0.016451 0.133963 +v 2.844152 1.087791 0.12664 +v 2.746305 1.060499 0.609414 +v 0.77167404 1.399494 -0.187916 +v 1.775802 2.292585 -0.273762 +v 3.1618319 0.10097 0.462145 +v 2.986357 -0.077431 0.492021 +v 1.342783 -0.149747 -0.604688 +v 1.529004 2.196668 -0.034051 +v 2.405405 0.312149 0.968318 +v 0.13503397 1.422518 0.849826 +v 0.322461 0.679915 -0.076252 +v 0.302773 0.824448 -0.077251 +v 0.30832696 0.992154 -0.063988 +v 1.529879 -0.037386 1.032238 +v 0.209517 0.963998 0.196709 +v 2.8635569 0.332947 0.540158 +v 1.999292 -0.277414 0.938915 +v 1.4559419 1.502474 0.347908 +v 1.123702 1.513891 0.426197 +v 0.27498806 1.54207 0.984246 +v 0.594172 0.224329 0.285109 +v 2.018526 0.028101 1.082396 +v 1.90413 0.157725 1.102226 +v 0.52098 0.435043 0.653007 +v 0.78942394 0.307507 0.664774 +v 0.80053306 0.496492 0.838375 +v 2.201754 0.746022 1.119187 +v 2.3423991 0.9068 0.957341 +v 2.155755 0.982028 0.982627 +v 0.09421098 1.514014 0.420251 +v 2.484914 -0.29972 0.238641 +v 2.338816 -0.307084 0.047956 +v 0.45667005 2.001675 -0.088456 +v 2.570428 0.829597 -0.420398 +v 2.307308 0.555817 -0.592592 +v 2.207536 0.828623 -0.626683 +v 2.250226 1.215063 0.788707 +v 1.972192 1.027334 0.88364 +v 2.019799 0.960872 1.059991 +v 1.8759 0.698862 1.151555 +v 0.628363 2.358822 -0.455232 +v 0.776026 2.175265 -0.454547 +v 0.27287197 0.608488 0.348094 +v 1.2453201 -0.231501 -0.193115 +v 1.457178 -0.227411 -0.359371 +v 0.70726204 2.067869 -0.002609 +v 0.68126297 1.431845 1.040827 +v 0.50775397 1.359446 1.073136 +v 1.626698 -0.098943 -0.562156 +v 0.22039998 0.752411 0.135209 +v 1.929982 0.479193 1.187786 +v 0.827878 0.851391 0.91167 +v 0.63391805 0.643331 0.860208 +v 0.75900996 1.939813 -0.059667 +v 1.161723 0.70737 0.848427 +v 1.149823 2.437413 -0.172501 +v 0.875391 -0.228734 0.958223 +v 0.22216296 0.993397 0.440722 +v 1.756119 0.388424 1.100894 +v 1.654563 1.465395 -0.130014 +v 1.3480229 1.446782 -0.145062 +v 1.924722 -0.027518 -0.617613 +v 1.713872 0.227649 -0.731269 +v 1.873656 0.362811 -0.708438 +v 1.69755 1.004593 0.881693 +v 1.762642 1.595642 0.123569 +v 1.858646 1.596759 0.500398 +v 2.169619 1.644939 0.280768 +v 1.634864 -0.297437 1.042007 +v 1.22324 -0.116857 0.82687 +v 1.566194 2.714358 -0.250615 +v 1.329809 2.478831 -0.020642 +v 1.436173 -0.018832 -0.486544 +v 1.925387 -0.145208 -0.508665 +v 2.26849 -0.042224 -0.521637 +v 2.494691 1.230701 -0.257862 +v 2.08877 1.286703 -0.402328 +v 2.204146 1.421923 -0.272873 +v 1.443084 0.696451 -0.727762 +v 0.56023395 1.70351 1.007824 +v 1.918171 0.661604 -0.753178 +v 1.761838 0.501004 -0.767078 +v 1.384199 0.25537 -0.410325 +v 1.359084 0.032052 -0.209933 +v 2.430927 0.243353 -0.527954 +v 2.367 0.888857 -0.480172 +v 2.369606 1.022056 -0.451923 +v 1.216954 -0.082089 -0.454203 +v 2.474841 1.468868 -0.016535 +v 2.123443 1.610684 -0.00335 +v 1.68799 2.730358 -0.517358 +v 1.756972 2.514544 -0.440292 +v 1.223417 2.232682 0.011187 +v 1.586896 2.562906 -0.313807 +v 1.662872 0.710368 -0.791895 +v 1.199512 2.131342 0.11552 +v 2.176886 0.443417 -0.667591 +v 2.031319 -0.314576 0.340269 +v 2.211614 -0.304826 0.541249 +v 0.875 1.521824 0.796579 +v 1.02064 1.620475 0.59526 +v 2.49046 1.125336 0.795452 +v 1.426545 1.514294 0.097736 +v 2.886995 0.82998 0.47941 +v 2.708091 0.794717 0.800908 +v 0.98179495 0.710677 0.91994 +v 2.624036 -0.241836 0.499252 +v 0.99767697 0.279923 0.693748 +v 3.141912 0.273601 0.516107 +v 2.341084 1.428278 0.677115 +v 2.245401 1.587681 0.486845 +v 2.00517 0.251326 1.138458 +o +g +f 1 2 3 +f 4 5 6 +f 7 8 9 +f 10 11 12 +f 13 14 15 +f 16 17 18 +f 19 20 21 +f 22 23 24 +f 25 26 27 +f 28 29 30 +f 31 32 33 +f 34 15 35 +f 36 37 30 +f 38 39 40 +f 41 42 43 +f 4 44 45 +f 46 47 48 +f 49 50 33 +f 51 52 53 +f 54 55 56 +f 57 58 59 +f 60 3 2 +f 61 62 63 +f 64 65 66 +f 67 68 69 +f 70 71 72 +f 73 74 69 +f 75 76 77 +f 78 79 80 +f 7 9 77 +f 10 81 82 +f 83 79 62 +f 84 85 2 +f 86 87 23 +f 88 89 90 +f 53 91 51 +f 92 93 94 +f 95 96 97 +f 79 78 98 +f 82 99 24 +f 100 101 102 +f 103 104 105 +f 106 107 101 +f 108 64 109 +f 83 110 111 +f 93 92 112 +f 97 113 22 +f 114 86 113 +f 115 116 117 +f 118 111 110 +f 47 46 119 +f 39 120 121 +f 85 122 60 +f 123 124 125 +f 15 126 13 +f 65 127 128 +f 129 130 26 +f 131 132 133 +f 22 86 23 +f 134 135 18 +f 136 5 115 +f 115 137 136 +f 138 139 140 +f 14 13 141 +f 142 69 68 +f 77 9 75 +f 143 144 145 +f 97 22 99 +f 35 15 146 +f 147 81 10 +f 114 47 119 +f 141 148 149 +f 88 150 151 +f 152 142 153 +f 73 154 155 +f 156 139 157 +f 120 73 69 +f 34 158 159 +f 160 161 162 +f 117 126 159 +f 163 164 165 +f 166 12 11 +f 167 64 66 +f 99 82 81 +f 56 168 169 +f 170 35 146 +f 146 171 170 +f 114 172 54 +f 91 173 174 +f 7 28 175 +f 176 177 178 +f 179 180 181 +f 182 183 184 +f 185 186 187 +f 27 102 49 +f 188 110 189 +f 28 37 173 +f 190 191 192 +f 193 194 195 +f 46 76 75 +f 164 147 196 +f 175 197 198 +f 199 8 200 +f 60 201 202 +f 138 140 55 +f 203 100 204 +f 205 206 87 +f 108 41 43 +f 174 51 91 +f 113 97 207 +f 96 208 207 +f 56 55 168 +f 168 29 28 +f 31 209 141 +f 210 59 211 +f 38 212 73 +f 213 214 82 +f 215 76 48 +f 148 141 13 +f 28 173 175 +f 216 181 217 +f 218 166 11 +f 161 147 163 +f 118 219 111 +f 106 78 107 +f 220 221 134 +f 157 222 156 +f 111 223 83 +f 223 111 219 +f 148 13 126 +f 147 95 81 +f 58 176 224 +f 56 77 76 +f 108 43 65 +f 41 108 225 +f 213 226 227 +f 6 228 44 +f 40 39 229 +f 139 156 190 +f 44 230 42 +f 34 159 126 +f 231 84 1 +f 91 53 232 +f 233 234 150 +f 158 34 35 +f 235 225 108 +f 205 87 236 +f 16 18 135 +f 40 237 238 +f 29 139 190 +f 239 240 241 +f 242 243 244 +f 45 41 245 +f 26 25 129 +f 181 216 179 +f 14 146 15 +f 94 246 247 +f 248 183 25 +f 126 116 148 +f 249 250 251 +f 252 253 244 +f 36 51 174 +f 8 199 46 +f 254 154 255 +f 191 190 156 +f 22 113 86 +f 170 256 257 +f 46 75 8 +f 8 75 9 +f 70 72 258 +f 36 259 260 +f 33 50 261 +f 213 227 228 +f 262 263 64 +f 264 123 125 +f 192 94 93 +f 226 72 265 +f 41 204 130 +f 109 203 235 +f 108 109 235 +f 120 39 38 +f 177 255 266 +f 267 268 241 +f 4 184 115 +f 62 269 63 +f 183 182 129 +f 205 258 72 +f 248 148 116 +f 248 149 148 +f 73 155 74 +f 67 270 68 +f 63 271 61 +f 61 189 110 +f 227 265 230 +f 175 272 7 +f 94 192 191 +f 141 149 31 +f 273 70 127 +f 274 255 212 +f 275 196 276 +f 25 27 49 +f 93 260 192 +f 230 228 227 +f 277 278 279 +f 103 105 131 +f 74 155 280 +f 14 141 209 +f 15 34 126 +f 85 134 122 +f 116 115 248 +f 243 177 58 +f 138 207 208 +f 281 282 283 +f 173 91 284 +f 285 199 200 +f 230 44 228 +f 99 81 95 +f 286 271 287 +f 153 68 270 +f 32 25 49 +f 127 43 273 +f 152 120 142 +f 264 125 278 +f 184 4 182 +f 264 222 288 +f 289 194 290 +f 291 292 293 +f 271 63 50 +f 161 160 294 +f 137 117 257 +f 146 209 171 +f 143 246 135 +f 60 122 201 +f 106 295 262 +f 236 86 114 +f 60 2 85 +f 296 279 297 +f 108 65 64 +f 298 299 208 +f 194 193 300 +f 236 87 86 +f 230 273 42 +f 24 99 22 +f 239 258 205 +f 7 272 200 +f 230 71 273 +f 207 172 113 +f 138 54 172 +f 94 247 92 +f 249 301 302 +f 161 294 124 +f 207 97 96 +f 226 23 206 +f 72 226 206 +f 239 119 240 +f 73 120 38 +f 138 303 157 +f 18 17 201 +f 238 274 38 +f 82 24 213 +f 7 77 28 +f 304 293 305 +f 284 175 173 +f 131 133 103 +f 306 189 286 +f 286 307 306 +f 54 215 114 +f 158 257 117 +f 117 159 158 +f 214 213 6 +f 71 265 72 +f 288 298 123 +f 308 309 286 +f 10 12 196 +f 4 115 5 +f 298 96 124 +f 50 63 269 +f 226 213 24 +f 192 260 190 +f 257 158 170 +f 3 131 105 +f 119 236 114 +f 248 184 183 +f 310 294 160 +f 311 83 223 +f 279 312 193 +f 138 157 139 +f 129 25 183 +f 125 124 294 +f 313 314 52 +f 257 33 269 +f 315 151 316 +f 255 274 266 +f 317 217 181 +f 58 57 243 +f 146 14 209 +f 114 113 172 +f 128 267 89 +f 275 276 318 +f 216 217 319 +f 307 286 309 +f 210 319 320 +f 102 101 78 +f 241 321 267 +f 322 187 186 +f 41 45 42 +f 319 210 231 +f 77 169 168 +f 52 112 313 +f 198 285 175 +f 239 70 258 +f 161 163 162 +f 256 170 171 +f 199 323 119 +f 152 153 323 +f 278 125 297 +f 185 324 84 +f 248 31 149 +f 325 180 326 +f 114 48 47 +f 64 263 109 +f 323 199 152 +f 204 26 130 +f 268 267 128 +f 268 70 239 +f 239 205 236 +f 185 220 324 +f 85 84 324 +f 238 327 178 +f 31 248 32 +f 1 2 3 +f 4 5 6 +f 7 8 9 +f 10 11 12 +f 13 14 15 +f 16 17 18 +f 19 20 21 +f 22 23 24 +f 25 26 27 +f 28 29 30 +f 31 32 33 +f 34 15 35 +f 36 37 30 +f 38 39 40 +f 41 42 43 +f 4 44 45 +f 46 47 48 +f 49 50 33 +f 51 52 53 +f 54 55 56 +f 57 58 59 +f 60 3 2 +f 61 62 63 +f 64 65 66 +f 67 68 69 +f 70 71 72 +f 73 74 69 +f 75 76 77 +f 78 79 80 +f 7 9 77 +f 10 81 82 +f 83 79 62 +f 84 85 2 +f 86 87 23 +f 88 89 90 +f 53 91 51 +f 92 93 94 +f 95 96 97 +f 79 78 98 +f 82 99 24 +f 100 101 102 +f 103 104 105 +f 106 107 101 +f 108 64 109 +f 83 110 111 +f 93 92 112 +f 97 113 22 +f 114 86 113 +f 115 116 117 +f 118 111 110 +f 47 46 119 +f 39 120 121 +f 85 122 60 +f 123 124 125 +f 15 126 13 +f 65 127 128 +f 129 130 26 +f 131 132 133 +f 22 86 23 +f 134 135 18 +f 136 5 115 +f 115 137 136 +f 138 139 140 +f 14 13 141 +f 142 69 68 +f 77 9 75 +f 143 144 145 +f 97 22 99 +f 35 15 146 +f 147 81 10 +f 114 47 119 +f 141 148 149 +f 88 150 151 +f 152 142 153 +f 73 154 155 +f 156 139 157 +f 120 73 69 +f 34 158 159 +f 160 161 162 +f 117 126 159 +f 163 164 165 +f 166 12 11 +f 167 64 66 +f 99 82 81 +f 56 168 169 +f 170 35 146 +f 146 171 170 +f 114 172 54 +f 91 173 174 +f 7 28 175 +f 176 177 178 +f 179 180 181 +f 182 183 184 +f 185 186 187 +f 27 102 49 +f 188 110 189 +f 28 37 173 +f 190 191 192 +f 193 194 195 +f 46 76 75 +f 164 147 196 +f 175 197 198 +f 199 8 200 +f 60 201 202 +f 138 140 55 +f 203 100 204 +f 205 206 87 +f 108 41 43 +f 174 51 91 +f 113 97 207 +f 96 208 207 +f 56 55 168 +f 168 29 28 +f 31 209 141 +f 210 59 211 +f 38 212 73 +f 213 214 82 +f 215 76 48 +f 148 141 13 +f 28 173 175 +f 216 181 217 +f 218 166 11 +f 161 147 163 +f 118 219 111 +f 106 78 107 +f 220 221 134 +f 157 222 156 +f 111 223 83 +f 223 111 219 +f 148 13 126 +f 147 95 81 +f 58 176 224 +f 56 77 76 +f 108 43 65 +f 41 108 225 +f 213 226 227 +f 6 228 44 +f 40 39 229 +f 139 156 190 +f 44 230 42 +f 34 159 126 +f 231 84 1 +f 91 53 232 +f 233 234 150 +f 158 34 35 +f 235 225 108 +f 205 87 236 +f 16 18 135 +f 40 237 238 +f 29 139 190 +f 239 240 241 +f 242 243 244 +f 45 41 245 +f 26 25 129 +f 181 216 179 +f 14 146 15 +f 94 246 247 +f 248 183 25 +f 126 116 148 +f 249 250 251 +f 252 253 244 +f 36 51 174 +f 8 199 46 +f 254 154 255 +f 191 190 156 +f 22 113 86 +f 170 256 257 +f 46 75 8 +f 8 75 9 +f 70 72 258 +f 36 259 260 +f 33 50 261 +f 213 227 228 +f 262 263 64 +f 264 123 125 +f 192 94 93 +f 226 72 265 +f 41 204 130 +f 109 203 235 +f 108 109 235 +f 120 39 38 +f 177 255 266 +f 267 268 241 +f 4 184 115 +f 62 269 63 +f 183 182 129 +f 205 258 72 +f 248 148 116 +f 248 149 148 +f 73 155 74 +f 67 270 68 +f 63 271 61 +f 61 189 110 +f 227 265 230 +f 175 272 7 +f 94 192 191 +f 141 149 31 +f 273 70 127 +f 274 255 212 +f 275 196 276 +f 25 27 49 +f 93 260 192 +f 230 228 227 +f 277 278 279 +f 103 105 131 +f 74 155 280 +f 14 141 209 +f 15 34 126 +f 85 134 122 +f 116 115 248 +f 243 177 58 +f 138 207 208 +f 281 282 283 +f 173 91 284 +f 285 199 200 +f 230 44 228 +f 99 81 95 +f 286 271 287 +f 153 68 270 +f 32 25 49 +f 127 43 273 +f 152 120 142 +f 264 125 278 +f 184 4 182 +f 264 222 288 +f 289 194 290 +f 291 292 293 +f 271 63 50 +f 161 160 294 +f 137 117 257 +f 146 209 171 +f 143 246 135 +f 60 122 201 +f 106 295 262 +f 236 86 114 +f 60 2 85 +f 296 279 297 +f 108 65 64 +f 298 299 208 +f 194 193 300 +f 236 87 86 +f 230 273 42 +f 24 99 22 +f 239 258 205 +f 7 272 200 +f 230 71 273 +f 207 172 113 +f 138 54 172 +f 94 247 92 +f 249 301 302 +f 161 294 124 +f 207 97 96 +f 226 23 206 +f 72 226 206 +f 239 119 240 +f 73 120 38 +f 138 303 157 +f 18 17 201 +f 238 274 38 +f 82 24 213 +f 7 77 28 +f 304 293 305 +f 284 175 173 +f 131 133 103 +f 306 189 286 +f 286 307 306 +f 54 215 114 +f 158 257 117 +f 117 159 158 +f 214 213 6 +f 71 265 72 +f 288 298 123 +f 308 309 286 +f 10 12 196 +f 4 115 5 +f 298 96 124 +f 50 63 269 +f 226 213 24 +f 192 260 190 +f 257 158 170 +f 3 131 105 +f 119 236 114 +f 248 184 183 +f 310 294 160 +f 311 83 223 +f 279 312 193 +f 138 157 139 +f 129 25 183 +f 125 124 294 +f 313 314 52 +f 257 33 269 +f 315 151 316 +f 255 274 266 +f 317 217 181 +f 58 57 243 +f 146 14 209 +f 114 113 172 +f 128 267 89 +f 275 276 318 +f 216 217 319 +f 307 286 309 +f 210 319 320 +f 102 101 78 +f 241 321 267 +f 322 187 186 +f 41 45 42 +f 319 210 231 +f 77 169 168 +f 52 112 313 +f 198 285 175 +f 239 70 258 +f 161 163 162 +f 256 170 171 +f 199 323 119 +f 152 153 323 +f 278 125 297 +f 185 324 84 +f 248 31 149 +f 325 180 326 +f 114 48 47 +f 64 263 109 +f 323 199 152 +f 204 26 130 +f 268 267 128 +f 268 70 239 +f 239 205 236 +f 185 220 324 +f 85 84 324 +f 238 327 178 +f 31 248 32 diff --git a/src/transformation/mesh_intersection/mesh_intersection.rs b/src/transformation/mesh_intersection/mesh_intersection.rs index 9d104d7d..57313126 100644 --- a/src/transformation/mesh_intersection/mesh_intersection.rs +++ b/src/transformation/mesh_intersection/mesh_intersection.rs @@ -667,7 +667,7 @@ fn merge_triangle_sets( mod tests { use super::*; use crate::bounding_volume::{bounding_sphere, BoundingSphere}; - use crate::shape::{Ball, Cuboid, TriMeshFlags}; + use crate::shape::{Ball, Cuboid, TopoHalfEdge, TriMeshFlags, TriMeshTopology}; use obj::Obj; use obj::ObjData; @@ -729,13 +729,13 @@ mod tests { TriMeshFlags::all(), ); - let res = intersect_meshes( + let mut res = intersect_meshes( &Isometry::translation(2.0, 0.0, 0.0), &mesh, false, &Isometry::translation(2.0, 0.0, 0.0), &mesh, // To Fix: - // .clone().scaled(&Vector3::new(1.001, 1.001, 1.001)) + // .clone().scaled(&Vector3::new(1.001, 1.001, 1.001)) false, ) .unwrap() @@ -745,13 +745,34 @@ mod tests { "test_same_mesh_same_position_far_from_origin.obj", )); - // Not sure how to test, maybe amount of triangles ? verify the mesh is manifold? assert!( - false, - "This test is failing, for now needs manual verification." + res.set_flags(TriMeshFlags::HALF_EDGE_TOPOLOGY).is_ok(), + "This intersection should be able to compute its half edges." + ); + // Not sure how to test, maybe amount of triangles ? verify the mesh is manifold? + assert_eq!( + true, + is_manifold(&res), + "Intersection resulted in a non-manifold mesh." ) } + /// Verifies that there are no holes in the given trimesh. + /// + /// Parameter `trimesh` must have its flags [`TriMeshFlags::HALF_EDGE_TOPOLOGY`] enabled. + fn is_manifold(trimesh: &TriMesh) -> bool { + let Some(topology) = trimesh.topology() else { + return false; + }; + for half_edge in &topology.half_edges { + if half_edge.twin == u32::MAX { + return false; + } + } + + return true; + } + #[test] fn test_non_origin_pos1_pos2_intersection() { let ball = Ball::new(2f32 as Real).to_trimesh(10, 10);