|
|
@ -9,7 +9,9 @@ use legion::world::SubWorld;
|
|
|
|
use legion::IntoQuery;
|
|
|
|
use legion::IntoQuery;
|
|
|
|
use legion::*;
|
|
|
|
use legion::*;
|
|
|
|
use nalgebra::Quaternion as naQuaternion;
|
|
|
|
use nalgebra::Quaternion as naQuaternion;
|
|
|
|
use rapier3d::dynamics::{IntegrationParameters, JointSet, RigidBodyBuilder, RigidBodySet, MassProperties};
|
|
|
|
use rapier3d::dynamics::{
|
|
|
|
|
|
|
|
IntegrationParameters, JointSet, MassProperties, RigidBodyBuilder, RigidBodySet,
|
|
|
|
|
|
|
|
};
|
|
|
|
use rapier3d::geometry::{BroadPhase, ColliderBuilder, ColliderSet, NarrowPhase};
|
|
|
|
use rapier3d::geometry::{BroadPhase, ColliderBuilder, ColliderSet, NarrowPhase};
|
|
|
|
use rapier3d::na::{Isometry3, Vector, Vector3};
|
|
|
|
use rapier3d::na::{Isometry3, Vector, Vector3};
|
|
|
|
use rapier3d::pipeline::{ChannelEventCollector, PhysicsPipeline};
|
|
|
|
use rapier3d::pipeline::{ChannelEventCollector, PhysicsPipeline};
|
|
|
@ -35,10 +37,10 @@ pub fn runtime_spawn(
|
|
|
|
#[resource] runtime_state: &mut RuntimeState,
|
|
|
|
#[resource] runtime_state: &mut RuntimeState,
|
|
|
|
#[resource] renderer: &mut RenderState,
|
|
|
|
#[resource] renderer: &mut RenderState,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
for entity in runtime_state.get_configured_entities() {
|
|
|
|
for entity in &runtime_state.get_entities() {
|
|
|
|
match entity.ent_type.as_ref() {
|
|
|
|
match entity.type_name.as_ref() {
|
|
|
|
"PhysicsEntity" => {
|
|
|
|
"PhysicsEntity" => {
|
|
|
|
let mesh_name = entity.mesh.unwrap();
|
|
|
|
let mesh_name = entity.mesh.as_ref().unwrap();
|
|
|
|
let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) {
|
|
|
|
let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) {
|
|
|
|
None => {
|
|
|
|
None => {
|
|
|
|
log::warn!("Skipping entity with invalid mesh file {:?} ", mesh_name);
|
|
|
|
log::warn!("Skipping entity with invalid mesh file {:?} ", mesh_name);
|
|
|
@ -47,14 +49,13 @@ pub fn runtime_spawn(
|
|
|
|
Some(mesh) => mesh,
|
|
|
|
Some(mesh) => mesh,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let collider = ColliderBuilder::trimesh(
|
|
|
|
|
|
|
|
raw_mesh.vertices.iter().map(|v| v.position()).collect(),
|
|
|
|
|
|
|
|
raw_mesh.indices.clone(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
// let collider = ColliderBuilder::trimesh(
|
|
|
|
let collider = ColliderBuilder::capsule_y(2.0, 1.0).build();
|
|
|
|
// raw_mesh.vertices.iter().map(|v| v.position()).collect(),
|
|
|
|
|
|
|
|
// raw_mesh.indices.clone(),
|
|
|
|
|
|
|
|
// ).density(1.0)
|
|
|
|
|
|
|
|
// .build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let collider = ColliderBuilder::ball(2.0).build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let gpu_mesh_buffer = renderer
|
|
|
|
let gpu_mesh_buffer = renderer
|
|
|
|
.upload_mesh_to_buffer(
|
|
|
|
.upload_mesh_to_buffer(
|
|
|
@ -68,19 +69,7 @@ pub fn runtime_spawn(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let position = match entity.position {
|
|
|
|
let position = Position::from(entity.position.clone());
|
|
|
|
None => Position {
|
|
|
|
|
|
|
|
x: 0.0,
|
|
|
|
|
|
|
|
y: rand::random::<f32>(),
|
|
|
|
|
|
|
|
z: 0.0,
|
|
|
|
|
|
|
|
rot: Euler {
|
|
|
|
|
|
|
|
x: Deg(0.0),
|
|
|
|
|
|
|
|
y: Deg(0.0),
|
|
|
|
|
|
|
|
z: Deg(0.0),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Some(position) => position
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut dynamic_body = RigidBodyBuilder::new_dynamic()
|
|
|
|
let mut dynamic_body = RigidBodyBuilder::new_dynamic()
|
|
|
|
.can_sleep(false)
|
|
|
|
.can_sleep(false)
|
|
|
@ -102,7 +91,7 @@ pub fn runtime_spawn(
|
|
|
|
));
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"Terrain" => {
|
|
|
|
"Terrain" => {
|
|
|
|
let mesh_name = entity.mesh.unwrap();
|
|
|
|
let mesh_name = entity.mesh.clone().unwrap();
|
|
|
|
let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) {
|
|
|
|
let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) {
|
|
|
|
None => {
|
|
|
|
None => {
|
|
|
|
log::warn!("Skipping entity with invalid mesh file {:?} ", mesh_name);
|
|
|
|
log::warn!("Skipping entity with invalid mesh file {:?} ", mesh_name);
|
|
|
@ -111,8 +100,13 @@ pub fn runtime_spawn(
|
|
|
|
Some(mesh) => mesh,
|
|
|
|
Some(mesh) => mesh,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let position = Position::from(entity.position.clone());
|
|
|
|
|
|
|
|
|
|
|
|
let mut static_body = RigidBodyBuilder::new_static()
|
|
|
|
let mut static_body = RigidBodyBuilder::new_static()
|
|
|
|
.position(Isometry3::new(Vector3::new(0.0, -8.0, 0.0), Vector::y()))
|
|
|
|
.position(Isometry3::new(
|
|
|
|
|
|
|
|
Vector3::new(position.x, position.y, position.z),
|
|
|
|
|
|
|
|
Vector::y(),
|
|
|
|
|
|
|
|
))
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
let mesh_collider = ColliderBuilder::trimesh(
|
|
|
|
let mesh_collider = ColliderBuilder::trimesh(
|
|
|
@ -133,21 +127,6 @@ pub fn runtime_spawn(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let position = match entity.position {
|
|
|
|
|
|
|
|
None => Position {
|
|
|
|
|
|
|
|
x: 0.0,
|
|
|
|
|
|
|
|
y: 0.0,
|
|
|
|
|
|
|
|
z: 0.0,
|
|
|
|
|
|
|
|
rot: Euler {
|
|
|
|
|
|
|
|
x: Deg(0.0),
|
|
|
|
|
|
|
|
y: Deg(0.0),
|
|
|
|
|
|
|
|
z: Deg(0.0),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Some(position) => position
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let entity: Entity = cmd.push((
|
|
|
|
let entity: Entity = cmd.push((
|
|
|
|
position,
|
|
|
|
position,
|
|
|
|
gpu_mesh_buffer,
|
|
|
|
gpu_mesh_buffer,
|
|
|
@ -162,21 +141,22 @@ pub fn runtime_spawn(
|
|
|
|
));
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"Camera" => {
|
|
|
|
"Camera" => {
|
|
|
|
|
|
|
|
let position = Position::from(entity.position.clone());
|
|
|
|
let entity: Entity = cmd.push((
|
|
|
|
let entity: Entity = cmd.push((
|
|
|
|
Camera {
|
|
|
|
Camera {
|
|
|
|
position: cgmath::Point3 {
|
|
|
|
position: cgmath::Point3 {
|
|
|
|
x: 0.0,
|
|
|
|
x: position.x,
|
|
|
|
y: 0.0,
|
|
|
|
y: position.y,
|
|
|
|
z: 10.0,
|
|
|
|
z: position.z,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
yaw: Rad(-PI),
|
|
|
|
yaw: Rad(-PI),
|
|
|
|
pitch: Rad(PI / 2.0),
|
|
|
|
pitch: Rad(PI / 2.0),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CameraController::new(3.0, 1.0),
|
|
|
|
CameraController::new(5.0, 1.0),
|
|
|
|
));
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"Light" => {
|
|
|
|
"Light" => {
|
|
|
|
let mesh_name = entity.mesh.unwrap();
|
|
|
|
let mesh_name = entity.mesh.clone().unwrap();
|
|
|
|
let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) {
|
|
|
|
let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) {
|
|
|
|
None => {
|
|
|
|
None => {
|
|
|
|
log::warn!("Skipping entity with invalid mesh file {:?} ", mesh_name);
|
|
|
|
log::warn!("Skipping entity with invalid mesh file {:?} ", mesh_name);
|
|
|
@ -185,19 +165,7 @@ pub fn runtime_spawn(
|
|
|
|
Some(mesh) => mesh,
|
|
|
|
Some(mesh) => mesh,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let position = match entity.position {
|
|
|
|
let position = Position::from(entity.position.clone());
|
|
|
|
None => Position {
|
|
|
|
|
|
|
|
x: 1.0,
|
|
|
|
|
|
|
|
y: 1.0,
|
|
|
|
|
|
|
|
z: 1.0,
|
|
|
|
|
|
|
|
rot: Euler {
|
|
|
|
|
|
|
|
x: Deg(0.0),
|
|
|
|
|
|
|
|
y: Deg(0.0),
|
|
|
|
|
|
|
|
z: Deg(0.0),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Some(position) => position
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let gpu_mesh_buffer = renderer
|
|
|
|
let gpu_mesh_buffer = renderer
|
|
|
|
.upload_mesh_to_buffer(
|
|
|
|
.upload_mesh_to_buffer(
|
|
|
@ -211,11 +179,8 @@ pub fn runtime_spawn(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let light_entity: Entity = cmd.push((
|
|
|
|
let light_entity: Entity =
|
|
|
|
position,
|
|
|
|
cmd.push((position, gpu_mesh_buffer, renderer.create_light()));
|
|
|
|
gpu_mesh_buffer,
|
|
|
|
|
|
|
|
renderer.create_light(),
|
|
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_ => {}
|
|
|
|
_ => {}
|
|
|
|