Skip to content

Commit

Permalink
improve error handling when loading materials
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Sep 2, 2024
1 parent 7546456 commit bfe9905
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 34 deletions.
54 changes: 35 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "vbsp-to-gltf"
version = "0.1.0"
edition = "2021"
rust-version = "1.80.0"
default-run = "vbsp-to-gltf"

[lib]
name = "vbsp_to_gltf"
Expand All @@ -27,7 +28,7 @@ tracing-tree = "0.4.0"
vtf = "0.3.0"
vmt-parser = "0.2.0"
image = "0.25.2"
tf-asset-loader = { version = "0.1.5", features = ["zip"] }
tf-asset-loader = { version = "0.1.7", features = ["zip"] }
vmdl = "0.2"
clap = { version = "4.4.18", features = ["derive"] }
gltf-json = { version = "1.4.1", features = ["KHR_texture_transform"] }
Expand Down
2 changes: 1 addition & 1 deletion src/materials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
19 changes: 6 additions & 13 deletions src/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
};
Expand Down

0 comments on commit bfe9905

Please sign in to comment.