From 339351c2073c750fc86b60f0cf506bda1e7ffaf2 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Sun, 18 Jul 2021 18:13:39 -0700 Subject: [PATCH 1/4] remove platform specific uses --- src/main.rs | 1 - src/render/state.rs | 1 - src/render/system.rs | 1 - 3 files changed, 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index c41f163..c55b9e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,7 +45,6 @@ use wgpu_subscriber; use winit_24::event::DeviceEvent::MouseMotion; use winit_24::event::{ElementState, VirtualKeyCode}; use winit_24::event_loop::EventLoopProxy; -use winit_24::platform::unix::x11::ffi::Time; use winit_24::window::Window; use winit_24::{ event::{self, WindowEvent}, diff --git a/src/render/state.rs b/src/render/state.rs index 86815de..1548af1 100644 --- a/src/render/state.rs +++ b/src/render/state.rs @@ -20,7 +20,6 @@ use rapier3d::parry::motion::RigidMotionComposition; use wgpu::util::DeviceExt; use wgpu::{BackendBit, BindGroup, BindGroupLayout, Buffer, BufferBindingType, Device, FragmentState, Instance, Queue, Surface, SwapChain, SwapChainDescriptor, SwapChainFrame, TextureView, VertexState, CommandEncoder}; use winit_24::dpi::PhysicalSize; -use winit_24::platform::unix::x11::ffi::Time; use winit_24::window::Window; use crate::camera::{Camera, CameraController}; diff --git a/src/render/system.rs b/src/render/system.rs index ce3aeb0..3abc569 100644 --- a/src/render/system.rs +++ b/src/render/system.rs @@ -26,7 +26,6 @@ use wgpu::{ TextureView, VertexState, }; use winit_24::dpi::PhysicalSize; -use winit_24::platform::unix::x11::ffi::Time; use winit_24::window::Window; use crate::camera::{Camera, CameraController}; From 73df55b689c40bf713c2c0d1df1b3ebe21a74a96 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Sat, 26 Jun 2021 13:51:02 -0700 Subject: [PATCH 2/4] tweaking for 2d --- conf/entity_spawns.toml | 19 ++----- resources/{20200527_165845.jpg => test.jpg} | Bin resources/textured-plane.mtl | 12 ++++ resources/textured-plane.obj | 17 ++++++ src/geometry.rs | 25 +++++++++ src/main.rs | 4 ++ src/runtime/system.rs | 59 +++++++++++++++++++- 7 files changed, 120 insertions(+), 16 deletions(-) rename resources/{20200527_165845.jpg => test.jpg} (100%) create mode 100644 resources/textured-plane.mtl create mode 100644 resources/textured-plane.obj diff --git a/conf/entity_spawns.toml b/conf/entity_spawns.toml index 2b2c437..4243422 100644 --- a/conf/entity_spawns.toml +++ b/conf/entity_spawns.toml @@ -1,30 +1,21 @@ [[entities]] name = "terrain.1" -type = "Terrain" +type = "StaticMesh" mesh = "test-textured.obj" [[entities]] -name = "ball.1" -type = "PhysicsEntity" -mesh = "ball.obj" +name = "tile.1" +type = "Sprite" +texture = "test.jpg" [entities.position] x = 15.0 y = 15.0 - z = 15.0 + z = 0.0 [entities.position.rotation] x = 0.0 y = 0.0 - z = 0.0 - - [entities.physics] - body_status = "static" - - [entities.physics.cuboid] - x = 1.0 - y = 1.0 - z = 1.0 [[entities]] name = "camera.1" diff --git a/resources/20200527_165845.jpg b/resources/test.jpg similarity index 100% rename from resources/20200527_165845.jpg rename to resources/test.jpg diff --git a/resources/textured-plane.mtl b/resources/textured-plane.mtl new file mode 100644 index 0000000..2e60d3c --- /dev/null +++ b/resources/textured-plane.mtl @@ -0,0 +1,12 @@ +# Blender MTL File: 'None' +# Material Count: 1 + +newmtl Material.001 +Ns 323.999994 +Ka 1.000000 1.000000 1.000000 +Kd 0.800000 0.800000 0.800000 +Ks 0.500000 0.500000 0.500000 +Ke 0.000000 0.000000 0.000000 +Ni 1.000000 +d 1.000000 +illum 2 diff --git a/resources/textured-plane.obj b/resources/textured-plane.obj new file mode 100644 index 0000000..fe4c537 --- /dev/null +++ b/resources/textured-plane.obj @@ -0,0 +1,17 @@ +# Blender v2.93.1 OBJ File: '' +# www.blender.org +mtllib textured-plane.mtl +o Plane +v -1.000000 0.000000 1.000000 +v 1.000000 0.000000 1.000000 +v -1.000000 0.000000 -1.000000 +v 1.000000 0.000000 -1.000000 +vt 1.000000 0.000000 +vt 0.000000 1.000000 +vt 0.000000 0.000000 +vt 1.000000 1.000000 +vn 0.0000 1.0000 0.0000 +usemtl Material.001 +s off +f 2/1/1 3/2/1 1/3/1 +f 2/1/1 4/4/1 3/2/1 diff --git a/src/geometry.rs b/src/geometry.rs index 6224b00..a125ca7 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -112,3 +112,28 @@ pub fn load_obj(obj_path: &str) -> Result { indices: index_data.to_vec(), }) } + +// pub fn create_quad_mesh() -> RawMesh { +// +// let mut index_data: Vec<[u32; 3]> = Vec::new(); +// let mut vertex_data = Vec::new(); +// +// vertex_data.push(Vertex::from( +// [ +// mesh.positions[3 * v], +// mesh.positions[3 * v + 1], +// mesh.positions[3 * v + 2], +// ], +// [ +// mesh.normals[3 * v], +// mesh.normals[3 * v + 1], +// mesh.normals[3 * v + 2], +// ], +// [mesh.texcoords[2 * v], mesh.texcoords[2 * v + 1]], +// )); +// +// RawMesh { +// vertices: vertex_data.to_vec(), +// indices: index_data.to_vec(), +// } +// } diff --git a/src/main.rs b/src/main.rs index c55b9e4..1cbb64a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -107,6 +107,10 @@ Todo: Figure out eventing, GameInput, passing all events, etc. + texturing +I need to figure out the way that I want to do 2d graphics in a 3d engine... +I suppose I will need sprites. And those are just 2 polygons which are textured + + */ diff --git a/src/runtime/system.rs b/src/runtime/system.rs index 6272cc6..d72c92d 100644 --- a/src/runtime/system.rs +++ b/src/runtime/system.rs @@ -19,11 +19,13 @@ use rapier3d::pipeline::{ChannelEventCollector, PhysicsPipeline}; use crate::camera::{Camera, CameraController}; use crate::components::{Collider, ImguiWindow, LoopState, Mesh, Physics, Position}; -use crate::geometry::RawMesh; +use crate::geometry; use crate::physics::state::PhysicsState; use crate::render::state::RenderState; use crate::render::system::{ImguiGenericOutputLine, ImguiPerformanceProfilerLine}; use crate::runtime::state::RuntimeState; +use crate::geometry::create_quad_mesh; +use crate::geometry::RawMesh; pub fn quad_color(color: [f32; 4]) -> [[f32; 4]; 4] { [color, color, color, color] @@ -126,6 +128,59 @@ pub fn runtime_spawn( ) { for entity in &runtime_state.get_entities() { match entity.type_name.as_ref() { + "Sprite" => { + + let raw_mesh = create_quad_mesh(); + + 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" => { let mesh_name = entity.mesh.as_ref().unwrap(); let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) { @@ -178,7 +233,7 @@ pub fn runtime_spawn( ImguiGenericOutputLine::new("wahoo! from a physics entity".to_string()), )); } - "Terrain" => { + "StaticMesh" => { let mesh_name = entity.mesh.clone().unwrap(); let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) { None => { From 00a4a4275afbb1f4ae2997d14bcf44fb173a078e Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Sun, 18 Jul 2021 17:54:41 -0700 Subject: [PATCH 3/4] . --- src/runtime/system.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/runtime/system.rs b/src/runtime/system.rs index d72c92d..932c285 100644 --- a/src/runtime/system.rs +++ b/src/runtime/system.rs @@ -24,7 +24,6 @@ use crate::physics::state::PhysicsState; use crate::render::state::RenderState; use crate::render::system::{ImguiGenericOutputLine, ImguiPerformanceProfilerLine}; use crate::runtime::state::RuntimeState; -use crate::geometry::create_quad_mesh; use crate::geometry::RawMesh; pub fn quad_color(color: [f32; 4]) -> [[f32; 4]; 4] { @@ -130,7 +129,7 @@ pub fn runtime_spawn( match entity.type_name.as_ref() { "Sprite" => { - let raw_mesh = create_quad_mesh(); + let mesh_name = entity.mesh.clone().unwrap(); let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) { @@ -199,6 +198,10 @@ pub fn runtime_spawn( let collider = ColliderBuilder::capsule_y(2.0, 1.0).build(); + + //let mut vec = Vec::new(); + //vec.push() + let gpu_mesh_buffer = renderer .upload_mesh_to_buffer( raw_mesh, From c06d884050c6a0543852d4b0c2e303c57d2008a9 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Sun, 18 Jul 2021 23:42:28 -0700 Subject: [PATCH 4/4] got a good obj file, finally --- resources/texture-test-1.mtl | 13 +++++ resources/texture-test-1.obj | 18 ++++++ src/geometry.rs | 5 ++ src/render/state.rs | 5 -- src/runtime/state.rs | 2 + src/runtime/system.rs | 106 +++++++++++++++++------------------ 6 files changed, 91 insertions(+), 58 deletions(-) create mode 100644 resources/texture-test-1.mtl create mode 100644 resources/texture-test-1.obj diff --git a/resources/texture-test-1.mtl b/resources/texture-test-1.mtl new file mode 100644 index 0000000..906169a --- /dev/null +++ b/resources/texture-test-1.mtl @@ -0,0 +1,13 @@ +# Blender MTL File: 'None' +# Material Count: 1 + +newmtl Material.002 +Ns 225.000000 +Ka 1.000000 1.000000 1.000000 +Kd 0.800000 0.800000 0.800000 +Ks 0.500000 0.500000 0.500000 +Ke 0.000000 0.000000 0.000000 +Ni 1.450000 +d 1.000000 +illum 2 +map_Kd /Users/mitchellhansen/source/minimum-viable-game-engine/resources/test.jpg diff --git a/resources/texture-test-1.obj b/resources/texture-test-1.obj new file mode 100644 index 0000000..f2b97ce --- /dev/null +++ b/resources/texture-test-1.obj @@ -0,0 +1,18 @@ +# Blender v2.93.1 OBJ File: '' +# www.blender.org +mtllib texture-test-1.mtl +o Plane_Plane.001 +v -1.000000 0.000000 1.000000 +v 1.000000 0.000000 1.000000 +v -1.000000 0.000000 -1.000000 +v 1.000000 0.000000 -1.000000 +vt 1.000000 0.000000 +vt 0.000000 1.000000 +vt 0.000000 0.000000 +vt 1.000000 1.000000 +vn 0.0000 1.0000 0.0000 +g Plane_Plane.001_Material.002 +usemtl Material.002 +s off +f 2/1/1 3/2/1 1/3/1 +f 2/1/1 4/4/1 3/2/1 diff --git a/src/geometry.rs b/src/geometry.rs index a125ca7..8af1efa 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -58,6 +58,11 @@ pub fn load_obj(obj_path: &str) -> Result { for model in models { let mesh = &model.mesh; + if let Some(mat_id) = mesh.material_id { + let mat : &Material = materials.get(mat_id).unwrap(); + println!("{:?}", mat); + } + // Cycle through the faces and chunk out the indices let mut next_face = 0; for f in 0..mesh.num_face_indices.len() { diff --git a/src/render/state.rs b/src/render/state.rs index 1548af1..73db5ec 100644 --- a/src/render/state.rs +++ b/src/render/state.rs @@ -290,11 +290,6 @@ impl RenderState { }], }); - /* - There appear to be two passes required for shadows, the shadow pass, and the forward pass - Need to open this up in renderdoc and see what it's actually doing - */ - let shadow_pass = { let uniform_size = mem::size_of::() as wgpu::BufferAddress; diff --git a/src/runtime/state.rs b/src/runtime/state.rs index 6d062d8..c5c3adb 100644 --- a/src/runtime/state.rs +++ b/src/runtime/state.rs @@ -111,5 +111,7 @@ impl RuntimeState { self.mesh_cache.insert(filename, mesh); } } + + panic!("nah"); } } diff --git a/src/runtime/system.rs b/src/runtime/system.rs index 932c285..c34e766 100644 --- a/src/runtime/system.rs +++ b/src/runtime/system.rs @@ -127,59 +127,59 @@ pub fn runtime_spawn( ) { for entity in &runtime_state.get_entities() { 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, - }, - )); - } + // "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" => { let mesh_name = entity.mesh.as_ref().unwrap(); let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) {