From f7e57f2aee9fc01b008e27168d95273634d2a4f1 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Sat, 25 Jun 2016 22:49:40 -0700 Subject: [PATCH] Scenes with lights now get parsed correctly. --- example_scenes/cube.psy | 16 ++++++++-------- src/assembly.rs | 2 +- src/light/sphere_light.rs | 14 +++++++++++++- src/parse/psy_assembly.rs | 16 ++++++++++++---- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/example_scenes/cube.psy b/example_scenes/cube.psy index dbef271..75968a1 100644 --- a/example_scenes/cube.psy +++ b/example_scenes/cube.psy @@ -43,13 +43,13 @@ Scene $Scene_fr1 { SurfaceShaderBind [$Material] Transform [1.000000 -0.000000 0.000000 -0.000000 -0.000000 1.000000 -0.000000 0.000000 0.000000 -0.000000 1.000000 -0.000000 -0.000000 0.000000 -1.000000 1.000000] } - #SphereLight $__Lamp { - # Color [50.000000 50.000000 50.000000] - # Radius [0.100000] - #} - #Instance { - # Data [$__Lamp] - # Transform [0.019856 -0.060763 0.000000 -0.000000 0.015191 0.079422 -0.000000 0.000000 0.000000 -0.000000 1.000000 -0.000000 -0.026851 -0.125233 -4.432303 1.000000] - #} + SphereLight $__Lamp { + Color [50.000000 50.000000 50.000000] + Radius [0.100000] + } + Instance { + Data [$__Lamp] + Transform [0.019856 -0.060763 0.000000 -0.000000 0.015191 0.079422 -0.000000 0.000000 0.000000 -0.000000 1.000000 -0.000000 -0.026851 -0.125233 -4.432303 1.000000] + } } } diff --git a/src/assembly.rs b/src/assembly.rs index 5beff75..4bb7ff8 100644 --- a/src/assembly.rs +++ b/src/assembly.rs @@ -161,7 +161,7 @@ impl AssemblyBuilder { let obj = &self.objects[inst.data_index]; match obj { &Object::Surface(ref s) => bbs.extend(s.bounds()), - &Object::Light(_) => unimplemented!(), + &Object::Light(ref l) => bbs.extend(l.bounds()), } } diff --git a/src/light/sphere_light.rs b/src/light/sphere_light.rs index d2a5018..c4fa44e 100644 --- a/src/light/sphere_light.rs +++ b/src/light/sphere_light.rs @@ -17,7 +17,19 @@ pub struct SphereLight { impl SphereLight { pub fn new(radii: Vec, colors: Vec) -> SphereLight { - unimplemented!() + let bbs = radii.iter() + .map(|r| { + BBox { + min: Point::new(-*r, -*r, -*r), + max: Point::new(*r, *r, *r), + } + }) + .collect(); + SphereLight { + radii: radii, + colors: colors, + bounds_: bbs, + } } } diff --git a/src/parse/psy_assembly.rs b/src/parse/psy_assembly.rs index 9667630..6080702 100644 --- a/src/parse/psy_assembly.rs +++ b/src/parse/psy_assembly.rs @@ -5,6 +5,7 @@ use std::result::Result; use super::DataTree; use super::psy::{parse_matrix, PsyParseError}; use super::psy_mesh_surface::parse_mesh_surface; +use super::psy_light::parse_sphere_light; use assembly::{Assembly, AssemblyBuilder, Object}; @@ -70,6 +71,17 @@ pub fn parse_assembly(tree: &DataTree) -> Result { } } + // Sphere Light + "SphereLight" => { + if let &DataTree::Internal { ident: Some(ident), .. } = child { + builder.add_object(ident, + Object::Light(Box::new(try!(parse_sphere_light(&child))))); + } else { + // TODO: error condition of some kind, because no ident + panic!(); + } + } + _ => { // TODO: some kind of error, because not a known type name } @@ -99,10 +111,6 @@ pub fn parse_assembly(tree: &DataTree) -> Result { // assembly->add_surface_shader(child.name, parse_surface_shader(child)); // } // - // // Sphere Light - // else if (child.type == "SphereLight") { - // assembly->add_object(child.name, parse_sphere_light(child)); - // } // // // Rectangle Light // else if (child.type == "RectangleLight") {