Commit: c895190
Parent: eac3d6e

Render bevy scene

Mårten Åsberg committed on 2026-09-20 at 15:16
Cargo.lock +6742 -0
Large diff (6742 lines changed) - not displayed
Cargo.toml +28 -0
diff --git a/Cargo.toml b/Cargo.toml
index 17cfd4c..b4236a0 100644
@@ -4,3 +4,31 @@ version = "0.1.0"
edition = "2024"
[dependencies]
bevy = { version = "0.20.0-rc.1", features = ["dynamic_linking", "free_camera"] }
# Enable a small amount of optimization in the dev profile.
[profile.dev]
opt-level = 1
# Enable a large amount of optimization in the dev profile for dependencies.
[profile.dev.package."*"]
opt-level = 3
# Enable more optimization in the release profile at the cost of compile time.
[profile.release]
# Compile the entire crate as one unit.
# Slows compile times, marginal improvements.
codegen-units = 1
# Do a second optimization pass over the entire program, including dependencies.
# Slows compile times, marginal improvements.
lto = "thin"
# Optimize for size in the wasm-release profile to reduce load times and bandwidth usage on web.
[profile.wasm-release]
# Default to release profile values.
inherits = "release"
# Optimize with size in mind (also try "z", sometimes it is better).
# Slightly slows compile times, great improvements to file size and runtime performance.
opt-level = "s"
# Strip all debugging information from the binary to slightly reduce file size.
strip = "debuginfo"
assets/Skybox.png +0 -0
diff --git a/assets/Skybox.png b/assets/Skybox.png
new file mode 100644
index 0000000..aa5c288
Binary files /dev/null and b/assets/Skybox.png differ
assets/Skybox.png.license +36 -0
diff --git a/assets/Skybox.png.license b/assets/Skybox.png.license
new file mode 100644
index 0000000..f6a5fa9
@@ -0,0 +1,36 @@
All Screaming Brain Studios assets have been released
under the CC0/Public Domain License. You are free to
use these assets in any and all projects, commercial
or non-commercial, with no restrictions, and can be
released with or without credit.
--------------------------------------------------
CC0 1.0 Universal (CC0 1.0)
Public Domain
https://creativecommons.org/publicdomain/zero/1.0/
--------------------------------------------------
|| A Very Special Thanks to all my Patrons ||
Dwayne Jarvis
Peardox - peardox.itch.io
David Williams
grob - groverburger.itch.io
Ragnar Random - ragnarrandom.com
warpdkirby
The Augur
Marina Kittaka - marinakittaka.com
Jeremy Dumont
AstralCastoff - astralcastoff.itch.io
CyberFoxar
kit.fox - https://falsefox.dev
Cody Sevier
Neo Te Aika - neoteaika.com/
Alex Robinson
Logan Dunlap
iamsoydev
Sarah Gray
Just Matt
Stray Molotov
The Arcology Podcast
assets/models/Village.glb +0 -0
diff --git a/assets/models/Village.glb b/assets/models/Village.glb
new file mode 100644
index 0000000..06d30ad
Binary files /dev/null and b/assets/models/Village.glb differ
assets/models/Village.glb.license +50 -0
diff --git a/assets/models/Village.glb.license b/assets/models/Village.glb.license
new file mode 100644
index 0000000..8f2e781
@@ -0,0 +1,50 @@
Thanks for buying the Source version of the Medieval Village MegaKit!
All textures can be found inside the Textures folder.
The SOURCE version of the Medieval Village MegaKit contains
all of the models and project files in Unity(URP), Unreal Engine and Godot projects
with the custom shaders already setup.
Versions used for the SOURCE version projects (anything above these work)
Godot_v4.3 | Unity (URP) 2022.3.4 | Unreal Engine 4.27.2
-------------------------------------------------------
License:
CC0 1.0 Universal (CC0 1.0)
Public Domain Dedication
https://creativecommons.org/publicdomain/zero/1.0/
------------------------------------------------------
Models by @Quaternius
Consider supporting me on Patreon!
https://www.patreon.com/quaternius
-------------------------------------------------------
Join the Discord Server:
https://discord.gg/vJqnRUYRfT
--------------------------------------------------------------------------------
This is the standard FREE version of the Stylized Nature MegaKit, which only contains
a portion of the models (68/116). You can buy the PRO version which has all the models,
or the SOURCE version which has all the models and also includes Unity(URP), Unreal Engine and Godot projects
with the stylized shader already set up.
You can get the other versions from the website https://quaternius.com
-------------------------------------------------------
License:
CC0 1.0 Universal (CC0 1.0)
Public Domain Dedication
https://creativecommons.org/publicdomain/zero/1.0/
------------------------------------------------------
Models by @Quaternius
Consider supporting me on Patreon!
https://www.patreon.com/quaternius
-------------------------------------------------------
Join the Discord Server:
https://discord.gg/vJqnRUYRfT
src/main.rs +90 -1
diff --git a/src/main.rs b/src/main.rs
index 9190b7d..5185e10 100644
@@ -1,3 +1,92 @@
use std::f32::consts::FRAC_PI_4;
use bevy::{
DefaultPlugins,
app::{App, Startup, Update},
asset::{AssetServer, Assets, Handle},
camera::{Camera3d, PerspectiveProjection, Projection},
ecs::{
resource::Resource,
system::{Commands, Res, ResMut, Single},
},
gltf::GltfAssetLabel,
image::Image,
light::{DirectionalLight, DirectionalLightShadowMap, Skybox},
log::error,
math::Vec3,
render::render_resource::{TextureViewDescriptor, TextureViewDimension},
transform::components::Transform,
world_serialization::WorldAssetRoot,
};
fn main() {
println!("Hello Window!");
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(Update, load_skybox)
.run();
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let handle = asset_server.load("Skybox.png");
commands.insert_resource(SkyboxHandle(handle.clone(), false));
commands.spawn((
Camera3d::default(),
Projection::from(PerspectiveProjection {
fov: FRAC_PI_4,
..Default::default()
}),
Transform::from_xyz(-7.0, 3.3, 14.0).looking_to(Vec3::new(0.6, 0.0, -0.8), Vec3::Y),
Skybox {
image: Some(handle),
brightness: 1000.0,
..Skybox::default()
},
));
commands.insert_resource(DirectionalLightShadowMap { size: 4096 });
commands.spawn((
DirectionalLight {
illuminance: 1000.0,
shadow_maps_enabled: true,
..DirectionalLight::default()
},
Transform::default().looking_to(Vec3::new(-2.5, -1.0, 0.0), Vec3::Y),
));
commands.spawn(WorldAssetRoot(
asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/Village.glb")),
));
}
#[derive(Resource)]
struct SkyboxHandle(Handle<Image>, bool);
fn load_skybox(
asset_server: Res<AssetServer>,
mut images: ResMut<Assets<Image>>,
mut skybox: Single<&mut Skybox>,
mut skybox_handle: ResMut<SkyboxHandle>,
) {
if skybox_handle.1 {
return;
}
if !asset_server.load_state(&skybox_handle.0).is_loaded() {
return;
}
let Some(mut image) = images.get_mut(&skybox_handle.0) else {
return;
};
if let Err(err) = image.reinterpret_stacked_2d_as_array(6) {
error!("Failed to reinterpret cubemap texture as 6 layers array: {err}");
skybox_handle.1 = true;
return;
}
image.texture_view_descriptor = Some(TextureViewDescriptor {
dimension: Some(TextureViewDimension::Cube),
..TextureViewDescriptor::default()
});
skybox.image = Some(skybox_handle.0.clone());
skybox_handle.1 = true;
}