diff options
| author | Crozet Sébastien <developer@crozet.re> | 2021-01-20 15:40:00 +0100 |
|---|---|---|
| committer | Crozet Sébastien <developer@crozet.re> | 2021-01-20 15:40:00 +0100 |
| commit | 28b7866aee68ca844406bea4761d630a7913188d (patch) | |
| tree | c664c3dae65e5300f606e4f8cfb1198023173ea6 | |
| parent | e2006599a8fa90090393ff4fed326ee78fd7c0b7 (diff) | |
| download | rapier-28b7866aee68ca844406bea4761d630a7913188d.tar.gz rapier-28b7866aee68ca844406bea4761d630a7913188d.tar.bz2 rapier-28b7866aee68ca844406bea4761d630a7913188d.zip | |
Switch to [u32; DIM] instead of Point<u32> for element indices.
| -rw-r--r-- | examples3d/convex_decomposition3.rs | 17 | ||||
| -rw-r--r-- | examples3d/debug_trimesh3.rs | 24 | ||||
| -rw-r--r-- | src/dynamics/solver/joint_constraint/revolute_position_constraint_wide.rs | 6 | ||||
| -rw-r--r-- | src/geometry/collider.rs | 13 | ||||
| -rw-r--r-- | src_testbed/engine.rs | 8 | ||||
| -rw-r--r-- | src_testbed/nphysics_backend.rs | 2 | ||||
| -rw-r--r-- | src_testbed/objects/convex.rs | 8 | ||||
| -rw-r--r-- | src_testbed/objects/heightfield.rs | 5 | ||||
| -rw-r--r-- | src_testbed/objects/mesh.rs | 7 |
9 files changed, 47 insertions, 43 deletions
diff --git a/examples3d/convex_decomposition3.rs b/examples3d/convex_decomposition3.rs index 2e35f43..abd2fe0 100644 --- a/examples3d/convex_decomposition3.rs +++ b/examples3d/convex_decomposition3.rs @@ -1,5 +1,5 @@ use kiss3d::loader::obj; -use na::{Isometry3, Point3, Translation3}; +use na::{Point3, Translation3}; use rapier3d::cdl::bounding_volume::{self, BoundingVolume}; use rapier3d::cdl::transformation::vhacd::{VHACDParameters, VHACD}; use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; @@ -74,11 +74,16 @@ pub fn init_world(testbed: &mut Testbed) { trimesh.scale_by_scalar(6.0 / diag); let params = VHACDParameters::default(); - let vertices = &trimesh.coords; - let indices = &trimesh.indices.unwrap_unified(); - let vhacd = VHACD::decompose(¶ms, vertices, indices, true); - - for (vertices, indices) in vhacd.compute_exact_convex_hulls(vertices, indices) { + let vertices = trimesh.coords; + let indices: Vec<_> = trimesh + .indices + .unwrap_unified() + .into_iter() + .map(|idx| [idx.x, idx.y, idx.z]) + .collect(); + let vhacd = VHACD::decompose(¶ms, &vertices, &indices, true); + + for (vertices, indices) in vhacd.compute_exact_convex_hulls(&vertices, &indices) { if let Some(convex) = ColliderShape::convex_mesh(vertices, &indices) { compound_parts.push(convex); } diff --git a/examples3d/debug_trimesh3.rs b/examples3d/debug_trimesh3.rs index 0d0b276..186e673 100644 --- a/examples3d/debug_trimesh3.rs +++ b/examples3d/debug_trimesh3.rs @@ -24,18 +24,18 @@ pub fn init_world(testbed: &mut Testbed) { Point3::new(-width, -width, width), ]; let idx = vec![ - Point3::new(0, 1, 2), - Point3::new(0, 2, 3), - Point3::new(4, 5, 6), - Point3::new(4, 6, 7), - Point3::new(0, 4, 7), - Point3::new(0, 7, 3), - Point3::new(1, 5, 6), - Point3::new(1, 6, 2), - Point3::new(3, 2, 7), - Point3::new(2, 6, 7), - Point3::new(0, 1, 5), - Point3::new(0, 5, 4), + [0, 1, 2], + [0, 2, 3], + [4, 5, 6], + [4, 6, 7], + [0, 4, 7], + [0, 7, 3], + [1, 5, 6], + [1, 6, 2], + [3, 2, 7], + [2, 6, 7], + [0, 1, 5], + [0, 5, 4], ]; // Dynamic box rigid body. diff --git a/src/dynamics/solver/joint_constraint/revolute_position_constraint_wide.rs b/src/dynamics/solver/joint_constraint/revolute_position_constraint_wide.rs index 44da104..e2d140d 100644 --- a/src/dynamics/solver/joint_constraint/revolute_position_constraint_wide.rs +++ b/src/dynamics/solver/joint_constraint/revolute_position_constraint_wide.rs @@ -1,8 +1,6 @@ use super::{RevolutePositionConstraint, RevolutePositionGroundConstraint}; -use crate::dynamics::{IntegrationParameters, JointIndex, RevoluteJoint, RigidBody}; -use crate::math::{AngularInertia, Isometry, Point, Real, Rotation, Vector, SIMD_WIDTH}; -use crate::utils::WAngularInertia; -use na::Unit; +use crate::dynamics::{IntegrationParameters, RevoluteJoint, RigidBody}; +use crate::math::{Isometry, Real, SIMD_WIDTH}; // TODO: this does not uses SIMD optimizations yet. #[derive(Debug)] diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs index 8533c81..96fcbf9 100644 --- a/src/geometry/collider.rs +++ b/src/geometry/collider.rs @@ -12,7 +12,6 @@ use cdl::shape::{ }; #[cfg(feature = "dim2")] use cdl::shape::{ConvexPolygon, RoundConvexPolygon}; -use na::Point3; use std::ops::Deref; use std::sync::Arc; @@ -123,7 +122,7 @@ impl ColliderShape { } /// Initializes a triangle mesh shape defined by its vertex and index buffers. - pub fn trimesh(vertices: Vec<Point<Real>>, indices: Vec<Point3<u32>>) -> Self { + pub fn trimesh(vertices: Vec<Point<Real>>, indices: Vec<[u32; 3]>) -> Self { ColliderShape(Arc::new(TriMesh::new(vertices, indices))) } @@ -140,7 +139,7 @@ impl ColliderShape { } #[cfg(feature = "dim3")] - pub fn convex_mesh(points: Vec<Point<Real>>, indices: &[Point3<u32>]) -> Option<Self> { + pub fn convex_mesh(points: Vec<Point<Real>>, indices: &[[u32; 3]]) -> Option<Self> { ConvexPolyhedron::from_convex_mesh(points, indices).map(|ch| ColliderShape(Arc::new(ch))) } @@ -174,7 +173,7 @@ impl ColliderShape { #[cfg(feature = "dim3")] pub fn round_convex_mesh( points: Vec<Point<Real>>, - indices: &[Point<u32>], + indices: &[[u32; 3]], border_radius: Real, ) -> Option<Self> { ConvexPolyhedron::from_convex_mesh(points, indices).map(|ch| { @@ -555,7 +554,7 @@ impl ColliderBuilder { } /// Initializes a collider builder with a triangle mesh shape defined by its vertex and index buffers. - pub fn trimesh(vertices: Vec<Point<Real>>, indices: Vec<Point3<u32>>) -> Self { + pub fn trimesh(vertices: Vec<Point<Real>>, indices: Vec<[u32; 3]>) -> Self { Self::new(ColliderShape::trimesh(vertices, indices)) } @@ -578,14 +577,14 @@ impl ColliderBuilder { } #[cfg(feature = "dim3")] - pub fn convex_mesh(points: Vec<Point<Real>>, indices: &[Point3<u32>]) -> Option<Self> { + pub fn convex_mesh(points: Vec<Point<Real>>, indices: &[[u32; 3]]) -> Option<Self> { ColliderShape::convex_mesh(points, indices).map(|cp| Self::new(cp)) } #[cfg(feature = "dim3")] pub fn round_convex_mesh( points: Vec<Point<Real>>, - indices: &[Point<u32>], + indices: &[[u32; 3]], border_radius: Real, ) -> Option<Self> { ColliderShape::round_convex_mesh(points, indices, border_radius).map(|cp| Self::new(cp)) diff --git a/src_testbed/engine.rs b/src_testbed/engine.rs index 0e415ea..cef12d6 100644 --- a/src_testbed/engine.rs +++ b/src_testbed/engine.rs @@ -336,7 +336,7 @@ impl GraphicsManager { out.push(Node::Mesh(Mesh::new( handle, vec![triangle.a, triangle.b, triangle.c], - vec![Point3::new(0, 1, 2)], + vec![[0, 1, 2]], color, window, ))) @@ -346,11 +346,7 @@ impl GraphicsManager { out.push(Node::Mesh(Mesh::new( handle, trimesh.vertices().to_vec(), - trimesh - .indices() - .iter() - .map(|idx| na::convert(*idx)) - .collect(), + trimesh.indices().to_vec(), color, window, ))) diff --git a/src_testbed/nphysics_backend.rs b/src_testbed/nphysics_backend.rs index 224b5d3..b2495bd 100644 --- a/src_testbed/nphysics_backend.rs +++ b/src_testbed/nphysics_backend.rs @@ -205,7 +205,7 @@ fn nphysics_collider_from_rapier_collider( trimesh .indices() .iter() - .map(|idx| na::convert(*idx)) + .map(|idx| na::Point3::new(idx[0] as usize, idx[1] as usize, idx[2] as usize)) .collect(), None, )) diff --git a/src_testbed/objects/convex.rs b/src_testbed/objects/convex.rs index 51b1cb4..95ef74a 100644 --- a/src_testbed/objects/convex.rs +++ b/src_testbed/objects/convex.rs @@ -21,7 +21,7 @@ impl Convex { body: ColliderHandle, delta: Isometry<f32>, vertices: Vec<Point<f32>>, - #[cfg(feature = "dim3")] indices: Vec<Point<u32>>, + #[cfg(feature = "dim3")] indices: Vec<[u32; 3]>, color: Point3<f32>, window: &mut Window, ) -> Convex { @@ -35,9 +35,9 @@ impl Convex { let mut mesh_indices = Vec::new(); for idx in indices { let i = mesh_vertices.len() as u16; - mesh_vertices.push(vertices[idx.x as usize]); - mesh_vertices.push(vertices[idx.y as usize]); - mesh_vertices.push(vertices[idx.z as usize]); + mesh_vertices.push(vertices[idx[0] as usize]); + mesh_vertices.push(vertices[idx[1] as usize]); + mesh_vertices.push(vertices[idx[2] as usize]); mesh_indices.push(Point3::new(i, i + 1, i + 2)); } diff --git a/src_testbed/objects/heightfield.rs b/src_testbed/objects/heightfield.rs index a2999b7..cb5edf3 100644 --- a/src_testbed/objects/heightfield.rs +++ b/src_testbed/objects/heightfield.rs @@ -55,7 +55,10 @@ impl HeightField { use std::rc::Rc; let (vertices, indices) = heightfield.to_trimesh(); - let indices = indices.into_iter().map(|i| na::convert(i)).collect(); + let indices = indices + .into_iter() + .map(|idx| Point3::new(idx[0] as u16, idx[1] as u16, idx[2] as u16)) + .collect(); let mesh = Mesh::new(vertices, indices, None, None, false); let mut res = HeightField { diff --git a/src_testbed/objects/mesh.rs b/src_testbed/objects/mesh.rs index 5187a8b..5505de3 100644 --- a/src_testbed/objects/mesh.rs +++ b/src_testbed/objects/mesh.rs @@ -17,12 +17,15 @@ impl Mesh { pub fn new( collider: ColliderHandle, vertices: Vec<Point<f32>>, - indices: Vec<Point3<u32>>, + indices: Vec<[u32; 3]>, color: Point3<f32>, window: &mut window::Window, ) -> Mesh { let vs = vertices; - let is = indices.into_iter().map(na::convert).collect(); + let is = indices + .into_iter() + .map(|idx| Point3::new(idx[0] as u16, idx[1] as u16, idx[2] as u16)) + .collect(); let mesh; let gfx; |
