mirror of
https://codeberg.org/icewind/vbsp-to-gltf.git
synced 2026-06-03 18:24:07 +02:00
improve error handling when loading materials
This commit is contained in:
parent
7546456665
commit
bfe990521f
4 changed files with 44 additions and 34 deletions
|
|
@ -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| {
|
||||
|
|
|
|||
19
src/prop.rs
19
src/prop.rs
|
|
@ -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
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue