mirror of
https://github.com/IllusionMan1212/3dobs.git
synced 2026-10-24 10:12:35 +00:00
ui: better objects table. better font. keybinds window. update fps every 100ms instead of every frame
This commit is contained in:
@@ -2,3 +2,4 @@
|
|||||||
|
|
||||||
3rdparty/*/target
|
3rdparty/*/target
|
||||||
models/**/*
|
models/**/*
|
||||||
|
3dobs.log
|
||||||
|
|||||||
@@ -32,5 +32,7 @@
|
|||||||
- [x] Toggle for dis/allowing the one instance option
|
- [x] Toggle for dis/allowing the one instance option
|
||||||
- [x] Show how much memory each loaded model is using
|
- [x] Show how much memory each loaded model is using
|
||||||
- [ ] Move the invisible point lights to be around selected object from all sides so it's nicely illuminated
|
- [ ] Move the invisible point lights to be around selected object from all sides so it's nicely illuminated
|
||||||
|
- [x] Shortcuts/keybinds window under the 'Help' menu item
|
||||||
|
- [ ] Texture support
|
||||||
|
|
||||||
- [ ] Bring back the regular camera movement (can maybe be a switch between them) (for later)
|
- [ ] Bring back the regular camera movement (can maybe be a switch between them) (for later)
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,93 @@
|
|||||||
|
Copyright 2017 The Exo Project Authors (https://github.com/NDISCOVER/Exo-1.0)
|
||||||
|
|
||||||
|
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||||
|
This license is copied below, and is also available with a FAQ at:
|
||||||
|
http://scripts.sil.org/OFL
|
||||||
|
|
||||||
|
|
||||||
|
-----------------------------------------------------------
|
||||||
|
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||||
|
-----------------------------------------------------------
|
||||||
|
|
||||||
|
PREAMBLE
|
||||||
|
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||||
|
development of collaborative font projects, to support the font creation
|
||||||
|
efforts of academic and linguistic communities, and to provide a free and
|
||||||
|
open framework in which fonts may be shared and improved in partnership
|
||||||
|
with others.
|
||||||
|
|
||||||
|
The OFL allows the licensed fonts to be used, studied, modified and
|
||||||
|
redistributed freely as long as they are not sold by themselves. The
|
||||||
|
fonts, including any derivative works, can be bundled, embedded,
|
||||||
|
redistributed and/or sold with any software provided that any reserved
|
||||||
|
names are not used by derivative works. The fonts and derivatives,
|
||||||
|
however, cannot be released under any other type of license. The
|
||||||
|
requirement for fonts to remain under this license does not apply
|
||||||
|
to any document created using the fonts or their derivatives.
|
||||||
|
|
||||||
|
DEFINITIONS
|
||||||
|
"Font Software" refers to the set of files released by the Copyright
|
||||||
|
Holder(s) under this license and clearly marked as such. This may
|
||||||
|
include source files, build scripts and documentation.
|
||||||
|
|
||||||
|
"Reserved Font Name" refers to any names specified as such after the
|
||||||
|
copyright statement(s).
|
||||||
|
|
||||||
|
"Original Version" refers to the collection of Font Software components as
|
||||||
|
distributed by the Copyright Holder(s).
|
||||||
|
|
||||||
|
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||||
|
or substituting -- in part or in whole -- any of the components of the
|
||||||
|
Original Version, by changing formats or by porting the Font Software to a
|
||||||
|
new environment.
|
||||||
|
|
||||||
|
"Author" refers to any designer, engineer, programmer, technical
|
||||||
|
writer or other person who contributed to the Font Software.
|
||||||
|
|
||||||
|
PERMISSION & CONDITIONS
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||||
|
redistribute, and sell modified and unmodified copies of the Font
|
||||||
|
Software, subject to the following conditions:
|
||||||
|
|
||||||
|
1) Neither the Font Software nor any of its individual components,
|
||||||
|
in Original or Modified Versions, may be sold by itself.
|
||||||
|
|
||||||
|
2) Original or Modified Versions of the Font Software may be bundled,
|
||||||
|
redistributed and/or sold with any software, provided that each copy
|
||||||
|
contains the above copyright notice and this license. These can be
|
||||||
|
included either as stand-alone text files, human-readable headers or
|
||||||
|
in the appropriate machine-readable metadata fields within text or
|
||||||
|
binary files as long as those fields can be easily viewed by the user.
|
||||||
|
|
||||||
|
3) No Modified Version of the Font Software may use the Reserved Font
|
||||||
|
Name(s) unless explicit written permission is granted by the corresponding
|
||||||
|
Copyright Holder. This restriction only applies to the primary font name as
|
||||||
|
presented to the users.
|
||||||
|
|
||||||
|
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||||
|
Software shall not be used to promote, endorse or advertise any
|
||||||
|
Modified Version, except to acknowledge the contribution(s) of the
|
||||||
|
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||||
|
permission.
|
||||||
|
|
||||||
|
5) The Font Software, modified or unmodified, in part or in whole,
|
||||||
|
must be distributed entirely under this license, and must not be
|
||||||
|
distributed under any other license. The requirement for fonts to
|
||||||
|
remain under this license does not apply to any document created
|
||||||
|
using the Font Software.
|
||||||
|
|
||||||
|
TERMINATION
|
||||||
|
This license becomes null and void if any of the above conditions are
|
||||||
|
not met.
|
||||||
|
|
||||||
|
DISCLAIMER
|
||||||
|
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||||
|
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||||
|
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||||
|
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||||
+10
-1
@@ -156,6 +156,8 @@ fn main() -> anyhow::Result<(), Box<dyn std::error::Error>> {
|
|||||||
utils::import_models_from_paths(&args_paths, &mut state);
|
utils::import_models_from_paths(&args_paths, &mut state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut time_since_last_frame_acc = 0.0;
|
||||||
|
|
||||||
// main loop
|
// main loop
|
||||||
while !window.should_close() {
|
while !window.should_close() {
|
||||||
let current_frame = glfw.get_time() as f32;
|
let current_frame = glfw.get_time() as f32;
|
||||||
@@ -166,6 +168,13 @@ fn main() -> anyhow::Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
state.camera.update_speed(delta_time);
|
state.camera.update_speed(delta_time);
|
||||||
|
|
||||||
|
time_since_last_frame_acc += delta_time;
|
||||||
|
|
||||||
|
if time_since_last_frame_acc >= 0.1 {
|
||||||
|
state.fps = 1.0 / delta_time;
|
||||||
|
time_since_last_frame_acc = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
// camera matrices
|
// camera matrices
|
||||||
let view_mat = glm::ext::look_at(state.camera.position, state.camera.position + state.camera.front, state.camera.up);
|
let view_mat = glm::ext::look_at(state.camera.position, state.camera.position + state.camera.front, state.camera.up);
|
||||||
let projection_mat = glm::ext::perspective(glm::radians(state.camera.fov), state.viewport_size[0] / state.viewport_size[1], 0.01, 200.0);
|
let projection_mat = glm::ext::perspective(glm::radians(state.camera.fov), state.viewport_size[0] / state.viewport_size[1], 0.01, 200.0);
|
||||||
@@ -270,7 +279,7 @@ fn main() -> anyhow::Result<(), Box<dyn std::error::Error>> {
|
|||||||
gl::Clear(gl::COLOR_BUFFER_BIT);
|
gl::Clear(gl::COLOR_BUFFER_BIT);
|
||||||
gl::Disable(gl::DEPTH_TEST);
|
gl::Disable(gl::DEPTH_TEST);
|
||||||
gl::Disable(gl::BLEND);
|
gl::Disable(gl::BLEND);
|
||||||
ui::draw_ui(&mut imgui, &renderer, &glfw_platform, &mut window, &mut state, delta_time, &mut last_cursor, scene_texture);
|
ui::draw_ui(&mut imgui, &renderer, &glfw_platform, &mut window, &mut state, &mut last_cursor, scene_texture);
|
||||||
|
|
||||||
glfw.poll_events();
|
glfw.poll_events();
|
||||||
window.swap_buffers();
|
window.swap_buffers();
|
||||||
|
|||||||
+134
-53
@@ -16,6 +16,7 @@ pub struct State {
|
|||||||
pub show_console: bool,
|
pub show_console: bool,
|
||||||
pub show_help_menu_about: bool,
|
pub show_help_menu_about: bool,
|
||||||
pub show_settings: bool,
|
pub show_settings: bool,
|
||||||
|
pub show_keybinds: bool,
|
||||||
pub is_cursor_captured: bool,
|
pub is_cursor_captured: bool,
|
||||||
pub can_capture_cursor: bool,
|
pub can_capture_cursor: bool,
|
||||||
pub draw_grid: bool,
|
pub draw_grid: bool,
|
||||||
@@ -29,6 +30,7 @@ pub struct State {
|
|||||||
pub viewport_size: [f32; 2],
|
pub viewport_size: [f32; 2],
|
||||||
pub logger: logger::WritableLog,
|
pub logger: logger::WritableLog,
|
||||||
pub settings: Settings,
|
pub settings: Settings,
|
||||||
|
pub fps: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for State {
|
impl Default for State {
|
||||||
@@ -38,6 +40,7 @@ impl Default for State {
|
|||||||
show_console: false,
|
show_console: false,
|
||||||
show_help_menu_about: false,
|
show_help_menu_about: false,
|
||||||
show_settings: false,
|
show_settings: false,
|
||||||
|
show_keybinds: false,
|
||||||
first_frame_drawn: false,
|
first_frame_drawn: false,
|
||||||
is_cursor_captured: false,
|
is_cursor_captured: false,
|
||||||
can_capture_cursor: false,
|
can_capture_cursor: false,
|
||||||
@@ -51,6 +54,7 @@ impl Default for State {
|
|||||||
viewport_size: [0.0, 0.0],
|
viewport_size: [0.0, 0.0],
|
||||||
logger: logger::WritableLog::default(),
|
logger: logger::WritableLog::default(),
|
||||||
settings: Settings::default(),
|
settings: Settings::default(),
|
||||||
|
fps: 0.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,12 +80,20 @@ pub fn init_imgui(window: &mut glfw::Window) -> (imgui::Context, imgui_glfw_supp
|
|||||||
glfw_platform.attach_window(
|
glfw_platform.attach_window(
|
||||||
imgui.io_mut(),
|
imgui.io_mut(),
|
||||||
&window,
|
&window,
|
||||||
imgui_glfw_support::HiDpiMode::Rounded
|
imgui_glfw_support::HiDpiMode::Default
|
||||||
);
|
);
|
||||||
|
|
||||||
imgui
|
imgui
|
||||||
.fonts()
|
.fonts()
|
||||||
.add_font(&[imgui::FontSource::DefaultFontData { config: None }]);
|
.add_font(&[imgui::FontSource::TtfData {
|
||||||
|
data: include_bytes!("../../assets/fonts/Exo-Regular.ttf"),
|
||||||
|
size_pixels: 20.0,
|
||||||
|
config: Some(imgui::FontConfig {
|
||||||
|
oversample_h: 3,
|
||||||
|
pixel_snap_h: true,
|
||||||
|
..imgui::FontConfig::default()
|
||||||
|
})
|
||||||
|
}]);
|
||||||
|
|
||||||
imgui.io_mut().font_global_scale = (1.0 / glfw_platform.hidpi_factor()) as f32;
|
imgui.io_mut().font_global_scale = (1.0 / glfw_platform.hidpi_factor()) as f32;
|
||||||
|
|
||||||
@@ -107,7 +119,7 @@ pub fn import_model(state: &mut State) {
|
|||||||
utils::import_models_from_paths(&models, state);
|
utils::import_models_from_paths(&models, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_main_menu_bar(ui: &imgui::Ui, state: &mut State, window: &mut glfw::Window, delta_time: f32) {
|
pub fn draw_main_menu_bar(ui: &imgui::Ui, state: &mut State, window: &mut glfw::Window) {
|
||||||
ui.main_menu_bar(|| {
|
ui.main_menu_bar(|| {
|
||||||
ui.menu("File", || {
|
ui.menu("File", || {
|
||||||
if ui.menu_item_config("Import Model(s)").shortcut("Ctrl+O").build() {
|
if ui.menu_item_config("Import Model(s)").shortcut("Ctrl+O").build() {
|
||||||
@@ -124,20 +136,48 @@ pub fn draw_main_menu_bar(ui: &imgui::Ui, state: &mut State, window: &mut glfw::
|
|||||||
if ui.menu_item_config("Show Grid").selected(state.draw_grid).build() {
|
if ui.menu_item_config("Show Grid").selected(state.draw_grid).build() {
|
||||||
state.draw_grid = !state.draw_grid;
|
state.draw_grid = !state.draw_grid;
|
||||||
}
|
}
|
||||||
|
if ui.menu_item_config("Draw Bounding Box").selected(state.draw_aabb).build() {
|
||||||
|
state.draw_aabb = !state.draw_aabb;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
ui.menu("Help", || {
|
ui.menu("Help", || {
|
||||||
|
if ui.menu_item_config("Keybinds").selected(state.show_keybinds).build() {
|
||||||
|
state.show_keybinds = !state.show_keybinds;
|
||||||
|
}
|
||||||
if ui.menu_item_config("About").selected(state.show_help_menu_about).build() {
|
if ui.menu_item_config("About").selected(state.show_help_menu_about).build() {
|
||||||
state.show_help_menu_about = !state.show_help_menu_about;
|
state.show_help_menu_about = !state.show_help_menu_about;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let mem = state.objects.iter().fold(0 as usize, |acc, m| acc + m.mem_usage) as f32;
|
let mem = state.objects.iter().fold(0 as usize, |acc, m| acc + m.mem_usage) as f32;
|
||||||
let mem_fps = format!("Mem: {:.1}MB | FPS: {:.1}", mem / (1024.0 * 1024.0), 1.0 / delta_time);
|
let mem_fps = format!("Mem: {:.1}MB | FPS: {:.1}", mem / (1024.0 * 1024.0), state.fps);
|
||||||
let avail_size = [*ui.content_region_avail().get(0).unwrap() - ui.calc_text_size(&mem_fps)[0], 0.0];
|
let avail_size = [*ui.content_region_avail().get(0).unwrap() - ui.calc_text_size(&mem_fps)[0], 0.0];
|
||||||
ui.dummy(avail_size);
|
ui.dummy(avail_size);
|
||||||
ui.text(&mem_fps);
|
ui.text(&mem_fps);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw_about_window(ui: &imgui::Ui, state: &mut State) {
|
||||||
|
if !state.show_help_menu_about {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let display_size = ui.io().display_size;
|
||||||
|
|
||||||
|
ui.window("About")
|
||||||
|
.resizable(false)
|
||||||
|
.movable(false)
|
||||||
|
.opened(&mut state.show_help_menu_about)
|
||||||
|
.position([display_size[0] / 2.0, display_size[1] / 2.0], imgui::Condition::Always)
|
||||||
|
.position_pivot([0.5, 0.5])
|
||||||
|
.build(|| {
|
||||||
|
ui.text("3dobs - 3D Object Browser");
|
||||||
|
ui.text(format!("Version: {}-{}", env!("CARGO_PKG_VERSION"), env!("GIT_HASH")));
|
||||||
|
ui.text(format!("{}", env!("CARGO_PKG_DESCRIPTION")));
|
||||||
|
ui.spacing();
|
||||||
|
ui.spacing();
|
||||||
|
ui.text(format!("Made by: {}", env!("CARGO_PKG_AUTHORS")));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
pub fn draw_settings_window(ui: &imgui::Ui, state: &mut State) {
|
pub fn draw_settings_window(ui: &imgui::Ui, state: &mut State) {
|
||||||
if !state.show_settings {
|
if !state.show_settings {
|
||||||
return;
|
return;
|
||||||
@@ -145,9 +185,9 @@ pub fn draw_settings_window(ui: &imgui::Ui, state: &mut State) {
|
|||||||
let display_size = ui.io().display_size;
|
let display_size = ui.io().display_size;
|
||||||
|
|
||||||
ui.window("Settings")
|
ui.window("Settings")
|
||||||
.size([500.0, 100.0], imgui::Condition::FirstUseEver)
|
|
||||||
.opened(&mut state.show_settings)
|
.opened(&mut state.show_settings)
|
||||||
.position([display_size[0] / 2.0, display_size[1] / 2.0], imgui::Condition::FirstUseEver)
|
.movable(false)
|
||||||
|
.position([display_size[0] / 2.0, display_size[1] / 2.0], imgui::Condition::Always)
|
||||||
.position_pivot([0.5, 0.5])
|
.position_pivot([0.5, 0.5])
|
||||||
.build(|| {
|
.build(|| {
|
||||||
if ui.checkbox("Only allow one program instance (Reboot required when enabling)", &mut state.settings.one_instance) {
|
if ui.checkbox("Only allow one program instance (Reboot required when enabling)", &mut state.settings.one_instance) {
|
||||||
@@ -156,6 +196,58 @@ pub fn draw_settings_window(ui: &imgui::Ui, state: &mut State) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw_keybinds_window(ui: &imgui::Ui, state: &mut State) {
|
||||||
|
if !state.show_keybinds {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let display_size = ui.io().display_size;
|
||||||
|
|
||||||
|
ui.window("Keybinds")
|
||||||
|
.opened(&mut state.show_keybinds)
|
||||||
|
.resizable(false)
|
||||||
|
.movable(false)
|
||||||
|
.position([display_size[0] / 2.0, display_size[1] / 2.0], imgui::Condition::Always)
|
||||||
|
.position_pivot([0.5, 0.5])
|
||||||
|
.build(|| {
|
||||||
|
if let Some(..) = ui.begin_table_with_sizing("Keybinds Table", 2, imgui::TableFlags::SIZING_STRETCH_SAME, [0.0, 0.0], 0.0) {
|
||||||
|
ui.table_next_column();
|
||||||
|
ui.text_colored([0.7, 0.7, 0.6, 1.0], "Key");
|
||||||
|
ui.table_next_column();
|
||||||
|
ui.text_colored([0.7, 0.7, 0.6, 1.0], "Action");
|
||||||
|
|
||||||
|
ui.table_next_column();
|
||||||
|
ui.text("Ctrl + O | Drag & Drop");
|
||||||
|
ui.table_next_column();
|
||||||
|
ui.text("Import Model(s)");
|
||||||
|
|
||||||
|
ui.table_next_column();
|
||||||
|
ui.text("Ctrl + Q");
|
||||||
|
ui.table_next_column();
|
||||||
|
ui.text("Quit");
|
||||||
|
|
||||||
|
ui.table_next_column();
|
||||||
|
ui.text("Left Mouse Button");
|
||||||
|
ui.table_next_column();
|
||||||
|
ui.text("Rotate object");
|
||||||
|
|
||||||
|
ui.table_next_column();
|
||||||
|
ui.text("Scroll");
|
||||||
|
ui.table_next_column();
|
||||||
|
ui.text("Zoom camera");
|
||||||
|
|
||||||
|
ui.table_next_column();
|
||||||
|
ui.text("Left Shift");
|
||||||
|
ui.table_next_column();
|
||||||
|
ui.text("Pan camera");
|
||||||
|
|
||||||
|
ui.table_next_column();
|
||||||
|
ui.text("Left Ctrl");
|
||||||
|
ui.table_next_column();
|
||||||
|
ui.text("Increase camera movement speed");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fn draw_transformations(ui: &imgui::Ui, mesh: &mut mesh::Mesh) {
|
fn draw_transformations(ui: &imgui::Ui, mesh: &mut mesh::Mesh) {
|
||||||
imgui::Drag::new("###XPos")
|
imgui::Drag::new("###XPos")
|
||||||
.range(f32::NEG_INFINITY, f32::INFINITY)
|
.range(f32::NEG_INFINITY, f32::INFINITY)
|
||||||
@@ -172,16 +264,6 @@ fn draw_transformations(ui: &imgui::Ui, mesh: &mut mesh::Mesh) {
|
|||||||
.speed(0.1)
|
.speed(0.1)
|
||||||
.display_format("Z: %.3f")
|
.display_format("Z: %.3f")
|
||||||
.build(ui, &mut mesh.position.z);
|
.build(ui, &mut mesh.position.z);
|
||||||
imgui::Drag::new("Scale")
|
|
||||||
.range(f32::NEG_INFINITY, f32::INFINITY)
|
|
||||||
.speed(0.1)
|
|
||||||
.display_format("%.7f")
|
|
||||||
.build_array(ui, mesh.scale.as_array_mut());
|
|
||||||
imgui::Drag::new("Rotation")
|
|
||||||
.range(f32::NEG_INFINITY, f32::INFINITY)
|
|
||||||
.speed(1.0)
|
|
||||||
.display_format("%.2f")
|
|
||||||
.build_array(ui, mesh.rotation.as_array_mut());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_mesh_hierarchy(ui: &imgui::Ui, mesh: &mut mesh::Mesh, i: usize) {
|
fn draw_mesh_hierarchy(ui: &imgui::Ui, mesh: &mut mesh::Mesh, i: usize) {
|
||||||
@@ -198,28 +280,26 @@ fn draw_mesh_hierarchy(ui: &imgui::Ui, mesh: &mut mesh::Mesh, i: usize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn draw_object_hierarchy(ui: &imgui::Ui, state: &mut State, idx: usize) -> bool {
|
fn draw_object_hierarchy(ui: &imgui::Ui, state: &mut State, idx: usize) -> bool {
|
||||||
let object = &mut state.objects[idx];
|
|
||||||
if let Some(..) = ui.begin_table_with_sizing("Objects Table", 2, imgui::TableFlags::SIZING_STRETCH_PROP, [0.0, 0.0], 0.0) {
|
|
||||||
ui.table_next_row();
|
|
||||||
ui.table_next_column();
|
ui.table_next_column();
|
||||||
ui.tree_node_config(format!("{} ({:.1}MB)###{}", object.name.as_str(), object.mem_usage as f32 / (1024.0 * 1024.0), idx))
|
if ui.checkbox(format!("###{}", state.objects[idx].id), &mut (Some(state.objects[idx].id) == state.active_model)) {
|
||||||
|
state.objects[idx].reset_rotation();
|
||||||
|
state.active_model = Some(state.objects[idx].id);
|
||||||
|
state.camera.focus_on_selected_model(state.active_model, &state.objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.table_next_column();
|
||||||
|
ui.tree_node_config(format!("{} ({:.1}MB)###{}", state.objects[idx].name.as_str(), state.objects[idx].mem_usage as f32 / (1024.0 * 1024.0), idx))
|
||||||
.build(|| {
|
.build(|| {
|
||||||
for (j, mesh) in &mut object.meshes.iter_mut().enumerate() {
|
for (j, mesh) in &mut state.objects[idx].meshes.iter_mut().enumerate() {
|
||||||
draw_mesh_hierarchy(ui, mesh, j);
|
draw_mesh_hierarchy(ui, mesh, j);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.table_next_column();
|
ui.table_next_column();
|
||||||
if ui.small_button(format!("X###{}-{}", object.name.as_str(), idx)) {
|
if ui.small_button(format!("X###{}-{}", state.objects[idx].name.as_str(), idx)) {
|
||||||
info!("Removing object {}", object.name);
|
info!("Removing object {}", state.objects[idx].name);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ui.checkbox("Selected", &mut (Some(state.objects[idx].id) == state.active_model)) {
|
|
||||||
state.objects[idx].reset_rotation();
|
|
||||||
state.active_model = Some(state.objects[idx].id);
|
|
||||||
state.camera.focus_on_selected_model(state.active_model, &state.objects);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -230,6 +310,26 @@ fn draw_objects_window(ui: &imgui::Ui, state: &mut State) {
|
|||||||
.build(|| {
|
.build(|| {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
|
||||||
|
if let Some(..) = ui.begin_table_with_sizing("Objects Table", 3, imgui::TableFlags::SIZING_FIXED_FIT, [0.0, 0.0], 0.0) {
|
||||||
|
ui.table_setup_column_with(imgui::TableColumnSetup {
|
||||||
|
name: "",
|
||||||
|
flags: imgui::TableColumnFlags::empty(),
|
||||||
|
init_width_or_weight: 30.0,
|
||||||
|
user_id: imgui::Id::default(),
|
||||||
|
});
|
||||||
|
ui.table_setup_column_with(imgui::TableColumnSetup {
|
||||||
|
name: "",
|
||||||
|
flags: imgui::TableColumnFlags::WIDTH_STRETCH,
|
||||||
|
init_width_or_weight: 0.0,
|
||||||
|
user_id: imgui::Id::default(),
|
||||||
|
});
|
||||||
|
ui.table_setup_column_with(imgui::TableColumnSetup {
|
||||||
|
name: "",
|
||||||
|
flags: imgui::TableColumnFlags::empty(),
|
||||||
|
init_width_or_weight: 20.0,
|
||||||
|
user_id: imgui::Id::default(),
|
||||||
|
});
|
||||||
|
|
||||||
while i < state.objects.len() {
|
while i < state.objects.len() {
|
||||||
if draw_object_hierarchy(ui, state, i) {
|
if draw_object_hierarchy(ui, state, i) {
|
||||||
let selected_obj_id = state.objects[i].id;
|
let selected_obj_id = state.objects[i].id;
|
||||||
@@ -244,6 +344,7 @@ fn draw_objects_window(ui: &imgui::Ui, state: &mut State) {
|
|||||||
|
|
||||||
i = i + 1;
|
i = i + 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,7 +353,7 @@ fn draw_console(ui: &imgui::Ui, state: &mut State) {
|
|||||||
.size([500.0, 200.0], imgui::Condition::FirstUseEver)
|
.size([500.0, 200.0], imgui::Condition::FirstUseEver)
|
||||||
.build(|| {
|
.build(|| {
|
||||||
ui.child_window("###ConsoleHistory")
|
ui.child_window("###ConsoleHistory")
|
||||||
.size([0.0, -27.0])
|
.size([0.0, -35.0])
|
||||||
.build(|| {
|
.build(|| {
|
||||||
for line in state.logger.arc.read().unwrap().history.iter() {
|
for line in state.logger.arc.read().unwrap().history.iter() {
|
||||||
let style = ui.push_style_color(imgui::StyleColor::Text, line.level);
|
let style = ui.push_style_color(imgui::StyleColor::Text, line.level);
|
||||||
@@ -384,8 +485,6 @@ fn draw_viewport(ui: &imgui::Ui, state: &mut State, texture: u32) {
|
|||||||
ui.same_line();
|
ui.same_line();
|
||||||
ui.checkbox("Wireframe", &mut state.wireframe);
|
ui.checkbox("Wireframe", &mut state.wireframe);
|
||||||
ui.same_line();
|
ui.same_line();
|
||||||
ui.checkbox("Bounding box", &mut state.draw_aabb);
|
|
||||||
ui.same_line();
|
|
||||||
ui.checkbox("FOV zoom", &mut state.fov_zoom);
|
ui.checkbox("FOV zoom", &mut state.fov_zoom);
|
||||||
ui.same_line();
|
ui.same_line();
|
||||||
ui.set_next_item_width(150.0);
|
ui.set_next_item_width(150.0);
|
||||||
@@ -418,39 +517,21 @@ pub fn draw_ui(
|
|||||||
glfw_platform: &imgui_glfw_support::GlfwPlatform,
|
glfw_platform: &imgui_glfw_support::GlfwPlatform,
|
||||||
window: &mut glfw::Window,
|
window: &mut glfw::Window,
|
||||||
state: &mut State,
|
state: &mut State,
|
||||||
delta_time: f32,
|
|
||||||
last_cursor: &mut Option<imgui::MouseCursor>,
|
last_cursor: &mut Option<imgui::MouseCursor>,
|
||||||
scene_fb_texture: u32,
|
scene_fb_texture: u32,
|
||||||
) {
|
) {
|
||||||
glfw_platform.prepare_frame(imgui.io_mut(), window).expect("Failed to prepare imgui frame");
|
glfw_platform.prepare_frame(imgui.io_mut(), window).expect("Failed to prepare imgui frame");
|
||||||
|
|
||||||
let display_size = imgui.io().display_size;
|
|
||||||
let ui = imgui.new_frame();
|
let ui = imgui.new_frame();
|
||||||
create_initial_docking(ui, state);
|
create_initial_docking(ui, state);
|
||||||
|
|
||||||
draw_main_menu_bar(ui, state, window, delta_time);
|
draw_main_menu_bar(ui, state, window);
|
||||||
|
|
||||||
if state.show_help_menu_about {
|
|
||||||
ui.window("About")
|
|
||||||
.size([300.0, 150.0], imgui::Condition::FirstUseEver)
|
|
||||||
.resizable(false)
|
|
||||||
.movable(false)
|
|
||||||
.opened(&mut state.show_help_menu_about)
|
|
||||||
.position([display_size[0] / 2.0, display_size[1] / 2.0], imgui::Condition::Always)
|
|
||||||
.position_pivot([0.5, 0.5])
|
|
||||||
.build(|| {
|
|
||||||
ui.text("3dobs - 3D Object Browser");
|
|
||||||
ui.text(format!("Version: {}-{}", env!("CARGO_PKG_VERSION"), env!("GIT_HASH")));
|
|
||||||
ui.text(format!("{}", env!("CARGO_PKG_DESCRIPTION")));
|
|
||||||
ui.spacing();
|
|
||||||
ui.spacing();
|
|
||||||
ui.text(format!("Made by: {}", env!("CARGO_PKG_AUTHORS")));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
draw_viewport(ui, state, scene_fb_texture);
|
draw_viewport(ui, state, scene_fb_texture);
|
||||||
draw_objects_window(ui, state);
|
draw_objects_window(ui, state);
|
||||||
draw_console(ui, state);
|
draw_console(ui, state);
|
||||||
|
draw_about_window(ui, state);
|
||||||
|
draw_keybinds_window(ui, state);
|
||||||
draw_settings_window(ui, state);
|
draw_settings_window(ui, state);
|
||||||
|
|
||||||
ui.end_frame_early();
|
ui.end_frame_early();
|
||||||
|
|||||||
Reference in New Issue
Block a user