aboutsummaryrefslogtreecommitdiff
path: root/src_testbed/objects/heightfield.rs
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2021-01-29 14:42:32 +0100
committerGitHub <noreply@github.com>2021-01-29 14:42:32 +0100
commit7ca46f38cde6cf8bf8bf41ea6067ae5bc938205c (patch)
tree3781b9d7c92a6a8111573ba4cae1c5d41435950e /src_testbed/objects/heightfield.rs
parente6fc8f67faf3e37afe38d683cbd930d457f289be (diff)
parent825f33efaec4ce6a8903751e836a0ea9c466ff92 (diff)
downloadrapier-7ca46f38cde6cf8bf8bf41ea6067ae5bc938205c.tar.gz
rapier-7ca46f38cde6cf8bf8bf41ea6067ae5bc938205c.tar.bz2
rapier-7ca46f38cde6cf8bf8bf41ea6067ae5bc938205c.zip
Merge pull request #79 from dimforge/split_geom
Move most of the geometric code to another crate.
Diffstat (limited to 'src_testbed/objects/heightfield.rs')
-rw-r--r--src_testbed/objects/heightfield.rs28
1 files changed, 18 insertions, 10 deletions
diff --git a/src_testbed/objects/heightfield.rs b/src_testbed/objects/heightfield.rs
index 0815592..913a732 100644
--- a/src_testbed/objects/heightfield.rs
+++ b/src_testbed/objects/heightfield.rs
@@ -1,15 +1,16 @@
-#[cfg(feature = "dim3")]
-use crate::objects::node::{self, GraphicsNode};
use kiss3d::window::Window;
use na::{self, Point3};
-use ncollide::shape;
-#[cfg(feature = "dim3")]
-use ncollide::transformation::ToTriMesh;
+use parry::shape;
use rapier::geometry::{ColliderHandle, ColliderSet};
#[cfg(feature = "dim2")]
use rapier::math::Point;
#[cfg(feature = "dim3")]
-use rapier::math::Vector;
+use {
+ crate::objects::node::{self, GraphicsNode},
+ kiss3d::resource::Mesh,
+ rapier::math::Vector,
+ std::cell::RefCell,
+};
pub struct HeightField {
color: Point3<f32>,
@@ -25,7 +26,7 @@ impl HeightField {
#[cfg(feature = "dim2")]
pub fn new(
collider: ColliderHandle,
- heightfield: &shape::HeightField<f32>,
+ heightfield: &shape::HeightField,
color: Point3<f32>,
_: &mut Window,
) -> HeightField {
@@ -47,16 +48,23 @@ impl HeightField {
#[cfg(feature = "dim3")]
pub fn new(
collider: ColliderHandle,
- heightfield: &shape::HeightField<f32>,
+ heightfield: &shape::HeightField,
color: Point3<f32>,
window: &mut Window,
) -> HeightField {
- let mesh = heightfield.to_trimesh(());
+ use std::rc::Rc;
+
+ let (vertices, indices) = heightfield.to_trimesh();
+ 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 {
color,
base_color: color,
- gfx: window.add_trimesh(mesh, Vector::repeat(1.0)),
+ gfx: window.add_mesh(Rc::new(RefCell::new(mesh)), Vector::repeat(1.0)),
collider: collider,
};