Skip to content

Commit

Permalink
docking bay improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Baezon committed Sep 29, 2023
1 parent d165d23 commit 1770419
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pof/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ trait ParseCtx<'a> {
let up = self.up();
let offset = Vec3d::from(center).from_coord(up);

println!("{:?}", node.name());
// println!("{:?}", node.name());
let name = match node.name() {
Some(name) => name,
None => continue,
Expand Down
Binary file added src/dockdemo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 60 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use glium::{
use glm::Mat4x4;
use native_dialog::FileDialog;
use pof::{
properties_get_field, BspData, Insignia, NameLink, NormalId, ObjVec, ObjectId, Parser, PolyVertex, Polygon, ShieldData, SubObject, TextureId,
Vec3d, VertexId,
properties_get_field, BspData, Insignia, NameLink, NormalId, NormalVec3, ObjVec, ObjectId, Parser, PolyVertex, Polygon, ShieldData, SubObject,
TextureId, Vec3d, VertexId,
};
use simplelog::*;
use std::{
Expand Down Expand Up @@ -661,18 +661,13 @@ fn main() {

let event_loop = glutin::event_loop::EventLoopBuilder::with_user_event().build();
let display = create_display(&event_loop);
let mut pt_gui = PofToolsGui::new(&display);

// this creates the raw bytes from png, how i make the icon
// File::create("zforward.raw")
// .unwrap()
// .write_all(&image::open("zforward.png").unwrap().into_rgba8().to_vec());

let mut args = std::env::args();
args.next();
let path = args.next().map(|arg| PathBuf::from(arg.as_str()));

let mut egui = egui_glium::EguiGlium::new(&display, &event_loop);
let mut pt_gui = PofToolsGui::new(&display, &egui.egui_ctx);

pt_gui.start_loading_model(path);

Expand Down Expand Up @@ -1436,6 +1431,8 @@ fn main() {
.unwrap();
}
}

// draw arrowheads
for arrowhead in &pt_gui.arrowheads {
let vert_matrix: [[f32; 4]; 4] = (perspective_matrix * view_mat * arrowhead.transform).into();
let uniforms = glium::uniform! {
Expand All @@ -1448,7 +1445,22 @@ fn main() {
&pt_gui.graphics.arrowhead_indices,
&pt_gui.graphics.arrowhead_shader,
&uniforms,
&pt_gui.graphics.arrowhead_draw_params,
&pt_gui.graphics.arrowhead_params,
)
.unwrap();

// darker, reverse depth, as above
let uniforms = glium::uniform! {
vert_matrix: vert_matrix,
lollipop_color: arrowhead.color.map(|col| col * 0.25 ),
};
target
.draw(
&pt_gui.graphics.arrowhead_verts,
&pt_gui.graphics.arrowhead_indices,
&pt_gui.graphics.arrowhead_shader,
&uniforms,
&pt_gui.graphics.arrowhead_rev_depth_params,
)
.unwrap();
}
Expand Down Expand Up @@ -1943,6 +1955,13 @@ impl PofToolsGui {
None
};

let get_matrix = |pos: Vec3d, dir: NormalVec3, scale| {
let mut m = glm::translation::<f32>(&pos.into());
m *= dir.0.to_rotation_matrix();
m *= glm::scaling(&glm::vec3(scale * 0.5, scale * 0.5, scale * 0.5));
m
};

const COLORS: [[f32; 4]; 3] = [LOLLIPOP_UNSELECTED_COLOR, LOLLIPOP_SELECTED_POINT_COLOR, LOLLIPOP_SELECTED_BANK_COLOR];
self.lollipops = build_lollipops(
&COLORS,
Expand All @@ -1953,11 +1972,28 @@ impl PofToolsGui {
if hover_lollipop == Some(TreeValue::DockingBays(DockingTreeValue::Bay(bay_idx))) {
radius *= 2.
};
let fvec = docking_bay.fvec.0 * radius * 3.0;
let uvec = docking_bay.uvec.0 * radius * 3.0;
let fvec = docking_bay.fvec.0 * radius * 2.0;
let uvec = docking_bay.uvec.0 * radius * 2.0;
// while we're here, add the arrowheads to indicate the directions
let (selection1, selection2) = if selected_bank == Some(bay_idx) {
self.arrowheads.push(GlArrowhead {
color: LOLLIPOP_SELECTED_BANK_COLOR,
transform: get_matrix(position + fvec, docking_bay.fvec, radius * 1.5),
});
self.arrowheads.push(GlArrowhead {
color: LOLLIPOP_SELECTED_POINT_COLOR,
transform: get_matrix(position + uvec, docking_bay.uvec, radius * 1.5),
});
(SELECTED_BANK, SELECTED_POINT)
} else {
self.arrowheads.push(GlArrowhead {
color: LOLLIPOP_UNSELECTED_COLOR,
transform: get_matrix(position + fvec, docking_bay.fvec, radius * 1.5),
});
self.arrowheads.push(GlArrowhead {
color: LOLLIPOP_UNSELECTED_COLOR,
transform: get_matrix(position + uvec, docking_bay.uvec, radius * 1.5),
});
(UNSELECTED, UNSELECTED)
};

Expand Down Expand Up @@ -2209,7 +2245,8 @@ struct Graphics {
frustum_verts: VertexBuffer<Vertex>,

default_material_draw_params: glium::DrawParameters<'static>,
arrowhead_draw_params: glium::DrawParameters<'static>,
arrowhead_params: glium::DrawParameters<'static>,
arrowhead_rev_depth_params: glium::DrawParameters<'static>,
shield_draw_params: glium::DrawParameters<'static>,
wireframe_params: glium::DrawParameters<'static>,
lollipop_params: glium::DrawParameters<'static>,
Expand Down Expand Up @@ -2261,13 +2298,21 @@ impl Graphics {
backface_culling: glium::draw_parameters::BackfaceCullingMode::CullCounterClockwise,
..Default::default()
},
arrowhead_draw_params: glium::DrawParameters {
arrowhead_params: glium::DrawParameters {
depth: glium::Depth {
test: glium::draw_parameters::DepthTest::Overwrite,
test: glium::draw_parameters::DepthTest::IfLess,
write: false,
..Default::default()
},
backface_culling: glium::draw_parameters::BackfaceCullingMode::CullCounterClockwise,
..Default::default()
},
arrowhead_rev_depth_params: glium::DrawParameters {
depth: glium::Depth {
test: glium::draw_parameters::DepthTest::IfMore,
write: false,
..Default::default()
},
line_width: Some(1.0),
backface_culling: glium::draw_parameters::BackfaceCullingMode::CullCounterClockwise,
..Default::default()
},
Expand Down
19 changes: 16 additions & 3 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ pub(crate) struct PofToolsGui {
pub ui_state: UiState,
pub display_mode: DisplayMode,
pub glow_point_simulation: bool,

pub dock_demo_img: egui::TextureHandle,
pub camera_pitch: f32,
pub camera_heading: f32,
pub camera_scale: f32,
Expand Down Expand Up @@ -545,7 +545,7 @@ impl std::ops::DerefMut for PofToolsGui {
}
}
impl PofToolsGui {
pub fn new(display: &Display) -> Self {
pub fn new(display: &Display, ctx: &egui::Context) -> Self {
Self {
model: Box::new(Model {
pof_model: pof::Model::default(),
Expand All @@ -557,6 +557,19 @@ impl PofToolsGui {
ui_state: Default::default(),
display_mode: DisplayMode::Textured,
glow_point_simulation: Default::default(),
dock_demo_img: {
ctx.load_texture(
"my-image",
{
let image = image::load_from_memory(include_bytes!("dockdemo.png")).unwrap();
let size = [image.width() as _, image.height() as _];
let image_buffer = image.to_rgba8();
let pixels = image_buffer.as_flat_samples();
egui::ColorImage::from_rgba_unmultiplied(size, pixels.as_slice())
},
egui::TextureFilter::Linear,
)
},
camera_pitch: Default::default(),
camera_heading: Default::default(),
camera_scale: Default::default(),
Expand Down Expand Up @@ -886,7 +899,7 @@ impl PofToolsGui {

if ui.button("Open").clicked() {
self.start_loading_model(None);
ui.output().cursor_icon = egui::CursorIcon::Wait;
// ui.output().cursor_icon = egui::CursorIcon::Wait;
ui.close_menu();
}

Expand Down
2 changes: 2 additions & 0 deletions src/ui_properties_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2080,6 +2080,8 @@ impl PofToolsGui {
job.append(".", 0.0, TextFormat::default());
ui.label(job);

ui.image(&self.dock_demo_img, self.dock_demo_img.size_vec2());

if let Some(response) = bay_idx_response {
let new_idx = response.get_new_ui_idx(&self.model.docking_bays);

Expand Down

0 comments on commit 1770419

Please sign in to comment.