Compare commits

...

3 Commits

Author SHA1 Message Date
mitchellhansen 00a4a4275a .
3 years ago
mitchellhansen 73df55b689 tweaking for 2d
3 years ago
mitchellhansen 339351c207 remove platform specific uses
3 years ago

@ -1,30 +1,21 @@
[[entities]] [[entities]]
name = "terrain.1" name = "terrain.1"
type = "Terrain" type = "StaticMesh"
mesh = "test-textured.obj" mesh = "test-textured.obj"
[[entities]] [[entities]]
name = "ball.1" name = "tile.1"
type = "PhysicsEntity" type = "Sprite"
mesh = "ball.obj" texture = "test.jpg"
[entities.position] [entities.position]
x = 15.0 x = 15.0
y = 15.0 y = 15.0
z = 15.0 z = 0.0
[entities.position.rotation] [entities.position.rotation]
x = 0.0 x = 0.0
y = 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]] [[entities]]
name = "camera.1" name = "camera.1"

@ -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

@ -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

@ -112,3 +112,28 @@ pub fn load_obj(obj_path: &str) -> Result<RawMesh, String> {
indices: index_data.to_vec(), 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(),
// }
// }

@ -45,7 +45,6 @@ use wgpu_subscriber;
use winit_24::event::DeviceEvent::MouseMotion; use winit_24::event::DeviceEvent::MouseMotion;
use winit_24::event::{ElementState, VirtualKeyCode}; use winit_24::event::{ElementState, VirtualKeyCode};
use winit_24::event_loop::EventLoopProxy; use winit_24::event_loop::EventLoopProxy;
use winit_24::platform::unix::x11::ffi::Time;
use winit_24::window::Window; use winit_24::window::Window;
use winit_24::{ use winit_24::{
event::{self, WindowEvent}, event::{self, WindowEvent},
@ -108,6 +107,10 @@ Todo:
Figure out eventing, GameInput, passing all events, etc. Figure out eventing, GameInput, passing all events, etc.
+ texturing + 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
*/ */

@ -20,7 +20,6 @@ use rapier3d::parry::motion::RigidMotionComposition;
use wgpu::util::DeviceExt; use wgpu::util::DeviceExt;
use wgpu::{BackendBit, BindGroup, BindGroupLayout, Buffer, BufferBindingType, Device, FragmentState, Instance, Queue, Surface, SwapChain, SwapChainDescriptor, SwapChainFrame, TextureView, VertexState, CommandEncoder}; 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::dpi::PhysicalSize;
use winit_24::platform::unix::x11::ffi::Time;
use winit_24::window::Window; use winit_24::window::Window;
use crate::camera::{Camera, CameraController}; use crate::camera::{Camera, CameraController};

@ -26,7 +26,6 @@ use wgpu::{
TextureView, VertexState, TextureView, VertexState,
}; };
use winit_24::dpi::PhysicalSize; use winit_24::dpi::PhysicalSize;
use winit_24::platform::unix::x11::ffi::Time;
use winit_24::window::Window; use winit_24::window::Window;
use crate::camera::{Camera, CameraController}; use crate::camera::{Camera, CameraController};

@ -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 => {

Loading…
Cancel
Save