mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-18 07:35:19 +00:00
clippy + fmt
This commit is contained in:
@@ -501,6 +501,7 @@ mod tests {
|
||||
use std::time::Duration;
|
||||
|
||||
// #[test] // FIXME
|
||||
#[allow(dead_code)]
|
||||
fn macro_create() {
|
||||
let bvh = bvh! {
|
||||
HIERARCHY
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
use std::{str::FromStr, time::Duration};
|
||||
|
||||
use bevy::{
|
||||
ecs::{
|
||||
entity::{EntityMapper, MapEntities},
|
||||
reflect::ReflectMapEntities,
|
||||
},
|
||||
prelude::*,
|
||||
utils::{hashbrown::HashMap, HashSet},
|
||||
};
|
||||
@@ -14,10 +10,13 @@ use bevy_tweening::{
|
||||
Animator, EaseMethod, Sequence, Targetable, Tracks, Tween, TweenCompleted,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use space_editor::{prelude::PrefabMarker, space_prefab::editor_registry::EditorRegistryExt};
|
||||
|
||||
use crate::{headless::HeadlessSettings, interaction::{MarkedForDeletion, Selectable}, StudioMode};
|
||||
use crate::{
|
||||
headless::HeadlessSettings,
|
||||
interaction::{MarkedForDeletion, Selectable},
|
||||
};
|
||||
|
||||
pub struct TimelinePlugin;
|
||||
|
||||
@@ -135,7 +134,7 @@ impl Default for TransformKeyframe {
|
||||
#[reflect(Component)]
|
||||
pub struct Keyframe {
|
||||
target: AnimationTarget,
|
||||
pub time: f32
|
||||
pub time: f32,
|
||||
}
|
||||
|
||||
#[derive(Component, Clone, Debug, Default, Reflect, PartialEq, Eq, PartialOrd, Ord)]
|
||||
@@ -152,7 +151,7 @@ impl Default for Keyframe {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
time: Default::default(),
|
||||
target: AnimationTarget::Unknown
|
||||
target: AnimationTarget::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -189,14 +188,16 @@ impl Default for TimedAnimationClipAsset {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Clone, Debug, Default, Reflect, PartialEq, Eq, Hash, Copy, Serialize, Deserialize)]
|
||||
#[derive(
|
||||
Component, Clone, Debug, Default, Reflect, PartialEq, Eq, Hash, Copy, Serialize, Deserialize,
|
||||
)]
|
||||
#[reflect(Component)]
|
||||
#[serde(try_from = "&str", into = "String")]
|
||||
pub enum AnimationTarget {
|
||||
#[default]
|
||||
Unknown,
|
||||
MainCamera,
|
||||
Uuid(uuid::Uuid)
|
||||
Uuid(uuid::Uuid),
|
||||
}
|
||||
|
||||
impl AnimationTarget {
|
||||
@@ -210,7 +211,7 @@ impl ToString for AnimationTarget {
|
||||
match self {
|
||||
Self::Unknown => "unknown".to_string(),
|
||||
Self::MainCamera => "MainCamera".to_string(),
|
||||
Self::Uuid(uuid) => uuid.to_string()
|
||||
Self::Uuid(uuid) => uuid.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -262,11 +263,15 @@ fn process_timeline_events(
|
||||
}
|
||||
}
|
||||
|
||||
fn update_tick(mut r_global_seek_time: ResMut<GlobalSeekTime>, time: Res<Time>, headless_settings: Option<Res<HeadlessSettings>>) {
|
||||
fn update_tick(
|
||||
mut r_global_seek_time: ResMut<GlobalSeekTime>,
|
||||
time: Res<Time>,
|
||||
headless_settings: Option<Res<HeadlessSettings>>,
|
||||
) {
|
||||
if r_global_seek_time.playing {
|
||||
let delta = match headless_settings {
|
||||
Some(headless_settings) => headless_settings.frame_delta,
|
||||
None => time.delta_seconds()
|
||||
None => time.delta_seconds(),
|
||||
};
|
||||
r_global_seek_time.time += delta;
|
||||
r_global_seek_time.delta = Some(delta);
|
||||
@@ -285,7 +290,8 @@ fn process_keyframe_events(
|
||||
info!("Processing Keyframe Event {event:?}");
|
||||
match event {
|
||||
KeyframeInteractionEvent::RecordKeyframe { target } => {
|
||||
if let Ok((target, transform, animation_target)) = q_animation_targets.get(*target) {
|
||||
if let Ok((_target, transform, animation_target)) = q_animation_targets.get(*target)
|
||||
{
|
||||
let mut existing = None;
|
||||
for (entity, keyframe) in q_keyframes.iter_mut() {
|
||||
if keyframe.target == *animation_target
|
||||
@@ -356,7 +362,10 @@ fn generate_transform_animation(
|
||||
valid_targets: Query<(Entity, &AnimationTarget)>,
|
||||
removed: Query<&Keyframe, With<MarkedForDeletion>>,
|
||||
) {
|
||||
let available_targets = valid_targets.iter().map(|(e,a)| (*a,e)).collect::<HashMap<_,_>>();
|
||||
let available_targets = valid_targets
|
||||
.iter()
|
||||
.map(|(e, a)| (*a, e))
|
||||
.collect::<HashMap<_, _>>();
|
||||
let changed_targets = changed
|
||||
.iter()
|
||||
.map(|keyframe| keyframe.target)
|
||||
@@ -364,12 +373,12 @@ fn generate_transform_animation(
|
||||
info!("Processing a removed keyframe {keyframe:?}");
|
||||
keyframe.target
|
||||
}))
|
||||
.chain(added_targets.iter().map(|(_,a)| *a))
|
||||
.chain(added_targets.iter().map(|(_, a)| *a))
|
||||
.collect::<HashSet<_>>();
|
||||
let keyframes = keyframes
|
||||
.iter()
|
||||
.filter(|(keyframe, _,_,_)| changed_targets.contains(&keyframe.target))
|
||||
.group_by(|(keyframe,_, _, _)| keyframe.target);
|
||||
.filter(|(keyframe, _, _, _)| changed_targets.contains(&keyframe.target))
|
||||
.group_by(|(keyframe, _, _, _)| keyframe.target);
|
||||
|
||||
for (target, keyframes) in &keyframes {
|
||||
let Some(target) = available_targets.get(&target) else {
|
||||
@@ -703,7 +712,7 @@ mod wasm {
|
||||
struct AddedAnimationTargetRecordItem {
|
||||
name: Option<String>,
|
||||
target_type: SceneElement,
|
||||
animation_target: AnimationTarget
|
||||
animation_target: AnimationTarget,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
@@ -742,7 +751,10 @@ mod wasm {
|
||||
|
||||
pub(super) fn notify_updated_animation_targets(
|
||||
q_window: Query<&Window, With<PrimaryWindow>>,
|
||||
q_cameras: Query<(Entity, Option<&Name>, &AnimationTarget), (Added<AnimationTarget>, With<Camera>)>,
|
||||
q_cameras: Query<
|
||||
(Entity, Option<&Name>, &AnimationTarget),
|
||||
(Added<AnimationTarget>, With<Camera>),
|
||||
>,
|
||||
q_scene_elements: Query<
|
||||
(Entity, Option<&Name>, &SceneElement, &AnimationTarget),
|
||||
(Added<AnimationTarget>, Without<Camera>),
|
||||
@@ -770,7 +782,7 @@ mod wasm {
|
||||
AddedAnimationTargetRecordItem {
|
||||
name: name.map(|v| v.to_string()),
|
||||
target_type: SceneElement::Generic,
|
||||
animation_target: *target
|
||||
animation_target: *target,
|
||||
},
|
||||
)
|
||||
})
|
||||
@@ -780,20 +792,24 @@ mod wasm {
|
||||
AddedAnimationTargetRecordItem {
|
||||
name: name.map(|v| v.to_string()),
|
||||
target_type: SceneElement::Camera,
|
||||
animation_target: *target
|
||||
},
|
||||
)
|
||||
}))
|
||||
.chain(q_scene_elements.iter().map(|(entity, name, element, target)| {
|
||||
(
|
||||
format!("{entity:?}"),
|
||||
AddedAnimationTargetRecordItem {
|
||||
name: name.map(|v| v.to_string()),
|
||||
target_type: *element,
|
||||
animation_target: *target
|
||||
animation_target: *target,
|
||||
},
|
||||
)
|
||||
}))
|
||||
.chain(
|
||||
q_scene_elements
|
||||
.iter()
|
||||
.map(|(entity, name, element, target)| {
|
||||
(
|
||||
format!("{entity:?}"),
|
||||
AddedAnimationTargetRecordItem {
|
||||
name: name.map(|v| v.to_string()),
|
||||
target_type: *element,
|
||||
animation_target: *target,
|
||||
},
|
||||
)
|
||||
}),
|
||||
)
|
||||
.collect::<HashMap<_, _>>();
|
||||
|
||||
let removed = removed.read().map(|v| format!("{v:?}")).collect::<Vec<_>>();
|
||||
|
||||
+14
-7
@@ -9,7 +9,12 @@ use space_editor::prelude::{EditorEvent, EditorPrefabPath};
|
||||
use wgpu::Extent3d;
|
||||
|
||||
use crate::{
|
||||
anim::timeline_animation::{Keyframe, TimelineInteractionEvent}, bvh::{BvhAnimCompleteEvent, TestBvh}, scene::SceneState, screenshot::{ScreenCapture, ScreenShotPlugin}, BvhPlugin, CommonPlugins, LoadLibraryObjectEvent, LoadSceneEvent, MainCamera, MixamoImportEvent, MixamoPlugin, RemoteAssetPlugin, SkyboxId, StudioMode, WorldGridPlugin
|
||||
anim::timeline_animation::{Keyframe, TimelineInteractionEvent},
|
||||
bvh::{BvhAnimCompleteEvent, TestBvh},
|
||||
scene::SceneState,
|
||||
screenshot::{ScreenCapture, ScreenShotPlugin},
|
||||
BvhPlugin, CommonPlugins, LoadLibraryObjectEvent, LoadSceneEvent, MainCamera,
|
||||
MixamoImportEvent, MixamoPlugin, RemoteAssetPlugin, SkyboxId, StudioMode, WorldGridPlugin,
|
||||
};
|
||||
|
||||
#[derive(Debug, Resource, Clone)]
|
||||
@@ -57,7 +62,7 @@ pub fn start_headless(
|
||||
close_when_requested: true,
|
||||
}),
|
||||
ScreenShotPlugin,
|
||||
CommonPlugins.build().disable::<WorldGridPlugin>()
|
||||
CommonPlugins.build().disable::<WorldGridPlugin>(),
|
||||
));
|
||||
|
||||
match mode {
|
||||
@@ -142,7 +147,7 @@ impl Default for HeadlessSettings {
|
||||
output_dir: "./screen_shots/".to_string(),
|
||||
max_frames: u32::MAX,
|
||||
fps: 24.0,
|
||||
frame_delta: 1.0 / 24.0
|
||||
frame_delta: 1.0 / 24.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -189,13 +194,15 @@ fn start_timeline_animation(
|
||||
keyframes: Query<&Keyframe>,
|
||||
camera: Query<Entity, With<MainCamera>>,
|
||||
mut commands: Commands,
|
||||
mut ev: EventWriter<TimelineInteractionEvent>
|
||||
mut ev: EventWriter<TimelineInteractionEvent>,
|
||||
) {
|
||||
if keyframes.is_empty() {
|
||||
return;
|
||||
}
|
||||
commands.remove_resource::<CameraMotion>();
|
||||
let total_time = keyframes.iter().fold(0f32, |previous, keyframe| previous.max(keyframe.time));
|
||||
let total_time = keyframes
|
||||
.iter()
|
||||
.fold(0f32, |previous, keyframe| previous.max(keyframe.time));
|
||||
let frames = (total_time * headless_settings.fps).ceil() as u32;
|
||||
headless_settings.max_frames = frames;
|
||||
ev.send(TimelineInteractionEvent::Play);
|
||||
@@ -204,5 +211,5 @@ fn start_timeline_animation(
|
||||
ScreenCapture::from_out(&headless_settings.output_dir)
|
||||
//Part of quick hack, see screenshot.rs#261
|
||||
.with_max_frames(headless_settings.max_frames + 3),
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
+8
-6
@@ -57,15 +57,17 @@ impl Plugin for ScenePlugin {
|
||||
)
|
||||
.add_systems(
|
||||
Update,
|
||||
(init_object_loading, init_scene_import, init_scene_loading, start_capture.run_if(is_headless))
|
||||
(
|
||||
init_object_loading,
|
||||
init_scene_import,
|
||||
init_scene_loading,
|
||||
start_capture.run_if(is_headless),
|
||||
)
|
||||
.in_set(SceneSpawnerSystem),
|
||||
)
|
||||
.add_systems(
|
||||
OnEnter(SceneState::Active),
|
||||
(
|
||||
tag_scene_elements,
|
||||
frame_scene_in_view,
|
||||
)
|
||||
(tag_scene_elements, frame_scene_in_view)
|
||||
.chain()
|
||||
.in_set(SceneSpawnerSystem),
|
||||
);
|
||||
@@ -338,7 +340,7 @@ fn initialiaze_headless(
|
||||
},
|
||||
..default()
|
||||
},
|
||||
CameraControllerBundle::new(focus, camera_xform.translation)
|
||||
CameraControllerBundle::new(focus, camera_xform.translation),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user