|
|
|
@ -1,18 +1,15 @@
|
|
|
|
|
extern crate imgui;
|
|
|
|
|
extern crate imgui_wgpu;
|
|
|
|
|
extern crate tobj;
|
|
|
|
|
extern crate winit_24;
|
|
|
|
|
#[macro_use]
|
|
|
|
|
extern crate lazy_static;
|
|
|
|
|
extern crate tobj;
|
|
|
|
|
extern crate winit_24;
|
|
|
|
|
|
|
|
|
|
use std::borrow::Borrow;
|
|
|
|
|
use std::f32::consts::PI;
|
|
|
|
|
use std::rc::Rc;
|
|
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
|
use std::time::{Duration, Instant};
|
|
|
|
|
|
|
|
|
|
use bytemuck::__core::ops::Range;
|
|
|
|
|
use cgmath::{
|
|
|
|
|
Decomposed, Deg, Euler, InnerSpace, Point3, Quaternion, Rad, Rotation3, SquareMatrix,
|
|
|
|
|
};
|
|
|
|
@ -32,6 +29,7 @@ use rapier3d::dynamics::{
|
|
|
|
|
};
|
|
|
|
|
use rapier3d::geometry::{BroadPhase, ColliderBuilder, ColliderHandle, ColliderSet, NarrowPhase};
|
|
|
|
|
use rapier3d::math;
|
|
|
|
|
use rapier3d::math::Point;
|
|
|
|
|
use rapier3d::na::{Isometry, Isometry3, Vector, Vector3};
|
|
|
|
|
use rapier3d::pipeline::PhysicsPipeline;
|
|
|
|
|
use wgpu::{BindGroup, Buffer, TextureView};
|
|
|
|
@ -45,7 +43,8 @@ use winit_24::{
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
use crate::camera::{Camera, CameraController};
|
|
|
|
|
use crate::components::{Collider, Color, ImguiWindow, LoopState, Physics, Position};
|
|
|
|
|
use crate::components::{Collider, ImguiWindow, LoopState, Physics, Position};
|
|
|
|
|
use crate::geometry::load_obj;
|
|
|
|
|
use crate::imgui_supp::extended_winit_imgui_support;
|
|
|
|
|
use crate::imgui_supp::imgui_support::{ImguiContext, ImguiPlatform};
|
|
|
|
|
use crate::owned_event::{OwnedEvent, OwnedEventExtension};
|
|
|
|
@ -91,8 +90,9 @@ ECS
|
|
|
|
|
|
|
|
|
|
// ImGUI works on more or less a global state. which is MegaLame
|
|
|
|
|
static mut CURRENT_UI: Option<imgui::Ui<'static>> = None;
|
|
|
|
|
pub unsafe fn current_ui<'a>() -> Option<&'a imgui::Ui<'a>> { CURRENT_UI.as_ref() }
|
|
|
|
|
|
|
|
|
|
pub unsafe fn current_ui<'a>() -> Option<&'a imgui::Ui<'a>> {
|
|
|
|
|
CURRENT_UI.as_ref()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
let mut world = World::default();
|
|
|
|
@ -190,18 +190,18 @@ fn main() {
|
|
|
|
|
if gamepad_.name() == "PS4" {
|
|
|
|
|
gamepad = Some(gamepad_);
|
|
|
|
|
}
|
|
|
|
|
println!(
|
|
|
|
|
"{} is {:?} {:?}",
|
|
|
|
|
gamepad_.name(),
|
|
|
|
|
gamepad_.power_info(),
|
|
|
|
|
gamepad_.id()
|
|
|
|
|
);
|
|
|
|
|
// println!(
|
|
|
|
|
// "{} is {:?} {:?}",
|
|
|
|
|
// gamepad_.name(),
|
|
|
|
|
// gamepad_.power_info(),
|
|
|
|
|
// gamepad_.id()
|
|
|
|
|
// );
|
|
|
|
|
}
|
|
|
|
|
let mut active_gamepad = None;
|
|
|
|
|
|
|
|
|
|
loop {
|
|
|
|
|
while let Some(GilEvent { id, event, time }) = gilrs.next_event() {
|
|
|
|
|
println!("{:?} New event from {}: {:?}", time, id, event);
|
|
|
|
|
//println!("{:?} New event from {}: {:?}", time, id, event);
|
|
|
|
|
active_gamepad = Some(id);
|
|
|
|
|
event_loop_proxy
|
|
|
|
|
.send_event(OwnedEventExtension::GamepadEvent {
|
|
|
|
@ -235,9 +235,7 @@ fn main() {
|
|
|
|
|
event_loop.run(move |event, _, control_flow| {
|
|
|
|
|
*control_flow = ControlFlow::Poll;
|
|
|
|
|
match event {
|
|
|
|
|
event::Event::NewEvents(cause) => {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
event::Event::NewEvents(cause) => {}
|
|
|
|
|
|
|
|
|
|
// This is the big boy section of the event loop
|
|
|
|
|
// We : dispatch events and clear the queue, query the loops
|
|
|
|
@ -266,7 +264,7 @@ fn main() {
|
|
|
|
|
}
|
|
|
|
|
accumulator_time += delta_time;
|
|
|
|
|
|
|
|
|
|
while ((accumulator_time - step_size) >= step_size) {
|
|
|
|
|
while accumulator_time - step_size >= step_size {
|
|
|
|
|
accumulator_time -= step_size;
|
|
|
|
|
// ==== DELTA TIME LOCKED ====
|
|
|
|
|
update_schedule.execute(&mut world, &mut resources);
|
|
|
|
@ -280,7 +278,6 @@ fn main() {
|
|
|
|
|
event: WindowEvent::Resized(size),
|
|
|
|
|
..
|
|
|
|
|
} => {
|
|
|
|
|
log::info!("Resizing to {:?}", size);
|
|
|
|
|
let width = size.width;
|
|
|
|
|
let height = size.height;
|
|
|
|
|
|
|
|
|
@ -308,10 +305,67 @@ fn main() {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn entity_loading(world: &mut World, renderer: &mut render::state::RenderState) {
|
|
|
|
|
pub fn load_colliding_mesh_entity(world: &mut World, renderer: &mut render::state::RenderState, mesh_path: &str) {
|
|
|
|
|
|
|
|
|
|
let mut static_floor_body = RigidBodyBuilder::new_static()
|
|
|
|
|
.position(Isometry3::new(Vector3::new(0.0, -8.0, 0.0), Vector::y()))
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
//let pair = import_mesh("./resources/terrain.obj");
|
|
|
|
|
let pair = load_obj(mesh_path);
|
|
|
|
|
|
|
|
|
|
let floor_collider = ColliderBuilder::trimesh(
|
|
|
|
|
pair.0
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|v| {
|
|
|
|
|
let position = v.position();
|
|
|
|
|
Point::<f32>::new(position.x, position.y, position.z)
|
|
|
|
|
})
|
|
|
|
|
.collect(),
|
|
|
|
|
pair.1
|
|
|
|
|
.chunks(3)
|
|
|
|
|
.map(|v| [v[0], v[1], v[2]])
|
|
|
|
|
.collect(),
|
|
|
|
|
)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
let plane_mesh = renderer.load_mesh_to_buffer(
|
|
|
|
|
"./resources/terrain.obj",
|
|
|
|
|
Some(wgpu::Color {
|
|
|
|
|
r: 1.0,
|
|
|
|
|
g: 0.7,
|
|
|
|
|
b: 0.3,
|
|
|
|
|
a: 1.0,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let plane_entity: Entity = world.push((
|
|
|
|
|
Position {
|
|
|
|
|
x: 0.0,
|
|
|
|
|
y: -8.0,
|
|
|
|
|
z: 0.0,
|
|
|
|
|
rot: Euler {
|
|
|
|
|
x: Deg(0.0),
|
|
|
|
|
y: Deg(0.0),
|
|
|
|
|
z: Deg(0.0),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
plane_mesh,
|
|
|
|
|
Physics {
|
|
|
|
|
rigid_body: static_floor_body,
|
|
|
|
|
rigid_body_handle: None,
|
|
|
|
|
},
|
|
|
|
|
Collider {
|
|
|
|
|
collider: floor_collider,
|
|
|
|
|
collider_handle: None,
|
|
|
|
|
},
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let monkey_mesh = renderer.load_mesh_to_buffer("./resources/monkey.obj");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn entity_loading(world: &mut World, renderer: &mut render::state::RenderState) {
|
|
|
|
|
let monkey_mesh =
|
|
|
|
|
renderer.load_mesh_to_buffer("./resources/monkey.obj", Some(wgpu::Color::GREEN));
|
|
|
|
|
|
|
|
|
|
let camera_ent: Entity = world.push((
|
|
|
|
|
Camera {
|
|
|
|
@ -323,16 +377,11 @@ pub fn entity_loading(world: &mut World, renderer: &mut render::state::RenderSta
|
|
|
|
|
yaw: Rad(-PI),
|
|
|
|
|
pitch: Rad(PI / 2.0),
|
|
|
|
|
},
|
|
|
|
|
Color {
|
|
|
|
|
r: 1.0,
|
|
|
|
|
g: 1.0,
|
|
|
|
|
b: 0.5,
|
|
|
|
|
a: 1.0,
|
|
|
|
|
},
|
|
|
|
|
CameraController::new(3.0, 1.0),
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let light_mesh = renderer.load_mesh_to_buffer("./resources/light.obj");
|
|
|
|
|
let light_mesh =
|
|
|
|
|
renderer.load_mesh_to_buffer("./resources/light.obj", Some(wgpu::Color::BLACK));
|
|
|
|
|
|
|
|
|
|
let light_entity: Entity = world.push((
|
|
|
|
|
Position {
|
|
|
|
@ -345,12 +394,6 @@ pub fn entity_loading(world: &mut World, renderer: &mut render::state::RenderSta
|
|
|
|
|
z: Deg(0.0),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Color {
|
|
|
|
|
r: 1.0,
|
|
|
|
|
g: 0.0,
|
|
|
|
|
b: 1.0,
|
|
|
|
|
a: 1.0,
|
|
|
|
|
},
|
|
|
|
|
light_mesh.clone(),
|
|
|
|
|
renderer.create_light(),
|
|
|
|
|
));
|
|
|
|
@ -384,61 +427,42 @@ pub fn entity_loading(world: &mut World, renderer: &mut render::state::RenderSta
|
|
|
|
|
}, //mx: cgmath::Matrix4::from(transform),
|
|
|
|
|
},
|
|
|
|
|
monkey_mesh,
|
|
|
|
|
Color {
|
|
|
|
|
r: 0.0,
|
|
|
|
|
g: 1.0,
|
|
|
|
|
b: 0.0,
|
|
|
|
|
a: 1.0,
|
|
|
|
|
},
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let mut dynamic_ball_body = RigidBodyBuilder::new_dynamic()
|
|
|
|
|
.position(Isometry3::new(Vector3::new(0.0, 0.0, 0.0), Vector::y()))
|
|
|
|
|
.can_sleep(false)
|
|
|
|
|
.mass(1.0)
|
|
|
|
|
//.position(Isometry3::new(Vector3::new(0.0, 10.0, 0.0), Vector::y()))
|
|
|
|
|
.translation(0.0, 35.0, 0.0)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
let mut static_floor_body = RigidBodyBuilder::new_static()
|
|
|
|
|
.position(Isometry3::new(Vector3::new(0.0, -8.0, 0.0), Vector::y()))
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
let ball_collider = ColliderBuilder::ball(1.5).build();
|
|
|
|
|
let floor_collider = ColliderBuilder::cuboid(10.0, 0.2, 10.0).build();
|
|
|
|
|
let pair = load_obj("./resources/ball.obj");
|
|
|
|
|
|
|
|
|
|
let plane_mesh = renderer.load_mesh_to_buffer("./resources/plane.obj");
|
|
|
|
|
let ball_collider = ColliderBuilder::trimesh(
|
|
|
|
|
pair.0
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|v| {
|
|
|
|
|
let position = v.position();
|
|
|
|
|
Point::<f32>::new(position.x, position.y, position.z)
|
|
|
|
|
})
|
|
|
|
|
.collect(),
|
|
|
|
|
pair.1
|
|
|
|
|
//.iter()
|
|
|
|
|
.chunks(3)
|
|
|
|
|
.map(|v| [v[0], v[1], v[2]])
|
|
|
|
|
.collect(),
|
|
|
|
|
)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
let plane_entity: Entity = world.push((
|
|
|
|
|
Position {
|
|
|
|
|
x: 0.0,
|
|
|
|
|
y: -8.0,
|
|
|
|
|
z: 0.0,
|
|
|
|
|
rot: Euler {
|
|
|
|
|
x: Deg(0.0),
|
|
|
|
|
y: Deg(0.0),
|
|
|
|
|
z: Deg(0.0),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
plane_mesh,
|
|
|
|
|
Color {
|
|
|
|
|
r: 1.0,
|
|
|
|
|
g: 0.5,
|
|
|
|
|
b: 0.5,
|
|
|
|
|
a: 1.0,
|
|
|
|
|
},
|
|
|
|
|
Physics {
|
|
|
|
|
rigid_body: static_floor_body,
|
|
|
|
|
rigid_body_handle: None,
|
|
|
|
|
},
|
|
|
|
|
Collider {
|
|
|
|
|
collider: floor_collider,
|
|
|
|
|
collider_handle: None,
|
|
|
|
|
},
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let ball_mesh = renderer.load_mesh_to_buffer("./resources/ball.obj");
|
|
|
|
|
|
|
|
|
|
let ball_mesh = renderer.load_mesh_to_buffer("./resources/ball.obj", Some(wgpu::Color::BLUE));
|
|
|
|
|
|
|
|
|
|
let ball_mesh: Entity = world.push((
|
|
|
|
|
Position {
|
|
|
|
|
x: 0.0,
|
|
|
|
|
y: 0.0,
|
|
|
|
|
y: 20.0,
|
|
|
|
|
z: 0.0,
|
|
|
|
|
rot: Euler {
|
|
|
|
|
x: Deg(25.0),
|
|
|
|
@ -447,12 +471,6 @@ pub fn entity_loading(world: &mut World, renderer: &mut render::state::RenderSta
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
ball_mesh,
|
|
|
|
|
Color {
|
|
|
|
|
r: 1.0,
|
|
|
|
|
g: 0.5,
|
|
|
|
|
b: 0.5,
|
|
|
|
|
a: 1.0,
|
|
|
|
|
},
|
|
|
|
|
Physics {
|
|
|
|
|
rigid_body: dynamic_ball_body,
|
|
|
|
|
rigid_body_handle: None,
|
|
|
|
|