material resolver now gives a warning if it unable to find a texture
resolve
@@ -274,15 +274,15 @@ async fn create_surfaces(
if let Some(filename) = path.file_name() {
let texture_path = match material_search_options {
MaterialSearchOptions::MaterialsDirectory(directory) => {
- directory.join(filename)
+ Some(directory.join(filename))
}
MaterialSearchOptions::RecursiveUp => {
- let mut texture_path = Default::default();
+ let mut texture_path = None;
let mut path = model_path.to_owned();
while let Some(parent) = path.parent() {
let candidate = parent.join(filename);
if io::exists(&candidate).await {
- texture_path = candidate;
+ texture_path = Some(candidate);
break;
}
path.pop();
@@ -290,22 +290,24 @@ async fn create_surfaces(
texture_path
}
MaterialSearchOptions::WorkingDirectory => {
- let mut texture_path = Default::default();
+ let mut texture_path = None;
for dir in WalkDir::new(".").into_iter().flatten() {
if dir.path().is_dir() {
let candidate = dir.path().join(filename);
if candidate.exists() {
- texture_path = candidate;
+ texture_path = Some(candidate);
break;
}
}
}
texture_path
}
- MaterialSearchOptions::UsePathDirectly => path.clone(),
+ MaterialSearchOptions::UsePathDirectly => Some(path.clone()),
};
- let texture = resource_manager.request_texture(texture_path.as_path(), None);
+ if let Some(texture_path) = texture_path {
+ let texture =
+ resource_manager.request_texture(texture_path.as_path(), None);
// Make up your mind, Autodesk.
// Handle all possible combinations of links to auto-import materials.
@@ -329,7 +331,8 @@ async fn create_surfaces(
|| name.contains("displacement_map")
{
Some(("heightTexture", SamplerFallback::Black))
- } else if name.contains("EmissiveColor") || name.contains("emit_color_map") {
+ } else if name.contains("EmissiveColor") || name.contains("emit_color_map")
+ {
Some(("emissionTexture", SamplerFallback::Black))
} else {
None
@@ -343,9 +346,25 @@ async fn create_surfaces(
fallback: usage,
},
) {
- Log::writeln(MessageKind::Error, format!("Unable to set material property {} for FBX material! Reason: {:?}", property_name, e));
+ Log::writeln(
+ MessageKind::Error,
+ format!(
+ "Unable to set material property {}\
+ for FBX material! Reason: {:?}",
+ property_name, e
+ ),
+ );
}
}
+ } else {
+ Log::writeln(
+ MessageKind::Warning,
+ format!(
+ "Unable to find a texture {:?} for 3D model {:?} using {:?} option!",
+ filename, model_path, material_search_options
+ ),
+ );
+ }
}
}
surfaces.push(surface);
