Skip to content

Commit

Permalink
v0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
robtfm committed Jan 8, 2025
1 parent b68a923 commit df11c31
Show file tree
Hide file tree
Showing 10 changed files with 459 additions and 555 deletions.
19 changes: 7 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
[package]
name = "boimp"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
license = "MIT OR Apache-2.0"

[dependencies]
# bevy = { git = "https://github.com/robtfm/bevy", branch = "0.14.2-plus-16188" }
bevy = "0.14"
# bevy = { git = "https://github.com/robtfm/bevy", branch = "release-0.14-dcl-cosmic-noimage" }
wgpu = "0.20"
crossbeam-channel = "0.5.13"
async-channel = "2.2.0"
image = "0.25.2"
bytemuck = "1.7"
bevy = "0.15"
wgpu = "23"
crossbeam-channel = "0.5"
async-channel = "2"
image = { version = "0.25.2", default-features = false }
bytemuck = "1"

# asset loader
zip = { version = "2", default-features = false }
Expand All @@ -22,6 +20,3 @@ serde = { version = "1", features = ["derive"] }
# examples
pico-args = "0.5.0"
rand = "0.8.5"

[patch.crates-io]
bevy = { git = "https://github.com/robtfm/bevy", branch = "0.14.2-plus-16188" }
143 changes: 0 additions & 143 deletions examples/custom_mesh.rs

This file was deleted.

104 changes: 46 additions & 58 deletions examples/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::f32::consts::{FRAC_PI_4, PI};

use bevy::{
animation::AnimationTarget,
asset::LoadState,
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
ecs::entity::EntityHashMap,
math::FloatOrd,
Expand All @@ -19,8 +18,8 @@ use bevy::{
utils::hashbrown::HashMap,
};
use boimp::{
render::DummyIndicesImage, GridMode, Imposter, ImposterBakeBundle, ImposterBakeCamera,
ImposterBakePlugin, ImposterData,
render::DummyIndicesImage, GridMode, Imposter, ImposterBakeCamera, ImposterBakePlugin,
ImposterData,
};
use camera_controller::{CameraController, CameraControllerPlugin};
use rand::{thread_rng, Rng};
Expand Down Expand Up @@ -116,8 +115,8 @@ impl SceneHandle {

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let mut args = pico_args::Arguments::from_env();
let grid_size = args.value_from_str("--grid").unwrap_or(9);
let tile_size = args.value_from_str("--tile").unwrap_or(64);
let grid_size = args.value_from_str("--grid").unwrap_or(15);
let tile_size = args.value_from_str("--tile").unwrap_or(128);
let mode = match args
.value_from_str("--mode")
.unwrap_or("h".to_owned())
Expand Down Expand Up @@ -172,7 +171,10 @@ fn scene_load_check(
) {
match scene_handle.instance_id {
None => {
if asset_server.load_state(&scene_handle.gltf_handle) == LoadState::Loaded {
if asset_server
.load_state(&scene_handle.gltf_handle)
.is_loaded()
{
let gltf = gltf_assets.get(&scene_handle.gltf_handle).unwrap();
if gltf.scenes.len() > 1 {
info!(
Expand Down Expand Up @@ -205,10 +207,10 @@ fn scene_load_check(
});

let root = commands
.spawn(SpatialBundle {
transform: Transform::from_scale(Vec3::splat(1.0)),
..Default::default()
})
.spawn((
Transform::from_scale(Vec3::splat(1.0)),
Visibility::default(),
))
.id();
scene_handle.instance_id =
Some(scene_spawner.spawn_as_child(gltf_scene_handle.clone_weak(), root));
Expand Down Expand Up @@ -321,15 +323,17 @@ fn setup_anim_after_load(
};
let graph = graphs.add(graph);
player.play(clips[0]).repeat();
commands.entity(player_entity).insert(graph);
commands
.entity(player_entity)
.insert(AnimationGraphHandle(graph));
}
}

fn setup_scene_after_load(
mut commands: Commands,
mut setup: Local<bool>,
mut scene_handle: ResMut<SceneHandle>,
meshes: Query<(&GlobalTransform, Option<&Aabb>), With<Handle<Mesh>>>,
meshes: Query<(&GlobalTransform, Option<&Aabb>), With<Mesh3d>>,
scene_spawner: Res<SceneSpawner>,
) {
if scene_handle.is_loaded && !*setup {
Expand Down Expand Up @@ -399,18 +403,10 @@ fn setup_scene_after_load(
info!("{:?}", *scene_handle);

commands.spawn((
Camera3dBundle {
projection: projection.into(),
transform: Transform::from_translation(
Vec3::from(aabb.center) + size * Vec3::new(0.5, 0.25, 0.5),
)
Camera3d::default(),
Projection::from(projection),
Transform::from_translation(Vec3::from(aabb.center) + size * Vec3::new(0.5, 0.25, 0.5))
.looking_at(Vec3::from(aabb.center), Vec3::Y),
camera: Camera {
is_active: true,
..default()
},
..default()
},
camera_controller,
RenderLayers::default().with(1), // we keep imposters off the primary renderlayer to avoid imposterception
));
Expand All @@ -419,10 +415,8 @@ fn setup_scene_after_load(
if !scene_handle.has_light {
info!("Spawning a directional light");
commands.spawn((
DirectionalLightBundle {
transform: Transform::from_xyz(1.0, 1.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
},
DirectionalLight::default(),
Transform::from_xyz(1.0, 1.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
RenderLayers::default().with(1),
));

Expand Down Expand Up @@ -485,46 +479,40 @@ fn impost(
rng.gen_range(rotate_range.clone()) * hemi_mult,
);
commands.spawn((
MaterialMeshBundle {
mesh: meshes.add(Plane3d::new(Vec3::Z, Vec2::splat(0.5))),
transform: Transform::from_translation(
translation + Vec3::from(scene_handle.sphere.center),
)
Mesh3d(meshes.add(Plane3d::new(Vec3::Z, Vec2::splat(0.5)))),
Transform::from_translation(translation + Vec3::from(scene_handle.sphere.center))
.with_rotation(Quat::from_euler(
EulerRot::XYZ,
rotation.x,
rotation.y,
rotation.z,
)),
material: materials.add(Imposter {
data: ImposterData::new(
Vec3::ZERO,
scene_handle.sphere.radius,
settings.grid_size,
settings.tile_size,
UVec2::ZERO,
UVec2::splat(settings.tile_size),
settings.mode,
settings.multisample_target,
false,
1.0,
),
pixels: camera.target.clone().unwrap(),
indices: dummy_indices.0.clone(),
alpha_mode: AlphaMode::Blend,
vram_bytes: 0,
}),
..Default::default()
},
MeshMaterial3d(materials.add(Imposter {
data: ImposterData::new(
Vec3::ZERO,
scene_handle.sphere.radius,
settings.grid_size,
settings.tile_size,
UVec2::ZERO,
UVec2::splat(settings.tile_size),
settings.mode,
settings.multisample_target,
false,
1.0,
),
pixels: camera.target.clone().unwrap(),
indices: dummy_indices.0.clone(),
alpha_mode: AlphaMode::Blend,
vram_bytes: 0,
})),
RenderLayers::layer(1),
));
}

commands.spawn(ImposterBakeBundle {
commands.spawn((
camera,
transform: Transform::from_translation(scene_handle.sphere.center.into()),
..Default::default()
});
Transform::from_translation(scene_handle.sphere.center.into()),
));
}
}

Expand All @@ -548,7 +536,7 @@ fn update_lights(
transform.rotation = Quat::from_euler(
EulerRot::ZYX,
0.0,
time.elapsed_seconds() * PI / 15.0,
time.elapsed_secs() * PI / 15.0,
-FRAC_PI_4,
);
}
Expand All @@ -560,7 +548,7 @@ pub struct Rotate;

fn rotate(mut q: Query<&mut Transform, With<Rotate>>, time: Res<Time>) {
for mut t in q.iter_mut() {
t.rotation = Quat::from_rotation_y(time.elapsed_seconds());
t.rotation = Quat::from_rotation_y(time.elapsed_secs());
}
}

Expand Down
Loading

0 comments on commit df11c31

Please sign in to comment.