small amount of cleanup, nphysics also seems to be getting phased out for rapier

master
mitchellhansen 4 years ago
parent 76a21ec73b
commit fe45a9f166

@ -29,4 +29,4 @@ wgpu-subscriber = "0.1.0"
tobj = "2.0.3" tobj = "2.0.3"
legion = "0.3.1" legion = "0.3.1"
nalgebra = "0.24.1" nalgebra = "0.24.1"
nphysics3d = "0.19.0" rapier3d = { version = "0.5.0", features = [ "simd-nightly", "parallel" ] }

@ -1,51 +0,0 @@
/*
pub trait Runtime: 'static + Sized {
fn optional_features() -> wgpu::Features {
wgpu::Features::empty()
}
fn required_features() -> wgpu::Features {
wgpu::Features::empty()
}
fn required_limits() -> wgpu::Limits {
wgpu::Limits::default()
}
fn init(
sc_desc: &wgpu::SwapChainDescriptor,
device: &wgpu::Device,
queue: &wgpu::Queue,
) -> Self;
fn resize(
&mut self,
sc_desc: &wgpu::SwapChainDescriptor,
device: &wgpu::Device,
queue: &wgpu::Queue,
);
fn update(&mut self, event: WindowEvent);
fn render(
&mut self,
frame: &wgpu::SwapChainTexture,
device: &wgpu::Device,
queue: &wgpu::Queue,
spawner: &impl LocalSpawn,
);
}
*/
/*
#[cfg(not(target_arch = "wasm32"))]
pub fn run<E: Runtime>(title: &str) {
let setup = futures::executor::block_on(setup::<E>(title));
start::<E>(setup);
}
#[cfg(target_arch = "wasm32")]
pub fn run<E: Runtime>(title: &str) {
let title = title.to_owned();
wasm_bindgen_futures::spawn_local(async move {
let setup = setup::<E>(&title).await;
start::<E>(setup);
});
}
*/

@ -1,4 +1,4 @@
extern crate nphysics3d;
extern crate tobj; extern crate tobj;
extern crate winit; extern crate winit;
@ -12,12 +12,6 @@ use bytemuck::__core::ops::Range;
use cgmath::{Decomposed, Deg, InnerSpace, Quaternion, Rotation3, SquareMatrix}; use cgmath::{Decomposed, Deg, InnerSpace, Quaternion, Rotation3, SquareMatrix};
use futures::task::LocalSpawn; use futures::task::LocalSpawn;
use legion::*; use legion::*;
use nphysics3d::math::Inertia;
use nphysics3d::math::Velocity as VelocityN;
use nphysics3d::nalgebra::{Isometry3, Matrix3, Matrix4, Point3, Point4, Vector3, Vector4};
use nphysics3d::ncollide3d::pipeline::CollisionGroups;
use nphysics3d::ncollide3d::shape::{Ball, ShapeHandle};
use nphysics3d::object::{BodyStatus, ColliderDesc, RigidBodyDesc, DefaultBodySet, DefaultColliderSet, BodyPartHandle};
use wgpu::{BindGroup, Buffer, TextureView}; use wgpu::{BindGroup, Buffer, TextureView};
use wgpu_subscriber; use wgpu_subscriber;
use winit::{ use winit::{
@ -26,13 +20,13 @@ use winit::{
}; };
use winit::event::DeviceEvent::MouseMotion; use winit::event::DeviceEvent::MouseMotion;
use winit::platform::unix::x11::ffi::Time; use winit::platform::unix::x11::ffi::Time;
use rapier3d::math;
use crate::render::Renderer; use crate::render::Renderer;
use nphysics3d::world::{DefaultMechanicalWorld, DefaultGeometricalWorld}; use rapier3d::pipeline::PhysicsPipeline;
use nphysics3d::joint::DefaultJointConstraintSet; use rapier3d::dynamics::{IntegrationParameters, RigidBodySet, JointSet, RigidBodyBuilder};
use nphysics3d::force_generator::DefaultForceGeneratorSet; use rapier3d::geometry::{BroadPhase, NarrowPhase, ColliderSet, ColliderBuilder};
use rapier3d::na::{Isometry, Isometry3, Vector, Vector3};
mod framework;
mod geometry; mod geometry;
mod light; mod light;
mod render; mod render;
@ -177,6 +171,7 @@ fn main() {
window.request_redraw(); window.request_redraw();
last_update_inst = Instant::now(); last_update_inst = Instant::now();
} }
physics();
pool.run_until_stalled(); pool.run_until_stalled();
} }
event::Event::DeviceEvent { event::Event::DeviceEvent {
@ -234,58 +229,118 @@ fn main() {
pub fn physics() { pub fn physics() {
let mut mechanical_world = DefaultMechanicalWorld::new(Vector3::new(0.0, -9.81, 0.0)); /* // let mut mechanical_world = DefaultMechanicalWorld::new(Vector3::new(0.0, -9.81, 0.0));
let mut geometrical_world = DefaultGeometricalWorld::new(); // let mut geometrical_world = DefaultGeometricalWorld::new();
//
let mut bodies = DefaultBodySet::new(); // let mut bodies = DefaultBodySet::new();
let mut colliders = DefaultColliderSet::new(); // let mut colliders = DefaultColliderSet::new();
let mut joint_constraints = DefaultJointConstraintSet::new(); // let mut joint_constraints = DefaultJointConstraintSet::new();
let mut force_generators = DefaultForceGeneratorSet::new(); // let mut force_generators = DefaultForceGeneratorSet::new();
//
// Run the simulation. // // Run the simulation.
mechanical_world.step( // mechanical_world.step(
&mut geometrical_world, // &mut geometrical_world,
&mut bodies, // &mut bodies,
&mut colliders, // &mut colliders,
&mut joint_constraints, // &mut joint_constraints,
&mut force_generators // &mut force_generators
); // );
//
let rigid_body = // let ground_handle = bodies.insert(Ground::new());
RigidBodyDesc::new() // let ground_shape = ShapeHandle::new(Cuboid::new(Vector3::new(3.0, 0.2, 3.0)
// The rigid body position. Will override `.translation(...)` and `.rotation(...)`. // ));
.position(Isometry3::new( //
// let main_floor = ColliderDesc::new(ground_shape)
// .translation(Vector3::y() * -0.2)
// .build(BodyPartHandle(ground_handle, 0));
// colliders.insert(main_floor);
//
// // Build the rigid body.
// let rb = RigidBodyDesc::new()
// .translation(Vector3::new(1.0, 1.0, 1.0))
// .build();
// let rb_handle = bodies.insert(rb);
//
// // Build the collider.
// let cuboid = ShapeHandle::new(Cuboid::new(Vector3::new(1.0, 1.0, 1.0)));
// let co = ColliderDesc::new(cuboid.clone())
// .density(1.0)
// .build(BodyPartHandle(rb_handle, 0));
// colliders.insert(co);
//
// //testbed.set_body_color(rb_handle, color);
//
// let rigid_body =
// RigidBodyDesc::new()
// // The rigid body position. Will override `.translation(...)` and `.rotation(...)`.
// .position(Isometry3::new(
// Vector3::new(1.0, 2.0, 3.0),
// Vector3::y() * PI,
// ))
// .gravity_enabled(true)
// .status(BodyStatus::Dynamic)
// .velocity(VelocityN::linear(1.0, 2.0, 3.0))
// .linear_damping(10.0)
// .angular_damping(5.0)
// .max_linear_velocity(10.0)
// .max_angular_velocity(1.7)
// .mass(1.2)
// // Arbitrary user-defined data associated to the rigid body to be built.
// .user_data(10)
// .build();
//
// let parent_handle = bodies.insert(rigid_body);
//
// let shape = ShapeHandle::new(Ball::new(1.5));
// let collider = ColliderDesc::new(shape)
// .density(1.0)
// .translation(Vector3::y() * 5.0)
// .build(BodyPartHandle(parent_handle, 0));
// let collider_handle = colliders.insert(collider);*/
// Here the gravity is -9.81 along the y axis.
let mut pipeline = PhysicsPipeline::new();
let gravity = rapier3d::math::Vector::new(0.0, -9.81, 0.0);
let integration_parameters = IntegrationParameters::default();
let mut broad_phase = BroadPhase::new();
let mut narrow_phase = NarrowPhase::new();
let mut bodies = RigidBodySet::new();
let mut colliders = ColliderSet::new();
let mut joints = JointSet::new();
// We ignore contact events for now.
let event_handler = ();
let mut dynamic_ball_body = RigidBodyBuilder::new_dynamic().build();
let mut dynamic_ball_body_handle = bodies.insert(dynamic_ball_body);
let mut static_floor_body = RigidBodyBuilder::new_static().position(Isometry3::new(
Vector3::new(1.0, 2.0, 3.0), Vector3::new(1.0, 2.0, 3.0),
Vector3::y() * PI, Vector::y() * PI,
)) )).build();
.gravity_enabled(true) let mut static_floor_body_handle = bodies.insert(static_floor_body);
.status(BodyStatus::Dynamic)
.velocity(VelocityN::linear(1.0, 2.0, 3.0))
.linear_damping(10.0)
.angular_damping(5.0)
.max_linear_velocity(10.0)
.max_angular_velocity(1.7)
.mass(1.2)
// Arbitrary user-defined data associated to the rigid body to be built.
.user_data(10)
.build();
// let parent_rigid_body = RigidBodyDesc::new() let ball_collider = ColliderBuilder::ball(0.5).build();
// .build(); let floor_collider = ColliderBuilder::cuboid(0.5, 0.2, 0.1).build();
let parent_handle = bodies.insert(rigid_body);
let shape = ShapeHandle::new(Ball::new(1.5)); let ball_collider_handle = colliders.insert(ball_collider, dynamic_ball_body_handle, &mut bodies);
let collider = ColliderDesc::new(shape) let floor_collider_handle = colliders.insert(floor_collider, dynamic_ball_body_handle, &mut bodies);
.density(1.0)
.translation(Vector3::y() * 5.0)
.build(BodyPartHandle(parent_handle, 0));
let collider_handle = colliders.insert(collider);
// let ball = ShapeHandle::new(Ball::new(1.5)); // Run the simulation in the game loop.
// loop {
// let collider = ColliderDesc::new(rigid_body) pipeline.step(
// .build(); &gravity,
&integration_parameters,
&mut broad_phase,
&mut narrow_phase,
&mut bodies,
&mut colliders,
&mut joints,
None,
None,
&event_handler
);
}
} }
pub fn entity_loading(world: &mut World, renderer: &mut Renderer) { pub fn entity_loading(world: &mut World, renderer: &mut Renderer) {

Loading…
Cancel
Save