Switch to [u32; DIM] instead of Point<u32> for element indices.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
use kiss3d::loader::obj;
|
use kiss3d::loader::obj;
|
||||||
use na::{Isometry3, Point3, Translation3};
|
use na::{Point3, Translation3};
|
||||||
use rapier3d::cdl::bounding_volume::{self, BoundingVolume};
|
use rapier3d::cdl::bounding_volume::{self, BoundingVolume};
|
||||||
use rapier3d::cdl::transformation::vhacd::{VHACDParameters, VHACD};
|
use rapier3d::cdl::transformation::vhacd::{VHACDParameters, VHACD};
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||||
@@ -74,11 +74,16 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
trimesh.scale_by_scalar(6.0 / diag);
|
trimesh.scale_by_scalar(6.0 / diag);
|
||||||
|
|
||||||
let params = VHACDParameters::default();
|
let params = VHACDParameters::default();
|
||||||
let vertices = &trimesh.coords;
|
let vertices = trimesh.coords;
|
||||||
let indices = &trimesh.indices.unwrap_unified();
|
let indices: Vec<_> = trimesh
|
||||||
let vhacd = VHACD::decompose(¶ms, vertices, indices, true);
|
.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) {
|
for (vertices, indices) in vhacd.compute_exact_convex_hulls(&vertices, &indices) {
|
||||||
if let Some(convex) = ColliderShape::convex_mesh(vertices, &indices) {
|
if let Some(convex) = ColliderShape::convex_mesh(vertices, &indices) {
|
||||||
compound_parts.push(convex);
|
compound_parts.push(convex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,18 +24,18 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
Point3::new(-width, -width, width),
|
Point3::new(-width, -width, width),
|
||||||
];
|
];
|
||||||
let idx = vec![
|
let idx = vec![
|
||||||
Point3::new(0, 1, 2),
|
[0, 1, 2],
|
||||||
Point3::new(0, 2, 3),
|
[0, 2, 3],
|
||||||
Point3::new(4, 5, 6),
|
[4, 5, 6],
|
||||||
Point3::new(4, 6, 7),
|
[4, 6, 7],
|
||||||
Point3::new(0, 4, 7),
|
[0, 4, 7],
|
||||||
Point3::new(0, 7, 3),
|
[0, 7, 3],
|
||||||
Point3::new(1, 5, 6),
|
[1, 5, 6],
|
||||||
Point3::new(1, 6, 2),
|
[1, 6, 2],
|
||||||
Point3::new(3, 2, 7),
|
[3, 2, 7],
|
||||||
Point3::new(2, 6, 7),
|
[2, 6, 7],
|
||||||
Point3::new(0, 1, 5),
|
[0, 1, 5],
|
||||||
Point3::new(0, 5, 4),
|
[0, 5, 4],
|
||||||
];
|
];
|
||||||
|
|
||||||
// Dynamic box rigid body.
|
// Dynamic box rigid body.
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
use super::{RevolutePositionConstraint, RevolutePositionGroundConstraint};
|
use super::{RevolutePositionConstraint, RevolutePositionGroundConstraint};
|
||||||
use crate::dynamics::{IntegrationParameters, JointIndex, RevoluteJoint, RigidBody};
|
use crate::dynamics::{IntegrationParameters, RevoluteJoint, RigidBody};
|
||||||
use crate::math::{AngularInertia, Isometry, Point, Real, Rotation, Vector, SIMD_WIDTH};
|
use crate::math::{Isometry, Real, SIMD_WIDTH};
|
||||||
use crate::utils::WAngularInertia;
|
|
||||||
use na::Unit;
|
|
||||||
|
|
||||||
// TODO: this does not uses SIMD optimizations yet.
|
// TODO: this does not uses SIMD optimizations yet.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ use cdl::shape::{
|
|||||||
};
|
};
|
||||||
#[cfg(feature = "dim2")]
|
#[cfg(feature = "dim2")]
|
||||||
use cdl::shape::{ConvexPolygon, RoundConvexPolygon};
|
use cdl::shape::{ConvexPolygon, RoundConvexPolygon};
|
||||||
use na::Point3;
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@@ -123,7 +122,7 @@ impl ColliderShape {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Initializes a triangle mesh shape defined by its vertex and index buffers.
|
/// 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)))
|
ColliderShape(Arc::new(TriMesh::new(vertices, indices)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +139,7 @@ impl ColliderShape {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "dim3")]
|
#[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)))
|
ConvexPolyhedron::from_convex_mesh(points, indices).map(|ch| ColliderShape(Arc::new(ch)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +173,7 @@ impl ColliderShape {
|
|||||||
#[cfg(feature = "dim3")]
|
#[cfg(feature = "dim3")]
|
||||||
pub fn round_convex_mesh(
|
pub fn round_convex_mesh(
|
||||||
points: Vec<Point<Real>>,
|
points: Vec<Point<Real>>,
|
||||||
indices: &[Point<u32>],
|
indices: &[[u32; 3]],
|
||||||
border_radius: Real,
|
border_radius: Real,
|
||||||
) -> Option<Self> {
|
) -> Option<Self> {
|
||||||
ConvexPolyhedron::from_convex_mesh(points, indices).map(|ch| {
|
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.
|
/// 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))
|
Self::new(ColliderShape::trimesh(vertices, indices))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -578,14 +577,14 @@ impl ColliderBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "dim3")]
|
#[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))
|
ColliderShape::convex_mesh(points, indices).map(|cp| Self::new(cp))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "dim3")]
|
#[cfg(feature = "dim3")]
|
||||||
pub fn round_convex_mesh(
|
pub fn round_convex_mesh(
|
||||||
points: Vec<Point<Real>>,
|
points: Vec<Point<Real>>,
|
||||||
indices: &[Point<u32>],
|
indices: &[[u32; 3]],
|
||||||
border_radius: Real,
|
border_radius: Real,
|
||||||
) -> Option<Self> {
|
) -> Option<Self> {
|
||||||
ColliderShape::round_convex_mesh(points, indices, border_radius).map(|cp| Self::new(cp))
|
ColliderShape::round_convex_mesh(points, indices, border_radius).map(|cp| Self::new(cp))
|
||||||
|
|||||||
@@ -336,7 +336,7 @@ impl GraphicsManager {
|
|||||||
out.push(Node::Mesh(Mesh::new(
|
out.push(Node::Mesh(Mesh::new(
|
||||||
handle,
|
handle,
|
||||||
vec![triangle.a, triangle.b, triangle.c],
|
vec![triangle.a, triangle.b, triangle.c],
|
||||||
vec![Point3::new(0, 1, 2)],
|
vec![[0, 1, 2]],
|
||||||
color,
|
color,
|
||||||
window,
|
window,
|
||||||
)))
|
)))
|
||||||
@@ -346,11 +346,7 @@ impl GraphicsManager {
|
|||||||
out.push(Node::Mesh(Mesh::new(
|
out.push(Node::Mesh(Mesh::new(
|
||||||
handle,
|
handle,
|
||||||
trimesh.vertices().to_vec(),
|
trimesh.vertices().to_vec(),
|
||||||
trimesh
|
trimesh.indices().to_vec(),
|
||||||
.indices()
|
|
||||||
.iter()
|
|
||||||
.map(|idx| na::convert(*idx))
|
|
||||||
.collect(),
|
|
||||||
color,
|
color,
|
||||||
window,
|
window,
|
||||||
)))
|
)))
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ fn nphysics_collider_from_rapier_collider(
|
|||||||
trimesh
|
trimesh
|
||||||
.indices()
|
.indices()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|idx| na::convert(*idx))
|
.map(|idx| na::Point3::new(idx[0] as usize, idx[1] as usize, idx[2] as usize))
|
||||||
.collect(),
|
.collect(),
|
||||||
None,
|
None,
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ impl Convex {
|
|||||||
body: ColliderHandle,
|
body: ColliderHandle,
|
||||||
delta: Isometry<f32>,
|
delta: Isometry<f32>,
|
||||||
vertices: Vec<Point<f32>>,
|
vertices: Vec<Point<f32>>,
|
||||||
#[cfg(feature = "dim3")] indices: Vec<Point<u32>>,
|
#[cfg(feature = "dim3")] indices: Vec<[u32; 3]>,
|
||||||
color: Point3<f32>,
|
color: Point3<f32>,
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
) -> Convex {
|
) -> Convex {
|
||||||
@@ -35,9 +35,9 @@ impl Convex {
|
|||||||
let mut mesh_indices = Vec::new();
|
let mut mesh_indices = Vec::new();
|
||||||
for idx in indices {
|
for idx in indices {
|
||||||
let i = mesh_vertices.len() as u16;
|
let i = mesh_vertices.len() as u16;
|
||||||
mesh_vertices.push(vertices[idx.x as usize]);
|
mesh_vertices.push(vertices[idx[0] as usize]);
|
||||||
mesh_vertices.push(vertices[idx.y as usize]);
|
mesh_vertices.push(vertices[idx[1] as usize]);
|
||||||
mesh_vertices.push(vertices[idx.z as usize]);
|
mesh_vertices.push(vertices[idx[2] as usize]);
|
||||||
mesh_indices.push(Point3::new(i, i + 1, i + 2));
|
mesh_indices.push(Point3::new(i, i + 1, i + 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,10 @@ impl HeightField {
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
let (vertices, indices) = heightfield.to_trimesh();
|
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 mesh = Mesh::new(vertices, indices, None, None, false);
|
||||||
|
|
||||||
let mut res = HeightField {
|
let mut res = HeightField {
|
||||||
|
|||||||
@@ -17,12 +17,15 @@ impl Mesh {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
collider: ColliderHandle,
|
collider: ColliderHandle,
|
||||||
vertices: Vec<Point<f32>>,
|
vertices: Vec<Point<f32>>,
|
||||||
indices: Vec<Point3<u32>>,
|
indices: Vec<[u32; 3]>,
|
||||||
color: Point3<f32>,
|
color: Point3<f32>,
|
||||||
window: &mut window::Window,
|
window: &mut window::Window,
|
||||||
) -> Mesh {
|
) -> Mesh {
|
||||||
let vs = vertices;
|
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 mesh;
|
||||||
let gfx;
|
let gfx;
|
||||||
|
|||||||
Reference in New Issue
Block a user