• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ekarpp / lumo / 6054336964

01 Sep 2023 10:00PM UTC coverage: 47.535% (-0.9%) from 48.466%
6054336964

push

github

web-flow
0.3.2 (#33)

- Rewrites sample gathering to use `FilmTiles`
- Fixes splat samples in BDPT
- Some BDPT medium bug fixes (Progresses #31)

Closes #32

180 of 180 new or added lines in 17 files covered. (100.0%)

2179 of 4584 relevant lines covered (47.53%)

6887198.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/parser/mtl.rs
1
use super::*;
2
use crate::tracer::Color;
3

4
/// Holds the properties of a microfacet material
5
pub struct MtlConfig {
6
    /// Base color of the material
7
    pub diffuse_color: Color,
8
    /// Specular color of the material. Currently material color = kd + ks
9
    pub specular_color: Color,
10
    /// Emittance of the material. If not zero vector, then createas a light
11
    pub emission_color: Color,
12
    /// How much each light channel passes on transmission. Unused ATM
13
    pub transmission_filter: Vec3,
14
    /// Refraction index of the material
15
    pub refraction_idx: Float,
16
    /// Roughness of the material
17
    pub roughness: Float,
18
    /// Illumination model, see docs.
19
    /// If 6 or 7 makes transparent, if 5 makes metal, otherwise unused.
20
    pub illumination_model: usize,
21
    /// Texture map
22
    pub map_kd: Option<Image>,
23
}
24

25
impl Default for MtlConfig {
26
    fn default() -> Self {
×
27
        Self {
×
28
            diffuse_color: Color::BLACK,
×
29
            specular_color: Color::BLACK,
×
30
            emission_color: Color::BLACK,
×
31
            transmission_filter: Vec3::ZERO,
×
32
            refraction_idx: 1.5,
×
33
            roughness: 1.0,
×
34
            illumination_model: 0,
×
35
            map_kd: None,
×
36
        }
×
37
    }
×
38
}
39

40
impl MtlConfig {
41
    pub fn build_material(&self) -> Material {
×
42
        if !self.emission_color.is_black() {
×
43
            Material::Light(Texture::Solid(self.emission_color))
×
44
        } else {
45
            let texture = if let Some(img) = &self.map_kd {
×
46
                Texture::Image(img.clone())
×
47
            } else {
48
                Texture::Solid(self.diffuse_color + self.specular_color)
×
49
            };
50

51
            let metallicity = if self.illumination_model == 5 { 1.0 } else { 0.0 };
×
52
            let is_transparent = self.illumination_model == 6
×
53
                || self.illumination_model == 7;
×
54

55
            Material::microfacet(
×
56
                texture,
×
57
                self.roughness,
×
58
                self.refraction_idx,
×
59
                metallicity,
×
60
                is_transparent,
×
61
            )
×
62
        }
63
    }
×
64
}
65

66
pub fn load_file(
×
67
    file: File,
×
68
    zip_file: Option<Vec<u8>>,
×
69
    materials: &mut HashMap<String, MtlConfig>,
×
70
) -> Result<()> {
×
71
    let reader = BufReader::new(file);
×
72

×
73
    let mut mtl = MtlConfig::default();
×
74
    let mut mtl_name = String::default();
×
75

76
    for line in reader.lines() {
×
77
        let line = line?.trim().to_string();
×
78
        if line.starts_with('#') || line.is_empty() {
×
79
            continue;
×
80
        }
×
81
        let tokens: Vec<&str> = line.split_ascii_whitespace().collect();
×
82

×
83
        match tokens[0] {
×
84
            "newmtl" => {
×
85
                if !mtl_name.is_empty() {
×
86
                    materials.insert(mtl_name, mtl);
×
87
                }
×
88
                mtl = MtlConfig::default();
×
89
                mtl_name = tokens[1].to_string();
×
90
            }
91
            /* diffuse color */
92
            "Kd" => {
×
93
                let kd = parse_vec3(&tokens)?;
×
94
                mtl.diffuse_color = Color::from(kd);
×
95
            }
96
            /* texture map */
97
            "map_Kd" => {
×
98
                if let Some(ref zip) = zip_file {
×
99
                    let tex_name = tokens[1].replace("\\", "/");
×
100
                    let img = super::_img_from_zip(zip.clone(), &tex_name)?;
×
101
                    mtl.map_kd = Some(img);
×
102
                }
×
103
            }
104
            /* emission color */
105
            "Ke" => {
×
106
                let ke = parse_vec3(&tokens)?;
×
107
                mtl.emission_color = Color::from(ke);
×
108
            }
109
            /* specular color */
110
            "Ks" => {
×
111
                let ks = parse_vec3(&tokens)?;
×
112
                mtl.specular_color = Color::from(ks);
×
113
            }
114
            /* transmission filter */
115
            "Tf" => {
×
116
                let tf = parse_vec3(&tokens)?;
×
117
                mtl.transmission_filter = tf;
×
118
            }
119
            /* refraction index */
120
            "Ni" => {
×
121
                let ni = parse_double(tokens[1])?;
×
122
                mtl.refraction_idx = ni;
×
123
            }
124
            /* roughness */
125
            "Ns" => {
×
126
                let ns = parse_double(tokens[1])?;
×
127
                // blender uses this mapping
128
                let roughness = 1.0 - ns.min(900.0).sqrt() / 30.0;
×
129
                mtl.roughness = roughness;
×
130
            }
131
            "illum" => {
×
132
                let illum = parse_double(tokens[1])?;
×
133
                mtl.illumination_model = illum as usize;
×
134
            }
135
            _ => (),
×
136
        }
137
    }
138

139
    materials.insert(mtl_name, mtl);
×
140

×
141
    Ok(())
×
142
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc