config works great, mesh colliders v mesh colliders are very sticky...

master
mitchellhansen 4 years ago
parent f4c6391e37
commit 2b77153f10

@ -9,16 +9,25 @@ type = "PhysicsEntity"
mesh = "ball.obj"
[entities.position]
x = 0.0
y = 0.0
z = 0.0
x = 15.0
y = 3.0
z = 30.0
[[entities]]
name = "camera.1"
type = "Camera"
[entities.position]
x = 15.0
y = 15.0
z = 15.0
[[entities]]
name = "light.1"
type = "Light"
mesh = "light.obj"
mesh = "light.obj"
[entities.position]
x = 20.0
y = 20.0
z = 20.0

@ -2,8 +2,8 @@
# Material Count: 1
newmtl None
Ns 0
Ka 0.000000 0.000000 0.000000
Ns 500
Ka 0.8 0.8 0.8
Kd 0.8 0.8 0.8
Ks 0.8 0.8 0.8
d 1

File diff suppressed because it is too large Load Diff

@ -0,0 +1,10 @@
# Blender MTL File: 'None'
# Material Count: 1
newmtl None
Ns 500
Ka 0.8 0.8 0.8
Kd 0.8 0.8 0.8
Ks 0.8 0.8 0.8
d 1
illum 2

File diff suppressed because it is too large Load Diff

@ -194,7 +194,7 @@ fn main() {
// Physics
let (physics_state, physics_pipeline) =
PhysicsState::build(rapier3d::math::Vector::new(0.0, -9.81, 0.05));
PhysicsState::build(rapier3d::math::Vector::new(0.0, -9.81, 0.0));
resources.insert(physics_state);
resources.insert(physics_pipeline);

@ -117,7 +117,7 @@ pub fn render_test(
if renderer.lights_are_dirty {
renderer.lights_are_dirty = false;
let mut query = <(&mut DirectionalLight, &mut Point3<f32>)>::query();
let mut query = <(&mut DirectionalLight, &mut Position)>::query();
for (i, (light, pos)) in query.iter_mut(world).enumerate() {
renderer.queue.write_buffer(
&renderer.light_uniform_buf,
@ -129,7 +129,7 @@ pub fn render_test(
push_debug_group_checked("shadow passes", &mut encoder);
let mut query = <(&mut DirectionalLight, &mut Point3<f32>)>::query();
let mut query = <(&mut DirectionalLight, &mut Position)>::query();
for (i, (light, pos)) in query.iter_mut(world).enumerate() {
insert_debug_marker_checked(&format!("shadow pass {} (light at position {:?})", i, pos), &mut encoder);

@ -1,14 +1,15 @@
use std::f32::consts::PI;
use std::path::PathBuf;
use std::time::Instant;
use cgmath::{Euler, Quaternion, Deg, Rad, Point3};
use cgmath::{Deg, Euler, Point3, Quaternion, Rad};
use imgui::FontSource;
use legion::*;
use legion::IntoQuery;
use legion::systems::CommandBuffer;
use legion::world::SubWorld;
use legion::IntoQuery;
use legion::*;
use nalgebra::Quaternion as naQuaternion;
use rapier3d::dynamics::{IntegrationParameters, JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::dynamics::{IntegrationParameters, JointSet, RigidBodyBuilder, RigidBodySet, MassProperties};
use rapier3d::geometry::{BroadPhase, ColliderBuilder, ColliderSet, NarrowPhase};
use rapier3d::na::{Isometry3, Vector, Vector3};
use rapier3d::pipeline::{ChannelEventCollector, PhysicsPipeline};
@ -19,14 +20,10 @@ 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)]
pub fn runtime_load(
world: &mut SubWorld,
#[resource] runtime_state: &mut RuntimeState,
) {
pub fn runtime_load(world: &mut SubWorld, #[resource] runtime_state: &mut RuntimeState) {
runtime_state.preload_meshes(PathBuf::from("./resources"));
}
@ -38,8 +35,7 @@ pub fn runtime_spawn(
#[resource] runtime_state: &mut RuntimeState,
#[resource] renderer: &mut RenderState,
) {
for entity in runtime_state.get_configured_entities(){
for entity in runtime_state.get_configured_entities() {
match entity.ent_type.as_ref() {
"PhysicsEntity" => {
let mesh_name = entity.mesh.unwrap();
@ -48,44 +44,52 @@ pub fn runtime_spawn(
log::warn!("Skipping entity with invalid mesh file {:?} ", mesh_name);
continue;
}
Some(mesh) => mesh
Some(mesh) => mesh,
};
let mut dynamic_body = RigidBodyBuilder::new_dynamic()
.can_sleep(false)
.mass(1.0)
.translation(0.0, 0.0, 0.0)
.build();
let collider = ColliderBuilder::trimesh(
raw_mesh.vertices
.iter()
.map(|v| v.position())
.collect(),
raw_mesh.indices.clone(),
).build();
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 entity: Entity = cmd.push((
Position {
// let collider = ColliderBuilder::trimesh(
// 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
.upload_mesh_to_buffer(
raw_mesh,
Some(wgpu::Color {
r: 1.0,
g: 0.7,
b: 0.3,
a: 1.0,
}),
)
.unwrap();
let position = match entity.position {
None => Position {
x: 0.0,
y: 20.0,
y: rand::random::<f32>(),
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),
},
},
Some(position) => position
};
let mut dynamic_body = RigidBodyBuilder::new_dynamic()
.can_sleep(false)
.mass(100.0)
.translation(position.x, position.y, position.z)
.build();
let entity: Entity = cmd.push((
position,
gpu_mesh_buffer,
Physics {
rigid_body: dynamic_body,
@ -96,7 +100,7 @@ pub fn runtime_spawn(
collider_handle: None,
},
));
},
}
"Terrain" => {
let mesh_name = entity.mesh.unwrap();
let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) {
@ -104,7 +108,7 @@ pub fn runtime_spawn(
log::warn!("Skipping entity with invalid mesh file {:?} ", mesh_name);
continue;
}
Some(mesh) => mesh
Some(mesh) => mesh,
};
let mut static_body = RigidBodyBuilder::new_static()
@ -112,28 +116,27 @@ pub fn runtime_spawn(
.build();
let mesh_collider = ColliderBuilder::trimesh(
raw_mesh.vertices
.iter()
.map(|v| v.position())
.collect(),
raw_mesh.vertices.iter().map(|v| v.position()).collect(),
raw_mesh.indices.clone(),
).build();
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 entity: Entity = cmd.push((
Position {
)
.build();
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 position = match entity.position {
None => Position {
x: 0.0,
y: -8.0,
y: 0.0,
z: 0.0,
rot: Euler {
x: Deg(0.0),
@ -141,6 +144,12 @@ pub fn runtime_spawn(
z: Deg(0.0),
},
},
Some(position) => position
};
let entity: Entity = cmd.push((
position,
gpu_mesh_buffer,
Physics {
rigid_body: static_body,
@ -151,9 +160,8 @@ pub fn runtime_spawn(
collider_handle: None,
},
));
},
}
"Camera" => {
let entity: Entity = cmd.push((
Camera {
position: cgmath::Point3 {
@ -166,7 +174,7 @@ pub fn runtime_spawn(
},
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()) {
@ -174,40 +182,43 @@ pub fn runtime_spawn(
log::warn!("Skipping entity with invalid mesh file {:?} ", mesh_name);
continue;
}
Some(mesh) => mesh
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: 5.0,
y: 10.0,
z: 5.0,
let position = match entity.position {
None => Position {
x: 1.0,
y: 1.0,
z: 1.0,
rot: Euler {
x: Deg(0.0),
y: Deg(-25.0),
y: Deg(0.0),
z: Deg(0.0),
},
},
Some(position) => position
};
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,
gpu_mesh_buffer,
renderer.create_light(),
));
}
_ => {},
_ => {}
}
}
}

Loading…
Cancel
Save