|
|
@ -26,7 +26,7 @@ use winit_24::window::Window;
|
|
|
|
use crate::camera::{Camera, CameraController};
|
|
|
|
use crate::camera::{Camera, CameraController};
|
|
|
|
use crate::components::{Mesh, Position, RangeCopy};
|
|
|
|
use crate::components::{Mesh, Position, RangeCopy};
|
|
|
|
use crate::current_ui;
|
|
|
|
use crate::current_ui;
|
|
|
|
use crate::geometry::{load_obj, Vertex};
|
|
|
|
use crate::geometry::{load_obj, Vertex, RawMesh};
|
|
|
|
use crate::imgui_supp::imgui_support::{ImguiContext, ImguiPlatform};
|
|
|
|
use crate::imgui_supp::imgui_support::{ImguiContext, ImguiPlatform};
|
|
|
|
use crate::light::{DirectionalLight, LightRaw};
|
|
|
|
use crate::light::{DirectionalLight, LightRaw};
|
|
|
|
use crate::render::{EntityUniforms, ShadowUniforms, ForwardUniforms};
|
|
|
|
use crate::render::{EntityUniforms, ShadowUniforms, ForwardUniforms};
|
|
|
@ -112,21 +112,30 @@ impl RenderState {
|
|
|
|
/// TODO I really should remove this / consolidate it
|
|
|
|
/// TODO I really should remove this / consolidate it
|
|
|
|
fn create_buffer(
|
|
|
|
fn create_buffer(
|
|
|
|
device: &wgpu::Device,
|
|
|
|
device: &wgpu::Device,
|
|
|
|
indices: Vec<u32>,
|
|
|
|
raw_mesh: RawMesh,
|
|
|
|
vertices: Vec<Vertex>,
|
|
|
|
|
|
|
|
) -> (Arc<Buffer>, Arc<Buffer>) {
|
|
|
|
) -> (Arc<Buffer>, Arc<Buffer>) {
|
|
|
|
let vertex_buf = Arc::new(
|
|
|
|
let vertex_buf = Arc::new(
|
|
|
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
|
|
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
|
|
|
label: Some("vertex-buffer"),
|
|
|
|
label: Some("vertex-buffer"),
|
|
|
|
contents: bytemuck::cast_slice(&vertices),
|
|
|
|
contents: bytemuck::cast_slice(&raw_mesh.vertices),
|
|
|
|
usage: wgpu::BufferUsage::VERTEX,
|
|
|
|
usage: wgpu::BufferUsage::VERTEX,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//println!("{:x?}", raw_mesh.indices);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// let mut hack = Vec::<u32>::new();
|
|
|
|
|
|
|
|
// for ind_chunk in raw_mesh.indices {
|
|
|
|
|
|
|
|
// hack.push(ind_chunk[0]);
|
|
|
|
|
|
|
|
// hack.push(ind_chunk[1]);
|
|
|
|
|
|
|
|
// hack.push(ind_chunk[2]);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
let index_buf = Arc::new(
|
|
|
|
let index_buf = Arc::new(
|
|
|
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
|
|
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
|
|
|
label: Some("index-buffer"),
|
|
|
|
label: Some("index-buffer"),
|
|
|
|
contents: bytemuck::cast_slice(&indices),
|
|
|
|
contents: bytemuck::cast_slice(&raw_mesh.indices),
|
|
|
|
usage: wgpu::BufferUsage::INDEX,
|
|
|
|
usage: wgpu::BufferUsage::INDEX,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -134,11 +143,16 @@ impl RenderState {
|
|
|
|
(vertex_buf, index_buf)
|
|
|
|
(vertex_buf, index_buf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Take a meshes
|
|
|
|
|
|
|
|
pub fn upload_mesh_to_buffer(mesh: RawMesh) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn load_mesh_to_buffer(&self, filepath: &str, color: Option<wgpu::Color>) -> Mesh {
|
|
|
|
pub fn load_mesh_to_buffer(&self, filepath: &str, color: Option<wgpu::Color>) -> Mesh {
|
|
|
|
let (vertices, indices) = load_obj(filepath);
|
|
|
|
let raw_mesh = load_obj(filepath);
|
|
|
|
let index_count = indices.len();
|
|
|
|
let index_count = raw_mesh.indices.len() * 3; // TODO bad bad bad bad!
|
|
|
|
|
|
|
|
|
|
|
|
let (vertex_buf, index_buf) = RenderState::create_buffer(&self.device, indices, vertices);
|
|
|
|
let (vertex_buf, index_buf) = RenderState::create_buffer(&self.device, raw_mesh);
|
|
|
|
|
|
|
|
|
|
|
|
let uniform_size = mem::size_of::<EntityUniforms>() as wgpu::BufferAddress;
|
|
|
|
let uniform_size = mem::size_of::<EntityUniforms>() as wgpu::BufferAddress;
|
|
|
|
|
|
|
|
|
|
|
|