Use a default white texture, srgb clear color
This commit is contained in:
parent
9349c45431
commit
066ec023f2
|
@ -91,7 +91,7 @@ pub struct Model {
|
|||
pub materials: HashMap<String, Material>,
|
||||
|
||||
/// Map associating the name of a texture and the real texture.
|
||||
pub textures: HashMap<String, Option<SrgbTexture2d>>,
|
||||
pub textures: HashMap<String, SrgbTexture2d>,
|
||||
|
||||
/// The list of parts of the model.
|
||||
pub parts: Vec<Part>,
|
||||
|
@ -157,6 +157,7 @@ impl Model {
|
|||
if let Some(id) = face.id {
|
||||
face.id = Some(id + face_offset);
|
||||
}
|
||||
face.material_name = new_part.material_name.clone();
|
||||
new_part.faces.push(face.clone());
|
||||
self.faces.push(face.clone());
|
||||
}
|
||||
|
@ -167,6 +168,7 @@ impl Model {
|
|||
for (name, material) in other.materials {
|
||||
let entry = self.materials.entry(name);
|
||||
if let Entry::Occupied(_) = entry {
|
||||
eprintln!("Warning: materials merged but sharing the same name");
|
||||
// Return error
|
||||
} else {
|
||||
entry.or_insert(material);
|
||||
|
@ -177,6 +179,7 @@ impl Model {
|
|||
for (name, texture) in other.textures {
|
||||
let entry = self.textures.entry(name);
|
||||
if let Entry::Occupied(_) = entry {
|
||||
eprintln!("Warning: textures merged but sharing the same name");
|
||||
// return Error;
|
||||
} else {
|
||||
entry.or_insert(texture);
|
||||
|
@ -435,17 +438,17 @@ impl Model {
|
|||
if let Some(path) = material.textures.get("map_Kd") {
|
||||
let texture = renderer.make_texture(path);
|
||||
// Don't need to insert multiple times the same texture
|
||||
self.textures.entry(path.to_owned()).or_insert(Some(texture));
|
||||
self.textures.entry(path.to_owned()).or_insert(texture);
|
||||
};
|
||||
}
|
||||
|
||||
/// Returns the rendering texture.
|
||||
pub fn get_texture_by_name(&self, name: &str) -> Option<&SrgbTexture2d> {
|
||||
self.textures[name].as_ref()
|
||||
self.textures.get(name)
|
||||
}
|
||||
|
||||
/// Returns a ref mut to the table of textures.
|
||||
pub fn textures_mut(&mut self) -> &mut HashMap<String, Option<SrgbTexture2d>> {
|
||||
pub fn textures_mut(&mut self) -> &mut HashMap<String, SrgbTexture2d> {
|
||||
&mut self.textures
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,9 @@ fn main() {
|
|||
for input in matches.values_of("input").unwrap() {
|
||||
match parse(&input) {
|
||||
Ok(model) => {
|
||||
if model.vertices.len() > 0 {
|
||||
bbox = bbox.union(&model.bounding_box());
|
||||
}
|
||||
models.push((input.to_owned(), model))
|
||||
},
|
||||
Err(e) => {
|
||||
|
|
|
@ -50,6 +50,9 @@ pub struct Renderer {
|
|||
|
||||
/// The background color.
|
||||
clear_color: (f32, f32, f32, f32),
|
||||
|
||||
/// The texture that will be applied to non textured models.
|
||||
default_texture: SrgbTexture2d,
|
||||
}
|
||||
|
||||
impl Renderer {
|
||||
|
@ -65,10 +68,14 @@ impl Renderer {
|
|||
None
|
||||
).unwrap();
|
||||
|
||||
let image = RawImage2d::from_raw_rgba(vec![1.0, 1.0, 1.0, 1.0], (1, 1));
|
||||
let texture = SrgbTexture2d::new(&display, image).ok().unwrap();
|
||||
|
||||
Renderer {
|
||||
display: display,
|
||||
program: program,
|
||||
clear_color: (0.0, 0.0, 0.0, 1.0),
|
||||
default_texture: texture,
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -107,7 +114,7 @@ impl Renderer {
|
|||
pub fn render<C: RenderCamera>(&self, scene: &Scene, camera: &C) {
|
||||
|
||||
let mut target = self.draw();
|
||||
target.clear_color_and_depth(self.clear_color, 1.0);
|
||||
target.clear_color_srgb_and_depth(self.clear_color, 1.0);
|
||||
|
||||
let perspective = camera.get_perspective_matrix();
|
||||
let view = camera.get_view_matrix();
|
||||
|
@ -130,7 +137,12 @@ impl Renderer {
|
|||
|
||||
let texture = self.get_texture_of_part(&model, part);
|
||||
|
||||
if let Some(texture) = texture {
|
||||
let texture = if let Some(texture) = texture {
|
||||
texture
|
||||
} else {
|
||||
&self.default_texture
|
||||
};
|
||||
|
||||
target.draw(
|
||||
buffer,
|
||||
NoIndices(PrimitiveType::TrianglesList),
|
||||
|
@ -142,18 +154,6 @@ impl Renderer {
|
|||
),
|
||||
¶ms,
|
||||
).unwrap();
|
||||
} else {
|
||||
target.draw(
|
||||
buffer,
|
||||
NoIndices(PrimitiveType::TrianglesList),
|
||||
&self.program,
|
||||
&uniform!(
|
||||
perspective: perspective,
|
||||
view: view,
|
||||
),
|
||||
¶ms,
|
||||
).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue