mirror of
https://github.com/JannisX11/blockbench.git
synced 2024-12-09 04:50:29 +08:00
Add Change Animation Speed Option
This commit is contained in:
parent
842eb413be
commit
bc10eb96c0
@ -802,6 +802,7 @@ class Animation extends AnimationItem {
|
||||
{name: 'menu.animation.loop.hold', icon: animation => (animation.loop == 'hold' ? 'far.fa-dot-circle' : 'far.fa-circle'), click(animation) {animation.setLoop('hold', true)}},
|
||||
{name: 'menu.animation.loop.loop', icon: animation => (animation.loop == 'loop' ? 'far.fa-dot-circle' : 'far.fa-circle'), click(animation) {animation.setLoop('loop', true)}},
|
||||
]},
|
||||
'change_animation_speed',
|
||||
new MenuSeparator('manage'),
|
||||
{
|
||||
name: 'menu.animation.save',
|
||||
@ -1186,6 +1187,68 @@ BARS.defineActions(function() {
|
||||
Undo.finishEdit('Bake animation into model')
|
||||
}
|
||||
})
|
||||
new Action('change_animation_speed', {
|
||||
icon: 'av_timer',
|
||||
category: 'animation',
|
||||
condition: {modes: ['animate'], method: () => Animation.selected},
|
||||
click() {
|
||||
let animation = Animation.selected;
|
||||
Undo.initEdit({animations: [animation]});
|
||||
let keyframes = [];
|
||||
let initial_times = {};
|
||||
let initial_snapping = animation.snapping;
|
||||
let initial_length = animation.length;
|
||||
for (let id in animation.animators) {
|
||||
let animator = animation.animators[id];
|
||||
keyframes.push(...animator.keyframes);
|
||||
}
|
||||
keyframes.forEach(kf => {
|
||||
initial_times[kf.uuid] = kf.time;
|
||||
})
|
||||
|
||||
let previous_speed = 1;
|
||||
let previous_snapping = initial_snapping;
|
||||
let dialog = new Dialog({
|
||||
id: 'change_animation_speed',
|
||||
title: 'action.change_animation_speed',
|
||||
darken: false,
|
||||
form: {
|
||||
speed: {label: 'dialog.change_animation_speed.speed', type: 'range', value: 1, min: 0.1, max: 4, step: 0.01, editable_range_label: true, full_width: true},
|
||||
adjust_snapping: {label: 'dialog.change_animation_speed.adjust_snapping', type: 'checkbox', value: true},
|
||||
snapping: {label: 'menu.animation.snapping', type: 'number', value: initial_snapping, min: 1, max: 500, condition: result => result.adjust_snapping},
|
||||
},
|
||||
onFormChange({speed, adjust_snapping, snapping}) {
|
||||
if (speed != previous_speed) {
|
||||
snapping = adjust_snapping ? Math.roundTo(initial_snapping * speed, 2) : initial_snapping
|
||||
dialog.setFormValues({snapping}, false);
|
||||
console.trace('c sp', speed, previous_speed)
|
||||
|
||||
} else if (snapping != previous_snapping) {
|
||||
speed = Math.clamp(Math.roundTo(snapping / initial_snapping, 2), 0.1, 4);
|
||||
dialog.setFormValues({speed}, false);
|
||||
console.trace('c snap', snapping, previous_snapping)
|
||||
}
|
||||
previous_speed = speed;
|
||||
previous_snapping = snapping;
|
||||
|
||||
animation.snapping = snapping;
|
||||
keyframes.forEach(kf => {
|
||||
kf.time = Timeline.snapTime(initial_times[kf.uuid] / speed, animation);
|
||||
})
|
||||
animation.setLength(initial_length / speed);
|
||||
console.log(animation.length);
|
||||
TickUpdates.keyframes = true;
|
||||
Animator.preview();
|
||||
},
|
||||
onConfirm(result) {
|
||||
Undo.finishEdit('Change animation speed');
|
||||
},
|
||||
onCancel() {
|
||||
Undo.cancelEdit();
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
|
@ -571,6 +571,9 @@
|
||||
"dialog.animation_import.title": "Select Animations to Import",
|
||||
"dialog.animation_export.title": "Select Animations to Export",
|
||||
|
||||
"dialog.change_animation_speed.speed": "Speed",
|
||||
"dialog.change_animation_speed.adjust_snapping": "Adjust Snapping",
|
||||
|
||||
"dialog.create_texture.folder": "Folder",
|
||||
"dialog.create_texture.type": "Type",
|
||||
"dialog.create_texture.type.blank": "Blank",
|
||||
@ -1699,6 +1702,8 @@
|
||||
"action.slider_animation_length.desc": "Change the length of the selected animation",
|
||||
"action.set_animation_end": "Set Animation End",
|
||||
"action.set_animation_end.desc": "Set the end of the selected animation to the current timeline time",
|
||||
"action.change_animation_speed": "Change Animation Speed...",
|
||||
"action.change_animation_speed.desc": "Change the speed of the selected animation",
|
||||
"action.slider_keyframe_time": "Timecode",
|
||||
"action.slider_keyframe_time.desc": "Change the timecode of the selected keyframes",
|
||||
"action.keyframe_interpolation": "Interpolation",
|
||||
|
Loading…
Reference in New Issue
Block a user