improve error handling when loading materials

This commit is contained in:
Robin Appelman 2024-09-02 14:13:45 +02:00
commit bfe990521f
4 changed files with 44 additions and 34 deletions

View file

@ -65,7 +65,7 @@ pub fn load_material(
let path = loader
.find_in_paths(&path, &dirs)
.ok_or(Error::Other(format!("Can't find file {}", path)))?;
let raw = loader.load(&path)?.expect("didn't find foudn path?");
let raw = loader.load(&path)?.expect("didn't find found path?");
let vdf = String::from_utf8(raw)?;
let material = from_str(&vdf).map_err(|e| {

View file

@ -131,7 +131,7 @@ pub fn push_or_get_model(
match get_mesh_index(&gltf.meshes, &skinned_name) {
Some(index) => Some(index),
None => {
let prop = load_prop(loader, model).expect("failed to load prop");
let prop = load_prop(loader, model).ok()?;
if prop.vertices().is_empty() {
None
} else {
@ -242,18 +242,11 @@ pub fn push_primitive(
gltf.accessors.push(accessor);
let material = if options.textures {
let texture = skin
.texture_info(mesh.material_index())
.expect("mat out of bounds");
let texture_path = find_material(&texture.name, &texture.search_paths, loader)
.expect("failed to find texture");
Some(push_or_get_material(
buffer,
gltf,
loader,
&texture_path,
options,
))
let texture = skin.texture_info(mesh.material_index());
let texture_path =
texture.and_then(|texture| find_material(&texture.name, &texture.search_paths, loader));
texture_path
.map(|texture_path| push_or_get_material(buffer, gltf, loader, &texture_path, options))
} else {
None
};