|
|
@ -19,11 +19,12 @@ use rapier3d::pipeline::{ChannelEventCollector, PhysicsPipeline};
|
|
|
|
|
|
|
|
|
|
|
|
use crate::camera::{Camera, CameraController};
|
|
|
|
use crate::camera::{Camera, CameraController};
|
|
|
|
use crate::components::{Collider, ImguiWindow, LoopState, Mesh, Physics, Position};
|
|
|
|
use crate::components::{Collider, ImguiWindow, LoopState, Mesh, Physics, Position};
|
|
|
|
use crate::geometry::RawMesh;
|
|
|
|
use crate::geometry;
|
|
|
|
use crate::physics::state::PhysicsState;
|
|
|
|
use crate::physics::state::PhysicsState;
|
|
|
|
use crate::render::state::RenderState;
|
|
|
|
use crate::render::state::RenderState;
|
|
|
|
use crate::render::system::{ImguiGenericOutputLine, ImguiPerformanceProfilerLine};
|
|
|
|
use crate::render::system::{ImguiGenericOutputLine, ImguiPerformanceProfilerLine};
|
|
|
|
use crate::runtime::state::RuntimeState;
|
|
|
|
use crate::runtime::state::RuntimeState;
|
|
|
|
|
|
|
|
use crate::geometry::RawMesh;
|
|
|
|
|
|
|
|
|
|
|
|
pub fn quad_color(color: [f32; 4]) -> [[f32; 4]; 4] {
|
|
|
|
pub fn quad_color(color: [f32; 4]) -> [[f32; 4]; 4] {
|
|
|
|
[color, color, color, color]
|
|
|
|
[color, color, color, color]
|
|
|
@ -126,6 +127,59 @@ pub fn runtime_spawn(
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
for entity in &runtime_state.get_entities() {
|
|
|
|
for entity in &runtime_state.get_entities() {
|
|
|
|
match entity.type_name.as_ref() {
|
|
|
|
match entity.type_name.as_ref() {
|
|
|
|
|
|
|
|
"Sprite" => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mesh_name = entity.mesh.clone().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 position = Position::from(entity.position.clone());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut static_body = RigidBodyBuilder::new_static()
|
|
|
|
|
|
|
|
.position(Isometry3::new(
|
|
|
|
|
|
|
|
Vector3::new(position.x, position.y, position.z),
|
|
|
|
|
|
|
|
Vector::y(),
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mesh_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,
|
|
|
|
|
|
|
|
gpu_mesh_buffer,
|
|
|
|
|
|
|
|
Physics {
|
|
|
|
|
|
|
|
rigid_body: static_body,
|
|
|
|
|
|
|
|
rigid_body_handle: None,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Collider {
|
|
|
|
|
|
|
|
collider: mesh_collider,
|
|
|
|
|
|
|
|
collider_handle: None,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
}
|
|
|
|
"PhysicsEntity" => {
|
|
|
|
"PhysicsEntity" => {
|
|
|
|
let mesh_name = entity.mesh.as_ref().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()) {
|
|
|
@ -144,6 +198,10 @@ pub fn runtime_spawn(
|
|
|
|
|
|
|
|
|
|
|
|
let collider = ColliderBuilder::capsule_y(2.0, 1.0).build();
|
|
|
|
let collider = ColliderBuilder::capsule_y(2.0, 1.0).build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//let mut vec = Vec::new();
|
|
|
|
|
|
|
|
//vec.push()
|
|
|
|
|
|
|
|
|
|
|
|
let gpu_mesh_buffer = renderer
|
|
|
|
let gpu_mesh_buffer = renderer
|
|
|
|
.upload_mesh_to_buffer(
|
|
|
|
.upload_mesh_to_buffer(
|
|
|
|
raw_mesh,
|
|
|
|
raw_mesh,
|
|
|
@ -178,7 +236,7 @@ pub fn runtime_spawn(
|
|
|
|
ImguiGenericOutputLine::new("wahoo! from a physics entity".to_string()),
|
|
|
|
ImguiGenericOutputLine::new("wahoo! from a physics entity".to_string()),
|
|
|
|
));
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"Terrain" => {
|
|
|
|
"StaticMesh" => {
|
|
|
|
let mesh_name = entity.mesh.clone().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 => {
|
|
|
|