2020-09-09 00:40:22 +08:00
|
|
|
class TimelineMarker {
|
|
|
|
constructor(data) {
|
|
|
|
this.time = 0;
|
|
|
|
this.color = 0;
|
|
|
|
if (data) {
|
|
|
|
this.extend(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
extend(data) {
|
|
|
|
Merge.number(this, data, 'color');
|
|
|
|
Merge.number(this, data, 'time');
|
|
|
|
}
|
2021-01-03 22:00:42 +08:00
|
|
|
getUndoCopy() {
|
|
|
|
return {
|
|
|
|
color: this.color,
|
|
|
|
time: this.time,
|
|
|
|
}
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
callPlayhead() {
|
|
|
|
Timeline.setTime(this.time)
|
|
|
|
Animator.preview()
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
showContextMenu(event) {
|
|
|
|
this.menu.open(event, this);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TimelineMarker.prototype.menu = new Menu([
|
2022-06-25 22:43:11 +08:00
|
|
|
{name: 'menu.cube.color', icon: 'color_lens', children() {
|
|
|
|
return [
|
|
|
|
...markerColors.map((color, i) => {return {
|
|
|
|
icon: 'flag',
|
|
|
|
color: color.standard,
|
|
|
|
name: color.name || 'cube.color.'+color.id,
|
|
|
|
click(marker) {marker.color = i;}
|
|
|
|
}})
|
|
|
|
];
|
|
|
|
}},
|
|
|
|
{
|
|
|
|
name: 'menu.timeline_marker.set_time',
|
|
|
|
icon: 'schedule',
|
|
|
|
click(marker) {
|
|
|
|
new Dialog({
|
|
|
|
id: 'timeline_marker_set_time',
|
|
|
|
title: 'menu.timeline_marker.set_time',
|
|
|
|
form: {
|
|
|
|
time: {label: 'action.slider_keyframe_time', value: Math.roundTo(marker.time, 4), type: 'number', min: 0}
|
|
|
|
},
|
|
|
|
onConfirm(form) {
|
|
|
|
marker.time = form.time;
|
|
|
|
}
|
|
|
|
}).show();
|
|
|
|
}
|
|
|
|
},
|
2021-01-24 18:39:04 +08:00
|
|
|
'_',
|
2020-09-09 00:40:22 +08:00
|
|
|
{icon: 'delete', name: 'generic.delete', click: function(marker) {
|
2020-09-15 20:21:04 +08:00
|
|
|
if (Animation.selected) Animation.selected.markers.remove(marker);
|
2020-09-09 00:40:22 +08:00
|
|
|
}}
|
|
|
|
])
|
|
|
|
|
|
|
|
const Timeline = {
|
|
|
|
animators: [],
|
2020-09-26 04:06:03 +08:00
|
|
|
selected: Keyframe.selected,//frames
|
2020-09-09 00:40:22 +08:00
|
|
|
playing_sounds: [],
|
|
|
|
playback_speed: 100,
|
|
|
|
time: 0,
|
|
|
|
get second() {return Timeline.time},
|
2020-09-15 20:21:04 +08:00
|
|
|
get animation_length() {return Animation.selected ? Animation.selected.length : 0;},
|
2020-09-09 00:40:22 +08:00
|
|
|
playing: false,
|
|
|
|
selector: {
|
|
|
|
start: [0, 0],
|
|
|
|
selecting: false,
|
|
|
|
selected_before: [],
|
|
|
|
down(e) {
|
|
|
|
if (e.which !== 1 || (
|
|
|
|
!e.target.classList.contains('keyframe_section') &&
|
|
|
|
!e.target.classList.contains('animator_head_bar') &&
|
2021-01-21 03:31:54 +08:00
|
|
|
e.target.id !== 'timeline_graph_editor' &&
|
2020-09-09 00:40:22 +08:00
|
|
|
e.target.id !== 'timeline_body_inner'
|
|
|
|
)) {
|
|
|
|
return
|
|
|
|
};
|
|
|
|
|
|
|
|
Timeline.selector.interval = setInterval(Timeline.selector.move, 1000/60);
|
|
|
|
document.addEventListener('mouseup', Timeline.selector.end, false);
|
|
|
|
|
|
|
|
var offset = $('#timeline_body_inner').offset();
|
|
|
|
var R = Timeline.selector;
|
|
|
|
R.panel_offset = [
|
|
|
|
offset.left,
|
|
|
|
offset.top,
|
|
|
|
]
|
|
|
|
R.start = [
|
|
|
|
e.clientX - R.panel_offset[0],
|
|
|
|
e.clientY - R.panel_offset[1],
|
|
|
|
]
|
2021-08-03 17:04:40 +08:00
|
|
|
if (e.shiftKey || Pressing.overrides.shift) {
|
2020-09-09 00:40:22 +08:00
|
|
|
Timeline.selector.selected_before = Timeline.selected.slice();
|
|
|
|
}
|
|
|
|
R.selecting = true;
|
|
|
|
$('#timeline_selector').show()
|
|
|
|
Timeline.selector.move(e)
|
|
|
|
},
|
|
|
|
move(e) {
|
|
|
|
var R = Timeline.selector;
|
|
|
|
if (!R.selecting) return;
|
|
|
|
//CSS
|
|
|
|
var offset = $('#timeline_body_inner').offset();
|
|
|
|
R.panel_offset = [
|
|
|
|
offset.left,
|
|
|
|
offset.top,
|
|
|
|
]
|
|
|
|
var rect = getRectangle(R.start[0], R.start[1], mouse_pos.x - R.panel_offset[0], mouse_pos.y - R.panel_offset[1])
|
|
|
|
$('#timeline_selector')
|
|
|
|
.css('width', rect.x + 'px')
|
|
|
|
.css('height', rect.y + 'px')
|
|
|
|
.css('left', rect.ax + 'px')
|
|
|
|
.css('top', rect.ay + 'px');
|
|
|
|
//Keyframes
|
|
|
|
var epsilon = 6;
|
2020-09-28 18:55:45 +08:00
|
|
|
let {channels} = Timeline.vue._data;
|
2020-09-09 00:40:22 +08:00
|
|
|
rect.ax -= epsilon;
|
|
|
|
rect.ay -= epsilon;
|
|
|
|
rect.bx += epsilon;
|
|
|
|
rect.by += epsilon;
|
|
|
|
|
|
|
|
var min_time = (rect.ax-Timeline.vue._data.head_width-8)/Timeline.vue._data.size;
|
|
|
|
var max_time = (rect.bx-Timeline.vue._data.head_width-8)/Timeline.vue._data.size;
|
|
|
|
|
|
|
|
Timeline.selected.empty()
|
|
|
|
for (var animator of Timeline.animators) {
|
|
|
|
var node = $('#timeline_body_inner .animator[uuid=' + animator.uuid + ']').get(0)
|
|
|
|
var offset = node && node.offsetTop;
|
|
|
|
for (var kf of animator.keyframes) {
|
|
|
|
if (Timeline.selector.selected_before.includes(kf)) {
|
|
|
|
Timeline.selected.push(kf);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
kf.selected = false;
|
|
|
|
if (kf.time > min_time &&
|
|
|
|
kf.time < max_time &&
|
2020-09-28 18:55:45 +08:00
|
|
|
channels[kf.channel] != false &&
|
2021-02-25 01:00:11 +08:00
|
|
|
(!Timeline.vue.graph_editor_open || (kf.channel == Timeline.vue.graph_editor_channel && animator.selected)) &&
|
2020-09-28 18:55:45 +08:00
|
|
|
(!channels.hide_empty || animator[kf.channel].length)
|
2020-09-09 00:40:22 +08:00
|
|
|
) {
|
2021-01-21 03:31:54 +08:00
|
|
|
if (!Timeline.vue.graph_editor_open) {
|
|
|
|
|
|
|
|
var channel_index = 0 //animator.channels.indexOf(kf.channel);
|
2021-11-20 02:36:19 +08:00
|
|
|
for (var channel in animator.channels) {
|
2021-01-21 03:31:54 +08:00
|
|
|
if (kf.channel == channel) break;
|
|
|
|
if (channels[channel] != false && (!channels.hide_empty || animator[channel].length)) {
|
|
|
|
channel_index++;
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
2021-01-21 03:31:54 +08:00
|
|
|
var height = offset + channel_index*24 + 36;
|
2020-09-28 18:55:45 +08:00
|
|
|
|
2021-01-21 03:31:54 +08:00
|
|
|
} else {
|
|
|
|
var height = Timeline.vue.graph_offset - (kf.display_value || 0) * Timeline.vue.graph_size + Timeline.vue.scroll_top;
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
if (height > rect.ay && height < rect.by) {
|
|
|
|
kf.selected = true;
|
|
|
|
Timeline.selected.push(kf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Scroll body
|
|
|
|
var body = $('#timeline_body').get(0)
|
|
|
|
var body_inner = $('#timeline_body_inner').get(0)
|
2021-01-22 00:33:43 +08:00
|
|
|
let speed = 15;
|
2020-09-09 00:40:22 +08:00
|
|
|
|
|
|
|
var lef = mouse_pos.x - R.panel_offset[0] - body.scrollLeft - Timeline.vue._data.head_width;
|
|
|
|
var rig = body.clientWidth - (mouse_pos.x - R.panel_offset[0] - body.scrollLeft);
|
|
|
|
if (lef < 0) body.scrollLeft = body.scrollLeft - speed;
|
|
|
|
if (rig < 0) body.scrollLeft = Math.clamp(body.scrollLeft + speed, 0, body_inner.clientWidth - body.clientWidth);
|
2020-09-27 16:01:39 +08:00
|
|
|
|
2021-01-22 00:33:43 +08:00
|
|
|
if (!Timeline.vue.graph_editor_open) {
|
|
|
|
var top = mouse_pos.y - R.panel_offset[1] - body.scrollTop;
|
|
|
|
var bot = body.scrollTop + body.clientHeight - (mouse_pos.y - R.panel_offset[1]);
|
|
|
|
if (top < 0) body.scrollTop = body.scrollTop - speed;
|
|
|
|
if (bot < 0) body.scrollTop = Math.clamp(body.scrollTop + speed, 0, body_inner.clientHeight - body.clientHeight + 3);
|
|
|
|
}
|
|
|
|
|
2020-09-27 16:01:39 +08:00
|
|
|
updateKeyframeSelection()
|
2020-09-09 00:40:22 +08:00
|
|
|
},
|
|
|
|
end(e) {
|
|
|
|
if (!Timeline.selector.selecting) return false;
|
|
|
|
e.stopPropagation();
|
|
|
|
document.removeEventListener('mousemove', Timeline.selector.move);
|
|
|
|
clearInterval(Timeline.selector.interval);
|
|
|
|
document.removeEventListener('mouseup', Timeline.selector.end);
|
|
|
|
|
|
|
|
updateKeyframeSelection()
|
|
|
|
Timeline.selector.selected_before.empty();
|
|
|
|
Timeline.selector.selecting = false;
|
|
|
|
$('#timeline_selector')
|
|
|
|
.css('width', 0)
|
|
|
|
.css('height', 0)
|
|
|
|
.hide()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
setTime(seconds, editing) {
|
|
|
|
seconds = limitNumber(seconds, 0, 1000)
|
|
|
|
Timeline.vue._data.playhead = seconds
|
|
|
|
Timeline.time = seconds
|
|
|
|
if (!editing) {
|
|
|
|
Timeline.setTimecode(seconds)
|
|
|
|
}
|
|
|
|
if (Timeline.getMaxLength() !== Timeline.vue._data.length) {
|
|
|
|
Timeline.updateSize()
|
|
|
|
}
|
|
|
|
Timeline.revealTime(seconds)
|
|
|
|
},
|
|
|
|
revealTime(time) {
|
2020-12-28 17:38:05 +08:00
|
|
|
var scroll = $('#timeline_body').scrollLeft();
|
|
|
|
var playhead = time * Timeline.vue._data.size + 8;
|
2021-01-20 20:42:14 +08:00
|
|
|
if (playhead < scroll || playhead > scroll + $('#timeline_vue').width() - Timeline.vue._data.head_width) {
|
2020-12-28 17:38:05 +08:00
|
|
|
$('#timeline_body').scrollLeft(playhead-16);
|
|
|
|
} else if (time == 0) {
|
|
|
|
$('#timeline_body').scrollLeft(0);
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
setTimecode(time) {
|
2021-05-20 04:01:30 +08:00
|
|
|
let second_fractions = settings.timecode_frame_number.value ? 1/Timeline.getStep() : 100;
|
2020-09-09 00:40:22 +08:00
|
|
|
let m = Math.floor(time/60)
|
|
|
|
let s = Math.floor(time%60)
|
2021-05-20 04:01:30 +08:00
|
|
|
let f = Math.floor((time%1) * second_fractions)
|
2020-09-09 00:40:22 +08:00
|
|
|
if ((s+'').length === 1) {s = '0'+s}
|
|
|
|
if ((f+'').length === 1) {f = '0'+f}
|
2021-01-20 20:42:14 +08:00
|
|
|
$('#timeline_timestamp').text(m + ':' + s + ':' + f)
|
2020-09-09 00:40:22 +08:00
|
|
|
},
|
2020-09-14 18:44:43 +08:00
|
|
|
snapTime(time, animation) {
|
2020-09-09 00:40:22 +08:00
|
|
|
//return time;
|
|
|
|
if (time == undefined || isNaN(time)) {
|
|
|
|
time = Timeline.time;
|
|
|
|
}
|
2020-09-15 20:21:04 +08:00
|
|
|
if (!animation) animation = Animation.selected;
|
2020-09-15 00:31:28 +08:00
|
|
|
var fps = Math.clamp(animation ? animation.snapping : settings.animation_snap.value, 1, 120);
|
2020-09-09 00:40:22 +08:00
|
|
|
return Math.clamp(Math.round(time*fps)/fps, 0);
|
|
|
|
},
|
|
|
|
getStep() {
|
2020-09-15 20:21:04 +08:00
|
|
|
return 1/Math.clamp(Animation.selected ? Animation.selected.snapping : settings.animation_snap.value, 1, 120);
|
2020-09-09 00:40:22 +08:00
|
|
|
},
|
|
|
|
setup() {
|
2021-02-02 02:33:42 +08:00
|
|
|
$('#timeline_body').on('mousedown', e => {
|
|
|
|
if (e.which === 2) {
|
|
|
|
let pos = [e.clientX, e.clientY];
|
|
|
|
let timeline = e.currentTarget;
|
|
|
|
function move(e2) {
|
|
|
|
timeline.scrollLeft += pos[0] - e2.clientX;
|
|
|
|
if (!Timeline.vue.graph_editor_open) {
|
|
|
|
timeline.scrollTop += pos[1] - e2.clientY;
|
|
|
|
}
|
|
|
|
pos = [e2.clientX, e2.clientY];
|
|
|
|
}
|
|
|
|
function stop(e2) {
|
|
|
|
document.removeEventListener('mousemove', move);
|
|
|
|
document.removeEventListener('mouseup', stop);
|
|
|
|
}
|
|
|
|
document.addEventListener('mousemove', move);
|
|
|
|
document.addEventListener('mouseup', stop);
|
|
|
|
e.preventDefault();
|
|
|
|
} else {
|
|
|
|
Timeline.selector.down(e);
|
|
|
|
}
|
|
|
|
})
|
2020-09-09 00:40:22 +08:00
|
|
|
|
|
|
|
$('#timeline_time').on('mousedown touchstart', e => {
|
|
|
|
if (e.which !== 1 && !event.changedTouches) return;
|
|
|
|
if (e.target.classList.contains('timeline_marker')) return;
|
|
|
|
|
|
|
|
if (e.target.id == 'timeline_endbracket') {
|
|
|
|
|
2020-09-15 20:21:04 +08:00
|
|
|
if (Animation.selected) {
|
2020-09-09 00:40:22 +08:00
|
|
|
Timeline.dragging_endbracket = true;
|
2020-09-15 20:21:04 +08:00
|
|
|
Undo.initEdit({animations: [Animation.selected]});
|
2020-09-09 00:40:22 +08:00
|
|
|
} else {
|
|
|
|
Blockbench.showQuickMessage('message.no_animation_selected');
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
convertTouchEvent(e);
|
|
|
|
Timeline.dragging_playhead = true;
|
2022-06-26 23:22:10 +08:00
|
|
|
if (Timeline.playing) Timeline.pause();
|
2020-09-09 00:40:22 +08:00
|
|
|
|
|
|
|
let offset = e.clientX - $('#timeline_time').offset().left;
|
2021-03-01 04:21:53 +08:00
|
|
|
let time = Math.clamp(offset / Timeline.vue._data.size, 0, Infinity);
|
2021-11-09 22:47:41 +08:00
|
|
|
if (!e.ctrlOrCmd && !Pressing.overrides.ctrl) time = Timeline.snapTime(time);
|
2020-09-09 00:40:22 +08:00
|
|
|
Timeline.setTime(time);
|
|
|
|
Animator.preview();
|
2021-11-30 06:50:51 +08:00
|
|
|
Interface.addSuggestedModifierKey('ctrl', 'modifier_actions.drag_without_snapping');
|
2022-10-03 20:05:13 +08:00
|
|
|
if (e.shiftKey || Pressing.overrides.shift) {
|
|
|
|
time = Timeline.snapTime(time);
|
|
|
|
|
|
|
|
for (let i = 0; i < Timeline.animators.length; i++) {
|
|
|
|
let animator = Timeline.animators[i];
|
|
|
|
for (let channel in animator.channels) {
|
|
|
|
if (Timeline.vue.channels[channel] !== false) {
|
|
|
|
let match = animator[channel].find(kf => Math.epsilon(kf.time, time, 0.01));
|
|
|
|
if (match && !match.selected) {
|
|
|
|
match.selected = true;
|
|
|
|
Timeline.selected.push(match);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateKeyframeSelection();
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
$(document).on('mousemove touchmove', e => {
|
|
|
|
if (Timeline.dragging_playhead) {
|
|
|
|
|
|
|
|
convertTouchEvent(e);
|
|
|
|
let offset = e.clientX - $('#timeline_time').offset().left;
|
2021-03-01 04:21:53 +08:00
|
|
|
let time = Math.clamp(offset / Timeline.vue._data.size, 0, Infinity);
|
2021-08-03 17:04:40 +08:00
|
|
|
if (!e.ctrlOrCmd && !Pressing.overrides.ctrl) time = Timeline.snapTime(time);
|
2020-09-09 00:40:22 +08:00
|
|
|
if (Timeline.time != time) {
|
|
|
|
Timeline.setTime(time)
|
|
|
|
Animator.preview()
|
|
|
|
}
|
|
|
|
} else if (Timeline.dragging_endbracket) {
|
|
|
|
|
|
|
|
convertTouchEvent(e);
|
|
|
|
let offset = e.clientX - $('#timeline_time').offset().left;
|
|
|
|
let time = Timeline.snapTime(offset / Timeline.vue._data.size)
|
|
|
|
|
2020-09-15 20:21:04 +08:00
|
|
|
Animation.selected.setLength(time)
|
2020-09-09 00:40:22 +08:00
|
|
|
Timeline.revealTime(time)
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.on('mouseup touchend', e => {
|
|
|
|
if (Timeline.dragging_playhead) {
|
2021-11-30 06:50:51 +08:00
|
|
|
delete Timeline.dragging_playhead;
|
|
|
|
Interface.removeSuggestedModifierKey('ctrl', 'modifier_actions.drag_without_snapping');
|
2020-09-09 00:40:22 +08:00
|
|
|
Timeline.pause();
|
|
|
|
|
|
|
|
} else if (Timeline.dragging_endbracket) {
|
|
|
|
|
|
|
|
Undo.finishEdit('Change Animation Length')
|
|
|
|
delete Timeline.dragging_endbracket
|
|
|
|
}
|
|
|
|
})
|
2020-09-14 00:31:46 +08:00
|
|
|
|
2020-09-09 00:40:22 +08:00
|
|
|
//Enter Time
|
2021-01-20 20:42:14 +08:00
|
|
|
$('#timeline_timestamp').click(e => {
|
|
|
|
if ($('#timeline_timestamp').attr('contenteditable') == 'true') return;
|
2020-09-09 00:40:22 +08:00
|
|
|
|
2021-01-20 20:42:14 +08:00
|
|
|
$('#timeline_timestamp').attr('contenteditable', true).focus().select()
|
|
|
|
var times = $('#timeline_timestamp').text().split(':')
|
2020-09-09 00:40:22 +08:00
|
|
|
while (times.length < 3) {
|
|
|
|
times.push('00')
|
|
|
|
}
|
2021-01-20 20:42:14 +08:00
|
|
|
var node = $('#timeline_timestamp').get(0).childNodes[0]
|
2020-10-05 05:44:06 +08:00
|
|
|
var selection = window.getSelection();
|
2020-09-09 00:40:22 +08:00
|
|
|
var range = document.createRange();
|
|
|
|
|
|
|
|
var sel = [0, node.length]
|
|
|
|
if (e.offsetX < 24) {
|
|
|
|
sel = [0, times[0].length]
|
|
|
|
} else if (e.offsetX < 54) {
|
|
|
|
sel = [times[0].length+1, times[1].length]
|
|
|
|
} else if (e.offsetX < 80) {
|
|
|
|
sel = [times[0].length+times[1].length+2, times[2].length]
|
|
|
|
}
|
|
|
|
sel[1] = limitNumber(sel[0]+sel[1], sel[0], node.length)
|
|
|
|
|
|
|
|
range.setStart(node, sel[0])
|
|
|
|
range.setEnd(node, sel[1])
|
|
|
|
selection.removeAllRanges();
|
|
|
|
selection.addRange(range);
|
|
|
|
})
|
|
|
|
.on('focusout keydown', e => {
|
|
|
|
if (e.type === 'focusout' || Keybinds.extra.confirm.keybind.isTriggered(e) || Keybinds.extra.cancel.keybind.isTriggered(e)) {
|
2021-01-20 20:42:14 +08:00
|
|
|
$('#timeline_timestamp').attr('contenteditable', false)
|
2020-09-09 00:40:22 +08:00
|
|
|
Timeline.setTimecode(Timeline.time)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.on('keyup', e => {
|
2021-01-20 20:42:14 +08:00
|
|
|
var times = $('#timeline_timestamp').text().split(':')
|
2020-09-09 00:40:22 +08:00
|
|
|
times.forEach((t, i) => {
|
|
|
|
times[i] = parseInt(t)
|
|
|
|
if (isNaN(times[i])) {
|
|
|
|
times[i] = 0
|
|
|
|
}
|
|
|
|
})
|
|
|
|
while (times.length < 3) {
|
|
|
|
times.push(0)
|
|
|
|
}
|
2021-05-20 04:01:30 +08:00
|
|
|
let second_fractions = settings.timecode_frame_number.value ? 1/Timeline.getStep() : 100;
|
|
|
|
let seconds
|
2020-09-09 00:40:22 +08:00
|
|
|
= times[0]*60
|
|
|
|
+ limitNumber(times[1], 0, 59)
|
2021-05-20 04:01:30 +08:00
|
|
|
+ limitNumber(times[2]/second_fractions, 0, second_fractions-1)
|
2020-09-09 00:40:22 +08:00
|
|
|
if (Math.abs(seconds-Timeline.time) > 1e-3 ) {
|
|
|
|
Timeline.setTime(seconds, true)
|
|
|
|
Animator.preview()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
$('#timeline_vue').on('mousewheel scroll', function(e) {
|
|
|
|
e.preventDefault()
|
2020-09-27 23:03:28 +08:00
|
|
|
let event = e.originalEvent;
|
2022-08-23 06:19:57 +08:00
|
|
|
let body = document.getElementById('timeline_body');
|
2020-09-09 00:40:22 +08:00
|
|
|
if (event.shiftKey) {
|
|
|
|
body.scrollLeft += event.deltaY/4
|
|
|
|
|
|
|
|
} else if (event.ctrlOrCmd) {
|
|
|
|
|
2020-09-27 23:03:28 +08:00
|
|
|
let offset = $('#timeline_body_inner').offset()
|
|
|
|
let offsetX = event.clientX - offset.left - Timeline.vue._data.head_width;
|
|
|
|
|
2020-09-09 00:40:22 +08:00
|
|
|
var zoom = 1 - event.deltaY/600
|
|
|
|
let original_size = Timeline.vue._data.size
|
2020-09-27 23:03:28 +08:00
|
|
|
let updated_size = limitNumber(Timeline.vue._data.size * zoom, 10, 1000)
|
|
|
|
Timeline.vue._data.size = updated_size;
|
|
|
|
|
|
|
|
body.scrollLeft += (updated_size - original_size) * (offsetX / original_size)
|
2020-09-09 00:40:22 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
body.scrollTop += event.deltaY/6.25
|
|
|
|
}
|
|
|
|
Timeline.updateSize()
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
BarItems.slider_animation_speed.update()
|
|
|
|
Timeline.is_setup = true
|
|
|
|
Timeline.setTime(0)
|
|
|
|
},
|
|
|
|
getMaxLength() {
|
2021-01-31 07:12:53 +08:00
|
|
|
let width = (document.getElementById('timeline_vue')||0).clientWidth;
|
|
|
|
var max_length = (width-8) / Timeline.vue._data.size;
|
2020-09-28 18:55:45 +08:00
|
|
|
if (Animation.selected) max_length = Math.max(max_length, Animation.selected.length)
|
2020-09-09 00:40:22 +08:00
|
|
|
Timeline.keyframes.forEach((kf) => {
|
|
|
|
max_length = Math.max(max_length, kf.time)
|
|
|
|
})
|
|
|
|
max_length = Math.max(max_length, Timeline.time) + 50/Timeline.vue._data.size
|
|
|
|
return max_length;
|
|
|
|
},
|
|
|
|
updateSize() {
|
2021-05-20 04:01:30 +08:00
|
|
|
Timeline.vue.updateTimecodes();
|
2020-09-09 00:40:22 +08:00
|
|
|
},
|
|
|
|
updateScroll(e) {
|
|
|
|
$('.channel_head').css('left', scroll_amount+'px')
|
|
|
|
$('#timeline_time').css('left', -scroll_amount+'px')
|
|
|
|
},
|
|
|
|
unselect(e) {
|
2020-09-15 20:21:04 +08:00
|
|
|
if (!Animation.selected) return;
|
2020-09-09 00:40:22 +08:00
|
|
|
Timeline.keyframes.forEach((kf) => {
|
|
|
|
if (kf.selected) {
|
|
|
|
Timeline.selected.remove(kf)
|
|
|
|
}
|
|
|
|
kf.selected = false
|
|
|
|
})
|
|
|
|
TickUpdates.keyframe_selection = true;
|
|
|
|
},
|
2021-04-10 23:28:40 +08:00
|
|
|
clear() {
|
|
|
|
Timeline.animators.purge();
|
|
|
|
Timeline.selected.empty();
|
2021-08-12 05:46:19 +08:00
|
|
|
Timeline.vue.markers = [];
|
|
|
|
Timeline.vue.animation_length = 0;
|
2021-04-10 23:28:40 +08:00
|
|
|
updateKeyframeSelection();
|
|
|
|
},
|
2020-09-09 00:40:22 +08:00
|
|
|
start() {
|
2020-09-15 20:21:04 +08:00
|
|
|
if (!Animation.selected) return;
|
|
|
|
Animation.selected.getMaxLength()
|
2021-01-25 05:35:22 +08:00
|
|
|
if (Timeline.playing) {
|
|
|
|
Timeline.pause()
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
Timeline.playing = true
|
|
|
|
BarItems.play_animation.setIcon('pause')
|
2021-01-03 18:14:24 +08:00
|
|
|
Timeline.last_frame_timecode = Date.now();
|
2020-09-15 20:21:04 +08:00
|
|
|
if (Animation.selected.loop == 'hold' && Timeline.time >= (Animation.selected.length||1e3)) {
|
2020-09-09 00:40:22 +08:00
|
|
|
Timeline.setTime(0)
|
|
|
|
}
|
2020-09-13 02:35:25 +08:00
|
|
|
if (Timeline.time > 0) {
|
|
|
|
Animator.animations.forEach(animation => {
|
|
|
|
if (animation.playing && animation.animators.effects) {
|
|
|
|
animation.animators.effects.startPreviousSounds();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
Timeline.loop()
|
|
|
|
},
|
|
|
|
loop() {
|
2021-01-25 05:35:22 +08:00
|
|
|
Animator.preview(true);
|
2020-09-15 20:21:04 +08:00
|
|
|
if (Animation.selected && Timeline.time < (Animation.selected.length||1e3)) {
|
2020-09-12 06:08:01 +08:00
|
|
|
|
2020-10-14 01:56:55 +08:00
|
|
|
var new_time;
|
2020-10-27 02:56:00 +08:00
|
|
|
if (Animation.selected && Animation.selected.anim_time_update) {
|
2020-10-14 01:56:55 +08:00
|
|
|
var new_time = Animator.MolangParser.parse(Animation.selected.anim_time_update);
|
|
|
|
}
|
|
|
|
if (new_time == undefined || new_time <= Timeline.time) {
|
|
|
|
var new_time = Animator.MolangParser.parse('query.anim_time + query.delta_time')
|
|
|
|
}
|
2021-02-15 06:20:46 +08:00
|
|
|
let time = Timeline.time + (new_time - Timeline.time) * (Timeline.playback_speed/100)
|
|
|
|
if (Animation.selected.loop == 'hold') {
|
|
|
|
time = Math.clamp(time, 0, Animation.selected.length);
|
|
|
|
}
|
|
|
|
Timeline.setTime(time);
|
2021-01-03 18:14:24 +08:00
|
|
|
Timeline.last_frame_timecode = Date.now();
|
2020-09-12 06:08:01 +08:00
|
|
|
|
2020-09-09 00:40:22 +08:00
|
|
|
} else {
|
2022-11-26 07:16:49 +08:00
|
|
|
if (Animation.selected.loop == 'loop' || BarItems.looped_animation_playback.value) {
|
|
|
|
Timeline.setTime(0)
|
|
|
|
} else if (Animation.selected.loop == 'once') {
|
2020-09-09 00:40:22 +08:00
|
|
|
Timeline.setTime(0)
|
|
|
|
Animator.preview()
|
|
|
|
Timeline.pause()
|
2020-09-15 20:21:04 +08:00
|
|
|
} else if (Animation.selected.loop == 'hold') {
|
2020-09-09 00:40:22 +08:00
|
|
|
Timeline.pause()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
pause() {
|
2020-10-10 20:31:41 +08:00
|
|
|
Animator.preview();
|
2020-09-09 00:40:22 +08:00
|
|
|
Timeline.playing = false;
|
|
|
|
BarItems.play_animation.setIcon('play_arrow')
|
|
|
|
Timeline.playing_sounds.forEach(media => {
|
|
|
|
if (!media.paused) {
|
|
|
|
media.pause();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
Timeline.playing_sounds.empty();
|
|
|
|
},
|
2020-09-13 02:35:25 +08:00
|
|
|
|
|
|
|
waveforms: {},
|
|
|
|
waveform_sample_rate: 60,
|
|
|
|
async visualizeAudioFile(path) {
|
|
|
|
|
|
|
|
if (!Timeline.waveforms[path]) {
|
|
|
|
Timeline.waveforms[path] = {
|
|
|
|
samples: [],
|
|
|
|
duration: 0
|
|
|
|
};
|
|
|
|
}
|
|
|
|
let {samples} = Timeline.waveforms[path];
|
|
|
|
|
|
|
|
let audioContext = new AudioContext()
|
|
|
|
let response = await fetch(path);
|
|
|
|
let arrayBuffer = await response.arrayBuffer();
|
|
|
|
let audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
|
|
|
|
let data_array = audioBuffer.getChannelData(0);
|
|
|
|
|
|
|
|
Timeline.waveforms[path].duration = audioBuffer.duration;
|
|
|
|
|
|
|
|
// Sample
|
|
|
|
let sample_count = Math.ceil(audioBuffer.duration * Timeline.waveform_sample_rate);
|
|
|
|
samples.splice(0, samples.length);
|
|
|
|
for (var i = 0; i < sample_count; i++) {
|
|
|
|
samples.push(0);
|
|
|
|
}
|
|
|
|
for (var i = 0; i < data_array.length; i++) {
|
|
|
|
let sample_index = Math.floor((i / data_array.length) * sample_count);
|
|
|
|
samples[sample_index] += Math.abs(data_array[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Normalize
|
|
|
|
let max = Math.max(...samples);
|
|
|
|
samples.forEach((v, i) => samples[i] = v / max);
|
|
|
|
|
|
|
|
Timeline.vue.$forceUpdate();
|
|
|
|
|
|
|
|
return samples;
|
|
|
|
},
|
2020-10-09 20:10:48 +08:00
|
|
|
|
2020-09-09 00:40:22 +08:00
|
|
|
get keyframes() {
|
|
|
|
var keyframes = [];
|
2021-01-22 00:33:43 +08:00
|
|
|
if (!Timeline.vue.graph_editor_open) {
|
|
|
|
Timeline.animators.forEach(animator => {
|
|
|
|
keyframes.push(...animator.keyframes)
|
|
|
|
})
|
2021-01-25 02:19:10 +08:00
|
|
|
} else if (Timeline.vue.graph_editor_animator && Timeline.vue.graph_editor_animator[Timeline.vue.graph_editor_channel]) {
|
2021-01-22 00:33:43 +08:00
|
|
|
keyframes.push(...Timeline.vue.graph_editor_animator[Timeline.vue.graph_editor_channel])
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
return keyframes;
|
|
|
|
},
|
|
|
|
showMenu(event) {
|
|
|
|
if (event.target.nodeName == 'KEYFRAME' || event.target.parentElement.nodeName == 'KEYFRAME') return;
|
|
|
|
Timeline.menu.open(event, event);
|
|
|
|
},
|
|
|
|
menu: new Menu([
|
|
|
|
'paste',
|
|
|
|
'_',
|
2021-06-09 02:05:43 +08:00
|
|
|
{name: 'menu.view.zoom', id: 'zoom', condition: isApp, icon: 'search', children: [
|
|
|
|
'zoom_in',
|
|
|
|
'zoom_out',
|
|
|
|
'zoom_reset'
|
|
|
|
]},
|
2020-09-09 00:40:22 +08:00
|
|
|
'select_all',
|
|
|
|
'fold_all_animations',
|
2022-01-31 04:07:43 +08:00
|
|
|
'_',
|
2022-02-01 03:06:47 +08:00
|
|
|
'timeline_setups',
|
|
|
|
'save_timeline_setup',
|
2022-01-31 04:07:43 +08:00
|
|
|
'bring_up_all_animations',
|
2020-09-09 00:40:22 +08:00
|
|
|
'clear_timeline',
|
2021-05-22 20:44:53 +08:00
|
|
|
'_',
|
|
|
|
'graph_editor_zero_line',
|
2020-09-09 00:40:22 +08:00
|
|
|
])
|
|
|
|
}
|
|
|
|
|
2022-02-23 01:12:27 +08:00
|
|
|
Interface.definePanels(() => {
|
|
|
|
Timeline.panel = new Panel('timeline', {
|
|
|
|
icon: 'timeline',
|
2022-12-01 03:15:47 +08:00
|
|
|
condition: {modes: ['animate'], method: () => !AnimationController.selected},
|
2022-02-23 01:12:27 +08:00
|
|
|
default_position: {
|
|
|
|
slot: 'bottom',
|
2022-03-04 04:13:30 +08:00
|
|
|
float_position: [100, 400],
|
|
|
|
float_size: [600, 300],
|
|
|
|
height: 260,
|
2020-09-09 00:40:22 +08:00
|
|
|
},
|
2022-12-23 01:33:19 +08:00
|
|
|
grow: true,
|
2023-02-05 20:47:40 +08:00
|
|
|
toolbars: [
|
|
|
|
new Toolbar('timeline', {
|
|
|
|
children: [
|
|
|
|
'timeline_graph_editor',
|
|
|
|
'timeline_focus',
|
|
|
|
'clear_timeline',
|
|
|
|
'bring_up_all_animations',
|
|
|
|
'select_effect_animator',
|
|
|
|
'add_marker',
|
|
|
|
'+',
|
|
|
|
'jump_to_timeline_start',
|
|
|
|
'play_animation',
|
|
|
|
'jump_to_timeline_end',
|
|
|
|
'+',
|
|
|
|
'slider_animation_speed',
|
|
|
|
],
|
|
|
|
default_place: true
|
|
|
|
})
|
|
|
|
],
|
2022-03-18 06:00:30 +08:00
|
|
|
onResize() {
|
|
|
|
Timeline.updateSize();
|
|
|
|
},
|
2022-02-23 01:12:27 +08:00
|
|
|
component: {
|
|
|
|
name: 'panel-timeline',
|
|
|
|
data() {return {
|
2023-02-17 07:11:27 +08:00
|
|
|
size: 300,
|
2022-02-23 01:12:27 +08:00
|
|
|
length: 10,
|
|
|
|
animation_length: 0,
|
|
|
|
scroll_left: 0,
|
|
|
|
scroll_top: 0,
|
|
|
|
head_width: Interface.data.timeline_head,
|
|
|
|
timecodes: [],
|
|
|
|
animators: Timeline.animators,
|
|
|
|
markers: [],
|
|
|
|
waveforms: Timeline.waveforms,
|
|
|
|
focus_channel: null,
|
|
|
|
playhead: Timeline.time,
|
2021-05-20 04:01:30 +08:00
|
|
|
|
2022-02-23 01:12:27 +08:00
|
|
|
graph_editor_open: false,
|
|
|
|
graph_editor_channel: 'rotation',
|
|
|
|
graph_editor_axis: 'x',
|
|
|
|
graph_offset: 200,
|
|
|
|
graph_size: 200,
|
|
|
|
show_zero_line: true,
|
2023-01-13 00:58:30 +08:00
|
|
|
show_all_handles: !Settings.get('only_selected_bezier_handles'),
|
2022-05-20 01:00:40 +08:00
|
|
|
loop_graph: '',
|
2021-05-20 04:01:30 +08:00
|
|
|
|
2022-02-23 01:12:27 +08:00
|
|
|
channels: {
|
|
|
|
rotation: true,
|
|
|
|
position: true,
|
|
|
|
scale: true,
|
|
|
|
hide_empty: false,
|
2021-05-20 04:01:30 +08:00
|
|
|
}
|
2022-02-23 01:12:27 +08:00
|
|
|
}},
|
|
|
|
computed: {
|
|
|
|
graph_editor_animator() {
|
|
|
|
return this.animators.find(animator => animator.selected && animator instanceof BoneAnimator);
|
|
|
|
},
|
|
|
|
zero_line() {
|
|
|
|
let height = this.graph_offset;
|
|
|
|
return `M0 ${height} L10000 ${height}`
|
|
|
|
},
|
|
|
|
one_line() {
|
|
|
|
let height = this.graph_offset - this.graph_size;
|
|
|
|
return `M0 ${height} L10000 ${height}`
|
|
|
|
},
|
|
|
|
graph() {
|
|
|
|
let ba = this.graph_editor_animator;
|
|
|
|
if (!ba || !ba[this.graph_editor_channel] || !ba[this.graph_editor_channel].length) {
|
2022-05-20 01:00:40 +08:00
|
|
|
this.loop_graph = '';
|
2022-02-23 01:12:27 +08:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
let original_time = Timeline.time;
|
|
|
|
let step = 2;
|
|
|
|
let clientWidth = this.$refs.timeline_body ? this.$refs.timeline_body.clientWidth : 400;
|
|
|
|
let clientHeight = this.$refs.timeline_body ? this.$refs.timeline_body.clientHeight : 400;
|
|
|
|
let keyframes = ba[this.graph_editor_channel];
|
|
|
|
let points = [];
|
2022-05-20 01:00:40 +08:00
|
|
|
let loop_points = [];
|
2022-02-23 01:12:27 +08:00
|
|
|
let min = this.show_zero_line ? -1 : 10000,
|
|
|
|
max = this.show_zero_line ? 1 : -10000;
|
2021-05-20 04:01:30 +08:00
|
|
|
|
2022-02-23 01:12:27 +08:00
|
|
|
for (let time = Math.clamp(this.scroll_left - 9, 0, Infinity); time < (clientWidth + this.scroll_left - this.head_width); time += step) {
|
|
|
|
Timeline.time = time / this.size;
|
2022-05-20 02:49:26 +08:00
|
|
|
|
2022-02-23 01:12:27 +08:00
|
|
|
let snap_kf = keyframes.find(kf => Timeline.time <= kf.time && Timeline.time > kf.time - step / this.size );
|
|
|
|
if (snap_kf) {
|
|
|
|
Timeline.time = snap_kf.time;
|
|
|
|
}
|
2022-10-15 06:11:36 +08:00
|
|
|
Animator.resetLastValues();
|
2022-02-23 01:12:27 +08:00
|
|
|
let value = ba.interpolate(this.graph_editor_channel, false, this.graph_editor_axis);
|
|
|
|
if (snap_kf) snap_kf.display_value = value;
|
2022-05-20 02:49:26 +08:00
|
|
|
|
|
|
|
if (Timeline.time > Animation.selected.length && Animation.selected.length && Animation.selected.loop === 'loop') {
|
|
|
|
if (points.length && !loop_points.length) loop_points.push(points.last())
|
2022-05-20 01:00:40 +08:00
|
|
|
loop_points.push(value);
|
2022-05-20 02:49:26 +08:00
|
|
|
} else {
|
|
|
|
points.push(value);
|
|
|
|
min = Math.min(min, value);
|
|
|
|
max = Math.max(max, value);
|
2022-05-20 01:00:40 +08:00
|
|
|
}
|
2021-05-20 04:01:30 +08:00
|
|
|
}
|
2022-12-20 01:51:17 +08:00
|
|
|
keyframes.forEach(kf => {
|
|
|
|
if (kf.interpolation === 'bezier') {
|
|
|
|
min = Math.min(min, kf.display_value + kf.bezier_left_value[this.graph_editor_axis_number]);
|
|
|
|
max = Math.max(max, kf.display_value + kf.bezier_left_value[this.graph_editor_axis_number]);
|
|
|
|
min = Math.min(min, kf.display_value + kf.bezier_right_value[this.graph_editor_axis_number]);
|
|
|
|
max = Math.max(max, kf.display_value + kf.bezier_right_value[this.graph_editor_axis_number]);
|
|
|
|
}
|
|
|
|
})
|
2022-02-23 01:12:27 +08:00
|
|
|
|
|
|
|
Timeline.time = original_time;
|
|
|
|
|
|
|
|
let padding = 16;
|
|
|
|
let min_size = 2.4;
|
|
|
|
let unit_size = Math.clamp(max-min, min_size, 1e4);
|
|
|
|
this.graph_size = (clientHeight - 2*padding) / unit_size;
|
|
|
|
let blend = Math.clamp(1 - (max-min) / min_size, 0, 1)
|
|
|
|
this.graph_offset = clientHeight - padding + (this.graph_size * (min - unit_size/2 * blend ) );
|
|
|
|
|
|
|
|
let string = '';
|
|
|
|
points.forEach((value, i) => {
|
|
|
|
string += `${string.length ? 'L' : 'M'}${i*step} ${this.graph_offset - value * this.graph_size} `
|
2021-05-20 04:01:30 +08:00
|
|
|
})
|
|
|
|
|
2022-05-20 01:00:40 +08:00
|
|
|
this.loop_graph = '';
|
|
|
|
if (loop_points.length) {
|
|
|
|
loop_points.forEach((value, i) => {
|
2022-05-20 02:49:26 +08:00
|
|
|
i = i + points.length - 1;
|
2022-05-20 01:00:40 +08:00
|
|
|
this.loop_graph += `${this.loop_graph.length ? 'L' : 'M'}${i*step} ${this.graph_offset - value * this.graph_size} `
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-02-23 01:12:27 +08:00
|
|
|
return string;
|
2022-12-20 01:51:17 +08:00
|
|
|
},
|
|
|
|
graph_editor_axis_number() {
|
|
|
|
return getAxisNumber(this.graph_editor_axis)
|
2021-02-13 21:32:31 +08:00
|
|
|
}
|
|
|
|
},
|
2022-02-23 01:12:27 +08:00
|
|
|
methods: {
|
|
|
|
tl,
|
|
|
|
updateTimecodes() {
|
|
|
|
if (!this._isMounted) return;
|
|
|
|
this.timecodes.empty();
|
|
|
|
let second_fractions = settings.timecode_frame_number.value ? 1/Timeline.getStep() : 100;
|
2022-03-04 04:13:30 +08:00
|
|
|
let timeline_container_width = Panels.timeline.node.clientWidth - this.head_width;
|
2022-02-23 01:12:27 +08:00
|
|
|
this.length = Timeline.getMaxLength();
|
2021-02-27 22:38:49 +08:00
|
|
|
|
2022-02-23 01:12:27 +08:00
|
|
|
var step = 1
|
|
|
|
if (this.size < 1) {step = 1}
|
|
|
|
else if (this.size < 20) {step = 4}
|
|
|
|
else if (this.size < 40) {step = 2}
|
|
|
|
else if (this.size < 100) {step = 1}
|
|
|
|
else if (this.size < 256) {step = 0.5}
|
|
|
|
else if (this.size < 520) {step = 0.25}
|
|
|
|
else if (this.size < 660) {step = 0.2}
|
|
|
|
else if (this.size < 860) {step = 0.1}
|
|
|
|
else {step = 0.05}
|
2021-02-27 22:38:49 +08:00
|
|
|
|
2022-02-23 01:12:27 +08:00
|
|
|
if (step < 1) {
|
|
|
|
var FPS = Timeline.getStep();
|
|
|
|
step = Math.round(step/FPS) * FPS
|
|
|
|
//step = 1/Math.round(1/step)
|
2021-02-27 22:38:49 +08:00
|
|
|
}
|
2021-01-20 03:15:20 +08:00
|
|
|
|
2022-02-23 01:12:27 +08:00
|
|
|
let substeps = step / Timeline.getStep()
|
|
|
|
while (substeps > 8) {
|
|
|
|
substeps /= 2;
|
2021-02-27 22:38:49 +08:00
|
|
|
}
|
2022-02-23 01:12:27 +08:00
|
|
|
|
|
|
|
var i = Math.floor(this.scroll_left / this.size / step) * step;
|
|
|
|
while (i < Math.ceil((this.scroll_left + timeline_container_width) / this.size / step) * step) {
|
|
|
|
if (settings.timecode_frame_number.value) {
|
|
|
|
var text = `${Math.floor(i)}:${Math.round((i % 1) * second_fractions)}`;
|
|
|
|
} else {
|
|
|
|
var text = Math.round(i*100)/100;
|
2021-02-27 22:38:49 +08:00
|
|
|
}
|
2022-02-23 01:12:27 +08:00
|
|
|
this.timecodes.push({
|
|
|
|
time: i,
|
|
|
|
width: step,
|
|
|
|
substeps,
|
|
|
|
text,
|
|
|
|
})
|
|
|
|
i += step;
|
2021-01-23 05:56:02 +08:00
|
|
|
}
|
|
|
|
|
2022-02-23 01:12:27 +08:00
|
|
|
if (this.graph_editor_open) {
|
|
|
|
this.graph_size += 1e-5;
|
2021-02-27 22:38:49 +08:00
|
|
|
}
|
2022-02-23 01:12:27 +08:00
|
|
|
},
|
|
|
|
toggleAnimator(animator) {
|
|
|
|
animator.expanded = !animator.expanded;
|
|
|
|
},
|
|
|
|
removeAnimator(animator) {
|
|
|
|
Timeline.animators.remove(animator);
|
|
|
|
},
|
2022-11-10 05:12:28 +08:00
|
|
|
toggleGlobalSpace(animator) {
|
|
|
|
Undo.initEdit({animations: [Animation.selected]});
|
|
|
|
animator.rotation_global = !animator.rotation_global;
|
|
|
|
Undo.finishEdit('Toggle rotation in global space');
|
|
|
|
Animator.preview();
|
|
|
|
},
|
2022-02-23 01:12:27 +08:00
|
|
|
selectChannel(animator, channel) {
|
|
|
|
if (this.graph_editor_channel == channel && animator.selected) return;
|
|
|
|
if (!animator.channels[channel].transform) return;
|
2022-10-09 03:57:10 +08:00
|
|
|
if (!animator.selected) animator.select();
|
|
|
|
// Select keyframe in new channel
|
|
|
|
if (animator[channel].length && Keyframe.selected.length > 0) {
|
|
|
|
if (animator[channel].length == 1 && Math.epsilon(animator[channel][0].time, Timeline.time, 0.002)) {
|
|
|
|
animator[channel][0].select();
|
|
|
|
} else if (animator[channel].find(kf => Math.epsilon(kf.time, Keyframe.selected[0].time))) {
|
|
|
|
let kf = animator[channel].find(kf => Math.epsilon(kf.time, Keyframe.selected[0].time, 0.002));
|
|
|
|
kf.select();
|
|
|
|
} else {
|
|
|
|
let kf = animator[channel].slice().sort((a, b) => Math.abs(a.time - Timeline.time) - Math.abs(b.time - Timeline.time))[0];
|
|
|
|
kf.select();
|
|
|
|
}
|
2021-01-22 00:33:43 +08:00
|
|
|
}
|
2022-02-23 01:12:27 +08:00
|
|
|
this.graph_editor_channel = channel;
|
|
|
|
},
|
|
|
|
getColor(index) {
|
|
|
|
if (index == -1 || index == undefined) return;
|
2022-06-25 22:43:11 +08:00
|
|
|
return markerColors[index % markerColors.length].standard;
|
2022-02-23 01:12:27 +08:00
|
|
|
},
|
|
|
|
getWaveformPoints(samples, size) {
|
|
|
|
let height = 23;
|
|
|
|
let points = [`0,${height}`];
|
|
|
|
samples.forEach((sample, i) => {
|
|
|
|
points.push(`${(i + 0.5) / Timeline.waveform_sample_rate * size},${(1 - sample) * height}`);
|
|
|
|
})
|
|
|
|
points.push(`${(samples.length) / Timeline.waveform_sample_rate * size},${height}`)
|
|
|
|
return points.join(' ');
|
|
|
|
},
|
|
|
|
updateScroll() {
|
|
|
|
this.scroll_left = this.$refs.timeline_body ? this.$refs.timeline_body.scrollLeft : 0;
|
|
|
|
this.scroll_top = this.$refs.timeline_body ? this.$refs.timeline_body.scrollTop : 0;
|
|
|
|
},
|
|
|
|
dragKeyframes(clicked, e1) {
|
|
|
|
convertTouchEvent(e1);
|
2022-12-20 01:51:17 +08:00
|
|
|
if (e1.target.classList.contains('keyframe_bezier_handle')) return;
|
2022-02-23 01:12:27 +08:00
|
|
|
let dragging_range;
|
|
|
|
let dragging_restriction;
|
|
|
|
let originalValue;
|
|
|
|
let previousValue;
|
|
|
|
let time_stretching;
|
|
|
|
let values_changed;
|
|
|
|
let is_setup = false;
|
|
|
|
|
|
|
|
function setup() {
|
|
|
|
dragging_range = [Infinity, 0];
|
|
|
|
dragging_restriction;
|
|
|
|
originalValue;
|
|
|
|
previousValue = 0;
|
|
|
|
time_stretching = !Timeline.vue.graph_editor_open && (e1.ctrlOrCmd || Pressing.overrides.ctrl) && Timeline.selected.length > 1;
|
|
|
|
values_changed = false;
|
2021-01-23 05:56:02 +08:00
|
|
|
|
2022-02-23 01:12:27 +08:00
|
|
|
if (!clicked.selected && !e1.shiftKey && !Pressing.overrides.shift && Timeline.selected.length != 0) {
|
|
|
|
clicked.select()
|
|
|
|
} else if (clicked && !clicked.selected) {
|
|
|
|
clicked.select({shiftKey: true})
|
2021-01-23 05:56:02 +08:00
|
|
|
}
|
|
|
|
|
2022-02-23 01:12:27 +08:00
|
|
|
Undo.initEdit({keyframes: Timeline.selected});
|
|
|
|
Timeline.dragging_keyframes = true;
|
|
|
|
|
|
|
|
for (var kf of Timeline.selected) {
|
|
|
|
kf.time_before = kf.time;
|
|
|
|
dragging_range[0] = Math.min(dragging_range[0], kf.time);
|
|
|
|
dragging_range[1] = Math.max(dragging_range[1], kf.time);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Timeline.vue.graph_editor_open) {
|
|
|
|
// Find dragging restriction
|
|
|
|
dragging_restriction = [-Infinity, Infinity];
|
|
|
|
let ba = this.graph_editor_animator || 0;
|
|
|
|
let all_keyframes = ba[this.graph_editor_channel];
|
|
|
|
if (all_keyframes) {
|
|
|
|
|
|
|
|
let frst_keyframe;
|
|
|
|
let last_keyframe;
|
|
|
|
Timeline.selected.forEach(kf => {
|
|
|
|
if (!frst_keyframe || frst_keyframe.time > kf.time) frst_keyframe = kf;
|
|
|
|
if (!last_keyframe || last_keyframe.time < kf.time) last_keyframe = kf;
|
|
|
|
})
|
|
|
|
let prvs_keyframe;
|
|
|
|
let next_keyframe;
|
|
|
|
all_keyframes.forEach(kf => {
|
|
|
|
if (kf.time < frst_keyframe.time && (!prvs_keyframe || prvs_keyframe.time < kf.time)) prvs_keyframe = kf;
|
|
|
|
if (kf.time > last_keyframe.time && (!next_keyframe || next_keyframe.time > kf.time)) next_keyframe = kf;
|
|
|
|
})
|
|
|
|
if (prvs_keyframe) dragging_restriction[0] = prvs_keyframe.time;
|
|
|
|
if (next_keyframe) dragging_restriction[1] = next_keyframe.time;
|
|
|
|
}
|
2021-01-23 05:56:02 +08:00
|
|
|
}
|
2022-02-23 01:12:27 +08:00
|
|
|
is_setup = true;
|
2021-01-23 05:56:02 +08:00
|
|
|
}
|
2022-02-23 01:12:27 +08:00
|
|
|
|
|
|
|
function slide(e2) {
|
|
|
|
convertTouchEvent(e2);
|
2022-08-07 19:39:27 +08:00
|
|
|
e2.preventDefault();
|
2022-02-23 01:12:27 +08:00
|
|
|
let offset = [
|
|
|
|
e2.clientX - e1.clientX,
|
|
|
|
e2.clientY - e1.clientY,
|
|
|
|
]
|
|
|
|
if (!is_setup) {
|
|
|
|
if (Math.pow(offset[0], 2) + Math.pow(offset[1], 2) > 40) {
|
|
|
|
setup();
|
2021-01-22 00:33:43 +08:00
|
|
|
} else {
|
2022-02-23 01:12:27 +08:00
|
|
|
return;
|
2021-01-22 00:33:43 +08:00
|
|
|
}
|
|
|
|
}
|
2022-02-23 01:12:27 +08:00
|
|
|
|
|
|
|
// Time
|
|
|
|
var difference = Math.clamp(offset[0] / Timeline.vue._data.size, -256, 256);
|
|
|
|
let [min, max] = dragging_range;
|
|
|
|
|
|
|
|
if (time_stretching) {
|
|
|
|
var time_factor = (clicked && clicked.time_before < (min + max) / 2)
|
|
|
|
? ((max-min-difference) / (max-min))
|
|
|
|
: ((max-min+difference) / (max-min));
|
|
|
|
time_factor = Math.roundTo(time_factor, 2);
|
2021-02-25 18:22:26 +08:00
|
|
|
}
|
2021-01-20 03:15:20 +08:00
|
|
|
|
2022-02-23 01:12:27 +08:00
|
|
|
// Value
|
|
|
|
let value = 0;
|
|
|
|
let value_diff = 0;
|
2021-01-24 07:09:44 +08:00
|
|
|
if (Timeline.vue.graph_editor_open) {
|
2022-02-23 01:12:27 +08:00
|
|
|
value = -offset[1] / Timeline.vue.graph_size;
|
|
|
|
var round_num = canvasGridSize(e2.shiftKey || Pressing.overrides.shift, e2.ctrlOrCmd || Pressing.overrides.ctrl);
|
|
|
|
if (Toolbox.selected.id === 'resize_tool') {
|
|
|
|
round_num *= 0.1;
|
|
|
|
}
|
|
|
|
value = Math.round(value/round_num)*round_num
|
|
|
|
previousValue = previousValue == undefined ? value : previousValue;
|
|
|
|
originalValue = originalValue == undefined ? value : originalValue;
|
2021-01-22 00:33:43 +08:00
|
|
|
|
2022-02-23 01:12:27 +08:00
|
|
|
if (value !== previousValue) {
|
|
|
|
value_diff = value - (previousValue||0);
|
|
|
|
previousValue = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-27 22:38:49 +08:00
|
|
|
for (var kf of Timeline.selected) {
|
2022-02-23 01:12:27 +08:00
|
|
|
if (time_stretching) {
|
|
|
|
if (clicked && clicked.time_before < (min + max) / 2) {
|
|
|
|
var t = max - (kf.time_before - max) * -time_factor;
|
|
|
|
} else {
|
|
|
|
var t = min + (kf.time_before - min) * time_factor;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var t = kf.time_before + difference;
|
|
|
|
}
|
|
|
|
let old_time = kf.time;
|
|
|
|
if (dragging_restriction) {
|
|
|
|
let step = Timeline.getStep();
|
|
|
|
kf.time = Timeline.snapTime(Math.clamp(t, dragging_restriction[0] + step, dragging_restriction[1] - step));
|
|
|
|
} else {
|
|
|
|
kf.time = Timeline.snapTime(t);
|
|
|
|
}
|
|
|
|
if (old_time !== kf.time) {
|
|
|
|
values_changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Timeline.vue.graph_editor_open && value_diff) {
|
|
|
|
kf.offset(Timeline.vue.graph_editor_axis, value_diff);
|
|
|
|
values_changed = true;
|
|
|
|
}
|
2021-02-27 22:38:49 +08:00
|
|
|
}
|
2022-02-23 01:12:27 +08:00
|
|
|
if (time_stretching) {
|
|
|
|
Blockbench.setStatusBarText(Math.round(time_factor * 100) + '%');
|
2021-02-27 22:38:49 +08:00
|
|
|
} else {
|
2022-02-23 01:12:27 +08:00
|
|
|
let text = trimFloatNumber(Math.round(difference * Animation.selected.snapping));
|
|
|
|
if (Timeline.vue.graph_editor_open) {
|
|
|
|
text += ` ⨉ ${trimFloatNumber(value - originalValue)}`
|
|
|
|
}
|
|
|
|
Blockbench.setStatusBarText(text);
|
|
|
|
}
|
|
|
|
BarItems.slider_keyframe_time.update()
|
|
|
|
Animator.showMotionTrail()
|
|
|
|
Animator.preview()
|
|
|
|
|
|
|
|
}
|
|
|
|
function off() {
|
|
|
|
removeEventListeners(document, 'mousemove touchmove', slide);
|
|
|
|
removeEventListeners(document, 'mouseup touchend', off);
|
|
|
|
|
|
|
|
if (is_setup) {
|
|
|
|
var deleted = []
|
|
|
|
for (var kf of Timeline.selected) {
|
|
|
|
delete kf.time_before;
|
|
|
|
kf.replaceOthers(deleted);
|
|
|
|
}
|
|
|
|
Blockbench.setStatusBarText();
|
|
|
|
if (values_changed) {
|
|
|
|
Animation.selected.setLength();
|
2022-07-26 02:26:01 +08:00
|
|
|
if (time_stretching) {
|
|
|
|
Undo.finishEdit('Stretch keyframes');
|
|
|
|
} else {
|
|
|
|
Undo.addKeyframeCasualties(deleted);
|
|
|
|
Undo.finishEdit('Drag keyframes');
|
|
|
|
}
|
2022-02-23 01:12:27 +08:00
|
|
|
} else {
|
|
|
|
Undo.cancelEdit();
|
|
|
|
}
|
|
|
|
setTimeout(() => {
|
|
|
|
Timeline.dragging_keyframes = false;
|
|
|
|
}, 20);
|
2021-02-27 22:38:49 +08:00
|
|
|
}
|
2021-02-25 18:22:26 +08:00
|
|
|
}
|
2022-08-07 19:39:27 +08:00
|
|
|
addEventListeners(document, 'mousemove touchmove', slide, {passive: false});
|
2022-02-23 01:12:27 +08:00
|
|
|
addEventListeners(document, 'mouseup touchend', off);
|
|
|
|
},
|
2022-12-20 01:51:17 +08:00
|
|
|
dragBezierHandle(clicked, side, e1) {
|
|
|
|
convertTouchEvent(e1);
|
|
|
|
let values_changed;
|
|
|
|
let is_setup = false;
|
|
|
|
let axis_number = getAxisNumber(this.graph_editor_axis);
|
|
|
|
let old_values = {};
|
|
|
|
|
|
|
|
function setup() {
|
|
|
|
|
|
|
|
if (!clicked.selected && !e1.shiftKey && !Pressing.overrides.shift && Timeline.selected.length != 0) {
|
|
|
|
clicked.select()
|
|
|
|
} else if (clicked && !clicked.selected) {
|
|
|
|
clicked.select({shiftKey: true})
|
|
|
|
}
|
|
|
|
|
|
|
|
Keyframe.selected.forEach(kf => {
|
|
|
|
if (kf.interpolation == 'bezier') {
|
|
|
|
old_values[kf.uuid] = {
|
|
|
|
bezier_left_time: kf.bezier_left_time.slice(),
|
|
|
|
bezier_left_value: kf.bezier_left_value.slice(),
|
|
|
|
bezier_right_time: kf.bezier_right_time.slice(),
|
|
|
|
bezier_right_value: kf.bezier_right_value.slice(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
Undo.initEdit({keyframes: Timeline.selected});
|
|
|
|
Timeline.dragging_keyframes = true;
|
|
|
|
|
|
|
|
is_setup = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function slide(e2) {
|
|
|
|
convertTouchEvent(e2);
|
|
|
|
e2.preventDefault();
|
|
|
|
let offset = [
|
|
|
|
e2.clientX - e1.clientX,
|
|
|
|
e2.clientY - e1.clientY,
|
|
|
|
]
|
|
|
|
if (!is_setup) {
|
|
|
|
if (Math.pow(offset[0], 2) + Math.pow(offset[1], 2) > 20) {
|
|
|
|
setup();
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var difference_time = Math.clamp(offset[0] / Timeline.vue._data.size, -256, 256);
|
|
|
|
var difference_value = Math.clamp(-offset[1] / Timeline.vue.graph_size, -256, 256);
|
|
|
|
|
|
|
|
for (var kf of Timeline.selected) {
|
|
|
|
if (kf.interpolation == 'bezier') {
|
|
|
|
|
|
|
|
kf.bezier_left_time.V3_set(old_values[kf.uuid].bezier_left_time);
|
|
|
|
kf.bezier_left_value.V3_set(old_values[kf.uuid].bezier_left_value);
|
|
|
|
kf.bezier_right_time.V3_set(old_values[kf.uuid].bezier_right_time);
|
|
|
|
kf.bezier_right_value.V3_set(old_values[kf.uuid].bezier_right_value);
|
|
|
|
|
|
|
|
if (side === 'left') {
|
|
|
|
kf.bezier_left_time[axis_number] = Math.min(0, old_values[kf.uuid].bezier_left_time[axis_number] + difference_time);
|
|
|
|
kf.bezier_left_value[axis_number] = old_values[kf.uuid].bezier_left_value[axis_number] + difference_value;
|
|
|
|
if (kf.bezier_linked) {
|
|
|
|
kf.bezier_right_time[axis_number] = -kf.bezier_left_time[axis_number];
|
|
|
|
kf.bezier_right_value[axis_number] = -kf.bezier_left_value[axis_number];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (side === 'right') {
|
|
|
|
kf.bezier_right_time[axis_number] = Math.max(0, old_values[kf.uuid].bezier_right_time[axis_number] + difference_time);
|
|
|
|
kf.bezier_right_value[axis_number] = old_values[kf.uuid].bezier_right_value[axis_number] + difference_value;
|
|
|
|
if (kf.bezier_linked) {
|
|
|
|
kf.bezier_left_time[axis_number] = -kf.bezier_right_time[axis_number];
|
|
|
|
kf.bezier_left_value[axis_number] = -kf.bezier_right_value[axis_number];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
values_changed = true;
|
|
|
|
}
|
|
|
|
}
|
2022-12-21 07:20:12 +08:00
|
|
|
let text = `${trimFloatNumber(Math.roundTo(difference_time, 2))} ⨉ ${trimFloatNumber(Math.roundTo(difference_value, 2))}`;
|
2022-12-20 01:51:17 +08:00
|
|
|
Blockbench.setStatusBarText(text);
|
|
|
|
|
|
|
|
Timeline.vue.show_zero_line = !Timeline.vue.show_zero_line;
|
|
|
|
Timeline.vue.show_zero_line = !Timeline.vue.show_zero_line;
|
|
|
|
Animator.showMotionTrail()
|
|
|
|
Animator.preview()
|
|
|
|
}
|
|
|
|
function off() {
|
|
|
|
removeEventListeners(document, 'mousemove touchmove', slide);
|
|
|
|
removeEventListeners(document, 'mouseup touchend', off);
|
|
|
|
|
|
|
|
if (is_setup) {
|
|
|
|
Blockbench.setStatusBarText();
|
|
|
|
if (values_changed) {
|
|
|
|
Undo.finishEdit('Adjust keyframe bezier handles');
|
|
|
|
} else {
|
|
|
|
Undo.cancelEdit();
|
|
|
|
}
|
|
|
|
setTimeout(() => {
|
|
|
|
Timeline.dragging_keyframes = false;
|
|
|
|
}, 20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addEventListeners(document, 'mousemove touchmove', slide, {passive: false});
|
|
|
|
addEventListeners(document, 'mouseup touchend', off);
|
|
|
|
},
|
|
|
|
getBezierHandleStyle(keyframe, side) {
|
|
|
|
let axis_number = getAxisNumber(this.graph_editor_axis);
|
|
|
|
let x_offset = -keyframe[`bezier_${side}_time`][axis_number] * this.size;
|
|
|
|
let y_offset = -keyframe[`bezier_${side}_value`][axis_number] * this.graph_size;
|
|
|
|
let length = Math.sqrt(Math.pow(x_offset, 2) + Math.pow(y_offset, 2));
|
|
|
|
let angle = Math.atan2(-y_offset, x_offset);
|
|
|
|
return {
|
|
|
|
right: x_offset + 'px',
|
|
|
|
top: y_offset + 'px',
|
|
|
|
'--length': Math.max(length - 6, 0) + 'px',
|
|
|
|
'--angle': Math.radToDeg(angle) + 'deg',
|
|
|
|
}
|
|
|
|
},
|
2022-02-23 01:12:27 +08:00
|
|
|
clamp: Math.clamp,
|
2022-10-09 03:57:10 +08:00
|
|
|
trimFloatNumber
|
2021-01-22 00:33:43 +08:00
|
|
|
},
|
2022-02-23 01:12:27 +08:00
|
|
|
watch: {
|
|
|
|
size() {this.updateTimecodes()},
|
|
|
|
length() {this.updateTimecodes()},
|
|
|
|
scroll_left() {this.updateTimecodes()},
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<div id="timeline_vue" :class="{graph_editor: graph_editor_open}">
|
|
|
|
<div id="timeline_header">
|
|
|
|
<div id="timeline_corner" v-bind:style="{width: head_width+'px'}">
|
|
|
|
<div id="timeline_timestamp"></div>
|
|
|
|
<div class="channel_axis_selector" v-if="graph_editor_open">
|
|
|
|
<div @click="graph_editor_axis = 'x';" :class="{selected: graph_editor_axis == 'x'}" style="color: var(--color-axis-x);">X</div>
|
|
|
|
<div @click="graph_editor_axis = 'y';" :class="{selected: graph_editor_axis == 'y'}" style="color: var(--color-axis-y);">Y</div>
|
|
|
|
<div @click="graph_editor_axis = 'z';" :class="{selected: graph_editor_axis == 'z'}" style="color: var(--color-axis-z);">Z</div>
|
|
|
|
</div>
|
2021-01-24 18:39:04 +08:00
|
|
|
</div>
|
2022-02-23 01:12:27 +08:00
|
|
|
<div id="timeline_time_wrapper">
|
|
|
|
<div id="timeline_time" v-bind:style="{width: (size*length)+'px', left: -scroll_left+'px'}">
|
|
|
|
<div v-for="t in timecodes" class="timeline_timecode" :key="t.text" :style="{left: (t.time * size) + 'px', width: (t.width * size) + 'px'}">
|
|
|
|
<span>{{ t.text }}</span>
|
|
|
|
<div class="substeps">
|
|
|
|
<div v-for="n in Math.ceil(t.substeps)" :key="t.text + '-' + n"></div>
|
|
|
|
</div>
|
2021-01-20 01:04:22 +08:00
|
|
|
</div>
|
2022-02-23 01:12:27 +08:00
|
|
|
<div id="timeline_playhead"
|
|
|
|
v-bind:style="{left: (playhead * size) + 'px'}"
|
|
|
|
></div>
|
|
|
|
<div id="timeline_endbracket"
|
|
|
|
v-bind:style="{left: (animation_length * size) + 'px'}"
|
|
|
|
></div>
|
|
|
|
<div
|
|
|
|
v-for="marker in markers"
|
|
|
|
class="timeline_marker"
|
2022-06-25 22:43:11 +08:00
|
|
|
v-bind:style="{left: (marker.time * size) + 'px', 'border-color': markerColors[marker.color % markerColors.length].standard}"
|
2022-02-23 01:12:27 +08:00
|
|
|
@contextmenu.prevent="marker.showContextMenu($event)"
|
|
|
|
v-on:click="marker.callPlayhead()"
|
|
|
|
></div>
|
2021-01-20 01:04:22 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-02-23 01:12:27 +08:00
|
|
|
<div id="timeline_body" ref="timeline_body" @scroll="updateScroll($event)">
|
|
|
|
<div id="timeline_body_inner" v-bind:style="{width: (size*length + head_width)+'px'}" @contextmenu.stop="Timeline.showMenu($event)">
|
|
|
|
<li v-for="animator in animators" class="animator" :class="{selected: animator.selected, boneless: animator.constructor.name == 'BoneAnimator' && !animator.group}" :uuid="animator.uuid" v-on:click="animator.select();">
|
|
|
|
<div class="animator_head_bar">
|
2022-09-26 01:46:02 +08:00
|
|
|
<div class="channel_head" v-bind:style="{left: scroll_left+'px', width: head_width+'px'}" v-on:dblclick.stop="toggleAnimator(animator)" @contextmenu.stop="animator.showContextMenu($event)">
|
2022-02-23 01:12:27 +08:00
|
|
|
<div class="text_button" v-on:click.stop="toggleAnimator(animator)">
|
|
|
|
<i class="icon-open-state fa" v-bind:class="{'fa-angle-right': !animator.expanded, 'fa-angle-down': animator.expanded}"></i>
|
|
|
|
</div>
|
|
|
|
<span v-on:click.stop="animator.select();">{{animator.name}}</span>
|
|
|
|
<div class="text_button" v-on:click.stop="removeAnimator(animator)">
|
|
|
|
<i class="material-icons">remove</i>
|
|
|
|
</div>
|
2021-01-20 01:04:22 +08:00
|
|
|
</div>
|
2022-02-23 01:12:27 +08:00
|
|
|
<div class="keyframe_section" v-if="!graph_editor_open">
|
|
|
|
<template v-for="(channel_options, channel) in animator.channels" v-if="!(animator.expanded && channels[channel] != false && (!channels.hide_empty || animator[channel].length))">
|
|
|
|
<div
|
|
|
|
v-for="keyframe in animator[channel]"
|
|
|
|
v-bind:style="{left: (8 + keyframe.time * size) + 'px'}"
|
|
|
|
class="keyframe"
|
|
|
|
v-bind:id="'_'+keyframe.uuid"
|
|
|
|
>
|
|
|
|
<i class="material-icons">lens</i>
|
|
|
|
</div>
|
|
|
|
</template>
|
2021-01-20 01:04:22 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-02-23 01:12:27 +08:00
|
|
|
<div class="animator_channel_bar"
|
|
|
|
v-bind:style="{width: (size*length + head_width)+'px'}"
|
|
|
|
v-for="(channel_options, channel) in animator.channels"
|
|
|
|
v-if="animator.expanded && channels[channel] != false && (!channels.hide_empty || animator[channel].length)"
|
|
|
|
>
|
|
|
|
<div class="channel_head"
|
|
|
|
:class="{selected: graph_editor_open && animator.selected && graph_editor_channel == channel}"
|
|
|
|
v-bind:style="{left: scroll_left+'px', width: head_width+'px'}"
|
|
|
|
@click.stop="selectChannel(animator, channel);"
|
2022-09-26 01:46:02 +08:00
|
|
|
@contextmenu.stop="animator.showContextMenu($event)"
|
2022-02-23 01:12:27 +08:00
|
|
|
>
|
|
|
|
<div class="text_button" v-if="channel_options.mutable" v-on:click.stop="animator.toggleMuted(channel)">
|
|
|
|
<template v-if="channel === 'sound'">
|
|
|
|
<i class="channel_mute fas fa-volume-mute" v-if="animator.muted[channel]"></i>
|
|
|
|
<i class="channel_mute fas fa-volume-up" v-else></i>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<i class="channel_mute fas fa-eye-slash" v-if="animator.muted[channel]"></i>
|
|
|
|
<i class="channel_mute fas fa-eye" v-else></i>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
<div class="text_button" v-else></div>
|
|
|
|
<span>{{ channel_options.name }}</span>
|
2022-11-10 05:12:28 +08:00
|
|
|
<div
|
|
|
|
class="text_button rotation_global" :class="{off: !animator.rotation_global}"
|
|
|
|
v-if="channel == 'rotation' && animator.type == 'bone'"
|
|
|
|
title="${tl('menu.animator.rotation_global')}"
|
|
|
|
@click.stop="toggleGlobalSpace(animator)"
|
|
|
|
>
|
|
|
|
<i class="material-icons">{{ animator.rotation_global ? 'public' : 'public_off' }}</i>
|
|
|
|
</div>
|
2022-02-23 01:12:27 +08:00
|
|
|
<div class="text_button" v-on:click.stop="animator.createKeyframe(null, null, channel, true)">
|
|
|
|
<i class="material-icons">add</i>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="keyframe_section" v-if="!graph_editor_open">
|
2021-09-21 17:20:10 +08:00
|
|
|
<div
|
2021-01-20 01:04:22 +08:00
|
|
|
v-for="keyframe in animator[channel]"
|
2022-02-23 01:12:27 +08:00
|
|
|
v-bind:style="{left: (8 + keyframe.time * size) + 'px', color: getColor(keyframe.color)}"
|
2021-01-20 01:04:22 +08:00
|
|
|
class="keyframe"
|
2022-02-23 01:12:27 +08:00
|
|
|
v-bind:class="[keyframe.channel, keyframe.selected?'selected':'']"
|
|
|
|
v-bind:id="keyframe.uuid"
|
|
|
|
v-on:click.stop="keyframe.select($event)"
|
|
|
|
v-on:dblclick="keyframe.callPlayhead()"
|
|
|
|
:title="tl('timeline.'+keyframe.channel)"
|
|
|
|
@mousedown="dragKeyframes(keyframe, $event)" @touchstart="dragKeyframes(keyframe, $event)"
|
|
|
|
@contextmenu.prevent.stop="keyframe.showContextMenu($event)"
|
2021-01-20 01:04:22 +08:00
|
|
|
>
|
2022-02-23 01:12:27 +08:00
|
|
|
<i class="material-icons keyframe_icon_smaller" v-if="keyframe.interpolation == 'catmullrom'">lens</i>
|
|
|
|
<i class="material-icons keyframe_icon_step" v-else-if="keyframe.interpolation == 'step'">eject</i>
|
2023-01-21 03:04:40 +08:00
|
|
|
<i class="icon-keyframe_bezier" v-else-if="keyframe.interpolation == 'bezier'"></i>
|
2022-02-23 01:12:27 +08:00
|
|
|
<i :class="keyframe.data_points.length == 1 ? 'icon-keyframe' : 'icon-keyframe_discontinuous'" v-else></i>
|
|
|
|
<svg class="keyframe_waveform" v-if="keyframe.channel == 'sound' && keyframe.data_points[0].file && waveforms[keyframe.data_points[0].file]" :style="{width: waveforms[keyframe.data_points[0].file].duration * size}">
|
|
|
|
<polygon :points="getWaveformPoints(waveforms[keyframe.data_points[0].file].samples, size)"></polygon>
|
|
|
|
</svg>
|
2021-09-21 17:20:10 +08:00
|
|
|
</div>
|
2021-01-20 01:04:22 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-02-23 01:12:27 +08:00
|
|
|
</li>
|
|
|
|
<div id="timeline_empty_head" class="channel_head" v-bind:style="{left: scroll_left+'px', width: head_width+'px'}">
|
|
|
|
</div>
|
|
|
|
<div id="timeline_selector" class="selection_rectangle"></div>
|
|
|
|
<div id="timeline_graph_editor" ref="graph_editor" v-if="graph_editor_open" :style="{left: head_width + 'px', top: scroll_top + 'px'}">
|
|
|
|
<svg :style="{'margin-left': clamp(scroll_left, 9, Infinity) + 'px'}">
|
|
|
|
<path :d="zero_line" style="stroke: var(--color-grid);"></path>
|
|
|
|
<path :d="one_line" style="stroke: var(--color-grid); stroke-dasharray: 6;" v-if="graph_editor_channel == 'scale'"></path>
|
2022-05-20 01:00:40 +08:00
|
|
|
<path :d="loop_graph" class="loop_graph" style="stroke: var(--color-grid);"></path>
|
2022-02-23 01:12:27 +08:00
|
|
|
<path :d="graph" :style="{stroke: 'var(--color-axis-' + graph_editor_axis + ')'}"></path>
|
|
|
|
</svg>
|
|
|
|
<template v-if="graph_editor_animator">
|
2021-09-21 17:20:10 +08:00
|
|
|
<div
|
2022-02-23 01:12:27 +08:00
|
|
|
v-for="keyframe in graph_editor_animator[graph_editor_channel]"
|
|
|
|
v-bind:style="{left: (10 + keyframe.time * size) + 'px', top: (graph_offset - keyframe.display_value * graph_size - 8) + 'px', color: getColor(keyframe.color)}"
|
|
|
|
class="keyframe graph_keyframe"
|
2021-01-20 01:04:22 +08:00
|
|
|
v-bind:class="[keyframe.channel, keyframe.selected?'selected':'']"
|
|
|
|
v-bind:id="keyframe.uuid"
|
|
|
|
v-on:click.stop="keyframe.select($event)"
|
|
|
|
v-on:dblclick="keyframe.callPlayhead()"
|
2022-12-23 01:33:19 +08:00
|
|
|
:title="trimFloatNumber(keyframe.time, 2) + ' ⨉ ' + trimFloatNumber(keyframe.display_value || 0)"
|
2021-01-22 00:33:43 +08:00
|
|
|
@mousedown="dragKeyframes(keyframe, $event)" @touchstart="dragKeyframes(keyframe, $event)"
|
2022-06-18 18:56:46 +08:00
|
|
|
@contextmenu.prevent.stop="keyframe.showContextMenu($event)"
|
2021-01-20 01:04:22 +08:00
|
|
|
>
|
|
|
|
<i class="material-icons keyframe_icon_smaller" v-if="keyframe.interpolation == 'catmullrom'">lens</i>
|
2021-12-05 22:39:42 +08:00
|
|
|
<i class="material-icons keyframe_icon_step" v-else-if="keyframe.interpolation == 'step'">eject</i>
|
2021-05-22 19:02:56 +08:00
|
|
|
<i :class="keyframe.data_points.length == 1 ? 'icon-keyframe' : 'icon-keyframe_discontinuous'" v-else></i>
|
2022-12-20 01:51:17 +08:00
|
|
|
|
2023-01-13 00:58:30 +08:00
|
|
|
<template v-if="keyframe.interpolation == 'bezier' && (show_all_handles || keyframe.selected)">
|
2022-12-20 01:51:17 +08:00
|
|
|
<div class="keyframe_bezier_handle"
|
|
|
|
:style="getBezierHandleStyle(keyframe, 'left')"
|
2022-12-22 02:18:05 +08:00
|
|
|
:title="'${tl('generic.left')}: ' + trimFloatNumber(keyframe.bezier_left_time[graph_editor_axis_number], 2) + ' ⨉ ' + trimFloatNumber(keyframe.bezier_left_value[graph_editor_axis_number])"
|
2022-12-20 01:51:17 +08:00
|
|
|
@mousedown="dragBezierHandle(keyframe, 'left', $event)" @touchstart="dragBezierHandle('left', $event)"
|
|
|
|
></div>
|
|
|
|
<div class="keyframe_bezier_handle"
|
|
|
|
:style="getBezierHandleStyle(keyframe, 'right')"
|
2022-12-22 02:18:05 +08:00
|
|
|
:title="'${tl('generic.right')}: ' + trimFloatNumber(keyframe.bezier_right_time[graph_editor_axis_number], 2) + ' ⨉ ' + trimFloatNumber(keyframe.bezier_right_value[graph_editor_axis_number])"
|
2022-12-20 01:51:17 +08:00
|
|
|
@mousedown="dragBezierHandle(keyframe, 'right', $event)" @touchstart="dragBezierHandle('right', $event)"
|
|
|
|
></div>
|
|
|
|
</template>
|
2021-09-21 17:20:10 +08:00
|
|
|
</div>
|
2022-02-23 01:12:27 +08:00
|
|
|
</template>
|
2021-01-20 01:04:22 +08:00
|
|
|
</div>
|
2021-01-21 03:31:54 +08:00
|
|
|
</div>
|
2021-01-20 01:04:22 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-02-23 01:12:27 +08:00
|
|
|
`
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
})
|
2022-02-23 01:12:27 +08:00
|
|
|
Timeline.vue = Timeline.panel.inside_vue;
|
2022-03-16 23:20:27 +08:00
|
|
|
Timeline.panel.on('change_zindex', ({zindex}) => {
|
|
|
|
if (Condition(Timeline.panel.condition)) {
|
|
|
|
document.getElementById('resizer_timeline_head').style.zIndex = zindex ? zindex+1 : null;
|
|
|
|
}
|
|
|
|
})
|
2020-09-09 00:40:22 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
BARS.defineActions(function() {
|
2021-01-24 07:09:44 +08:00
|
|
|
new Toggle('timeline_graph_editor', {
|
|
|
|
icon: 'timeline',
|
|
|
|
category: 'animation',
|
|
|
|
condition: {modes: ['animate']},
|
|
|
|
keybind: new Keybind({key: 114}),
|
|
|
|
onChange(state) {
|
|
|
|
Timeline.vue.graph_editor_open = state;
|
2021-11-20 02:36:19 +08:00
|
|
|
if (Timeline.vue.graph_editor_open &&
|
|
|
|
Timeline.selected.length &&
|
|
|
|
Timeline.selected_animator &&
|
|
|
|
Timeline.selected_animator.channels[Timeline.selected[0].channel] &&
|
|
|
|
Timeline.selected_animator.channels[Timeline.selected[0].channel].transform
|
|
|
|
) {
|
2021-01-24 07:09:44 +08:00
|
|
|
Timeline.vue.graph_editor_channel = Timeline.selected[0].channel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2021-05-22 20:44:53 +08:00
|
|
|
new Toggle('graph_editor_zero_line', {
|
|
|
|
icon: 'exposure_zero',
|
|
|
|
category: 'animation',
|
|
|
|
condition: {modes: ['animate'], method: () => Timeline.vue.graph_editor_open},
|
|
|
|
default: true,
|
|
|
|
onChange(state) {
|
|
|
|
Timeline.vue.show_zero_line = state;
|
|
|
|
}
|
|
|
|
})
|
2020-09-09 00:40:22 +08:00
|
|
|
new Action('play_animation', {
|
|
|
|
icon: 'play_arrow',
|
|
|
|
category: 'animation',
|
|
|
|
keybind: new Keybind({key: 32}),
|
2022-12-15 01:04:06 +08:00
|
|
|
condition: {modes: ['animate'], selected: {animation_controller: false}},
|
2020-09-09 00:40:22 +08:00
|
|
|
click: function () {
|
|
|
|
|
2020-09-15 20:21:04 +08:00
|
|
|
if (!Animation.selected) {
|
2020-09-09 00:40:22 +08:00
|
|
|
Blockbench.showQuickMessage('message.no_animation_selected')
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Timeline.playing) {
|
|
|
|
Timeline.pause()
|
|
|
|
} else {
|
|
|
|
Timeline.start()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2022-11-26 07:16:49 +08:00
|
|
|
new Toggle('looped_animation_playback', {
|
|
|
|
icon: 'fa-repeat',
|
|
|
|
category: 'animation',
|
|
|
|
condition: {modes: ['animate']},
|
|
|
|
default: false
|
|
|
|
})
|
2020-09-09 00:40:22 +08:00
|
|
|
new NumSlider('slider_animation_speed', {
|
|
|
|
category: 'animation',
|
|
|
|
condition: {modes: ['animate']},
|
2021-11-17 07:20:51 +08:00
|
|
|
settings: {
|
|
|
|
default: 100,
|
|
|
|
min: 0,
|
|
|
|
max: 10000
|
|
|
|
},
|
2020-09-09 00:40:22 +08:00
|
|
|
get: function() {
|
|
|
|
return Timeline.playback_speed;
|
|
|
|
},
|
|
|
|
change: function(modify) {
|
|
|
|
Timeline.playback_speed = limitNumber(modify(Timeline.playback_speed), 0, 10000)
|
|
|
|
},
|
|
|
|
getInterval: (e) => {
|
|
|
|
var val = BarItems.slider_animation_speed.get()
|
|
|
|
if (e.shiftKey) {
|
|
|
|
if (val < 50) {
|
|
|
|
return 10;
|
|
|
|
} else {
|
|
|
|
return 50;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (e.ctrlOrCmd) {
|
|
|
|
if (val < 500) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (val < 10) {
|
|
|
|
return 1;
|
|
|
|
} else if (val < 50) {
|
|
|
|
return 5;
|
|
|
|
} else if (val < 160) {
|
|
|
|
return 10;
|
|
|
|
} else if (val < 300) {
|
|
|
|
return 20;
|
|
|
|
} else if (val < 1000) {
|
|
|
|
return 50;
|
|
|
|
} else {
|
|
|
|
return 500;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
new Action('jump_to_timeline_start', {
|
|
|
|
icon: 'skip_previous',
|
|
|
|
category: 'animation',
|
|
|
|
condition: {modes: ['animate']},
|
|
|
|
keybind: new Keybind({key: 36}),
|
|
|
|
click: function () {
|
2022-06-26 23:22:10 +08:00
|
|
|
let was_playing = Timeline.playing;
|
|
|
|
if (Timeline.playing) Timeline.pause();
|
|
|
|
Timeline.setTime(0);
|
|
|
|
if (was_playing) {
|
|
|
|
Timeline.start();
|
|
|
|
} else {
|
|
|
|
Animator.preview();
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
new Action('jump_to_timeline_end', {
|
|
|
|
icon: 'skip_next',
|
|
|
|
category: 'animation',
|
|
|
|
condition: {modes: ['animate']},
|
|
|
|
keybind: new Keybind({key: 35}),
|
|
|
|
click: function () {
|
2022-06-26 23:22:10 +08:00
|
|
|
let was_playing = Timeline.playing;
|
|
|
|
if (Timeline.playing) Timeline.pause();
|
2020-09-15 20:21:04 +08:00
|
|
|
Timeline.setTime(Animation.selected ? Animation.selected.length : 0)
|
2022-06-26 23:22:10 +08:00
|
|
|
if (was_playing) {
|
|
|
|
Timeline.start();
|
|
|
|
} else {
|
|
|
|
Animator.preview();
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
|
|
|
})
|
2020-10-08 04:15:29 +08:00
|
|
|
new Action('timeline_frame_back', {
|
|
|
|
icon: 'arrow_back',
|
|
|
|
category: 'animation',
|
2022-06-22 05:30:18 +08:00
|
|
|
condition: {modes: ['animate', 'edit', 'paint'], method: () => (Modes.animate || Interface.Panels.textures.inside_vue.maxFrameCount())},
|
2020-10-08 04:15:29 +08:00
|
|
|
keybind: new Keybind({key: 188}),
|
|
|
|
click: function (e) {
|
2022-06-22 05:30:18 +08:00
|
|
|
if (Modes.animate || Prop.active_panel == 'timeline') {
|
2022-01-22 06:37:33 +08:00
|
|
|
let time = Timeline.snapTime(limitNumber(Timeline.time - Timeline.getStep(), 0, 1e4));
|
|
|
|
Timeline.setTime(time);
|
|
|
|
Animator.preview()
|
2022-06-22 05:30:18 +08:00
|
|
|
} else {
|
|
|
|
BarItems.animated_texture_frame.change(v => v - 1);
|
2022-01-22 06:37:33 +08:00
|
|
|
}
|
2020-10-08 04:15:29 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
new Action('timeline_frame_forth', {
|
|
|
|
icon: 'arrow_forward',
|
|
|
|
category: 'animation',
|
2022-06-22 05:30:18 +08:00
|
|
|
condition: {modes: ['animate', 'edit', 'paint'], method: () => (Modes.animate || Interface.Panels.textures.inside_vue.maxFrameCount())},
|
2020-10-08 04:15:29 +08:00
|
|
|
keybind: new Keybind({key: 190}),
|
|
|
|
click: function (e) {
|
2022-06-22 05:30:18 +08:00
|
|
|
if (Modes.animate || Prop.active_panel == 'timeline') {
|
2022-01-22 06:37:33 +08:00
|
|
|
let time = Timeline.snapTime(limitNumber(Timeline.time + Timeline.getStep(), 0, 1e4));
|
|
|
|
Timeline.setTime(time);
|
|
|
|
Animator.preview()
|
2022-06-22 05:30:18 +08:00
|
|
|
} else {
|
|
|
|
BarItems.animated_texture_frame.change(v => v + 1);
|
2022-01-22 06:37:33 +08:00
|
|
|
}
|
2020-10-08 04:15:29 +08:00
|
|
|
}
|
|
|
|
})
|
2020-09-09 00:40:22 +08:00
|
|
|
|
|
|
|
new Action('bring_up_all_animations', {
|
|
|
|
icon: 'fa-sort-amount-up',
|
|
|
|
category: 'animation',
|
|
|
|
condition: {modes: ['animate']},
|
|
|
|
click: function () {
|
2020-09-15 20:21:04 +08:00
|
|
|
if (!Animation.selected) return;
|
|
|
|
for (var uuid in Animation.selected.animators) {
|
|
|
|
var ba = Animation.selected.animators[uuid]
|
2020-10-05 05:44:06 +08:00
|
|
|
if (ba && ba.keyframes.length) {
|
|
|
|
ba.addToTimeline();
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
new Action('fold_all_animations', {
|
|
|
|
icon: 'format_indent_decrease',
|
|
|
|
category: 'animation',
|
|
|
|
condition: {modes: ['animate']},
|
|
|
|
click: function () {
|
|
|
|
for (var animator of Timeline.animators) {
|
2020-10-05 05:44:06 +08:00
|
|
|
animator.expanded = false;
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
new Action('clear_timeline', {
|
|
|
|
icon: 'clear_all',
|
|
|
|
category: 'animation',
|
|
|
|
condition: {modes: ['animate']},
|
|
|
|
click: function () {
|
|
|
|
Timeline.vue._data.animators.purge();
|
|
|
|
unselectAll();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
new Action('select_effect_animator', {
|
|
|
|
icon: 'fa-magic',
|
|
|
|
category: 'animation',
|
|
|
|
condition: {modes: ['animate']},
|
|
|
|
click: function () {
|
2020-09-15 20:21:04 +08:00
|
|
|
if (!Animation.selected) return;
|
|
|
|
if (!Animation.selected.animators.effects) {
|
|
|
|
var ea = Animation.selected.animators.effects = new EffectAnimator(Animation.selected);
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
2020-09-15 20:21:04 +08:00
|
|
|
Animation.selected.animators.effects.select()
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
|
|
|
})
|
2020-09-28 18:55:45 +08:00
|
|
|
new Action('timeline_focus', {
|
|
|
|
icon: 'fas.fa-filter',
|
|
|
|
category: 'animation',
|
|
|
|
condition: {modes: ['animate']},
|
|
|
|
click: function (e) {
|
|
|
|
new Menu(this.children()).open(e.target)
|
2020-09-09 00:40:22 +08:00
|
|
|
},
|
2020-09-28 18:55:45 +08:00
|
|
|
children: function() {
|
|
|
|
let on = 'fas.fa-check-square';
|
|
|
|
let off = 'far.fa-square';
|
|
|
|
let {channels} = Timeline.vue._data;
|
|
|
|
return [
|
|
|
|
{name: 'timeline.rotation', icon: channels.rotation ? on : off, click() {channels.rotation = !channels.rotation}},
|
|
|
|
{name: 'timeline.position', icon: channels.position ? on : off, click() {channels.position = !channels.position}},
|
|
|
|
{name: 'timeline.scale', icon: channels.scale ? on : off, click() {channels.scale = !channels.scale}},
|
2020-09-28 23:26:39 +08:00
|
|
|
'_',
|
2020-09-28 18:55:45 +08:00
|
|
|
{name: 'action.timeline_focus.hide_empty', icon: channels.hide_empty ? on : off, click() {channels.hide_empty = !channels.hide_empty}},
|
|
|
|
]
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
new Action('add_marker', {
|
|
|
|
icon: 'flag',
|
|
|
|
category: 'animation',
|
|
|
|
condition: {modes: ['animate']},
|
2021-02-20 18:58:53 +08:00
|
|
|
keybind: new Keybind({ctrl: true, key: 'm'}),
|
2020-09-09 00:40:22 +08:00
|
|
|
click: function (event) {
|
2020-09-15 20:21:04 +08:00
|
|
|
if (!Animation.selected) {
|
2020-09-09 00:40:22 +08:00
|
|
|
Blockbench.showQuickMessage('message.no_animation_selected')
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var time = Timeline.snapTime();
|
|
|
|
var original_marker;
|
2020-09-15 20:21:04 +08:00
|
|
|
for (var m of Animation.selected.markers) {
|
2020-09-09 00:40:22 +08:00
|
|
|
if (Math.abs(m.time - time) < 0.01) {
|
|
|
|
original_marker = m;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (original_marker) {
|
2020-09-15 20:21:04 +08:00
|
|
|
Animation.selected.markers.remove(original_marker);
|
2020-09-09 00:40:22 +08:00
|
|
|
} else {
|
|
|
|
let marker = new TimelineMarker({time});
|
2020-09-15 20:21:04 +08:00
|
|
|
Animation.selected.markers.push(marker);
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2022-02-01 03:06:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new Action('timeline_setups', {
|
|
|
|
icon: 'folder_special',
|
2022-02-01 05:39:46 +08:00
|
|
|
condition: {modes: ['animate'], project: true, method: () => Project.timeline_setups.length},
|
2022-02-01 03:06:47 +08:00
|
|
|
children() {
|
|
|
|
return Project.timeline_setups.map(setup => {
|
|
|
|
return {
|
|
|
|
name: setup.name,
|
|
|
|
icon: 'star_outline',
|
2022-02-01 05:39:46 +08:00
|
|
|
click() {
|
|
|
|
Timeline.vue._data.animators.purge();
|
|
|
|
unselectAll();
|
|
|
|
setup.animators.forEach(uuid => {
|
|
|
|
var ba = Animation.selected.animators[uuid]
|
|
|
|
if (ba) ba.addToTimeline();
|
|
|
|
})
|
|
|
|
Timeline.vue.channels.position = !!setup.channels.position;
|
|
|
|
Timeline.vue.channels.rotation = !!setup.channels.rotation;
|
|
|
|
Timeline.vue.channels.scale = !!setup.channels.scale;
|
|
|
|
Timeline.vue.channels.hide_empty = !!setup.channels.hide_empty;
|
|
|
|
},
|
2022-02-01 03:06:47 +08:00
|
|
|
children: [
|
|
|
|
{icon: 'delete', name: 'generic.delete', click() {
|
|
|
|
Project.timeline_setups.remove(setup);
|
|
|
|
}}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
click(e) {
|
|
|
|
new Menu(this.children()).open(e.target);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
new Action('save_timeline_setup', {
|
|
|
|
icon: 'star',
|
2022-02-01 05:39:46 +08:00
|
|
|
condition: {modes: ['animate']},
|
2022-02-01 03:06:47 +08:00
|
|
|
async click() {
|
|
|
|
let name = await Blockbench.textPrompt('generic.name', 'Timeline Setup');
|
|
|
|
let setup = {
|
|
|
|
name: name || 'Setup',
|
|
|
|
channels: {
|
|
|
|
position: Timeline.vue.channels.position,
|
|
|
|
rotation: Timeline.vue.channels.rotation,
|
|
|
|
scale: Timeline.vue.channels.scale,
|
|
|
|
hide_empty: Timeline.vue.channels.hide_empty
|
|
|
|
},
|
|
|
|
animators: Timeline.animators.map(animator => animator.uuid),
|
|
|
|
};
|
|
|
|
Project.timeline_setups.push(setup);
|
2022-02-01 05:39:46 +08:00
|
|
|
BARS.updateConditions();
|
2022-02-01 03:06:47 +08:00
|
|
|
}
|
|
|
|
})
|
2021-02-15 06:20:46 +08:00
|
|
|
})
|