fix loading screen

This commit is contained in:
rewin
2024-01-26 23:09:43 +03:00
parent 9a648b892a
commit 89eb7d15ca
3 changed files with 39 additions and 20 deletions
+3 -3
View File
@@ -1,6 +1,6 @@
{
"space_editor_ui::settings::NewWindowSettings": "{\"space_editor_ui::settings::NewWindowSettings\":(new_tab:SameNode)}",
"space_editor_core::hotkeys::HotkeySet<space_editor_ui::tools::gizmo::GizmoHotkey>": "{\"space_editor_core::hotkeys::HotkeySet<space_editor_ui::tools::gizmo::GizmoHotkey>\":(bindings:{Rotate:[R],Translate:[G],Scale:[S],Multiple:[ShiftLeft],Clone:[AltLeft],Delete:[X]},name:\"GizmoHotkey\")}",
"space_persistence::PersistenceSettings": "{\"space_persistence::PersistenceSettings\":(load_on_startup:true,save_on_close:true)}",
"space_undo::ChangeChainSettings": "{\"space_undo::ChangeChainSettings\":(max_change_chain_size:200)}",
"space_persistence::PersistenceSettings": "{\"space_persistence::PersistenceSettings\":(load_on_startup:true,save_on_close:true)}",
"space_editor_core::hotkeys::HotkeySet<space_editor_ui::tools::gizmo::GizmoHotkey>": "{\"space_editor_core::hotkeys::HotkeySet<space_editor_ui::tools::gizmo::GizmoHotkey>\":(bindings:{Rotate:[R],Translate:[G],Scale:[S],Multiple:[ShiftLeft],Clone:[AltLeft],Delete:[X]},name:\"GizmoHotkey\")}",
"space_editor_ui::settings::NewWindowSettings": "{\"space_editor_ui::settings::NewWindowSettings\":(new_tab:SameNode)}",
}
+20
View File
@@ -187,6 +187,26 @@ pub fn start_editor(
);
}
#[cfg_attr(feature = "wasm", wasm_bindgen)]
pub fn start(
object_id: &str,
skybox_id: &str,
canvas_selector: &str,
canvas_alt: &str,
viewport_size: ViewportSize,
studio_mode: StudioMode,
) {
start_internal(
object_id,
skybox_id,
canvas_selector,
canvas_alt,
viewport_size,
studio_mode,
)
.run();
}
// TODO: These `start_` functiions should be refactored to better support the
// needs of the "reaodnly viewer" vs "full studio editor" use cases. See
// notes in `studio-web/src/lib/viewer.element.ts` for more info.
+16 -17
View File
@@ -42,7 +42,6 @@ impl Plugin for ScenePlugin {
(
spawn_test_bvh.run_if(resource_exists::<TestBvh>()), // TODO
init_scene_loading,
tick_scene_spawning.run_if(in_state(SceneState::Spawning)),
)
.in_set(SceneSpawnerSystem),
)
@@ -101,7 +100,6 @@ pub enum SceneState {
#[default]
None,
Loading,
Spawning,
Active,
}
@@ -124,6 +122,10 @@ fn check_loading(
) {
if !loading_queue.queue.is_empty() {
//filter queue to only include notloaded assets
let mut not_loaded_count = 0;
loading_queue.queue.retain(|h| {
if let Some((load_state, dep_load_state, rec_load_state)) =
asset_server.get_load_states(h.id())
@@ -134,15 +136,25 @@ fn check_loading(
|| rec_load_state == RecursiveDependencyLoadState::Failed
|| load_state == LoadState::Failed;
if load_state == LoadState::NotLoaded {
not_loaded_count += 1;
}
!(is_failed || is_loaded)
} else {
false
}
});
info!("Loading {} assets", loading_queue.queue.len());
st_next.set(SceneState::Loading);
if loading_queue.queue.len() - not_loaded_count == 0 {
//not change state
} else {
st_next.set(SceneState::Loading);
}
} else {
st_next.set(SceneState::Active);
}
@@ -191,7 +203,7 @@ pub struct BindPoseGlobal(pub Affine3A);
#[derive(Component, Clone, Copy, Debug, Deref, DerefMut)]
pub struct InvBindPose(pub Affine3A);
fn initialize(mut cmd: Commands, r_assets: Res<AssetServer>) {
fn initialize(mut cmd: Commands) {
// Camera, graphics settings
let focus = Vec3::ZERO;
let camera_xform = Transform::from_xyz(-2.5, 4.5, 5.0).looking_at(focus, Vec3::Y);
@@ -243,7 +255,6 @@ fn spawn_test_bvh(
fn init_scene_loading(
mut cmd: Commands,
mut er: EventReader<LoadSceneEvent>,
mut st_next: ResMut<NextState<SceneState>>,
) {
if let Some(id) = er.read().last() {
info!("Loading scene: {}", id.0);
@@ -259,18 +270,6 @@ fn init_scene_loading(
}
}
fn tick_scene_spawning(
r_scene_spawner: Res<SceneSpawner>,
r_active_scene: Res<ActiveScene>,
mut st_next: ResMut<NextState<SceneState>>,
) {
// TODO: The instance is considered "ready" even if shaders still need to be
// compiled, so this event isn't really sufficient for controlling a
// loading screen.
if r_scene_spawner.instance_is_ready(**r_active_scene) {
st_next.set(SceneState::Active);
}
}
#[derive(Component)]
pub struct NoMeshElement;