Make primitive materials optional
Previously it wasn't optional, so I couldn't load models without adding a material
This commit is contained in:
parent
e7d3ef2b14
commit
a287a3be2e
1 changed files with 71 additions and 70 deletions
|
|
@ -29,7 +29,7 @@ where
|
||||||
// ---------- MATERIAL ----------
|
// ---------- MATERIAL ----------
|
||||||
let mut mat = Material::default();
|
let mut mat = Material::default();
|
||||||
|
|
||||||
let mat_idx = primitive.material().index().context("primitive has no material")?;
|
if let Some(mat_idx) = primitive.material().index() {
|
||||||
let material = doc.materials().nth(mat_idx).unwrap();
|
let material = doc.materials().nth(mat_idx).unwrap();
|
||||||
let pbr = material.pbr_metallic_roughness();
|
let pbr = material.pbr_metallic_roughness();
|
||||||
|
|
||||||
|
|
@ -85,21 +85,21 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normal map (linear)
|
// Normal map (linear)
|
||||||
if let Some(info) = primitive.material().normal_texture() {
|
if let Some(info) = material.normal_texture() {
|
||||||
update_sampler(&mut mat, &info.texture());
|
update_sampler(&mut mat, &info.texture());
|
||||||
let view = info.texture().source().index();
|
let view = info.texture().source().index();
|
||||||
mat.normal = Some(glium_linear_texture(facade, &images[view])?);
|
mat.normal = Some(glium_linear_texture(facade, &images[view])?);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Occlusion (linear)
|
// Occlusion (linear)
|
||||||
if let Some(info) = primitive.material().occlusion_texture() {
|
if let Some(info) = material.occlusion_texture() {
|
||||||
update_sampler(&mut mat, &info.texture());
|
update_sampler(&mut mat, &info.texture());
|
||||||
let view = info.texture().source().index();
|
let view = info.texture().source().index();
|
||||||
mat.occlusion = Some(glium_linear_texture(facade, &images[view])?);
|
mat.occlusion = Some(glium_linear_texture(facade, &images[view])?);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emissive (sRGB)
|
// Emissive (sRGB)
|
||||||
if let Some(info) = primitive.material().emissive_texture() {
|
if let Some(info) = material.emissive_texture() {
|
||||||
update_sampler(&mut mat, &info.texture());
|
update_sampler(&mut mat, &info.texture());
|
||||||
let view = info.texture().source().index();
|
let view = info.texture().source().index();
|
||||||
mat.emissive = Some(glium_srgb_texture(facade, &images[view])?);
|
mat.emissive = Some(glium_srgb_texture(facade, &images[view])?);
|
||||||
|
|
@ -112,6 +112,7 @@ where
|
||||||
mat.uv_scale = Vec2::new(xform.scale()[0], xform.scale()[1]);
|
mat.uv_scale = Vec2::new(xform.scale()[0], xform.scale()[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ---- Vertex/index data ----
|
// ---- Vertex/index data ----
|
||||||
let reader = primitive.reader(|buf| Some(&buffers[buf.index()].0));
|
let reader = primitive.reader(|buf| Some(&buffers[buf.index()].0));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue