From 30bf3c32fcbc037505b038210e97a94d24546316 Mon Sep 17 00:00:00 2001 From: mandeep <10521687+mandeep@users.noreply.github.com> Date: Thu, 4 Jun 2026 00:00:12 -0400 Subject: [PATCH] Add handling of the emissive material attribute Ke --- src/lib.rs | 9 +++++++++ src/tests.rs | 5 +---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f94e3b8..f341cc5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -132,6 +132,12 @@ //! specular[0], specular[1], specular[2] //! ); //! } +//! if let Some(emissive) = m.emissive { +//! println!( +//! " material.Ke = ({}, {}, {})", +//! emissive[0], emissive[1], emissive[2] +//! ); +//! } //! if let Some(shininess) = m.shininess { //! println!(" material.Ns = {}", shininess); //! } @@ -588,6 +594,8 @@ pub struct Material { pub diffuse: Option<[Float; 3]>, /// Specular color of the material. pub specular: Option<[Float; 3]>, + /// Emissive color of the material. + pub emissive: Option<[Float; 3]>, /// Material shininess attribute. Also called `glossiness`. pub shininess: Option, /// Dissolve attribute is the alpha term for the material. Referred to as @@ -1811,6 +1819,7 @@ fn parse_mtl_line( Some("Ka") => cur_mat.ambient = Some(parse_float3(words)?), Some("Kd") => cur_mat.diffuse = Some(parse_float3(words)?), Some("Ks") => cur_mat.specular = Some(parse_float3(words)?), + Some("Ke") => cur_mat.emissive = Some(parse_float3(words)?), Some("Ns") => cur_mat.shininess = Some(parse_float(words.next())?), Some("Ni") => cur_mat.optical_density = Some(parse_float(words.next())?), Some("d") => cur_mat.dissolve = Some(parse_float(words.next())?), diff --git a/src/tests.rs b/src/tests.rs index 75bb520..7d9bf93 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -393,10 +393,7 @@ fn validate_cornell(models: Vec, mats: Vec) { assert_float_eq!(mat.ambient.unwrap(), [0.0, 0.0, 0.0], r2nd_all <= TOL); assert_float_eq!(mat.diffuse.unwrap(), [1.0, 1.0, 1.0], r2nd_all <= TOL); assert_float_eq!(mat.specular.unwrap(), [0.0, 0.0, 0.0], r2nd_all <= TOL); - assert_eq!( - mat.unknown_param.get("Ke").map(|s| s.as_ref()), - Some("1 1 1") - ); + assert_float_eq!(mat.emissive.unwrap(), [1.0, 1.0, 1.0], r2nd_all <= TOL); assert_eq!(mat.illumination_model, None); // Verify red material loaded properly