Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
- Added hotkeys to add to current route. <kbd>+</kbd> adds at the end of the route, or after current node, <kbd>-</kbd> adds before the selected node
- Content confidentiality dialog on first startup
- Log unimplemented TFX bytecode ops in the TFX debugger
- Added Cuboid utility shape. Scaling Gizmo will be made nicer in the future... @Froggy618157725
in [#43](https://github.com/cohaereo/alkahest/pull/43)
### Changed

- Enable SSAO by default
Expand All @@ -76,6 +78,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
- Added transparency sorting for sky objects (fixes broken skyboxes such as the Anomaly in Vesper's Host)
- Fixed a water related map loading error on Disjunction
- Hotkeys are no longer triggered when typing in text fields
- Fix certain Utility Objects spawning at Infinity

## 0.5.0 - 2024-07-24

Expand Down
89 changes: 87 additions & 2 deletions crates/alkahest-renderer/src/ecs/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use glam::Vec3;
use super::{
common::{Icon, Label, Mutable, RenderCommonBundle},
route::{Route, RouteNode},
tags::{NodeFilter, Tags},
tags::{EntityTag, NodeFilter, Tags},
visibility::VisibilityHelper,
MapInfo,
};
Expand All @@ -22,7 +22,7 @@ use crate::{
hierarchy::Children, resources::SelectedEntity, transform::Transform,
visibility::ViewVisibility,
},
icons::{ICON_RULER_SQUARE, ICON_SIGN_POLE, ICON_SPHERE},
icons::{ICON_CUBE_OUTLINE, ICON_RULER_SQUARE, ICON_SIGN_POLE, ICON_SPHERE},
renderer::{LabelAlign, Renderer, RendererShared},
util::{
color::{Color, ColorExt, Hsv},
Expand Down Expand Up @@ -119,6 +119,55 @@ impl Utility for Sphere {
}
}

#[derive(Component)]
pub struct Cuboid {
pub color: Color,
pub rainbow: bool,
}

impl Default for Cuboid {
fn default() -> Self {
Self {
color: Color::from_rgba_premultiplied(1.0, 1.0, 1.0, 0.3),
rainbow: false,
}
}
}

impl Utility for Cuboid {
fn default_label() -> Label {
Label::new_default("Cuboid").with_offset(0.0, 0.0, -1.0)
}

fn icon() -> Icon {
Icon::Unicode(ICON_CUBE_OUTLINE)
}
}

#[derive(Bundle)]
pub struct CuboidBundle {
pub transform: Transform,
pub cuboid: Cuboid,
pub util_common: UtilityCommonBundle,
}

impl CuboidBundle {
pub fn new(transform: Transform, cuboid: Cuboid) -> Self {
Self {
transform,
cuboid,
util_common: UtilityCommonBundle {
label: Cuboid::default_label(),
icon: Cuboid::icon(),
filter: NodeFilter::Utility,
tags: Tags::from_iter([EntityTag::Utility]),
mutable: Mutable,
render_common: RenderCommonBundle::default(),
},
}
}
}

#[derive(Component)]
pub struct Beacon {
pub color: Color,
Expand Down Expand Up @@ -155,6 +204,7 @@ pub fn draw_utilities_system(
selected: ResMut<SelectedEntity>,
q_ruler: Query<(Entity, &Ruler, Option<&ViewVisibility>)>,
q_sphere: Query<(Entity, &Transform, &Sphere, Option<&ViewVisibility>)>,
q_cuboid: Query<(Entity, &Transform, &Cuboid, Option<&ViewVisibility>)>,
q_beacon: Query<(Entity, &Transform, &Beacon, Option<&ViewVisibility>)>,
q_route: Query<(Entity, &Route, &Children, Option<&ViewVisibility>)>,
q_route_node: Query<(Entity, &Transform, &RouteNode)>,
Expand All @@ -171,6 +221,12 @@ pub fn draw_utilities_system(
}
}

for (e, transform, cuboid, vis) in q_cuboid.iter() {
if vis.is_visible(renderer.active_view) {
draw_cuboid(&renderer, transform, cuboid, e, &selected);
}
}

for (e, transform, beacon, vis) in q_beacon.iter() {
if vis.is_visible(renderer.active_view) {
draw_beacon(&renderer, transform, beacon, e, &selected);
Expand Down Expand Up @@ -362,6 +418,35 @@ fn draw_sphere(
.sphere(transform.translation, transform.radius(), color);
}

fn draw_cuboid(
renderer: &Renderer,
transform: &Transform,
cuboid: &Cuboid,
entity: Entity,
selected: &SelectedEntity,
) {
let color = if cuboid.rainbow {
Color::from(*Hsv::rainbow())
} else {
cuboid.color
};

let color = selected.select_fade_color(color, Some(entity));

let color_opaque = color.to_opaque();
let cross_color = color_opaque.invert().keep_bright();
renderer.immediate.cross(
transform.translation,
0.25 * transform.scale.length(),
cross_color,
);

renderer
.immediate
.cube_outline(transform.local_to_world(), color);
renderer.immediate.cube(transform.local_to_world(), color);
}

fn draw_beacon(
renderer: &Renderer,
transform: &Transform,
Expand Down
7 changes: 4 additions & 3 deletions crates/alkahest-renderer/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,15 @@ impl Renderer {
);
}

// TODO(cohae): Move debug shapes to a separate system
scene.run_system_once_with(
resources.get::<RendererShared>().clone(),
draw_debugshapes_system,
draw_utilities_system,
);

// TODO(cohae): Move debug shapes to a separate system
scene.run_system_once_with(
resources.get::<RendererShared>().clone(),
draw_utilities_system,
draw_debugshapes_system,
);
// scene.run_system_once_with(resources.get::<RendererShared>().clone(), draw_aabb_system);

Expand Down
3 changes: 2 additions & 1 deletion crates/alkahest/src/gui/inspector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use alkahest_renderer::{
route::{Route, RouteNode},
tags::{insert_tag, remove_tag, EntityTag, Tags},
transform::{OriginalTransform, Transform, TransformFlags},
utility::{Beacon, Ruler, Sphere},
utility::{Beacon, Cuboid, Ruler, Sphere},
visibility::{Visibility, VisibilityHelper},
Scene,
},
Expand Down Expand Up @@ -299,6 +299,7 @@ fn show_inspector_components(
// EntityWorldId,
Ruler,
Sphere,
Cuboid,
Beacon,
Route,
RouteNode,
Expand Down
46 changes: 40 additions & 6 deletions crates/alkahest/src/gui/inspector/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use alkahest_renderer::{
resources::SelectedEntity,
route::{Route, RouteNode, RouteNodeBundle, RouteNodeData},
transform::Transform,
utility::{Beacon, Ruler, Sphere, Utility},
utility::{Beacon, Cuboid, Ruler, Sphere, Utility},
Scene, SceneInfo,
},
icons::{
Expand Down Expand Up @@ -38,7 +38,7 @@ impl ComponentPanel for Ruler {
}

fn inspector_icon() -> char {
Ruler::icon().char()
Self::icon().char()
}

fn show_inspector_ui(
Expand Down Expand Up @@ -171,7 +171,7 @@ impl ComponentPanel for Sphere {
}

fn inspector_icon() -> char {
Sphere::icon().char()
Self::icon().char()
}

fn show_inspector_ui(
Expand Down Expand Up @@ -208,13 +208,47 @@ impl ComponentPanel for Sphere {
}
}

impl ComponentPanel for Cuboid {
fn inspector_name() -> &'static str {
"Cuboid"
}

fn inspector_icon() -> char {
Self::icon().char()
}

fn show_inspector_ui(
&mut self,
_: &mut Scene,
_: &mut Commands<'_, '_>,
e: EntityRef<'_>,
ui: &mut egui::Ui,
_resources: &AppResources,
) {
if !e.contains::<Transform>() {
ui.label(format!(
"{} This entity has no transform component",
ICON_ALERT
));
}

ui.horizontal(|ui| {
color_edit_button_rgba(ui, &mut self.color, Alpha::OnlyBlend).context_menu(|ui| {
ui.checkbox(&mut self.rainbow, "Rainbow mode");
});

ui.label("Color");
});
}
}

impl ComponentPanel for Beacon {
fn inspector_name() -> &'static str {
"Beacon"
}

fn inspector_icon() -> char {
Beacon::icon().char()
Self::icon().char()
}

fn show_inspector_ui(
Expand Down Expand Up @@ -320,7 +354,7 @@ impl ComponentPanel for Route {
}

fn inspector_icon() -> char {
Route::icon().char()
Self::icon().char()
}

fn show_inspector_ui(
Expand Down Expand Up @@ -436,7 +470,7 @@ impl ComponentPanel for RouteNode {
}

fn inspector_icon() -> char {
RouteNode::icon().char()
Self::icon().char()
}

fn show_inspector_ui(
Expand Down
45 changes: 41 additions & 4 deletions crates/alkahest/src/gui/menu/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ use alkahest_renderer::{
route::{Route, RouteNodeBundle, RouteNodeData},
tags::{EntityTag, NodeFilter, Tags},
transform::{Transform, TransformFlags},
utility::{Beacon, Ruler, Sphere, Utility},
utility::{Beacon, Cuboid, CuboidBundle, Ruler, Sphere, Utility},
SceneInfo,
},
icons::{ICON_MAP_MARKER_PATH, ICON_POKEBALL, ICON_RULER_SQUARE, ICON_SIGN_POLE, ICON_SPHERE},
icons::{
ICON_CUBE_OUTLINE, ICON_MAP_MARKER_PATH, ICON_POKEBALL, ICON_RULER_SQUARE, ICON_SIGN_POLE,
ICON_SPHERE,
},
renderer::RendererShared,
resources::AppResources,
shader::shader_ball::ShaderBallComponent,
Expand Down Expand Up @@ -76,7 +79,11 @@ impl MenuBar {
let e = map.scene.spawn((
NodeFilter::Utility,
Transform {
translation: if distance > 24.0 { position_base } else { pos },
translation: if !pos.is_finite() || distance > 24.0 {
position_base
} else {
pos
},
scale: Vec3::splat(9.0),
flags: TransformFlags::IGNORE_ROTATION | TransformFlags::SCALE_IS_RADIUS,
..Default::default()
Expand All @@ -94,6 +101,36 @@ impl MenuBar {
ui.close_menu();
}
}
if ui.button(format!("{} Cuboid", ICON_CUBE_OUTLINE)).clicked() {
let mut maps = resources.get_mut::<MapList>();
let renderer = resources.get::<RendererShared>();
let camera = resources.get::<Camera>();
let (distance, pos) = renderer
.data
.lock()
.gbuffers
.depth_buffer_distance_pos_center(&camera);
if let Some(map) = maps.current_map_mut() {
let camera = resources.get::<Camera>();
let position_base = camera.position() + camera.forward() * 24.0;
let e = map.scene.spawn(CuboidBundle::new(
Transform {
translation: if !pos.is_finite() || distance > 24.0 {
position_base
} else {
pos
},
scale: Vec3::splat(12.0),
..Default::default()
},
Cuboid::default(),
));

resources.get_mut::<SelectedEntity>().select(e.id());

ui.close_menu();
}
}
if ui.button(format!("{} Beacon", ICON_SIGN_POLE)).clicked() {
let mut maps: std::cell::RefMut<'_, MapList> = resources.get_mut::<MapList>();
let renderer = resources.get::<RendererShared>();
Expand All @@ -109,7 +146,7 @@ impl MenuBar {
let e = map.scene.spawn((
NodeFilter::Utility,
Transform {
translation: if distance > 24.0 {
translation: if !pos.is_finite() || distance > 24.0 {
camera.position()
} else {
pos
Expand Down
Loading