Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assorted fixes in Scene editor and GLTF loading #55

Merged
merged 2 commits into from
Nov 11, 2023
Merged
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exclude = []
base64 = "0.21"
bitflags = "2"
bytemuck = { version = "1", features = ["derive"] }
choir = { git = "https://github.com/kvark/choir", rev = "2d7c6ffb74a21a34c18c70aeb0b93a61a42eb04f" }
choir = "0.7"
egui = "0.23"
glam = { version = "0.24", features = ["mint"] }
log = "0.4"
Expand Down
12 changes: 8 additions & 4 deletions blade-render/src/model/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
borrow::Cow,
collections::hash_map::{Entry, HashMap},

Check warning on line 3 in blade-render/src/model/mod.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused imports: `Entry`, `HashMap`

Check warning on line 3 in blade-render/src/model/mod.rs

View workflow job for this annotation

GitHub Actions / build (MacOS, macos-latest, x86_64-apple-darwin)

unused imports: `Entry`, `HashMap`

Check warning on line 3 in blade-render/src/model/mod.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unused imports: `Entry`, `HashMap`
fmt, hash, mem,
ops::Range,
ptr, str,
Expand Down Expand Up @@ -318,8 +318,8 @@
Some(&TextureSource::Embedded(ref _task, ref sub_cooker)) => {
self.embedded_data = Cow::Owned(sub_cooker.extract_embedded());
}
Some(&TextureSource::Path(ref relative)) => {
self.path = Cow::Owned(relative.as_bytes().to_owned());
Some(&TextureSource::Path(ref full)) => {
self.path = Cow::Owned(full.as_bytes().to_owned());
}
None => {}
}
Expand Down Expand Up @@ -376,6 +376,7 @@
&self,
texture: gltf::texture::Texture,
meta: super::texture::Meta,
parent_cooker: &blade_asset::Cooker<Baker>,
data_buffers: &[Vec<u8>],
) -> TextureSource {
match texture.source().source() {
Expand Down Expand Up @@ -412,10 +413,11 @@
} else {
uri
};
let full = parent_cooker.base_path().join(relative);
if PRELOAD_TEXTURES {
self.asset_textures.load(relative, meta);
self.asset_textures.load(&full, meta);
}
TextureSource::Path(relative.to_string())
TextureSource::Path(full.to_str().unwrap().to_string())
}
}
}
Expand Down Expand Up @@ -454,11 +456,11 @@

fn cook(
&self,
source: &[u8],

Check warning on line 459 in blade-render/src/model/mod.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `source`

Check warning on line 459 in blade-render/src/model/mod.rs

View workflow job for this annotation

GitHub Actions / build (MacOS, macos-latest, x86_64-apple-darwin)

unused variable: `source`

Check warning on line 459 in blade-render/src/model/mod.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unused variable: `source`
extension: &str,
meta: Meta,

Check warning on line 461 in blade-render/src/model/mod.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `meta`

Check warning on line 461 in blade-render/src/model/mod.rs

View workflow job for this annotation

GitHub Actions / build (MacOS, macos-latest, x86_64-apple-darwin)

unused variable: `meta`

Check warning on line 461 in blade-render/src/model/mod.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unused variable: `meta`
cooker: Arc<blade_asset::Cooker<Self>>,

Check warning on line 462 in blade-render/src/model/mod.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `cooker`

Check warning on line 462 in blade-render/src/model/mod.rs

View workflow job for this annotation

GitHub Actions / build (MacOS, macos-latest, x86_64-apple-darwin)

unused variable: `cooker`

Check warning on line 462 in blade-render/src/model/mod.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unused variable: `cooker`
exe_context: &choir::ExecutionContext,

Check warning on line 463 in blade-render/src/model/mod.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `exe_context`

Check warning on line 463 in blade-render/src/model/mod.rs

View workflow job for this annotation

GitHub Actions / build (MacOS, macos-latest, x86_64-apple-darwin)

unused variable: `exe_context`

Check warning on line 463 in blade-render/src/model/mod.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unused variable: `exe_context`
) {
match extension {
#[cfg(feature = "asset")]
Expand Down Expand Up @@ -505,6 +507,7 @@
Some(info) => sources.insert(self.cook_texture(
info.texture(),
META_BASE_COLOR,
&cooker,
&buffers,
)),
None => !0,
Expand All @@ -517,6 +520,7 @@
Some(info) => sources.insert(self.cook_texture(
info.texture(),
META_NORMAL,
&cooker,
&buffers,
)),
None => !0,
Expand Down
Binary file added examples/scene/data/plane.glb
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/scene/data/scene.ron
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
average_luminocity: 0.3,
objects: [
(
path: "monkey.gltf",
path: "plane.glb",
),
],
)
19 changes: 11 additions & 8 deletions examples/scene/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ struct Example {
need_picked_selection_frames: usize,
gizmo_mode: egui_gizmo::GizmoMode,
have_objects_changed: bool,
have_fallback_scene: bool,
scene_revision: usize,
camera: blade_render::Camera,
fly_speed: f32,
debug: blade_render::DebugConfig,
Expand Down Expand Up @@ -230,7 +230,7 @@ impl Example {
need_picked_selection_frames: 0,
gizmo_mode: egui_gizmo::GizmoMode::Translate,
have_objects_changed: false,
have_fallback_scene: false,
scene_revision: 0,
camera: blade_render::Camera {
pos: mint::Vector3 {
x: 0.0,
Expand Down Expand Up @@ -440,12 +440,14 @@ impl Example {
temp,
);
self.have_objects_changed = false;
self.have_fallback_scene = true;
self.scene_revision += 1;
}

// We should be able to update TLAS and render content
// even while it's still being loaded.
if self.scene_load_task.is_none() || (RENDER_WHILE_LOADING && self.have_fallback_scene) {
let do_render =
self.scene_load_task.is_none() || (RENDER_WHILE_LOADING && self.scene_revision != 0);
if do_render {
self.renderer.prepare(
command_encoder,
&self.camera,
Expand Down Expand Up @@ -481,7 +483,7 @@ impl Example {
physical_size: (physical_size.width, physical_size.height),
scale_factor,
};
if self.scene_load_task.is_none() {
if do_render {
let mut debug_blit_array = [blade_render::DebugBlit::default()];
let debug_blits = match self.debug_blit {
Some(ref blit) => {
Expand Down Expand Up @@ -1026,6 +1028,7 @@ fn main() {
let mut last_mouse_pos = [0i32; 2];

event_loop.run(move |event, _, control_flow| {
example.choir.check_panic();
*control_flow = winit::event_loop::ControlFlow::Poll;
let delta = last_event.elapsed().as_secs_f32();
last_event = time::Instant::now();
Expand Down Expand Up @@ -1150,13 +1153,13 @@ fn main() {
.draw_flags
.set(blade_render::DebugDrawFlags::SPACE, false);
}
winit::event::WindowEvent::DroppedFile(file_path) => {
winit::event::WindowEvent::DroppedFile(ref file_path) => {
example.is_file_hovered = false;
example
.debug
.draw_flags
.set(blade_render::DebugDrawFlags::SPACE, false);
if !example.add_object(&file_path) {
if !example.add_object(file_path) {
log::warn!(
"Unable to drop {}, loading in progress",
file_path.display()
Expand Down Expand Up @@ -1204,7 +1207,7 @@ fn main() {
});

//HACK: https://github.com/urholaukkarinen/egui-gizmo/issues/29
if example.have_objects_changed {
if example.have_objects_changed && egui_ctx.wants_pointer_input() {
drag_start = None;
}

Expand Down
Loading