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 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);
|
||||
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) {
|
||||
for (vertices, indices) in vhacd.compute_exact_convex_hulls(&vertices, &indices) {
|
||||
if let Some(convex) = ColliderShape::convex_mesh(vertices, &indices) {
|
||||
compound_parts.push(convex);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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,
|
||||
)))
|
||||
|
||||
@@ -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,
|
||||
))
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user