Skip to content

Commit

Permalink
test scene + path fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kayhhh committed Dec 30, 2024
1 parent 81a5f61 commit 8c0ca88
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/unavi-app/assets/images/dev-white.png.meta
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(
meta_format_version: "1.0",
asset: Load(
loader: "bevy_render::texture::image_loader::ImageLoader",
loader: "bevy_image::image_loader::ImageLoader",
settings: (
format: FromExtension,
is_srgb: true,
Expand Down
2 changes: 2 additions & 0 deletions crates/unavi-app/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ let
];

postInstall = ''
mv $out/bin/* $out
rm -r $out/bin
cp -r crates/unavi-app/assets $out
cp LICENSE $out
'';
Expand Down
1 change: 1 addition & 0 deletions crates/unavi-app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::sync::LazyLock;
use directories::ProjectDirs;

pub mod icon;
pub mod scene;
pub mod update;

pub static DIRS: LazyLock<ProjectDirs> = LazyLock::new(|| {
Expand Down
11 changes: 9 additions & 2 deletions crates/unavi-app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy::prelude::*;
use unavi_app::{icon::set_window_icon, update::check_for_updates};
use unavi_app::update::check_for_updates;

fn main() {
if cfg!(not(debug_assertions)) {
Expand All @@ -21,7 +21,14 @@ fn main() {
})
.finish(&mut app);

app.add_systems(Startup, set_window_icon);
app.add_systems(
Startup,
(
unavi_app::icon::set_window_icon,
unavi_app::scene::spawn_lights,
unavi_app::scene::spawn_scene,
),
);

app.run();
}
53 changes: 53 additions & 0 deletions crates/unavi-app/src/scene.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use bevy::{prelude::*, render::mesh::VertexAttributeValues};

pub fn spawn_lights(mut commands: Commands, mut ambient: ResMut<AmbientLight>) {
ambient.brightness = 40.0;
ambient.color = Color::linear_rgb(0.95, 0.95, 1.0);

commands.spawn((
DirectionalLight {
color: Color::linear_rgb(1.0, 1.0, 0.98),
illuminance: 5000.0,
shadows_enabled: true,
..default()
},
Transform::from_xyz(-4.5, 10.0, 7.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}

pub fn spawn_scene(
asset_server: Res<AssetServer>,
mut commands: Commands,
mut materials: ResMut<Assets<StandardMaterial>>,
mut meshes: ResMut<Assets<Mesh>>,
) {
let ground_size = 30.0;

let ground_texture = asset_server.load("images/dev-white.png");
let ground_texture_scale = ground_size / 4.0;

let mut ground_mesh = Mesh::from(Cuboid {
half_size: Vec3::new(ground_size / 2.0, 0.05, ground_size / 2.0),
});

match ground_mesh.attribute_mut(Mesh::ATTRIBUTE_UV_0).unwrap() {
VertexAttributeValues::Float32x2(uvs) => {
for uv in uvs {
uv[0] *= ground_texture_scale;
uv[1] *= ground_texture_scale;
}
}
_ => unreachable!(),
}

commands.spawn((
Mesh3d(meshes.add(ground_mesh)),
MeshMaterial3d(materials.add(StandardMaterial {
base_color_texture: Some(ground_texture),
..default()
})),
Transform::from_xyz(0.0, -0.1, 0.0),
));

commands.spawn((Camera3d::default(), Transform::from_xyz(0.0, 1.0, 0.0)));
}
5 changes: 4 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
formatter = treefmtEval.config.build.wrapper;

apps = rec {
app = flake-utils.lib.mkApp { drv = unavi-app.package; };
app = flake-utils.lib.mkApp {
drv = unavi-app.package;
exePath = "/unavi-app";
};
default = app;
};

Expand Down

0 comments on commit 8c0ca88

Please sign in to comment.