Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRY-80 UI optimierung #46

Merged
merged 68 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
75f99bd
TRY-65 added reflections and specular highlight
phaman09 Dec 13, 2023
4a06baf
TRY-66 create skybox.rs
Dec 13, 2023
b8913b5
TRY-66 implement skybox in scene
Dec 13, 2023
fd4d234
TRY-68 implement UV
MarcelQ5 Dec 13, 2023
0ef00c6
TRY-66 add missing imports in skybox.rs
Dec 13, 2023
9c6e99a
TRY-66 add get_background_color to skybox.rs
Dec 13, 2023
bb6054e
TRY-66 implement skybox into settings.rs
Dec 13, 2023
b01cf7b
TRY-65 Shading
phaman09 Dec 13, 2023
df7d7ac
TRY-66 replace background color with skybox
Dec 13, 2023
f769314
TRY-66 add skybox_texture.sky.jpg
Dec 13, 2023
9ddc238
TRY-68 Merge branch 'TRY-65-Shading' into TRY-68_Texture_Implementation
bircni Dec 13, 2023
8fbd801
TRY-68 add texture rendering
bircni Dec 13, 2023
9785501
TRY-66 add skybox texture path to yaml
Dec 13, 2023
3804c00
TRY-66 add skybox with color in render
Dec 13, 2023
694a0d5
TRY-65 add Refraction and Reflection
phaman09 Dec 13, 2023
ece3b55
TRY-65 Merge Shading
LesKlugi Dec 13, 2023
992fe59
TRY-68 fix texture display
bircni Dec 13, 2023
29e8a64
TRY-68 add test.blend
bircni Dec 13, 2023
5c214c9
TRY-68 Refactoring
Fabus1184 Dec 13, 2023
5bf6ae2
Merge branch 'TRY-68_Texture_Implementation' of github.com:bircni/Ray…
Fabus1184 Dec 13, 2023
2302676
TRY-68 update
Fabus1184 Dec 13, 2023
092b62b
TRY-68 fix textures
Fabus1184 Dec 13, 2023
83efb1a
TRY-67 movement via keyboard functional, mouse still buggy
GitNether Dec 13, 2023
ca29629
TRY-67 out of bounds still wonky, otherwise functional
GitNether Dec 14, 2023
60167f1
TRY-67 bit wonky if mouse moves too fast, otherwise works now
GitNether Dec 14, 2023
34fe6c3
TRY-67 changed sensitivity
GitNether Dec 14, 2023
c69b18e
TRY-68 new model
Fabus1184 Dec 14, 2023
bfa6547
TRY-72 rework
bircni Dec 14, 2023
93b678c
TRY-72 rework
bircni Dec 14, 2023
1fd631b
TRY-72 fix workflows
bircni Dec 14, 2023
ce58e09
TRY-66 merge TRY-68 into branch
Dec 14, 2023
25137c5
TRY-68 Merge branch 'main' into TRY-68_Texture_Implementation
bircni Dec 15, 2023
766e8dd
TRY-68 update config.yaml to standard version
bircni Dec 17, 2023
38a5625
TRY-66 add another skybox exr
Dec 19, 2023
d96f4db
TRY-66 remove unneccesary imports
Dec 19, 2023
0a73323
TRY-66 add update_skybox method
Dec 19, 2023
0af1d13
TRY-66 change update_skybox method
Dec 19, 2023
eb30d35
TRY-66 working skybox loader
Dec 19, 2023
2cc96dd
TRY-66 selectable skyboxes in ui
Dec 19, 2023
d0fb497
TRY-66 cleanup and add more Skyboxes
Dec 19, 2023
ab01e40
TRY-68 adjust `config.yaml`
bircni Dec 19, 2023
a91dd96
TRY-68 refactor for new yaml
Fabus1184 Dec 19, 2023
54ead09
TRY-68 add final testconfig yaml
bircni Dec 19, 2023
5d497b9
TRY-68 fix textsize error
bircni Dec 19, 2023
48dd018
TRY-68 fix save path
Fabus1184 Dec 19, 2023
ed33db6
Merge branch 'TRY-68_Texture_Implementation' of github.com:bircni/Ray…
Fabus1184 Dec 19, 2023
eb8fbb2
TRY-68 fix 2.mtl
Fabus1184 Dec 19, 2023
be124d3
TRY-66 improvements and loadiung via url
bircni Dec 20, 2023
b89e99f
TRY-66 cleanup
Dec 20, 2023
d4fdd54
TRY-66 update
bircni Dec 20, 2023
e40193b
TRY-66 Merge branch 'TRY-68_Texture_Implementation' into TRY-66-Skybox
bircni Dec 20, 2023
c964a76
TRY-66 add download button
bircni Dec 20, 2023
2fb8fd1
TRY-66 update yamls
bircni Dec 20, 2023
5e29e5d
TRY-66 enable correct linting
bircni Dec 20, 2023
8cc8327
TRY-66 refactoring
bircni Dec 21, 2023
bfc8d1d
TRY-80 UI init
bircni Dec 21, 2023
28cf5a9
TRY-80 add info-bar
bircni Dec 21, 2023
d3a6840
TRY-66 fix Skybox Holes
bircni Dec 21, 2023
859b62d
TRY-82 fix intensity
bircni Dec 22, 2023
a48a030
TRY-84 save/load Skybox in YAML
bircni Dec 22, 2023
89f4c29
TRY-80 variable button colors for light and dark mode
HermanoGranger Dec 22, 2023
ddf59ae
TRY-80 improved UI to be more uniform
HermanoGranger Dec 22, 2023
1b1b2db
TRY-80 import the correct crate
bircni Dec 22, 2023
edb4541
TRY-80 Merge branch 'TRY-66-Skybox' into TRY-80-UI-Optimierung
bircni Dec 22, 2023
187ef59
TRY-80 fix 'dowload all skyboxes'-button to actually work + fix out o…
HermanoGranger Jan 10, 2024
fad3ca1
TRY-80 Merge branch 'main'
bircni Jan 12, 2024
6697509
TRY-80 update
bircni Jan 12, 2024
55124d6
TRY-80 center preview, infobar
bircni Jan 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 33 additions & 15 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use egui::{
mutex::Mutex, pos2, Align, CursorIcon, Frame, Layout, ProgressBar, Rect, Rounding, Stroke, Vec2,
};
use egui::{
Align2, Button, CentralPanel, Color32, ColorImage, ImageData, Key, Sense, TextStyle,
Align2, Button, CentralPanel, Color32, ColorImage, ImageData, Key, RichText, Sense, TextStyle,
TextureHandle, TextureOptions, Ui,
};
use egui_file::FileDialog;
use image::{ImageBuffer, RgbImage};
use log::{info, warn};
use nalgebra::OPoint;
use std::path::PathBuf;
use std::sync::atomic::{AtomicBool, AtomicU16, Ordering};
use std::sync::atomic::{AtomicBool, AtomicU16, AtomicU32, Ordering};
use std::sync::Arc;
use std::thread::JoinHandle;

Expand Down Expand Up @@ -65,7 +65,6 @@ impl std::fmt::Display for RenderSize {
}
}
}

pub struct App {
current_tab: usize,
scene: Scene,
Expand All @@ -78,6 +77,7 @@ pub struct App {
save_image_dialog: Option<FileDialog>,
render_size: RenderSize,
rendering_progress: Arc<AtomicU16>,
rendering_time: Arc<AtomicU32>,
preview_zoom: f32,
preview_position: Vec2,
preview_activate_movement: bool,
Expand Down Expand Up @@ -132,6 +132,7 @@ impl App {
save_image_dialog: None,
render_size,
rendering_progress: Arc::new(AtomicU16::new(0)),
rendering_time: Arc::new(AtomicU32::new(0)),
rendering_cancel: Arc::new(AtomicBool::new(false)),
render_image: image_buffer,
preview_activate_movement: false,
Expand Down Expand Up @@ -193,8 +194,15 @@ impl App {
}

fn preview(&mut self, ui: &mut Ui) {
ui.vertical(|ui| {
let available_size = ui.available_size();
let width = available_size.x;
let size = self.render_size.as_size();
let height = (width / size.0 as f32) * size.1 as f32;
ui.allocate_space(Vec2::new(0.0, (available_size.y - height - 20.0) / 2.0));
Frame::canvas(ui.style())
.outer_margin(10.0)
.inner_margin(0.0)
.fill(match self.scene.settings.skybox {
Skybox::Image { ..} => Color32::GRAY,
Skybox::Color(c) => Color32::from_rgb(
Expand All @@ -205,15 +213,15 @@ impl App {
})
.show(ui, |ui| {
let (response, painter) =
ui.allocate_painter(ui.available_size(), Sense::click_and_drag());
ui.allocate_painter(Vec2 { x: width - 20.0, y: height }, Sense::click_and_drag());
painter.add(Preview::paint(response.rect, &self.scene));
if response.hover_pos().is_some() && !self.preview_activate_movement {
egui::show_tooltip(ui.ctx(), egui::Id::new("preview_tooltip"), |ui| {
ui.label("Click to change camera position");
});
}
if response.clicked() {
self.change_preview_movement(ui, &response, true);
self.change_preview_movement(ui, &response, true);
}
if self.preview_activate_movement {
painter.debug_text(
Expand All @@ -230,7 +238,7 @@ impl App {
// exit movement mode when tabbed out
self.change_preview_movement(ui, &response, false);
}
});
})});
}

fn move_camera(&mut self, ui: &mut Ui, response: &egui::Response) {
Expand Down Expand Up @@ -477,15 +485,26 @@ impl eframe::App for App {
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
self.export_button(ui);
self.render_button(ui);

let progress = f32::from(self.rendering_progress.load(Ordering::Relaxed))
/ f32::from(u16::MAX);
#[allow(clippy::float_cmp)]
ui.add(
ProgressBar::new(
f32::from(self.rendering_progress.load(Ordering::Relaxed))
/ f32::from(u16::MAX),
)
.desired_width(ui.available_width() / 3.0)
.show_percentage()
.fill(Color32::DARK_BLUE),
ProgressBar::new(progress)
.desired_width(ui.available_width() / 3.0)
.text(
RichText::new(if progress == 1.0 {
format!(
"Done in: {:.2} s",
self.rendering_time.load(Ordering::Relaxed) as f32 / 1000.0
)
} else if progress > 0.0 {
format!("{:.1}%", progress * 100.0)
} else {
String::new()
})
.color(Color32::WHITE),
)
.fill(Color32::DARK_BLUE),
);

ui.label("Rendering progress");
Expand All @@ -499,7 +518,6 @@ impl eframe::App for App {
match self.current_tab {
0 => {
self.properties(ui);

self.preview(ui);
}

Expand Down
58 changes: 50 additions & 8 deletions src/ui/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ use crate::{

use super::{App, RenderSize};

pub const SMALL_SPACE: f32 = 2.5;
pub const MEDIUM_SPACE: f32 = 5.0;
pub const LARGE_SPACE: f32 = 10.0;
Fabus1184 marked this conversation as resolved.
Show resolved Hide resolved

fn xyz_drag_value(ui: &mut Ui, value: &mut XYZ<f32>) {
ui.horizontal(|ui| {
ui.add(DragValue::new(&mut value.x).speed(0.1).prefix("x: "));
Expand All @@ -36,12 +40,17 @@ impl App {
ui.heading("Properties");

ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
let tint_color = if ui.visuals().dark_mode {
hex_color!("#ffffff")
} else {
hex_color!("#000000")
};
ui.add_sized(
[20.0, 20.0],
ImageButton::new(include_image!(
"../../res/icons/floppy-disk-solid.svg"
))
.tint(hex_color!("#ffffff")),
.tint(tint_color),
)
.on_hover_text("Save Scene")
.clicked()
Expand All @@ -51,21 +60,23 @@ impl App {
});
});

ui.add_space(5.0);
ui.add_space(MEDIUM_SPACE);

self.camera_settings(ui);

ui.add_space(10.0);
ui.add_space(LARGE_SPACE);

self.scene_settings(ui);

ui.add_space(10.0);
ui.add_space(LARGE_SPACE);

self.lights(ui);

ui.add_space(10.0);
ui.add_space(LARGE_SPACE);

self.objects(ui);

ui.add_space(SMALL_SPACE);
});
});
}
Expand All @@ -80,18 +91,26 @@ impl App {

ui.vertical(|ui| {
ui.label("Position:");
ui.add_space(SMALL_SPACE);
xyz_drag_value(ui, &mut self.scene.camera.position);

ui.add_space(MEDIUM_SPACE);

ui.label("Look at:");
ui.add_space(SMALL_SPACE);
xyz_drag_value(ui, &mut self.scene.camera.look_at);

ui.add_space(MEDIUM_SPACE);

ui.label("Field of View:");
ui.add_space(SMALL_SPACE);
ui.add(
Slider::new(&mut self.scene.camera.fov, 0.0..=std::f32::consts::PI)
.step_by(0.01)
.custom_formatter(|x, _| format!("{:.2}°", x.to_degrees()))
.clamp_to_range(true),
);
ui.add_space(SMALL_SPACE);
});
});
}
Expand All @@ -106,11 +125,11 @@ impl App {

self.render_options(ui);

ui.separator();
ui.add_space(MEDIUM_SPACE);

self.skybox_options(ui);

ui.separator();
ui.add_space(MEDIUM_SPACE);

ui.label("Ambient Color:");
color_picker::color_edit_button_rgb(ui, self.scene.settings.ambient_color.as_mut());
Expand All @@ -121,7 +140,7 @@ impl App {
.clamp_to_range(true),
);

ui.separator();
ui.add_space(MEDIUM_SPACE);
});
}

Expand Down Expand Up @@ -296,6 +315,7 @@ impl App {
.size(14.0)
.family(FontFamily::Monospace),
);
ui.add_space(SMALL_SPACE);
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
remove = ui
.add_sized(
Expand All @@ -310,14 +330,23 @@ impl App {
});

ui.label("Position:");
ui.add_space(SMALL_SPACE);
xyz_drag_value(ui, &mut light.position);

ui.add_space(MEDIUM_SPACE);

ui.label("Intensity:");
ui.add_space(SMALL_SPACE);
ui.add(Slider::new(&mut light.intensity, 0.0..=100.0).clamp_to_range(true));

ui.add_space(MEDIUM_SPACE);

ui.label("Color:");
ui.add_space(SMALL_SPACE);
color_picker::color_edit_button_rgb(ui, light.color.as_mut());

ui.add_space(MEDIUM_SPACE);

remove.then_some(n)
})
.collect::<Vec<_>>()
Expand All @@ -327,6 +356,7 @@ impl App {
});

ui.separator();
ui.add_space(SMALL_SPACE);
ui.vertical_centered(|ui| {
ui.add(Button::new(RichText::new("+ Add Light")).frame(false))
.clicked()
Expand All @@ -351,15 +381,19 @@ impl App {

let mut objects_to_remove = Vec::new();

#[allow(clippy::out_of_bounds_indexing)]
for (n, o) in self.scene.objects.iter_mut().enumerate() {
ui.separator();

ui.add_space(SMALL_SPACE);

ui.horizontal(|ui| {
ui.label(
RichText::new(format!("Object {} ({} ▲)", n, o.triangles.len()))
.size(14.0)
.family(FontFamily::Monospace),
);
ui.add_space(SMALL_SPACE);
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
if ui
.add_sized(
Expand All @@ -375,9 +409,12 @@ impl App {
});

ui.label("Position");
ui.add_space(SMALL_SPACE);
xyz_drag_value(ui, &mut o.translation);
ui.add_space(MEDIUM_SPACE);

ui.label("Rotation");
ui.add_space(SMALL_SPACE);
ui.horizontal(|ui| {
let (mut x, mut y, mut z) = o.rotation.euler_angles();

Expand All @@ -397,15 +434,20 @@ impl App {
})
});

ui.add_space(MEDIUM_SPACE);

ui.label("Scale");
ui.add_space(SMALL_SPACE);
xyz_drag_value(ui, &mut o.scale);
ui.add_space(MEDIUM_SPACE);
}

for o in objects_to_remove {
self.scene.objects.remove(o);
}

ui.separator();
ui.add_space(SMALL_SPACE);
ui.vertical_centered(|ui| {
if ui
.add(Button::new(RichText::new("+ Add Object")).frame(false))
Expand Down
3 changes: 3 additions & 0 deletions src/ui/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ impl super::App {
let block_size = [render_size.0 / 20, render_size.1 / 20];

let rendering_progress = self.rendering_progress.clone();
let rendering_time = self.rendering_time.clone();
let rendering_cancel = self.rendering_cancel.clone();

let image_buffer = self.render_image.clone();

rendering_progress.store(0, Ordering::Relaxed);
rendering_time.store(0, Ordering::Relaxed);

self.rendering_thread = Some(std::thread::spawn(move || {
let start = std::time::Instant::now();
Expand Down Expand Up @@ -115,6 +117,7 @@ impl super::App {
});

rendering_progress.store(u16::MAX, Ordering::Relaxed);
rendering_time.store(start.elapsed().as_millis() as u32, Ordering::Relaxed);

info!("rendering finished: {:?}", start.elapsed());
}));
Expand Down
Loading