diff --git a/studio-frontend/src/app/anim-editor.element.ts b/studio-frontend/src/app/anim-editor.element.ts index 74be637..790b92a 100644 --- a/studio-frontend/src/app/anim-editor.element.ts +++ b/studio-frontend/src/app/anim-editor.element.ts @@ -28,7 +28,7 @@ export class AnimEditorElement extends LitElement { @state() timelineEnd = 5; @state() clipStart = 0; - @state() clipEnd = 15_000; + @state() clipEnd = 0; @state() playHead = 0; @state() playing = false; @@ -103,21 +103,22 @@ export class AnimEditorElement extends LitElement { this.keyframes = keyframes; - let min = 0; - let max = 5; + let min = Infinity + let max = -Infinity; for (const keyframe of Object.keys(this.keyframes)) { let time = this.keyframes[keyframe].time; if (typeof time != "number") { continue; } if (time > max) { - max = time + 1; + max = time; + } + if (time < min) { + min = time; } } - this.clipStart = min; - this.clipEnd = max; - this.timelineEnd = max; - this.timelineStart = min; + this.clipStart = Math.max(min, 0.); + this.clipEnd = Math.max(max, min); } @@ -136,6 +137,17 @@ export class AnimEditorElement extends LitElement { } } + @on("rangeStart-change") + onRangeStartChange({detail}: {detail:number}): void { + this.timelineStart = detail; + } + + + @on("rangeEnd-change") + onRangeEndChange({detail}: {detail:number}): void { + this.timelineStart = detail; + } + onSidebarResize(event: PointerEvent): void { this.sidebarWidth = Math.max(Math.min(this.sidebarWidth + event.movementX, 512), 128); } @@ -225,10 +237,16 @@ export class AnimEditorElement extends LitElement { const selected = typeof this.selected_track === "object" && "track" in this.selected_track ? this.selected_track.track : false; const can_add_selected = typeof this.selected_track === "object" && "outside_entity" in this.selected_track ? this.selected_track.outside_entity : false; + let length = this.timelineEnd - this.timelineStart; + let clip_start = (this.clipStart - this.timelineStart) / length; + let clip_end = (this.clipEnd - this.timelineStart) / length; + - let track_count = { + let timeline_css_variables = { '--track-count': `${this.trackCount()}`, - '--row-count': `calc(var(--track-count) + ${can_add_selected ? 2 : 1})` + '--row-count': `calc(var(--track-count) + ${can_add_selected ? 2 : 1})`, + '--clip-end': `${clip_end * 100}%`, + '--clip-start': `${clip_start * 100}%` }; const tracklist = this.track_ordered.map((entity) => { @@ -263,7 +281,7 @@ export class AnimEditorElement extends LitElement { -
{ - r_global_seek_time.time = *time; + r_global_seek_time.time = time.max(0.); } } @@ -316,7 +316,7 @@ fn generate_transform_animation( if (time - last_time).abs() > 0.00001 { translation_list.push(Tween::new( EaseMethod::Linear, - Duration::from_secs_f32(time - last_time), + Duration::from_secs_f32((time - last_time).max(0.00001)), TransformPositionLens { start, end: translation, @@ -336,7 +336,7 @@ fn generate_transform_animation( if (time - last_time).abs() > 0.00001 { rotation_list.push(Tween::new( EaseMethod::Linear, - Duration::from_secs_f32(time - last_time), + Duration::from_secs_f32((time - last_time).max(0.00001)), TransformRotationLens { start, end: rotation, @@ -353,7 +353,7 @@ fn generate_transform_animation( if (time - last_time).abs() > 0.00001 { scale_list.push(Tween::new( EaseMethod::Linear, - Duration::from_secs_f32(time - last_time), + Duration::from_secs_f32((time - last_time).max(0.00001)), TransformScaleLens { start, end: scale }, )); } @@ -433,7 +433,7 @@ pub fn timeline_bound_component_animator_system( mut query: Query<(Entity, &mut T, &mut Animator)>, events: ResMut>, ) { - if time.is_changed() { + if time.is_changed() && time.time >= 0.0 { info!("Animating with time: {time:?}"); let mut events: Mut> = events.into(); for (entity, target, mut animator) in query.iter_mut() { @@ -452,7 +452,7 @@ pub fn timeline_bound_component_animator_system( } else { info!("setting tween time to {}", time.time); let tween = animator.tweenable_mut(); - tween.set_elapsed(Duration::from_secs_f32(time.time)); + tween.set_elapsed(Duration::from_secs_f32(time.time.max(0.))); info!("Tween time set successfully"); tween.tick(Duration::ZERO, &mut target, entity, &mut events); }