update text texture and mesh!!
This commit is contained in:
@@ -432,14 +432,6 @@ impl VulkanRenderer {
|
||||
}
|
||||
|
||||
pub fn upload_mesh(self: &mut Self, mesh: CPUMesh, original_path: Option<String>) -> usize {
|
||||
// let mut collision_mesh = mgf::Mesh::new();
|
||||
// mesh.vertices.iter().for_each(|v| {
|
||||
// collision_mesh.push_vert(v.position.into());
|
||||
// }); // TODO: convert vert pos to world space
|
||||
// for i in (0..mesh.indices.len()).step_by(3) {
|
||||
// collision_mesh.push_face((mesh.indices[i] as usize, mesh.indices[i + 1] as usize, mesh.indices[i + 2] as usize));
|
||||
// }
|
||||
|
||||
let index_buffer = CpuAccessibleBuffer::from_iter(self.device.clone(), BufferUsage::index_buffer(), false, mesh.indices.into_iter()).unwrap();
|
||||
|
||||
match mesh.vertices.get(0).unwrap() {
|
||||
@@ -465,6 +457,31 @@ impl VulkanRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_mesh(self: &mut Self, mesh_index: usize, vertices: Vec<CPUVertex>, indices: Vec<u32>) {
|
||||
let index_buffer = CpuAccessibleBuffer::from_iter(self.device.clone(), BufferUsage::index_buffer(), false, indices.into_iter()).unwrap();
|
||||
|
||||
match vertices.get(0).unwrap() {
|
||||
CPUVertex::Vertex3D(_) => {
|
||||
let verts: Vec<Vertex> = vertices.into_iter().filter_map(|v| match v {
|
||||
CPUVertex::Vertex3D(vert) => Some(vert),
|
||||
CPUVertex::VertexText(_) => None
|
||||
}).collect();
|
||||
let mesh = &mut self.game_data.meshes[mesh_index];
|
||||
mesh.vertex_buffer = CpuAccessibleBuffer::from_iter(self.device.clone(), BufferUsage::vertex_buffer(), false, verts.into_iter()).unwrap();
|
||||
mesh.index_buffer = index_buffer;
|
||||
},
|
||||
CPUVertex::VertexText(_) => {
|
||||
let verts: Vec<TextVertex> = vertices.into_iter().filter_map(|v| match v {
|
||||
CPUVertex::Vertex3D(_) => None,
|
||||
CPUVertex::VertexText(vert) => Some(vert)
|
||||
}).collect();
|
||||
let mesh = &mut self.game_data.meshes_text[mesh_index];
|
||||
mesh.vertex_buffer = CpuAccessibleBuffer::from_iter(self.device.clone(), BufferUsage::vertex_buffer(), false, verts.into_iter()).unwrap();
|
||||
mesh.index_buffer = index_buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn upload_texture(self: &mut Self, bytes: &[u8], width: u32, height: u32, format: Format, filter: Filter, wrap: SamplerAddressMode, device: Arc<Device>) -> Texture {
|
||||
let dimensions = Dimensions::Dim2d { width, height };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user