Add example for 3D convex polyhedron.
This commit is contained in:
@@ -14,7 +14,7 @@ use crate::objects::node::{GraphicsNode, Node};
|
||||
use rapier::dynamics::{RigidBodyHandle, RigidBodySet};
|
||||
use rapier::geometry::{Collider, ColliderHandle, ColliderSet};
|
||||
//use crate::objects::capsule::Capsule;
|
||||
//use crate::objects::convex::Convex;
|
||||
use crate::objects::convex::Convex;
|
||||
//#[cfg(feature = "dim3")]
|
||||
//use crate::objects::mesh::Mesh;
|
||||
//use crate::objects::plane::Plane;
|
||||
@@ -292,7 +292,10 @@ impl GraphicsManager {
|
||||
// window,
|
||||
// ))),
|
||||
|
||||
if let Some(cuboid) = shape.as_cuboid() {
|
||||
if let Some(cuboid) = shape
|
||||
.as_cuboid()
|
||||
.or(shape.as_round_cuboid().map(|r| &r.base_shape))
|
||||
{
|
||||
out.push(Node::Box(BoxNode::new(
|
||||
handle,
|
||||
cuboid.half_extents,
|
||||
@@ -305,7 +308,10 @@ impl GraphicsManager {
|
||||
out.push(Node::Capsule(Capsule::new(handle, capsule, color, window)))
|
||||
}
|
||||
|
||||
if let Some(triangle) = shape.as_triangle() {
|
||||
if let Some(triangle) = shape
|
||||
.as_triangle()
|
||||
.or(shape.as_round_triangle().map(|r| &r.base_shape))
|
||||
{
|
||||
out.push(Node::Mesh(Mesh::new(
|
||||
handle,
|
||||
vec![triangle.a, triangle.b, triangle.c],
|
||||
@@ -338,10 +344,21 @@ impl GraphicsManager {
|
||||
)))
|
||||
}
|
||||
|
||||
#[cfg(feature = "dim3")]
|
||||
if let Some(convex_polyhedron) = shape
|
||||
.as_convex_polyhedron()
|
||||
.or(shape.as_round_convex_polyhedron().map(|r| &r.base_shape))
|
||||
{
|
||||
let (vertices, indices) = convex_polyhedron.to_trimesh();
|
||||
out.push(Node::Convex(Convex::new(
|
||||
handle, vertices, indices, color, window,
|
||||
)))
|
||||
}
|
||||
|
||||
#[cfg(feature = "dim3")]
|
||||
if let Some(cylinder) = shape
|
||||
.as_cylinder()
|
||||
.or(shape.as_round_cylinder().map(|r| &r.cylinder))
|
||||
.or(shape.as_round_cylinder().map(|r| &r.base_shape))
|
||||
{
|
||||
out.push(Node::Cylinder(Cylinder::new(
|
||||
handle,
|
||||
@@ -353,7 +370,10 @@ impl GraphicsManager {
|
||||
}
|
||||
|
||||
#[cfg(feature = "dim3")]
|
||||
if let Some(cone) = shape.as_cone() {
|
||||
if let Some(cone) = shape
|
||||
.as_cone()
|
||||
.or(shape.as_round_cone().map(|r| &r.base_shape))
|
||||
{
|
||||
out.push(Node::Cone(Cone::new(
|
||||
handle,
|
||||
cone.half_height,
|
||||
|
||||
@@ -19,13 +19,20 @@ impl Convex {
|
||||
pub fn new(
|
||||
body: ColliderHandle,
|
||||
vertices: Vec<Point<f32>>,
|
||||
#[cfg(feature = "dim3")] indices: Vec<Point<u32>>,
|
||||
color: Point3<f32>,
|
||||
window: &mut Window,
|
||||
) -> Convex {
|
||||
#[cfg(feature = "dim2")]
|
||||
let node = window.add_convex_polygon(vertices, Vector::from_element(1.0));
|
||||
#[cfg(feature = "dim3")]
|
||||
let node = unimplemented!();
|
||||
let node = {
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
let is = indices.into_iter().map(na::convert).collect();
|
||||
let mesh = kiss3d::resource::Mesh::new(vertices, is, None, None, false);
|
||||
window.add_mesh(Rc::new(RefCell::new(mesh)), na::Vector3::from_element(1.0))
|
||||
};
|
||||
|
||||
let mut res = Convex {
|
||||
color,
|
||||
|
||||
Reference in New Issue
Block a user