Active light flag
This commit is contained in:
31
src/gui.rs
31
src/gui.rs
@@ -1,8 +1,10 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
camera::Camera,
|
camera::Camera,
|
||||||
light::Light,
|
light::Light,
|
||||||
|
material::*,
|
||||||
|
node::*,
|
||||||
primitive::*,
|
primitive::*,
|
||||||
scene::{Node, Scene},
|
scene::*,
|
||||||
state::{INIT_FILE, SAVE_FILE},
|
state::{INIT_FILE, SAVE_FILE},
|
||||||
};
|
};
|
||||||
use imgui::*;
|
use imgui::*;
|
||||||
@@ -33,21 +35,21 @@ const RAYS_MAX: i32 = 10000;
|
|||||||
const MIN_COLOUR: f32 = 0.0;
|
const MIN_COLOUR: f32 = 0.0;
|
||||||
const MIN_FALLOFF: f32 = 0.0;
|
const MIN_FALLOFF: f32 = 0.0;
|
||||||
const MIN_SCALE: f64 = 0.0;
|
const MIN_SCALE: f64 = 0.0;
|
||||||
const MIN_POSITION: f64 = -10.0;
|
//const MIN_POSITION: f64 = -10.0;
|
||||||
const MIN_ROTATION: f64 = -180.0;
|
const MIN_ROTATION: f64 = -180.0;
|
||||||
const MIN_TRANSLATE: f64 = -10.0;
|
const MIN_TRANSLATE: f64 = -10.0;
|
||||||
//--
|
//--
|
||||||
const MAX_COLOUR: f32 = 1.0;
|
const MAX_COLOUR: f32 = 1.0;
|
||||||
const MAX_FALLOFF: f32 = 1.0;
|
const MAX_FALLOFF: f32 = 1.0;
|
||||||
const MAX_SCALE: f64 = 3.0;
|
const MAX_SCALE: f64 = 3.0;
|
||||||
const MAX_POSITION: f64 = 10.0;
|
//const MAX_POSITION: f64 = 10.0;
|
||||||
const MAX_ROTATION: f64 = 180.0;
|
const MAX_ROTATION: f64 = 180.0;
|
||||||
const MAX_TRANSLATE: f64 = 10.0;
|
const MAX_TRANSLATE: f64 = 10.0;
|
||||||
|
|
||||||
// CAMERA CONSTANTS
|
// CAMERA CONSTANTS
|
||||||
const MIN_FOV: f32 = 10.0;
|
const MIN_FOV: f32 = 10.0;
|
||||||
const MAX_FOV: f32 = 160.0;
|
const MAX_FOV: f32 = 160.0;
|
||||||
const CAMERA_INIT: f32 = 5.0;
|
//const CAMERA_INIT: f32 = 5.0;
|
||||||
|
|
||||||
/// Manages all state required for rendering Dear ImGui over `Pixels`test.
|
/// Manages all state required for rendering Dear ImGui over `Pixels`test.
|
||||||
pub enum GuiEvent {
|
pub enum GuiEvent {
|
||||||
@@ -272,6 +274,8 @@ impl Gui {
|
|||||||
// Edit transformation of nodes
|
// Edit transformation of nodes
|
||||||
if let Some(_t) = ui.tree_node("Nodes") {
|
if let Some(_t) = ui.tree_node("Nodes") {
|
||||||
for (label, node) in &mut self.scene.nodes {
|
for (label, node) in &mut self.scene.nodes {
|
||||||
|
ui.checkbox(format!("##active{label}"), &mut node.active);
|
||||||
|
ui.same_line();
|
||||||
if let Some(_t) = ui.tree_node(label) {
|
if let Some(_t) = ui.tree_node(label) {
|
||||||
ui.slider_config("Translation", MIN_TRANSLATE, MAX_TRANSLATE)
|
ui.slider_config("Translation", MIN_TRANSLATE, MAX_TRANSLATE)
|
||||||
.build_array(&mut node.translation);
|
.build_array(&mut node.translation);
|
||||||
@@ -297,6 +301,8 @@ impl Gui {
|
|||||||
//Edit color, position and falloff of lights
|
//Edit color, position and falloff of lights
|
||||||
if let Some(_t) = ui.tree_node("Lights") {
|
if let Some(_t) = ui.tree_node("Lights") {
|
||||||
for (label, light) in &mut self.scene.lights {
|
for (label, light) in &mut self.scene.lights {
|
||||||
|
ui.checkbox(format!("##activelight{label}"), &mut light.active);
|
||||||
|
ui.same_line();
|
||||||
if let Some(_t) = ui.tree_node(label) {
|
if let Some(_t) = ui.tree_node(label) {
|
||||||
ui.slider_config("Colour", MIN_COLOUR, MAX_COLOUR)
|
ui.slider_config("Colour", MIN_COLOUR, MAX_COLOUR)
|
||||||
.build_array(light.colour.as_mut_slice());
|
.build_array(light.colour.as_mut_slice());
|
||||||
@@ -377,11 +383,13 @@ pub fn init_engine() -> Engine {
|
|||||||
.register_fn("translate", Node::translate)
|
.register_fn("translate", Node::translate)
|
||||||
.register_fn("rotate", Node::rotate)
|
.register_fn("rotate", Node::rotate)
|
||||||
.register_fn("scale", Node::scale)
|
.register_fn("scale", Node::scale)
|
||||||
.register_fn("child", Node::child);
|
.register_fn("child", Node::child)
|
||||||
|
.register_fn("active", Node::set_active);
|
||||||
engine
|
engine
|
||||||
.register_type::<Light>()
|
.register_type::<Light>()
|
||||||
.register_fn("Light", Light::new)
|
.register_fn("Light", Light::new)
|
||||||
.register_fn("Ambient", Light::ambient);
|
.register_fn("Ambient", Light::ambient)
|
||||||
|
.register_fn("active", Light::set_active);
|
||||||
engine
|
engine
|
||||||
.register_type::<Material>()
|
.register_type::<Material>()
|
||||||
.register_fn("Material", Material::new)
|
.register_fn("Material", Material::new)
|
||||||
@@ -398,6 +406,10 @@ pub fn init_engine() -> Engine {
|
|||||||
.register_type::<Cube>()
|
.register_type::<Cube>()
|
||||||
.register_fn("Cube", Cube::new)
|
.register_fn("Cube", Cube::new)
|
||||||
.register_fn("CubeUnit", Cube::unit);
|
.register_fn("CubeUnit", Cube::unit);
|
||||||
|
engine
|
||||||
|
.register_type::<Triangle>()
|
||||||
|
.register_fn("Triangle", Triangle::new)
|
||||||
|
.register_fn("TriangleUnit", Triangle::unit);
|
||||||
engine
|
engine
|
||||||
.register_type::<Cone>()
|
.register_type::<Cone>()
|
||||||
.register_fn("Cone", Cone::new)
|
.register_fn("Cone", Cone::new)
|
||||||
@@ -435,4 +447,11 @@ pub fn init_engine() -> Engine {
|
|||||||
.register_type::<Gnonom>()
|
.register_type::<Gnonom>()
|
||||||
.register_fn("Gnonom", Gnonom::new);
|
.register_fn("Gnonom", Gnonom::new);
|
||||||
engine
|
engine
|
||||||
|
.register_type::<Mesh>()
|
||||||
|
.register_fn("Mesh", Mesh::from_file);
|
||||||
|
engine
|
||||||
|
.register_type::<Rectangle>()
|
||||||
|
.register_fn("Rectange", Rectangle::new)
|
||||||
|
.register_fn("RectangleUnit", Rectangle::unit);
|
||||||
|
engine
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ pub struct Light {
|
|||||||
pub colour: Vector3<f32>,
|
pub colour: Vector3<f32>,
|
||||||
pub falloff: Vector3<f32>,
|
pub falloff: Vector3<f32>,
|
||||||
pub ambient: bool,
|
pub ambient: bool,
|
||||||
|
pub active: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Light {
|
impl Light {
|
||||||
@@ -17,6 +18,7 @@ impl Light {
|
|||||||
colour,
|
colour,
|
||||||
falloff,
|
falloff,
|
||||||
ambient: false,
|
ambient: false,
|
||||||
|
active: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn ambient(colour: Vector3<f64>) -> Light {
|
pub fn ambient(colour: Vector3<f64>) -> Light {
|
||||||
@@ -25,6 +27,10 @@ impl Light {
|
|||||||
colour: colour.cast(),
|
colour: colour.cast(),
|
||||||
falloff: Vector3::new(0.0, 0.0, 0.0),
|
falloff: Vector3::new(0.0, 0.0, 0.0),
|
||||||
ambient: true,
|
ambient: true,
|
||||||
|
active: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn set_active(&mut self, active: bool) {
|
||||||
|
self.active = active;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user