going to make entity spawning a little easier

This commit is contained in:
2021-02-18 19:54:06 -08:00
parent 722bf45a7a
commit e3c1ce7789
8 changed files with 195 additions and 170 deletions

View File

@@ -24,9 +24,9 @@ use winit_24::platform::unix::x11::ffi::Time;
use winit_24::window::Window;
use crate::camera::{Camera, CameraController};
use crate::components::{Color, Mesh, Position, RangeCopy};
use crate::components::{Mesh, Position, RangeCopy};
use crate::current_ui;
use crate::geometry::{import_mesh, vertex, Vertex};
use crate::geometry::{load_obj, Vertex};
use crate::imgui_supp::imgui_support::{ImguiContext, ImguiPlatform};
use crate::light::{DirectionalLight, LightRaw};
use crate::render::{EntityUniforms, ShadowUniforms, ForwardUniforms};
@@ -134,6 +134,46 @@ impl RenderState {
(vertex_buf, index_buf)
}
pub fn load_mesh_to_buffer(&self, filepath: &str, color: Option<wgpu::Color>) -> Mesh {
let (vertices, indices) = load_obj(filepath);
let index_count = indices.len();
let (vertex_buf, index_buf) = RenderState::create_buffer(&self.device, indices, vertices);
let uniform_size = mem::size_of::<EntityUniforms>() as wgpu::BufferAddress;
let uniform_buf = Arc::new(self.device.create_buffer(&wgpu::BufferDescriptor {
label: Some("Mesh Uniform Buf"),
size: uniform_size,
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
mapped_at_creation: false,
}));
let bind_group = Arc::new(self.device.create_bind_group(&wgpu::BindGroupDescriptor {
label: Some("Mesh Bind Group"),
layout: &self.entity_bind_group_layout,
entries: &[wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::Buffer {
buffer: &uniform_buf,
offset: 0,
size: wgpu::BufferSize::new(uniform_size),
},
}],
}));
Mesh {
index_buffer: index_buf,
index_count: index_count,
// TODO: This is hardcoded by tobj, maybe think about doing something a little more clever?
index_format: wgpu::IndexFormat::Uint32,
vertex_buffer: vertex_buf,
uniform_buffer: uniform_buf,
bind_group: bind_group,
color: color.unwrap_or(wgpu::Color::RED),
}
}
/// When creating a light we have to give it a target view to render to
/// This is major danger scary since we have a 10 light limit, and only
/// 2 views created at this moment, need to smarten this up
@@ -170,44 +210,6 @@ impl RenderState {
}
}
pub fn load_mesh_to_buffer(&self, filepath: &str) -> Mesh {
let (vertices, indices) = import_mesh(filepath);
let index_count = indices.len();
let (vertex_buf, index_buf) = RenderState::create_buffer(&self.device, indices, vertices);
let uniform_size = mem::size_of::<EntityUniforms>() as wgpu::BufferAddress;
let uniform_buf = Arc::new(self.device.create_buffer(&wgpu::BufferDescriptor {
label: Some("Mesh Uniform Buf"),
size: uniform_size,
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
mapped_at_creation: false,
}));
let bind_group = Arc::new(self.device.create_bind_group(&wgpu::BindGroupDescriptor {
label: Some("Mesh Bind Group"),
layout: &self.entity_bind_group_layout,
entries: &[wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::Buffer {
buffer: &uniform_buf,
offset: 0,
size: wgpu::BufferSize::new(uniform_size),
},
}],
}));
Mesh {
index_buffer: index_buf,
index_count: index_count,
// TODO: This is hardcoded by tobj, maybe think about doing something a little more clever?
index_format: wgpu::IndexFormat::Uint32,
vertex_buffer: vertex_buf,
uniform_buffer: uniform_buf,
bind_group: bind_group,
}
}
pub fn init(window: &Window, imgui_context: &mut ImguiContext) -> RenderState {
// Grab the GPU instance, and query its features
let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
@@ -437,7 +439,7 @@ impl RenderState {
cgmath::Deg(75f32), // FOV, might wanna hook this up somewhere
sc_desc.width as f32 / sc_desc.height as f32,
1.0,
20.0,
50.0,
);
let forward_pass = {