@ -26,7 +26,7 @@ use winit_24::window::Window;
use crate ::camera ::{ Camera , CameraController } ;
use crate ::components ::{ Mesh , Position , RangeCopy } ;
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 ::light ::{ DirectionalLight , LightRaw } ;
use crate ::render ::{ EntityUniforms , ShadowUniforms , ForwardUniforms } ;
@ -112,21 +112,30 @@ impl RenderState {
/// TODO I really should remove this / consolidate it
fn create_buffer (
device : & wgpu ::Device ,
indices : Vec < u32 > ,
vertices : Vec < Vertex > ,
raw_mesh : RawMesh ,
) -> ( Arc < Buffer > , Arc < Buffer > ) {
let vertex_buf = Arc ::new (
device . create_buffer_init ( & wgpu ::util ::BufferInitDescriptor {
label : Some ( "vertex-buffer" ) ,
contents : bytemuck ::cast_slice ( & vertices) ,
contents : bytemuck ::cast_slice ( & raw_mesh. vertices) ,
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 (
device . create_buffer_init ( & wgpu ::util ::BufferInitDescriptor {
label : Some ( "index-buffer" ) ,
contents : bytemuck ::cast_slice ( & indices ) ,
contents : bytemuck ::cast_slice ( & raw_mesh. indices) ,
usage : wgpu ::BufferUsage ::INDEX ,
} ) ,
) ;
@ -134,11 +143,16 @@ impl RenderState {
( 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 {
let ( vertices , indices ) = load_obj ( filepath ) ;
let index_count = indices . len ( ) ;
let raw_mesh = load_obj ( filepath ) ;
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 ;