This commit is contained in:
2021-08-15 22:34:29 +02:00
parent c619f945a3
commit 40aa7f635e
11 changed files with 273 additions and 56 deletions

View File

@@ -6,6 +6,8 @@ use gltf::mesh::util::{ReadJoints, ReadNormals, ReadPositions, ReadTangents, Rea
use crate::vulkan::mesh::LoadError::{GltfError, MeshDataMissing, NoIndices};
use crate::vulkan::Vertex;
use super::TextVertex;
#[derive(Debug)]
pub enum LoadError {
GltfError(gltf::Error),
@@ -25,9 +27,15 @@ impl From<String> for LoadError {
}
}
#[derive(Debug)]
pub enum CPUVertex {
Vertex3D(Vertex),
VertexText(TextVertex)
}
#[derive(Debug)]
pub struct CPUMesh {
pub vertices: Vec<Vertex>,
pub vertices: Vec<CPUVertex>,
pub indices: Vec<u32>,
pub local_texture_index: Option<usize>,
pub local_normal_map_index: Option<usize>,
@@ -41,7 +49,7 @@ fn read_file(path: &str) -> Vec<u8> {
glb_bytes
}
pub fn load_mesh(mesh_path: &str, print_status: bool) -> Result<(Vec<CPUMesh>, Document), LoadError> {
pub fn load_mesh<V>(mesh_path: &str, print_status: bool) -> Result<(Vec<CPUMesh>, Document), LoadError> {
let mut start_time = None;
let mut total_vertices = 0;
let mut total_indices = 0;
@@ -80,7 +88,7 @@ pub fn load_mesh(mesh_path: &str, print_status: bool) -> Result<(Vec<CPUMesh>, D
reader.read_tangents(),
reader.read_joints(0),
reader.read_weights(0));
let vertices = vertices_result?;
let vertices = vertices_result?.iter().map(|v| CPUVertex::Vertex3D(v.clone())).collect();
let cpu_mesh = CPUMesh {
vertices,
indices: indices.into_u32().collect(),