|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
use std::time::Instant;
|
|
|
|
|
|
|
|
|
|
use cgmath::{Euler, Quaternion, Deg};
|
|
|
|
|
use cgmath::{Euler, Quaternion, Deg, Rad, Point3};
|
|
|
|
|
use imgui::FontSource;
|
|
|
|
|
use legion::*;
|
|
|
|
|
use legion::IntoQuery;
|
|
|
|
@ -19,6 +19,7 @@ use crate::geometry::RawMesh;
|
|
|
|
|
use crate::physics::state::PhysicsState;
|
|
|
|
|
use crate::render::state::RenderState;
|
|
|
|
|
use crate::runtime::state::RuntimeState;
|
|
|
|
|
use std::f32::consts::PI;
|
|
|
|
|
|
|
|
|
|
#[system]
|
|
|
|
|
#[write_component(Mesh)]
|
|
|
|
@ -40,20 +41,23 @@ pub fn runtime_spawn(
|
|
|
|
|
|
|
|
|
|
for entity in runtime_state.get_configured_entities(){
|
|
|
|
|
match entity.ent_type.as_ref() {
|
|
|
|
|
"Terrain" => {
|
|
|
|
|
let raw_mesh = match runtime_state.get_mesh(entity.mesh.as_str()) {
|
|
|
|
|
"PhysicsEntity" => {
|
|
|
|
|
let mesh_name = entity.mesh.unwrap();
|
|
|
|
|
let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) {
|
|
|
|
|
None => {
|
|
|
|
|
log::warn!("Skipping entity with invalid mesh file {:?} ", entity.mesh);
|
|
|
|
|
log::warn!("Skipping entity with invalid mesh file {:?} ", mesh_name);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
Some(mesh) => mesh
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let mut static_body = RigidBodyBuilder::new_static()
|
|
|
|
|
.position(Isometry3::new(Vector3::new(0.0, -8.0, 0.0), Vector::y()))
|
|
|
|
|
let mut dynamic_body = RigidBodyBuilder::new_dynamic()
|
|
|
|
|
.can_sleep(false)
|
|
|
|
|
.mass(1.0)
|
|
|
|
|
.translation(0.0, 0.0, 0.0)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
let mesh_collider = ColliderBuilder::trimesh(
|
|
|
|
|
let collider = ColliderBuilder::trimesh(
|
|
|
|
|
raw_mesh.vertices
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|v| v.position())
|
|
|
|
@ -71,46 +75,43 @@ pub fn runtime_spawn(
|
|
|
|
|
})
|
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let entity: Entity = cmd.push((
|
|
|
|
|
Position {
|
|
|
|
|
x: 0.0,
|
|
|
|
|
y: -8.0,
|
|
|
|
|
y: 20.0,
|
|
|
|
|
z: 0.0,
|
|
|
|
|
rot: Euler {
|
|
|
|
|
x: Deg(0.0),
|
|
|
|
|
y: Deg(0.0),
|
|
|
|
|
z: Deg(0.0),
|
|
|
|
|
x: Deg(25.0),
|
|
|
|
|
y: Deg(45.0),
|
|
|
|
|
z: Deg(15.0),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
gpu_mesh_buffer,
|
|
|
|
|
Physics {
|
|
|
|
|
rigid_body: static_body,
|
|
|
|
|
rigid_body: dynamic_body,
|
|
|
|
|
rigid_body_handle: None,
|
|
|
|
|
},
|
|
|
|
|
Collider {
|
|
|
|
|
collider: mesh_collider,
|
|
|
|
|
collider: collider,
|
|
|
|
|
collider_handle: None,
|
|
|
|
|
},
|
|
|
|
|
));
|
|
|
|
|
},
|
|
|
|
|
"PhysicsEntity" => {
|
|
|
|
|
|
|
|
|
|
let raw_mesh = match runtime_state.get_mesh(entity.mesh.as_str()) {
|
|
|
|
|
"Terrain" => {
|
|
|
|
|
let mesh_name = entity.mesh.unwrap();
|
|
|
|
|
let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) {
|
|
|
|
|
None => {
|
|
|
|
|
log::warn!("Skipping entity with invalid mesh file {:?} ", entity.mesh);
|
|
|
|
|
log::warn!("Skipping entity with invalid mesh file {:?} ", mesh_name);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
Some(mesh) => mesh
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let mut dynamic_body = RigidBodyBuilder::new_dynamic()
|
|
|
|
|
.can_sleep(false)
|
|
|
|
|
.mass(1.0)
|
|
|
|
|
.translation(0.0, 35.0, 0.0)
|
|
|
|
|
let mut static_body = RigidBodyBuilder::new_static()
|
|
|
|
|
.position(Isometry3::new(Vector3::new(0.0, -8.0, 0.0), Vector::y()))
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
let collider = ColliderBuilder::trimesh(
|
|
|
|
|
let mesh_collider = ColliderBuilder::trimesh(
|
|
|
|
|
raw_mesh.vertices
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|v| v.position())
|
|
|
|
@ -128,28 +129,81 @@ pub fn runtime_spawn(
|
|
|
|
|
})
|
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let entity: Entity = cmd.push((
|
|
|
|
|
Position {
|
|
|
|
|
x: 0.0,
|
|
|
|
|
y: 20.0,
|
|
|
|
|
y: -8.0,
|
|
|
|
|
z: 0.0,
|
|
|
|
|
rot: Euler {
|
|
|
|
|
x: Deg(25.0),
|
|
|
|
|
y: Deg(45.0),
|
|
|
|
|
z: Deg(15.0),
|
|
|
|
|
x: Deg(0.0),
|
|
|
|
|
y: Deg(0.0),
|
|
|
|
|
z: Deg(0.0),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
gpu_mesh_buffer,
|
|
|
|
|
Physics {
|
|
|
|
|
rigid_body: dynamic_body,
|
|
|
|
|
rigid_body: static_body,
|
|
|
|
|
rigid_body_handle: None,
|
|
|
|
|
},
|
|
|
|
|
Collider {
|
|
|
|
|
collider: collider,
|
|
|
|
|
collider: mesh_collider,
|
|
|
|
|
collider_handle: None,
|
|
|
|
|
},
|
|
|
|
|
));
|
|
|
|
|
},
|
|
|
|
|
"Camera" => {
|
|
|
|
|
|
|
|
|
|
let entity: Entity = cmd.push((
|
|
|
|
|
Camera {
|
|
|
|
|
position: cgmath::Point3 {
|
|
|
|
|
x: 0.0,
|
|
|
|
|
y: 0.0,
|
|
|
|
|
z: 10.0,
|
|
|
|
|
},
|
|
|
|
|
yaw: Rad(-PI),
|
|
|
|
|
pitch: Rad(PI / 2.0),
|
|
|
|
|
},
|
|
|
|
|
CameraController::new(3.0, 1.0),
|
|
|
|
|
));
|
|
|
|
|
},
|
|
|
|
|
"Light" => {
|
|
|
|
|
let mesh_name = entity.mesh.unwrap();
|
|
|
|
|
let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) {
|
|
|
|
|
None => {
|
|
|
|
|
log::warn!("Skipping entity with invalid mesh file {:?} ", mesh_name);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
Some(mesh) => mesh
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let gpu_mesh_buffer = renderer.upload_mesh_to_buffer(
|
|
|
|
|
raw_mesh,
|
|
|
|
|
Some(wgpu::Color {
|
|
|
|
|
r: 1.0,
|
|
|
|
|
g: 0.7,
|
|
|
|
|
b: 0.3,
|
|
|
|
|
a: 1.0,
|
|
|
|
|
})
|
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
|
|
let light_entity: Entity = cmd.push((
|
|
|
|
|
Position {
|
|
|
|
|
x: 0.0,
|
|
|
|
|
y: 0.0,
|
|
|
|
|
z: 0.0,
|
|
|
|
|
rot: Euler {
|
|
|
|
|
x: Deg(0.0),
|
|
|
|
|
y: Deg(-25.0),
|
|
|
|
|
z: Deg(0.0),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
gpu_mesh_buffer,
|
|
|
|
|
renderer.create_light(),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_ => {},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|