-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fcc80f
commit bcf5b19
Showing
9 changed files
with
149 additions
and
55 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
camera.pos = {-2.0, 2.0, 1.0} | ||
camera.center = {0.0, 0.0, -1.0} | ||
camera.up = {0.0, 1.0, 0.0} | ||
camera.fov = math.rad(20.0) | ||
camera.focus_dist = 3.4 | ||
camera.lens_angle = math.rad(10.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
mod camera; | ||
mod material; | ||
pub mod primitive; | ||
mod primitive; | ||
mod ray; | ||
mod scene; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ pub mod core; | |
pub mod materials; | ||
pub mod math; | ||
pub mod primitives; | ||
pub mod scripting; | ||
pub mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use crate::config::Config; | ||
use crate::core::{Camera, CameraBuilder, Scene}; | ||
use crate::materials::{Dielectric, Lambertian, Metal}; | ||
use crate::primitives::Sphere; | ||
use mlua::{prelude::*, Table}; | ||
use nalgebra::{Point3, Vector3}; | ||
use palette::LinSrgb; | ||
use std::rc::Rc; | ||
|
||
pub struct Scripting { | ||
lua: Lua, | ||
} | ||
|
||
impl Scripting { | ||
pub fn new() -> LuaResult<Self> { | ||
let lua = Lua::new(); | ||
|
||
let camera = lua.create_table()?; | ||
lua.globals().set("camera", camera)?; | ||
|
||
Ok(Self { lua }) | ||
} | ||
|
||
pub fn load(&self, config: &Config, script: &String) -> LuaResult<(Camera, Scene)> { | ||
self.lua.load(script).exec()?; | ||
|
||
let camera: Table = self.lua.globals().get("camera")?; | ||
let camera = CameraBuilder::new(config.size.width, config.size.height) | ||
.pos(table_to_point3(&camera.get("pos")?)?) | ||
.center(table_to_point3(&camera.get("center")?)?) | ||
.up(table_to_vector3(&camera.get("up")?)?) | ||
.fov(camera.get("fov")?) | ||
.focus_dist(camera.get("focus_dist")?) | ||
.lens_angle(camera.get("lens_angle")?) | ||
.build(); | ||
|
||
let mut scene = Scene::new(); | ||
|
||
let material_ground = Lambertian::new(LinSrgb::new(0.8, 0.8, 0.0)); | ||
let material_center = Lambertian::new(LinSrgb::new(0.1, 0.2, 0.5)); | ||
let material_left = Dielectric::new(1.5); | ||
let material_bubble = Dielectric::new(1.0 / 1.5); | ||
let material_right = Metal::new(LinSrgb::new(0.8, 0.6, 0.2), 1.0); | ||
|
||
scene.add(Box::new(Sphere::new( | ||
Point3::new(0.0, -100.5, -1.0), | ||
100.0, | ||
Rc::new(material_ground), | ||
))); | ||
scene.add(Box::new(Sphere::new( | ||
Point3::new(0.0, 0.0, -1.2), | ||
0.5, | ||
Rc::new(material_center), | ||
))); | ||
scene.add(Box::new(Sphere::new( | ||
Point3::new(-1.0, 0.0, -1.0), | ||
0.5, | ||
Rc::new(material_left), | ||
))); | ||
scene.add(Box::new(Sphere::new( | ||
Point3::new(-1.0, 0.0, -1.0), | ||
0.4, | ||
Rc::new(material_bubble), | ||
))); | ||
scene.add(Box::new(Sphere::new( | ||
Point3::new(1.0, 0.0, -1.0), | ||
0.5, | ||
Rc::new(material_right), | ||
))); | ||
|
||
Ok((camera, scene)) | ||
} | ||
} | ||
|
||
fn table_to_point3(table: &Table) -> LuaResult<Point3<f64>> { | ||
Ok(Point3::new(table.get(1)?, table.get(2)?, table.get(3)?)) | ||
} | ||
|
||
fn table_to_vector3(table: &Table) -> LuaResult<Vector3<f64>> { | ||
Ok(Vector3::new(table.get(1)?, table.get(2)?, table.get(3)?)) | ||
} |