2018-10-24 03:49:04 +08:00
|
|
|
class Animation {
|
|
|
|
constructor(data) {
|
|
|
|
this.name = '';
|
|
|
|
this.uuid = guid()
|
2020-07-16 15:32:59 +08:00
|
|
|
this.loop = 'once';
|
2019-07-18 00:02:07 +08:00
|
|
|
this.playing = false;
|
2018-10-24 03:49:04 +08:00
|
|
|
this.override = false;
|
|
|
|
this.selected = false;
|
2018-11-12 04:19:08 +08:00
|
|
|
this.anim_time_update = '';
|
2019-08-18 00:26:14 +08:00
|
|
|
this.length = 0;
|
|
|
|
this.animators = {};
|
2020-01-24 01:53:36 +08:00
|
|
|
this.markers = [];
|
2018-10-24 03:49:04 +08:00
|
|
|
if (typeof data === 'object') {
|
|
|
|
this.extend(data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
extend(data) {
|
|
|
|
Merge.string(this, data, 'name')
|
2020-07-16 15:32:59 +08:00
|
|
|
Merge.string(this, data, 'loop', val => ['once', 'loop', 'hold'].includes(val))
|
2018-10-24 03:49:04 +08:00
|
|
|
Merge.boolean(this, data, 'override')
|
2018-11-12 04:19:08 +08:00
|
|
|
Merge.string(this, data, 'anim_time_update')
|
|
|
|
Merge.number(this, data, 'length')
|
2020-04-26 02:25:07 +08:00
|
|
|
if (typeof data.length == 'number') {
|
|
|
|
this.setLength(this.length)
|
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
if (data.bones && !data.animators) {
|
|
|
|
data.animators = data.bones;
|
|
|
|
}
|
2020-01-24 01:53:36 +08:00
|
|
|
if (data.animators instanceof Object) {
|
2019-08-18 00:26:14 +08:00
|
|
|
for (var key in data.animators) {
|
2019-08-01 06:01:47 +08:00
|
|
|
var group = Group.all.findInArray( isUUID(key) ? 'uuid' : 'name', key )
|
2019-03-10 05:06:35 +08:00
|
|
|
if (group) {
|
|
|
|
var ba = this.getBoneAnimator(group)
|
2019-08-18 00:26:14 +08:00
|
|
|
var kfs = data.animators[key]
|
2019-03-10 05:06:35 +08:00
|
|
|
if (kfs && ba) {
|
2020-04-26 02:25:07 +08:00
|
|
|
ba.rotation.empty();
|
|
|
|
ba.position.empty();
|
|
|
|
ba.scale.empty();
|
2019-03-10 05:06:35 +08:00
|
|
|
kfs.forEach(kf_data => {
|
2019-09-04 15:37:38 +08:00
|
|
|
ba.addKeyframe(kf_data, kf_data.uuid);
|
2019-03-10 05:06:35 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-24 01:53:36 +08:00
|
|
|
if (data.markers instanceof Array) {
|
|
|
|
data.markers.forEach(marker => {
|
|
|
|
this.markers.push(new TimelineMarker(marker));
|
|
|
|
})
|
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
return this;
|
|
|
|
}
|
2019-09-04 15:37:38 +08:00
|
|
|
getUndoCopy(options, save) {
|
2018-12-03 02:37:06 +08:00
|
|
|
var scope = this;
|
|
|
|
var copy = {
|
|
|
|
uuid: this.uuid,
|
|
|
|
name: this.name,
|
|
|
|
loop: this.loop,
|
|
|
|
override: this.override,
|
|
|
|
anim_time_update: this.anim_time_update,
|
|
|
|
length: this.length,
|
|
|
|
selected: this.selected,
|
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
if (Object.keys(this.animators).length) {
|
|
|
|
copy.animators = {}
|
|
|
|
for (var uuid in this.animators) {
|
|
|
|
var kfs = this.animators[uuid].keyframes
|
2018-12-03 02:37:06 +08:00
|
|
|
if (kfs && kfs.length) {
|
2019-08-18 00:26:14 +08:00
|
|
|
if (options && options.bone_names && this.animators[uuid] instanceof BoneAnimator) {
|
|
|
|
var group = this.animators[uuid].getGroup();
|
2019-09-04 15:37:38 +08:00
|
|
|
uuid = group ? group.name : '';
|
2019-03-10 05:06:35 +08:00
|
|
|
}
|
2019-09-04 15:37:38 +08:00
|
|
|
copy.animators[uuid] = [];
|
2018-12-03 02:37:06 +08:00
|
|
|
kfs.forEach(kf => {
|
2019-09-04 15:37:38 +08:00
|
|
|
copy.animators[uuid].push(kf.getUndoCopy(save));
|
2018-12-03 02:37:06 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return copy;
|
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
select() {
|
2018-11-12 04:19:08 +08:00
|
|
|
var scope = this;
|
2019-12-16 03:04:31 +08:00
|
|
|
Prop.active_panel = 'animations';
|
|
|
|
if (this == Animator.selected) return;
|
|
|
|
var selected_bone = Group.selected;
|
2018-10-24 03:49:04 +08:00
|
|
|
Animator.animations.forEach(function(a) {
|
2019-07-18 00:02:07 +08:00
|
|
|
a.selected = a.playing = false;
|
2018-10-24 03:49:04 +08:00
|
|
|
})
|
2019-12-16 03:04:31 +08:00
|
|
|
Timeline.animators.purge();
|
|
|
|
Timeline.selected.empty();
|
2020-01-24 01:53:36 +08:00
|
|
|
Timeline.vue._data.markers = this.markers;
|
2020-04-26 02:25:07 +08:00
|
|
|
Timeline.vue._data.animation_length = this.length;
|
2019-07-18 00:02:07 +08:00
|
|
|
this.selected = true;
|
|
|
|
this.playing = true;
|
2019-12-16 03:04:31 +08:00
|
|
|
Animator.selected = this;
|
|
|
|
unselectAll();
|
|
|
|
BarItems.slider_animation_length.update();
|
2018-11-12 04:19:08 +08:00
|
|
|
|
2019-07-18 00:02:07 +08:00
|
|
|
Group.all.forEach(group => {
|
2019-12-16 03:04:31 +08:00
|
|
|
scope.getBoneAnimator(group);
|
2019-07-18 00:02:07 +08:00
|
|
|
})
|
2018-12-03 02:37:06 +08:00
|
|
|
|
|
|
|
if (selected_bone) {
|
2019-12-16 03:04:31 +08:00
|
|
|
selected_bone.select();
|
2018-12-03 02:37:06 +08:00
|
|
|
}
|
2019-12-16 03:04:31 +08:00
|
|
|
Animator.preview();
|
2018-11-12 04:19:08 +08:00
|
|
|
return this;
|
|
|
|
}
|
2020-04-26 02:25:07 +08:00
|
|
|
setLength(len) {
|
|
|
|
len = limitNumber(len, 0, 1e4)
|
|
|
|
this.length = len;
|
|
|
|
if (Animator.selected == this) {
|
|
|
|
Timeline.vue._data.animation_length = this.length;
|
|
|
|
BarItems.slider_animation_length.update()
|
|
|
|
}
|
|
|
|
}
|
2019-08-01 06:01:47 +08:00
|
|
|
createUniqueName(arr) {
|
|
|
|
var scope = this;
|
|
|
|
var others = Animator.animations;
|
|
|
|
if (arr && arr.length) {
|
|
|
|
arr.forEach(g => {
|
|
|
|
others.safePush(g)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
var name = this.name.replace(/\d+$/, '');
|
|
|
|
function check(n) {
|
|
|
|
for (var i = 0; i < others.length; i++) {
|
|
|
|
if (others[i] !== scope && others[i].name == n) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (check(this.name)) {
|
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
for (var num = 2; num < 8e3; num++) {
|
|
|
|
if (check(name+num)) {
|
|
|
|
scope.name = name+num;
|
|
|
|
return scope.name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-11-12 04:19:08 +08:00
|
|
|
rename() {
|
|
|
|
var scope = this;
|
2019-12-16 03:04:31 +08:00
|
|
|
Blockbench.textPrompt('generic.rename', this.name, function(name) {
|
2019-04-08 00:53:33 +08:00
|
|
|
if (name && name !== scope.name) {
|
2019-08-01 06:01:47 +08:00
|
|
|
Undo.initEdit({animations: [scope]});
|
|
|
|
scope.name = name;
|
|
|
|
scope.createUniqueName();
|
|
|
|
Undo.finishEdit('rename animation');
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
editUpdateVariable() {
|
|
|
|
var scope = this;
|
2019-07-18 00:02:07 +08:00
|
|
|
Blockbench.textPrompt('message.animation_update_var', scope.anim_time_update, function(name) {
|
2019-09-04 15:37:38 +08:00
|
|
|
if (name !== scope.anim_time_update) {
|
2019-07-18 00:02:07 +08:00
|
|
|
Undo.initEdit({animations: [scope]})
|
2018-11-12 04:19:08 +08:00
|
|
|
scope.anim_time_update = name
|
2019-04-08 00:53:33 +08:00
|
|
|
Undo.finishEdit('change animation variable')
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
|
|
|
})
|
2018-10-24 03:49:04 +08:00
|
|
|
return this;
|
|
|
|
}
|
2019-07-18 00:02:07 +08:00
|
|
|
togglePlayingState(state) {
|
|
|
|
if (!this.selected) {
|
|
|
|
this.playing = state !== undefined ? state : !this.playing;
|
|
|
|
Animator.preview();
|
|
|
|
} else {
|
|
|
|
Timeline.start();
|
|
|
|
}
|
|
|
|
return this.playing;
|
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
showContextMenu(event) {
|
|
|
|
this.select();
|
|
|
|
this.menu.open(event, this);
|
|
|
|
return this;
|
|
|
|
}
|
2018-11-12 04:19:08 +08:00
|
|
|
getBoneAnimator(group) {
|
2019-07-18 00:02:07 +08:00
|
|
|
if (!group && Group.selected) {
|
|
|
|
group = Group.selected
|
2018-11-12 04:19:08 +08:00
|
|
|
} else if (!group) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var uuid = group.uuid
|
2019-08-18 00:26:14 +08:00
|
|
|
if (!this.animators[uuid]) {
|
|
|
|
this.animators[uuid] = new BoneAnimator(uuid, this);
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
return this.animators[uuid];
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
2019-04-08 00:53:33 +08:00
|
|
|
add(undo) {
|
|
|
|
if (undo) {
|
|
|
|
Undo.initEdit({animations: []})
|
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
if (!Animator.animations.includes(this)) {
|
|
|
|
Animator.animations.push(this)
|
|
|
|
}
|
2019-04-08 00:53:33 +08:00
|
|
|
if (undo) {
|
|
|
|
this.select()
|
|
|
|
Undo.finishEdit('add animation', {animations: [this]})
|
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
return this;
|
|
|
|
}
|
2019-04-08 00:53:33 +08:00
|
|
|
remove(undo) {
|
|
|
|
if (undo) {
|
|
|
|
Undo.initEdit({animations: [this]})
|
|
|
|
}
|
2018-11-12 04:19:08 +08:00
|
|
|
if (Animator.selected === this) {
|
|
|
|
Animator.selected = false
|
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
Animator.animations.remove(this)
|
2019-04-08 00:53:33 +08:00
|
|
|
if (undo) {
|
|
|
|
Undo.finishEdit('remove animation', {animation: null})
|
|
|
|
}
|
|
|
|
Blockbench.dispatchEvent('remove_animation', {animations: [this]})
|
2018-10-24 03:49:04 +08:00
|
|
|
return this;
|
|
|
|
}
|
2018-11-12 04:19:08 +08:00
|
|
|
getMaxLength() {
|
|
|
|
var len = this.length||0
|
|
|
|
|
2019-08-18 00:26:14 +08:00
|
|
|
for (var uuid in this.animators) {
|
|
|
|
var bone = this.animators[uuid]
|
|
|
|
var keyframes = bone.keyframes;
|
2018-11-12 04:19:08 +08:00
|
|
|
var i = 0;
|
2019-08-18 00:26:14 +08:00
|
|
|
while (i < keyframes.length) {
|
|
|
|
len = Math.max(len, keyframes[i].time)
|
2018-11-12 04:19:08 +08:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2020-04-26 02:25:07 +08:00
|
|
|
this.setLength(len)
|
2018-11-12 04:19:08 +08:00
|
|
|
if (this == Animator.selected) {
|
|
|
|
BarItems.slider_animation_length.update()
|
|
|
|
}
|
|
|
|
return len
|
|
|
|
}
|
2020-07-16 15:32:59 +08:00
|
|
|
setLoop(value, undo) {
|
|
|
|
if ((value == 'once' || value == 'loop' || value == 'hold') && value !== this.loop) {
|
|
|
|
if (undo) Undo.initEdit({animations: [this]})
|
|
|
|
this.loop = value;
|
|
|
|
if (undo) Undo.finishEdit('change animation loop mode')
|
|
|
|
}
|
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
|
|
|
Animation.prototype.menu = new Menu([
|
2020-07-16 15:32:59 +08:00
|
|
|
{name: 'menu.animation.loop', icon: 'loop', children: [
|
|
|
|
{name: 'menu.animation.loop.once', icon: animation => (animation.loop == 'once' ? 'radio_button_checked' : 'radio_button_unchecked'), click(animation) {animation.setLoop('once', true)}},
|
|
|
|
{name: 'menu.animation.loop.hold', icon: animation => (animation.loop == 'hold' ? 'radio_button_checked' : 'radio_button_unchecked'), click(animation) {animation.setLoop('hold', true)}},
|
|
|
|
{name: 'menu.animation.loop.loop', icon: animation => (animation.loop == 'loop' ? 'radio_button_checked' : 'radio_button_unchecked'), click(animation) {animation.setLoop('loop', true)}},
|
|
|
|
]},
|
2018-11-12 04:19:08 +08:00
|
|
|
{name: 'menu.animation.override', icon: (a) => (a.override?'check_box':'check_box_outline_blank'), click: function(animation) {
|
|
|
|
animation.override = !animation.override
|
|
|
|
}},
|
|
|
|
{name: 'menu.animation.anim_time_update', icon: 'update', click: function(animation) {
|
|
|
|
animation.editUpdateVariable()
|
|
|
|
}},
|
2019-08-01 06:01:47 +08:00
|
|
|
'_',
|
|
|
|
'duplicate',
|
|
|
|
'rename',
|
|
|
|
'delete',
|
2018-10-24 03:49:04 +08:00
|
|
|
])
|
2020-01-24 01:53:36 +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');
|
|
|
|
}
|
|
|
|
callPlayhead() {
|
|
|
|
Timeline.setTime(this.time)
|
|
|
|
Animator.preview()
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
showContextMenu(event) {
|
|
|
|
this.menu.open(event, this);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TimelineMarker.prototype.menu = new Menu([
|
|
|
|
{icon: 'flag', color: markerColors[0].standard, name: 'cube.color.'+markerColors[0].name, click: function(marker) {marker.color = 0;}},
|
|
|
|
{icon: 'flag', color: markerColors[1].standard, name: 'cube.color.'+markerColors[1].name, click: function(marker) {marker.color = 1;}},
|
|
|
|
{icon: 'flag', color: markerColors[2].standard, name: 'cube.color.'+markerColors[2].name, click: function(marker) {marker.color = 2;}},
|
|
|
|
{icon: 'flag', color: markerColors[3].standard, name: 'cube.color.'+markerColors[3].name, click: function(marker) {marker.color = 3;}},
|
|
|
|
{icon: 'flag', color: markerColors[4].standard, name: 'cube.color.'+markerColors[4].name, click: function(marker) {marker.color = 4;}},
|
|
|
|
{icon: 'flag', color: markerColors[5].standard, name: 'cube.color.'+markerColors[5].name, click: function(marker) {marker.color = 5;}},
|
|
|
|
{icon: 'flag', color: markerColors[6].standard, name: 'cube.color.'+markerColors[6].name, click: function(marker) {marker.color = 6;}},
|
|
|
|
{icon: 'flag', color: markerColors[7].standard, name: 'cube.color.'+markerColors[7].name, click: function(marker) {marker.color = 7;}},
|
|
|
|
{icon: 'delete', name: 'generic.delete', click: function(marker) {
|
|
|
|
if (Animator.selected) Animator.selected.markers.remove(marker);
|
|
|
|
}}
|
|
|
|
])
|
2019-08-18 00:26:14 +08:00
|
|
|
class GeneralAnimator {
|
2019-07-22 05:17:36 +08:00
|
|
|
constructor(uuid, animation) {
|
|
|
|
this.animation = animation;
|
2019-08-18 00:26:14 +08:00
|
|
|
this.expanded = false;
|
|
|
|
this.selected = false;
|
|
|
|
this.uuid = uuid || guid();
|
2020-03-05 03:56:17 +08:00
|
|
|
this.muted = {};
|
|
|
|
this.channels.forEach(channel => {
|
|
|
|
this.muted[channel] = false;
|
|
|
|
})
|
2019-08-18 00:26:14 +08:00
|
|
|
}
|
|
|
|
select() {
|
|
|
|
var scope = this;
|
|
|
|
TickUpdates.keyframes = true;
|
|
|
|
for (var key in Animator.selected.animators) {
|
|
|
|
Animator.selected.animators[key].selected = false;
|
|
|
|
}
|
|
|
|
this.selected = true;
|
|
|
|
Timeline.selected_animator = this;
|
2019-12-16 03:04:31 +08:00
|
|
|
this.addToTimeline();
|
2019-08-18 00:26:14 +08:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
scope.scrollTo();
|
|
|
|
})
|
2019-12-16 03:04:31 +08:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
addToTimeline() {
|
|
|
|
if (!Timeline.animators.includes(this)) {
|
|
|
|
Timeline.animators.splice(0, 0, this);
|
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
if (!this.expanded) this.expanded = true;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
addKeyframe(data, uuid) {
|
|
|
|
var channel = data.channel;
|
2019-09-04 15:37:38 +08:00
|
|
|
if (typeof channel == 'number') channel = this.channels[channel];
|
2019-08-18 00:26:14 +08:00
|
|
|
if (channel && this[channel]) {
|
|
|
|
var kf = new Keyframe(data, uuid);
|
|
|
|
this[channel].push(kf);
|
|
|
|
kf.animator = this;
|
|
|
|
return kf;
|
|
|
|
}
|
|
|
|
}
|
2019-12-16 03:04:31 +08:00
|
|
|
createKeyframe(value, time, channel, undo, select) {
|
2019-08-18 00:26:14 +08:00
|
|
|
if (!this[channel]) return;
|
|
|
|
var keyframes = [];
|
|
|
|
if (undo) {
|
|
|
|
Undo.initEdit({keyframes})
|
|
|
|
}
|
|
|
|
var keyframe = new Keyframe({
|
|
|
|
channel: channel,
|
|
|
|
time: time
|
|
|
|
});
|
|
|
|
keyframes.push(keyframe);
|
|
|
|
|
2019-12-16 03:04:31 +08:00
|
|
|
if (value) {
|
2019-08-18 00:26:14 +08:00
|
|
|
keyframe.extend(value);
|
2019-12-16 03:04:31 +08:00
|
|
|
} else if (this.fillValues) {
|
2020-04-26 02:25:07 +08:00
|
|
|
this.fillValues(keyframe, value, true);
|
2019-08-18 00:26:14 +08:00
|
|
|
}
|
|
|
|
keyframe.channel = channel;
|
|
|
|
keyframe.time = time;
|
|
|
|
|
|
|
|
this[channel].push(keyframe);
|
|
|
|
keyframe.animator = this;
|
2019-12-16 03:04:31 +08:00
|
|
|
|
|
|
|
if (select !== false) {
|
|
|
|
keyframe.select();
|
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
TickUpdates.keyframes = true;
|
|
|
|
|
|
|
|
var deleted = [];
|
|
|
|
delete keyframe.time_before;
|
|
|
|
keyframe.replaceOthers(deleted);
|
|
|
|
Undo.addKeyframeCasualties(deleted);
|
|
|
|
|
|
|
|
if (undo) {
|
|
|
|
Undo.finishEdit('added keyframe')
|
|
|
|
}
|
|
|
|
return keyframe;
|
|
|
|
}
|
2019-12-16 03:04:31 +08:00
|
|
|
getOrMakeKeyframe(channel) {
|
|
|
|
var before, result;
|
|
|
|
|
|
|
|
for (var kf of this[channel]) {
|
|
|
|
if (Math.abs(kf.time - Timeline.time) < 0.02) {
|
|
|
|
before = kf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = before ? before : this.createKeyframe(null, Timeline.time, channel, false, false);
|
|
|
|
return {before, result};
|
|
|
|
}
|
2020-03-05 03:56:17 +08:00
|
|
|
toggleMuted(channel) {
|
|
|
|
this.muted[channel] = !this.muted[channel];
|
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
scrollTo() {
|
|
|
|
var el = $(`#timeline_body_inner > li[uuid=${this.uuid}]`).get(0)
|
|
|
|
if (el) {
|
|
|
|
var offset = el.offsetTop;
|
|
|
|
var timeline = $('#timeline_body').scrollTop();
|
|
|
|
var height = $('#timeline_body').height();
|
|
|
|
if (offset < timeline) {
|
|
|
|
$('#timeline_body').animate({
|
|
|
|
scrollTop: offset
|
|
|
|
}, 200);
|
|
|
|
}
|
|
|
|
if (offset + el.clientHeight > timeline + height) {
|
|
|
|
$('#timeline_body').animate({
|
|
|
|
scrollTop: offset - (height-el.clientHeight-20)
|
|
|
|
}, 200);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class BoneAnimator extends GeneralAnimator {
|
|
|
|
constructor(uuid, animation) {
|
|
|
|
super(uuid, animation);
|
|
|
|
this.uuid = uuid;
|
|
|
|
|
|
|
|
this.rotation = [];
|
|
|
|
this.position = [];
|
|
|
|
this.scale = [];
|
|
|
|
}
|
|
|
|
get name() {
|
|
|
|
var group = this.getGroup();
|
|
|
|
if (group) return group.name;
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
get keyframes() {
|
|
|
|
return [...this.rotation, ...this.position, ...this.scale];
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
|
|
|
getGroup() {
|
2019-08-01 06:01:47 +08:00
|
|
|
this.group = Group.all.findInArray('uuid', this.uuid)
|
2018-10-24 03:49:04 +08:00
|
|
|
if (!this.group) {
|
2018-11-12 04:19:08 +08:00
|
|
|
console.log('no group found for '+this.uuid)
|
2019-08-18 00:26:14 +08:00
|
|
|
if (this.animation && this.animation.animators[this.uuid] && this.animation.animators[this.uuid].type == 'bone') {
|
2019-07-22 05:17:36 +08:00
|
|
|
delete this.animation.bones[this.uuid];
|
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
|
|
|
return this.group
|
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
select(group_is_selected) {
|
2020-04-30 05:35:47 +08:00
|
|
|
if (this.getGroup().locked) return this;
|
|
|
|
|
2019-07-18 00:02:07 +08:00
|
|
|
var duplicates;
|
2019-08-18 00:26:14 +08:00
|
|
|
for (var key in this.animation.animators) {
|
|
|
|
this.animation.animators[key].selected = false;
|
|
|
|
}
|
|
|
|
if (group_is_selected !== true) {
|
|
|
|
this.group.select();
|
|
|
|
}
|
2019-07-18 00:02:07 +08:00
|
|
|
function iterate(arr) {
|
|
|
|
arr.forEach((it) => {
|
|
|
|
if (it.type === 'group' && !duplicates) {
|
|
|
|
if (it.name === Group.selected.name && it !== Group.selected) {
|
2019-12-16 03:04:31 +08:00
|
|
|
duplicates = true;
|
2019-07-18 00:02:07 +08:00
|
|
|
} else if (it.children && it.children.length) {
|
2019-12-16 03:04:31 +08:00
|
|
|
iterate(it.children);
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2019-12-16 03:04:31 +08:00
|
|
|
iterate(Outliner.root);
|
2019-07-18 00:02:07 +08:00
|
|
|
if (duplicates) {
|
|
|
|
Blockbench.showMessageBox({
|
|
|
|
translateKey: 'duplicate_groups',
|
|
|
|
icon: 'folder',
|
|
|
|
buttons: ['dialog.ok'],
|
2019-12-16 03:04:31 +08:00
|
|
|
});
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
super.select();
|
2019-07-18 00:02:07 +08:00
|
|
|
|
2019-08-18 00:26:14 +08:00
|
|
|
if (this[Toolbox.selected.animation_channel] && (Timeline.selected.length == 0 || Timeline.selected[0].animator != this)) {
|
|
|
|
var nearest;
|
|
|
|
this[Toolbox.selected.animation_channel].forEach(kf => {
|
|
|
|
if (Math.abs(kf.time - Timeline.time) < 0.002) {
|
|
|
|
nearest = kf;
|
|
|
|
}
|
2019-07-18 00:02:07 +08:00
|
|
|
})
|
2019-08-18 00:26:14 +08:00
|
|
|
if (nearest) {
|
|
|
|
nearest.select();
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
|
2019-07-18 00:02:07 +08:00
|
|
|
if (this.group && this.group.parent && this.group.parent !== 'root') {
|
2019-12-16 03:04:31 +08:00
|
|
|
this.group.parent.openUp();
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
2020-04-26 02:25:07 +08:00
|
|
|
fillValues(keyframe, values, allow_expression) {
|
2019-08-18 00:26:14 +08:00
|
|
|
|
|
|
|
if (values instanceof Array) {
|
2018-11-12 04:19:08 +08:00
|
|
|
keyframe.extend({
|
|
|
|
x: values[0],
|
|
|
|
y: values[1],
|
|
|
|
z: values[2]
|
|
|
|
})
|
2018-12-27 21:03:04 +08:00
|
|
|
if (values[3]) {
|
|
|
|
keyframe.extend({w: values[3], isQuaternion: true})
|
|
|
|
}
|
2018-11-12 04:19:08 +08:00
|
|
|
} else if (typeof values === 'number' || typeof values === 'string') {
|
|
|
|
keyframe.extend({
|
2019-07-18 00:02:07 +08:00
|
|
|
x: values,
|
|
|
|
y: values,
|
|
|
|
z: values
|
2018-11-12 04:19:08 +08:00
|
|
|
})
|
2019-08-18 00:26:14 +08:00
|
|
|
} else if (values == null) {
|
2020-04-26 02:25:07 +08:00
|
|
|
var ref = this.interpolate(keyframe.channel, allow_expression)
|
2018-11-12 04:19:08 +08:00
|
|
|
if (ref) {
|
|
|
|
let e = 1e2
|
2018-12-27 21:03:04 +08:00
|
|
|
ref.forEach((r, i) => {
|
|
|
|
if (!isNaN(r)) {
|
|
|
|
ref[i] = Math.round(parseFloat(r)*e)/e
|
|
|
|
}
|
|
|
|
})
|
2018-11-12 04:19:08 +08:00
|
|
|
keyframe.extend({
|
2018-12-27 21:03:04 +08:00
|
|
|
x: ref[0],
|
|
|
|
y: ref[1],
|
|
|
|
z: ref[2],
|
|
|
|
w: ref.length === 4 ? ref[3] : undefined,
|
2018-11-12 04:19:08 +08:00
|
|
|
isQuaternion: ref.length === 4
|
|
|
|
})
|
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
} else {
|
|
|
|
keyframe.extend(values)
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
2018-11-12 04:19:08 +08:00
|
|
|
pushKeyframe(keyframe) {
|
2019-08-18 00:26:14 +08:00
|
|
|
this[keyframe.channel].push(keyframe)
|
|
|
|
keyframe.animator = this;
|
2018-11-12 04:19:08 +08:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
doRender() {
|
2018-10-24 03:49:04 +08:00
|
|
|
this.getGroup()
|
2019-01-09 22:54:35 +08:00
|
|
|
if (this.group && this.group.children && this.group.mesh) {
|
|
|
|
let mesh = this.group.mesh
|
2018-11-12 04:19:08 +08:00
|
|
|
return (mesh && mesh.fix_rotation)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
displayRotation(arr) {
|
2019-01-09 22:54:35 +08:00
|
|
|
var bone = this.group.mesh
|
2018-10-24 03:49:04 +08:00
|
|
|
|
2018-11-12 04:19:08 +08:00
|
|
|
if (!arr) {
|
|
|
|
} else if (arr.length === 4) {
|
2018-12-03 02:37:06 +08:00
|
|
|
var added_rotation = new THREE.Euler().setFromQuaternion(new THREE.Quaternion().fromArray(arr), 'ZYX')
|
2018-11-12 04:19:08 +08:00
|
|
|
bone.rotation.x -= added_rotation.x
|
|
|
|
bone.rotation.y -= added_rotation.y
|
2018-10-24 03:49:04 +08:00
|
|
|
bone.rotation.z += added_rotation.z
|
|
|
|
} else {
|
|
|
|
arr.forEach((n, i) => {
|
2020-02-08 02:06:24 +08:00
|
|
|
bone.rotation[getAxisLetter(i)] += Math.degToRad(n) * (i == 2 ? 1 : -1)
|
2018-10-24 03:49:04 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
displayPosition(arr) {
|
2019-01-09 22:54:35 +08:00
|
|
|
var bone = this.group.mesh
|
2018-11-12 04:19:08 +08:00
|
|
|
if (arr) {
|
2020-05-31 21:54:04 +08:00
|
|
|
bone.position.x += -arr[0];
|
|
|
|
bone.position.y += arr[1];
|
|
|
|
bone.position.z += arr[2];
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
displayScale(arr) {
|
2019-07-18 00:02:07 +08:00
|
|
|
if (!arr) return this;
|
|
|
|
var bone = this.group.mesh;
|
|
|
|
bone.scale.x *= arr[0] || 0.00001;
|
|
|
|
bone.scale.y *= arr[1] || 0.00001;
|
|
|
|
bone.scale.z *= arr[2] || 0.00001;
|
2018-10-24 03:49:04 +08:00
|
|
|
return this;
|
|
|
|
}
|
2020-04-26 02:25:07 +08:00
|
|
|
interpolate(channel, allow_expression) {
|
|
|
|
let time = Timeline.time;
|
2018-11-12 04:19:08 +08:00
|
|
|
var i = 0;
|
|
|
|
var before = false
|
|
|
|
var after = false
|
|
|
|
var result = false
|
2019-08-18 00:26:14 +08:00
|
|
|
for (var keyframe of this[channel]) {
|
2018-10-24 03:49:04 +08:00
|
|
|
|
2019-08-18 00:26:14 +08:00
|
|
|
if (keyframe.time < time) {
|
2018-11-12 04:19:08 +08:00
|
|
|
if (!before || keyframe.time > before.time) {
|
|
|
|
before = keyframe
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
2018-11-12 04:19:08 +08:00
|
|
|
} else {
|
|
|
|
if (!after || keyframe.time < after.time) {
|
|
|
|
after = keyframe
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
|
|
|
}
|
2018-11-12 04:19:08 +08:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (before && Math.abs(before.time - time) < 1/1200) {
|
|
|
|
result = before
|
|
|
|
} else if (after && Math.abs(after.time - time) < 1/1200) {
|
|
|
|
result = after
|
|
|
|
} else if (before && !after) {
|
|
|
|
result = before
|
|
|
|
} else if (after && !before) {
|
|
|
|
result = after
|
|
|
|
} else if (!before && !after) {
|
|
|
|
//
|
|
|
|
} else {
|
|
|
|
let alpha = Math.lerp(before.time, after.time, time)
|
2019-07-18 00:02:07 +08:00
|
|
|
if (Blockbench.hasFlag('no_interpolations')) {
|
|
|
|
alpha = Math.round(alpha)
|
|
|
|
}
|
2018-11-12 04:19:08 +08:00
|
|
|
result = [
|
2019-04-08 00:53:33 +08:00
|
|
|
before.getLerp(after, 'x', alpha, allow_expression),
|
|
|
|
before.getLerp(after, 'y', alpha, allow_expression),
|
|
|
|
before.getLerp(after, 'z', alpha, allow_expression)
|
2018-11-12 04:19:08 +08:00
|
|
|
]
|
2018-12-27 21:03:04 +08:00
|
|
|
if (before.isQuaternion && after.isQuaternion) {
|
|
|
|
result[3] = before.getLerp(after, 'q', alpha, allow_expression)
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result && result.type === 'keyframe') {
|
|
|
|
let keyframe = result
|
2018-12-27 21:03:04 +08:00
|
|
|
let method = allow_expression ? 'get' : 'calc'
|
2018-11-12 04:19:08 +08:00
|
|
|
result = [
|
2019-04-08 00:53:33 +08:00
|
|
|
keyframe[method]('x'),
|
|
|
|
keyframe[method]('y'),
|
|
|
|
keyframe[method]('z')
|
2018-11-12 04:19:08 +08:00
|
|
|
]
|
|
|
|
if (keyframe.isQuaternion) {
|
2018-12-27 21:03:04 +08:00
|
|
|
result[3] = keyframe[method]('w')
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
2020-04-26 02:25:07 +08:00
|
|
|
displayFrame() {
|
2018-11-12 04:19:08 +08:00
|
|
|
if (!this.doRender()) return;
|
|
|
|
this.getGroup()
|
2019-07-18 00:02:07 +08:00
|
|
|
|
2020-04-26 02:25:07 +08:00
|
|
|
if (!this.muted.rotation) this.displayRotation(this.interpolate('rotation'))
|
|
|
|
if (!this.muted.position) this.displayPosition(this.interpolate('position'))
|
|
|
|
if (!this.muted.scale) this.displayScale(this.interpolate('scale'))
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
BoneAnimator.prototype.channels = ['rotation', 'position', 'scale']
|
|
|
|
class EffectAnimator extends GeneralAnimator {
|
|
|
|
constructor(animation) {
|
|
|
|
super(null, animation);
|
|
|
|
|
|
|
|
this.name = tl('timeline.effects')
|
|
|
|
this.selected = false;
|
|
|
|
|
|
|
|
this.particle = [];
|
|
|
|
this.sound = [];
|
2019-12-16 03:04:31 +08:00
|
|
|
this.timeline = [];
|
2019-08-18 00:26:14 +08:00
|
|
|
}
|
|
|
|
get keyframes() {
|
2019-12-16 03:04:31 +08:00
|
|
|
return [...this.particle, ...this.sound, ...this.timeline];
|
2019-08-18 00:26:14 +08:00
|
|
|
}
|
|
|
|
pushKeyframe(keyframe) {
|
|
|
|
this[keyframe.channel].push(keyframe)
|
|
|
|
keyframe.animator = this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
displayFrame() {
|
2020-03-05 03:56:17 +08:00
|
|
|
if (!this.muted.sound) {
|
|
|
|
this.sound.forEach(kf => {
|
|
|
|
var diff = kf.time - Timeline.time;
|
|
|
|
if (diff >= 0 && diff < (1/60) * (Timeline.playback_speed/100)) {
|
|
|
|
if (kf.file && !kf.cooldown) {
|
|
|
|
var media = new Audio(kf.file);
|
2020-04-26 02:25:07 +08:00
|
|
|
window._media = media
|
2020-03-05 03:56:17 +08:00
|
|
|
media.volume = Math.clamp(settings.volume.value/100, 0, 1);
|
|
|
|
media.play();
|
|
|
|
Timeline.playing_sounds.push(media);
|
|
|
|
media.onended = function() {
|
|
|
|
Timeline.playing_sounds.remove(media);
|
|
|
|
}
|
|
|
|
|
|
|
|
kf.cooldown = true;
|
|
|
|
setTimeout(() => {
|
|
|
|
delete kf.cooldown;
|
|
|
|
}, 400)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
}
|
|
|
|
}
|
2019-12-16 03:04:31 +08:00
|
|
|
EffectAnimator.prototype.channels = ['particle', 'sound', 'timeline']
|
2018-10-24 03:49:04 +08:00
|
|
|
class Keyframe {
|
2019-08-01 06:01:47 +08:00
|
|
|
constructor(data, uuid) {
|
2018-11-12 04:19:08 +08:00
|
|
|
this.type = 'keyframe'
|
2019-08-18 00:26:14 +08:00
|
|
|
this.channel = 'rotation';
|
2018-10-24 03:49:04 +08:00
|
|
|
this.time = 0;
|
|
|
|
this.selected = 0;
|
2018-11-12 04:19:08 +08:00
|
|
|
this.x = '0';
|
|
|
|
this.y = '0';
|
|
|
|
this.z = '0';
|
|
|
|
this.w = '0';
|
2018-10-24 03:49:04 +08:00
|
|
|
this.isQuaternion = false;
|
2019-08-18 00:26:14 +08:00
|
|
|
this.effect = '';
|
|
|
|
this.file = '';
|
|
|
|
this.locator = '';
|
2020-01-24 01:53:36 +08:00
|
|
|
this.script = '';
|
2019-12-16 03:04:31 +08:00
|
|
|
this.instructions = '';
|
2019-08-01 06:01:47 +08:00
|
|
|
this.uuid = (uuid && isUUID(uuid)) ? uuid : guid();
|
2018-10-24 03:49:04 +08:00
|
|
|
if (typeof data === 'object') {
|
2019-08-18 00:26:14 +08:00
|
|
|
Merge.string(this, data, 'channel')
|
|
|
|
this.transform = this.channel === 'rotation' || this.channel === 'position' || this.channel === 'scale';
|
2018-10-24 03:49:04 +08:00
|
|
|
this.extend(data)
|
2019-04-08 00:53:33 +08:00
|
|
|
if (this.channel === 'scale' && data.x == undefined && data.y == undefined && data.z == undefined) {
|
|
|
|
this.x = this.y = this.z = 1;
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
extend(data) {
|
|
|
|
Merge.number(this, data, 'time')
|
|
|
|
|
|
|
|
if (this.transform) {
|
|
|
|
if (data.values != undefined) {
|
|
|
|
if (typeof data.values == 'number' || typeof data.values == 'string') {
|
|
|
|
data.x = data.y = data.z = data.values;
|
|
|
|
|
|
|
|
} else if (data.values instanceof Array) {
|
|
|
|
data.x = data.values[0];
|
|
|
|
data.y = data.values[1];
|
|
|
|
data.z = data.values[2];
|
|
|
|
data.w = data.values[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Merge.string(this, data, 'x')
|
|
|
|
Merge.string(this, data, 'y')
|
|
|
|
Merge.string(this, data, 'z')
|
|
|
|
Merge.string(this, data, 'w')
|
|
|
|
Merge.boolean(this, data, 'isQuaternion')
|
|
|
|
} else {
|
2019-09-04 15:37:38 +08:00
|
|
|
if (data.values) {
|
|
|
|
data.effect = data.values.effect;
|
|
|
|
data.locator = data.values.locator;
|
2020-01-24 01:53:36 +08:00
|
|
|
data.script = data.values.script;
|
2019-09-04 15:37:38 +08:00
|
|
|
data.file = data.values.file;
|
2019-12-16 03:04:31 +08:00
|
|
|
data.instructions = data.values.instructions;
|
2019-09-04 15:37:38 +08:00
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
Merge.string(this, data, 'effect')
|
|
|
|
Merge.string(this, data, 'locator')
|
2020-01-24 01:53:36 +08:00
|
|
|
Merge.string(this, data, 'script')
|
2019-08-18 00:26:14 +08:00
|
|
|
Merge.string(this, data, 'file')
|
2019-12-16 03:04:31 +08:00
|
|
|
Merge.string(this, data, 'instructions')
|
2019-08-18 00:26:14 +08:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
get(axis) {
|
2018-12-16 23:18:20 +08:00
|
|
|
if (!this[axis]) {
|
2019-08-18 00:26:14 +08:00
|
|
|
return this.transform ? 0 : '';
|
2018-12-16 23:18:20 +08:00
|
|
|
} else if (!isNaN(this[axis])) {
|
|
|
|
return parseFloat(this[axis])
|
2018-11-12 04:19:08 +08:00
|
|
|
} else {
|
2018-12-16 23:18:20 +08:00
|
|
|
return this[axis]
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
calc(axis) {
|
2019-07-18 00:02:07 +08:00
|
|
|
return Molang.parse(this[axis])
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
|
|
|
set(axis, value) {
|
2019-08-18 00:26:14 +08:00
|
|
|
this[axis] = value;
|
2018-12-27 21:03:04 +08:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
offset(axis, amount) {
|
|
|
|
var value = this.get(axis)
|
|
|
|
if (!value || value === '0') {
|
|
|
|
this.set(axis, amount)
|
2019-08-18 00:26:14 +08:00
|
|
|
return amount;
|
2018-12-27 21:03:04 +08:00
|
|
|
}
|
|
|
|
if (typeof value === 'number') {
|
|
|
|
this.set(axis, value+amount)
|
|
|
|
return value+amount
|
|
|
|
}
|
|
|
|
var start = value.match(/^-?\s*\d*(\.\d+)?\s*(\+|-)/)
|
|
|
|
if (start) {
|
|
|
|
var number = parseFloat( start[0].substr(0, start[0].length-1) ) + amount
|
|
|
|
value = trimFloatNumber(number) + value.substr(start[0].length-1)
|
|
|
|
} else {
|
|
|
|
|
|
|
|
var end = value.match(/(\+|-)\s*\d*(\.\d+)?\s*$/)
|
|
|
|
if (end) {
|
2020-07-16 15:32:59 +08:00
|
|
|
var number = (parseFloat( end[0] ) + amount)
|
|
|
|
value = value.substr(0, end.index) + ((number.toString()).substr(0,1)=='-'?'':'+') + trimFloatNumber(number)
|
2018-12-27 21:03:04 +08:00
|
|
|
} else {
|
|
|
|
value = trimFloatNumber(amount) +(value.substr(0,1)=='-'?'':'+')+ value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.set(axis, value)
|
|
|
|
return value;
|
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
flip(axis) {
|
|
|
|
if (!this.transform) return this;
|
|
|
|
function negate(value) {
|
|
|
|
if (!value || value === '0') {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
if (typeof value === 'number') {
|
|
|
|
return -value;
|
|
|
|
}
|
|
|
|
var start = value.match(/^-?\s*\d*(\.\d+)?\s*(\+|-)/)
|
|
|
|
if (start) {
|
|
|
|
var number = parseFloat( start[0].substr(0, start[0].length-1) );
|
|
|
|
return trimFloatNumber(-number) + value.substr(start[0].length-1);
|
|
|
|
} else {
|
|
|
|
return `-(${value})`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.channel == 'rotation') {
|
|
|
|
for (var i = 0; i < 3; i++) {
|
|
|
|
if (i != axis) {
|
|
|
|
let l = getAxisLetter(i)
|
|
|
|
this.set(l, negate(this.get(l)))
|
|
|
|
}
|
|
|
|
}
|
2020-03-05 03:56:17 +08:00
|
|
|
} else if (this.channel == 'position') {
|
2019-08-18 00:26:14 +08:00
|
|
|
let l = getAxisLetter(axis)
|
|
|
|
this.set(l, negate(this.get(l)))
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
2018-12-27 21:03:04 +08:00
|
|
|
getLerp(other, axis, amount, allow_expression) {
|
|
|
|
if (allow_expression && this.get(axis) === other.get(axis)) {
|
|
|
|
return this.get(axis)
|
|
|
|
} else {
|
|
|
|
let calc = this.calc(axis)
|
|
|
|
return calc + (other.calc(axis) - calc) * amount
|
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
|
|
|
getArray() {
|
|
|
|
var arr = [
|
|
|
|
this.get('x'),
|
|
|
|
this.get('y'),
|
|
|
|
this.get('z'),
|
|
|
|
]
|
|
|
|
return arr;
|
|
|
|
}
|
2020-02-08 02:06:24 +08:00
|
|
|
getFixed() {
|
|
|
|
if (this.channel === 'rotation') {
|
|
|
|
let fix = this.animator.group.mesh.fix_rotation;
|
|
|
|
return new THREE.Quaternion().setFromEuler(new THREE.Euler(
|
|
|
|
fix.x - Math.degToRad(this.calc('x')),
|
|
|
|
fix.y - Math.degToRad(this.calc('y')),
|
|
|
|
fix.z + Math.degToRad(this.calc('z')),
|
|
|
|
'ZYX'
|
|
|
|
));
|
|
|
|
} else if (this.channel === 'position') {
|
|
|
|
let fix = this.animator.group.mesh.fix_position;
|
|
|
|
return new THREE.Vector3(
|
|
|
|
fix.x - this.calc('x'),
|
|
|
|
fix.y + this.calc('y'),
|
|
|
|
fix.z + this.calc('z')
|
|
|
|
)
|
|
|
|
} else if (this.channel === 'scale') {
|
|
|
|
return new THREE.Vector3(
|
|
|
|
this.calc('x'),
|
|
|
|
this.calc('y'),
|
|
|
|
this.calc('z')
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
replaceOthers(save) {
|
|
|
|
var scope = this;
|
|
|
|
var arr = this.animator[this.channel];
|
|
|
|
var replaced;
|
|
|
|
arr.forEach(kf => {
|
|
|
|
if (kf != scope && Math.abs(kf.time - scope.time) < 0.0001) {
|
|
|
|
save.push(kf);
|
|
|
|
kf.remove();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
select(event) {
|
2018-11-12 04:19:08 +08:00
|
|
|
var scope = this;
|
2019-08-18 00:26:14 +08:00
|
|
|
if (Timeline.dragging_keyframes) {
|
|
|
|
Timeline.dragging_keyframes = false
|
2018-11-12 04:19:08 +08:00
|
|
|
return this;
|
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
if (!event || (!event.shiftKey && !event.ctrlOrCmd)) {
|
2018-10-24 03:49:04 +08:00
|
|
|
Timeline.selected.forEach(function(kf) {
|
|
|
|
kf.selected = false
|
|
|
|
})
|
2020-04-26 02:25:07 +08:00
|
|
|
Timeline.selected.empty()
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
2018-11-12 04:19:08 +08:00
|
|
|
if (event && event.shiftKey && Timeline.selected.length) {
|
|
|
|
var last = Timeline.selected[Timeline.selected.length-1]
|
2019-08-18 00:26:14 +08:00
|
|
|
if (last && last.channel === scope.channel && last.animator == scope.animator) {
|
2018-11-12 04:19:08 +08:00
|
|
|
Timeline.keyframes.forEach((kf) => {
|
|
|
|
if (kf.channel === scope.channel &&
|
2019-08-18 00:26:14 +08:00
|
|
|
kf.animator === scope.animator &&
|
2018-11-12 04:19:08 +08:00
|
|
|
Math.isBetween(kf.time, last.time, scope.time) &&
|
|
|
|
!kf.selected
|
|
|
|
) {
|
|
|
|
kf.selected = true
|
|
|
|
Timeline.selected.push(kf)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
Timeline.selected.safePush(this);
|
|
|
|
if (Timeline.selected.length == 1 && Timeline.selected[0].animator.selected == false) {
|
|
|
|
Timeline.selected[0].animator.select()
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
|
2019-07-18 00:02:07 +08:00
|
|
|
var select_tool = true;
|
|
|
|
Timeline.selected.forEach(kf => {
|
|
|
|
if (kf.channel != scope.channel) select_tool = false;
|
|
|
|
})
|
2018-10-24 03:49:04 +08:00
|
|
|
this.selected = true
|
2019-09-06 06:16:54 +08:00
|
|
|
TickUpdates.keyframe_selection = true;
|
2019-07-18 00:02:07 +08:00
|
|
|
if (select_tool) {
|
2019-08-18 00:26:14 +08:00
|
|
|
switch (this.channel) {
|
|
|
|
case 'rotation': BarItems.rotate_tool.select(); break;
|
|
|
|
case 'position': BarItems.move_tool.select(); break;
|
|
|
|
case 'scale': BarItems.resize_tool.select(); break;
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
|
|
|
}
|
2018-11-12 04:19:08 +08:00
|
|
|
return this;
|
|
|
|
}
|
2020-01-24 01:53:36 +08:00
|
|
|
callPlayhead() {
|
2018-11-12 04:19:08 +08:00
|
|
|
Timeline.setTime(this.time)
|
|
|
|
Animator.preview()
|
|
|
|
return this;
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
|
|
|
showContextMenu(event) {
|
2018-11-12 04:19:08 +08:00
|
|
|
if (!this.selected) {
|
|
|
|
this.select();
|
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
this.menu.open(event, this);
|
|
|
|
return this;
|
|
|
|
}
|
2018-12-03 02:37:06 +08:00
|
|
|
remove() {
|
2019-08-18 00:26:14 +08:00
|
|
|
if (this.animator) {
|
|
|
|
this.animator[this.channel].remove(this)
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
2019-01-09 22:54:35 +08:00
|
|
|
Timeline.selected.remove(this)
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
2019-09-04 15:37:38 +08:00
|
|
|
getUndoCopy(save) {
|
2018-12-03 02:37:06 +08:00
|
|
|
var copy = {
|
2019-09-04 15:37:38 +08:00
|
|
|
animator: save ? undefined : this.animator && this.animator.uuid,
|
|
|
|
uuid: save && this.uuid,
|
2019-08-18 00:26:14 +08:00
|
|
|
channel: this.channel,
|
2018-12-03 02:37:06 +08:00
|
|
|
time: this.time,
|
|
|
|
x: this.x,
|
2019-07-18 00:02:07 +08:00
|
|
|
y: this.y,
|
|
|
|
z: this.z,
|
2018-12-03 02:37:06 +08:00
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
if (this.transform) {
|
|
|
|
copy.x = this.x;
|
|
|
|
copy.y = this.y;
|
|
|
|
copy.z = this.z;
|
|
|
|
if (this.channel == 'rotation' && this.isQuaternion) {
|
|
|
|
copy.w = this.w
|
|
|
|
}
|
2019-12-16 03:04:31 +08:00
|
|
|
} else if (this.channel == 'particle') {
|
2019-08-18 00:26:14 +08:00
|
|
|
copy.effect = this.effect;
|
2019-12-16 03:04:31 +08:00
|
|
|
copy.locator = this.locator;
|
2020-01-24 01:53:36 +08:00
|
|
|
copy.script = this.script;
|
2019-12-16 03:04:31 +08:00
|
|
|
|
|
|
|
} else if (this.channel == 'sound') {
|
|
|
|
copy.effect = this.effect;
|
|
|
|
copy.file = this.file;
|
|
|
|
|
|
|
|
} else if (this.channel == 'timeline') {
|
|
|
|
copy.instructions = this.instructions;
|
2018-12-03 02:37:06 +08:00
|
|
|
}
|
|
|
|
return copy;
|
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
|
|
|
Keyframe.prototype.menu = new Menu([
|
2019-12-16 03:04:31 +08:00
|
|
|
//Quaternions have been removed in Bedrock 1.10.0
|
|
|
|
/*
|
2018-11-12 04:19:08 +08:00
|
|
|
{name: 'menu.keyframe.quaternion',
|
|
|
|
icon: (keyframe) => (keyframe.isQuaternion ? 'check_box' : 'check_box_outline_blank'),
|
|
|
|
condition: (keyframe) => keyframe.channel === 'rotation',
|
|
|
|
click: function(keyframe) {
|
|
|
|
keyframe.select()
|
|
|
|
var state = !keyframe.isQuaternion
|
|
|
|
Timeline.keyframes.forEach((kf) => {
|
|
|
|
kf.isQuaternion = state
|
|
|
|
})
|
|
|
|
updateKeyframeSelection()
|
|
|
|
}
|
2019-12-16 03:04:31 +08:00
|
|
|
},*/
|
2019-08-18 00:26:14 +08:00
|
|
|
'change_keyframe_file',
|
|
|
|
'_',
|
2019-04-08 00:53:33 +08:00
|
|
|
'copy',
|
2019-07-18 00:02:07 +08:00
|
|
|
'delete',
|
2018-10-24 03:49:04 +08:00
|
|
|
])
|
2020-01-24 01:53:36 +08:00
|
|
|
//Misc Functions
|
|
|
|
function updateKeyframeValue(obj) {
|
|
|
|
var axis = $(obj).attr('axis');
|
|
|
|
var value = $(obj).val();
|
|
|
|
Timeline.selected.forEach(function(kf) {
|
|
|
|
kf.set(axis, value);
|
|
|
|
})
|
|
|
|
if (!['effect', 'locator', 'script'].includes(axis)) {
|
|
|
|
Animator.preview();
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
2020-01-24 01:53:36 +08:00
|
|
|
}
|
|
|
|
function updateKeyframeSelection() {
|
|
|
|
var multi_channel = false;
|
|
|
|
var channel = false;
|
|
|
|
Timeline.selected.forEach((kf) => {
|
|
|
|
if (channel === false) {
|
|
|
|
channel = kf.channel
|
|
|
|
} else if (channel !== kf.channel) {
|
|
|
|
multi_channel = true
|
2018-12-27 21:03:04 +08:00
|
|
|
}
|
2020-01-24 01:53:36 +08:00
|
|
|
})
|
|
|
|
$('.panel#keyframe .bar').hide();
|
2018-10-24 03:49:04 +08:00
|
|
|
|
2020-01-24 01:53:36 +08:00
|
|
|
if (Timeline.selected.length && !multi_channel) {
|
|
|
|
var first = Timeline.selected[0]
|
2019-12-16 03:04:31 +08:00
|
|
|
|
2020-01-24 01:53:36 +08:00
|
|
|
$('#keyframe_type_label').text(tl('panel.keyframe.type', [tl('timeline.'+first.channel)] ))
|
2019-08-18 00:26:14 +08:00
|
|
|
|
2020-01-24 01:53:36 +08:00
|
|
|
if (first.animator instanceof BoneAnimator) {
|
|
|
|
function _gt(axis) {
|
|
|
|
var n = first.get(axis);
|
|
|
|
if (typeof n == 'number') return trimFloatNumber(n);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
$('#keyframe_bar_x, #keyframe_bar_y, #keyframe_bar_z').show();
|
|
|
|
$('#keyframe_bar_w').toggle(first.channel === 'rotation' && first.isQuaternion)
|
|
|
|
|
|
|
|
$('#keyframe_bar_x input').val(_gt('x'));
|
|
|
|
$('#keyframe_bar_y input').val(_gt('y'));
|
|
|
|
$('#keyframe_bar_z input').val(_gt('z'));
|
|
|
|
if (first.channel === 'rotation' && first.isQuaternion) {
|
|
|
|
$('#keyframe_bar_w input').val(_gt('w'));
|
|
|
|
}
|
|
|
|
} else if (first.channel == 'particle') {
|
|
|
|
$('#keyframe_bar_effect').show();
|
|
|
|
$('#keyframe_bar_effect input').val(first.get('effect'));
|
|
|
|
$('#keyframe_bar_locator').show();
|
|
|
|
$('#keyframe_bar_locator input').val(first.get('locator'));
|
|
|
|
$('#keyframe_bar_script').show();
|
|
|
|
$('#keyframe_bar_script input').val(first.get('script'));
|
|
|
|
|
|
|
|
} else if (first.channel == 'sound') {
|
|
|
|
$('#keyframe_bar_effect').show();
|
|
|
|
$('#keyframe_bar_effect input').val(first.get('effect'));
|
|
|
|
|
|
|
|
} else if (first.channel == 'timeline') {
|
|
|
|
$('#keyframe_bar_instructions').show();
|
|
|
|
$('#keyframe_bar_instructions textarea').val(first.get('instructions'));
|
|
|
|
}
|
|
|
|
BarItems.slider_keyframe_time.update()
|
|
|
|
} else {
|
|
|
|
$('#keyframe_type_label').text('')
|
|
|
|
$('#keyframe_bar_x, #keyframe_bar_y, #keyframe_bar_z, #keyframe_bar_w').hide()
|
2019-08-18 00:26:14 +08:00
|
|
|
}
|
2020-01-24 01:53:36 +08:00
|
|
|
BARS.updateConditions()
|
2020-05-31 21:54:04 +08:00
|
|
|
Blockbench.dispatchEvent('update_keyframe_selection');
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
2020-01-24 01:53:36 +08:00
|
|
|
function selectAllKeyframes() {
|
|
|
|
if (!Animator.selected) return;
|
|
|
|
var state = Timeline.selected.length !== Timeline.keyframes.length
|
|
|
|
Timeline.keyframes.forEach((kf) => {
|
|
|
|
if (state && !kf.selected) {
|
|
|
|
Timeline.selected.push(kf)
|
|
|
|
} else if (!state && kf.selected) {
|
|
|
|
Timeline.selected.remove(kf)
|
|
|
|
}
|
|
|
|
kf.selected = state
|
2019-07-18 00:02:07 +08:00
|
|
|
})
|
2020-01-24 01:53:36 +08:00
|
|
|
updateKeyframeSelection()
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
2020-01-24 01:53:36 +08:00
|
|
|
function removeSelectedKeyframes() {
|
|
|
|
Undo.initEdit({keyframes: Timeline.selected})
|
|
|
|
var i = Timeline.keyframes.length;
|
|
|
|
while (i > 0) {
|
|
|
|
i--;
|
|
|
|
let kf = Timeline.keyframes[i]
|
|
|
|
if (Timeline.selected.includes(kf)) {
|
|
|
|
kf.remove()
|
|
|
|
}
|
2019-09-06 06:16:54 +08:00
|
|
|
}
|
2020-01-24 01:53:36 +08:00
|
|
|
updateKeyframeSelection()
|
|
|
|
Animator.preview()
|
|
|
|
Undo.finishEdit('remove keyframes')
|
|
|
|
}
|
|
|
|
function findBedrockAnimation() {
|
|
|
|
var animation_path = ModelMeta.export_path.split(osfs)
|
|
|
|
var index = animation_path.lastIndexOf('models')
|
|
|
|
animation_path.splice(index)
|
|
|
|
var path1 = [...animation_path, 'animations', pathToName(ModelMeta.export_path)+'.json'].join(osfs)
|
|
|
|
var path2 = [...animation_path, 'animations', pathToName(ModelMeta.export_path).replace('.geo', '')+'.animation.json'].join(osfs)
|
|
|
|
if (fs.existsSync(path1)) {
|
|
|
|
Blockbench.read([path1], {}, (files) => {
|
|
|
|
Animator.loadFile(files[0])
|
|
|
|
})
|
|
|
|
} else if (fs.existsSync(path2)) {
|
|
|
|
Blockbench.read([path2], {}, (files) => {
|
|
|
|
Animator.loadFile(files[0])
|
|
|
|
})
|
2019-09-06 06:16:54 +08:00
|
|
|
}
|
2020-01-24 01:53:36 +08:00
|
|
|
}
|
|
|
|
//Clipbench
|
|
|
|
Clipbench.setKeyframes = function() {
|
|
|
|
|
|
|
|
var keyframes = Timeline.selected;
|
2019-09-06 06:16:54 +08:00
|
|
|
|
2020-01-24 01:53:36 +08:00
|
|
|
Clipbench.keyframes = []
|
|
|
|
if (!keyframes || keyframes.length === 0) {
|
|
|
|
return;
|
2019-09-06 06:16:54 +08:00
|
|
|
}
|
2020-01-24 01:53:36 +08:00
|
|
|
var first = keyframes[0];
|
|
|
|
var single_animator;
|
|
|
|
keyframes.forEach(function(kf) {
|
|
|
|
if (kf.time < first.time) {
|
|
|
|
first = kf
|
2019-09-06 06:16:54 +08:00
|
|
|
}
|
2020-01-24 01:53:36 +08:00
|
|
|
if (single_animator && single_animator !== kf.animator.uuid) {
|
|
|
|
single_animator = false;
|
|
|
|
} else if (single_animator == undefined) {
|
|
|
|
single_animator = kf.animator.uuid;
|
|
|
|
}
|
|
|
|
})
|
2019-09-06 06:16:54 +08:00
|
|
|
|
2020-01-24 01:53:36 +08:00
|
|
|
keyframes.forEach(function(kf) {
|
|
|
|
var copy = kf.getUndoCopy();
|
|
|
|
copy.time_offset = kf.time - first.time;
|
|
|
|
if (single_animator != false) {
|
|
|
|
delete copy.animator;
|
|
|
|
}
|
|
|
|
Clipbench.keyframes.push(copy)
|
2019-12-16 03:04:31 +08:00
|
|
|
})
|
2020-01-24 01:53:36 +08:00
|
|
|
if (isApp) {
|
|
|
|
clipboard.writeHTML(JSON.stringify({type: 'keyframes', content: Clipbench.keyframes}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Clipbench.pasteKeyframes = function() {
|
|
|
|
if (isApp) {
|
|
|
|
var raw = clipboard.readHTML()
|
|
|
|
try {
|
|
|
|
var data = JSON.parse(raw)
|
|
|
|
if (data.type === 'keyframes' && data.content) {
|
|
|
|
Clipbench.keyframes = data.content
|
|
|
|
}
|
|
|
|
} catch (err) {}
|
|
|
|
}
|
|
|
|
if (Clipbench.keyframes && Clipbench.keyframes.length) {
|
|
|
|
|
|
|
|
if (!Animator.selected) return;
|
|
|
|
var keyframes = [];
|
|
|
|
Undo.initEdit({keyframes});
|
|
|
|
Timeline.selected.empty();
|
|
|
|
Timeline.keyframes.forEach((kf) => {
|
|
|
|
kf.selected = false;
|
|
|
|
})
|
|
|
|
Clipbench.keyframes.forEach(function(data, i) {
|
2019-09-06 06:16:54 +08:00
|
|
|
|
2020-01-24 01:53:36 +08:00
|
|
|
if (data.animator) {
|
|
|
|
var animator = Animator.selected.animators[data.animator];
|
|
|
|
if (animator && !Timeline.animators.includes(animator)) {
|
|
|
|
animator.addToTimeline();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var animator = Timeline.selected_animator;
|
|
|
|
}
|
|
|
|
if (animator) {
|
|
|
|
var kf = animator.createKeyframe(data, Timeline.time + data.time_offset, data.channel, false, false)
|
|
|
|
keyframes.push(kf);
|
|
|
|
kf.selected = true;
|
|
|
|
Timeline.selected.push(kf);
|
2019-09-06 06:16:54 +08:00
|
|
|
}
|
|
|
|
|
2020-01-24 01:53:36 +08:00
|
|
|
})
|
|
|
|
TickUpdates.keyframe_selection = true;
|
|
|
|
Animator.preview()
|
|
|
|
Undo.finishEdit('paste keyframes');
|
|
|
|
}
|
2019-09-06 06:16:54 +08:00
|
|
|
}
|
|
|
|
|
2018-10-24 03:49:04 +08:00
|
|
|
const Animator = {
|
2019-12-16 03:04:31 +08:00
|
|
|
possible_channels: {rotation: true, position: true, scale: true, sound: true, particle: true, timeline: true},
|
2018-11-12 04:19:08 +08:00
|
|
|
open: false,
|
2018-10-24 03:49:04 +08:00
|
|
|
animations: [],
|
|
|
|
frame: 0,
|
|
|
|
interval: false,
|
2019-07-18 00:02:07 +08:00
|
|
|
join() {
|
2018-10-24 03:49:04 +08:00
|
|
|
|
2018-11-12 04:19:08 +08:00
|
|
|
Animator.open = true;
|
2020-04-26 02:25:07 +08:00
|
|
|
selected.empty()
|
2019-07-18 00:02:07 +08:00
|
|
|
Canvas.updateAllBones()
|
2018-10-24 03:49:04 +08:00
|
|
|
|
2020-03-05 03:56:17 +08:00
|
|
|
//if (quad_previews.enabled) {
|
|
|
|
// quad_previews.enabled_before = true
|
|
|
|
//}
|
|
|
|
//main_preview.fullscreen()
|
|
|
|
//main_preview.setNormalCamera()
|
2018-10-24 03:49:04 +08:00
|
|
|
|
|
|
|
$('body').addClass('animation_mode')
|
|
|
|
if (!Animator.timeline_node) {
|
|
|
|
Animator.timeline_node = $('#timeline').get(0)
|
|
|
|
}
|
|
|
|
updateInterface()
|
2019-12-16 03:04:31 +08:00
|
|
|
Toolbars.element_origin.toPlace('bone_origin')
|
2018-11-12 04:19:08 +08:00
|
|
|
if (!Timeline.is_setup) {
|
|
|
|
Timeline.setup()
|
|
|
|
}
|
2019-04-08 00:53:33 +08:00
|
|
|
TickUpdates.keyframes = true;
|
2018-10-24 03:49:04 +08:00
|
|
|
if (outlines.children.length) {
|
2020-04-26 02:25:07 +08:00
|
|
|
outlines.children.empty()
|
2018-10-24 03:49:04 +08:00
|
|
|
Canvas.updateAllPositions()
|
|
|
|
}
|
2020-02-08 02:06:24 +08:00
|
|
|
if (!Animator.selected && Animator.animations.length) {
|
2019-03-10 05:06:35 +08:00
|
|
|
Animator.animations[0].select()
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
2019-07-18 00:02:07 +08:00
|
|
|
if (isApp && !ModelMeta.animation_path && !Animator.animations.length && ModelMeta.export_path) {
|
2018-12-16 23:18:20 +08:00
|
|
|
//Load
|
|
|
|
findBedrockAnimation()
|
|
|
|
}
|
2020-02-08 02:06:24 +08:00
|
|
|
Animator.preview()
|
2018-10-24 03:49:04 +08:00
|
|
|
},
|
2019-08-18 00:26:14 +08:00
|
|
|
leave() {
|
2018-11-12 04:19:08 +08:00
|
|
|
Timeline.pause()
|
|
|
|
Animator.open = false;
|
2018-10-24 03:49:04 +08:00
|
|
|
$('body').removeClass('animation_mode')
|
2020-03-05 03:56:17 +08:00
|
|
|
//resizeWindow()
|
|
|
|
//updateInterface()
|
2019-12-16 03:04:31 +08:00
|
|
|
Toolbars.element_origin.toPlace()
|
2020-03-05 03:56:17 +08:00
|
|
|
//if (quad_previews.enabled_before) {
|
|
|
|
// openQuadView()
|
|
|
|
//}
|
2019-07-18 00:02:07 +08:00
|
|
|
Canvas.updateAllBones()
|
2018-10-24 03:49:04 +08:00
|
|
|
},
|
2020-02-08 02:06:24 +08:00
|
|
|
showDefaultPose(no_matrix_update) {
|
2019-07-18 00:02:07 +08:00
|
|
|
Group.all.forEach(group => {
|
|
|
|
var bone = group.mesh;
|
|
|
|
bone.rotation.copy(bone.fix_rotation)
|
|
|
|
bone.position.copy(bone.fix_position)
|
|
|
|
bone.scale.x = bone.scale.y = bone.scale.z = 1;
|
|
|
|
|
2020-02-08 02:06:24 +08:00
|
|
|
if (!no_matrix_update) group.mesh.updateMatrixWorld()
|
|
|
|
})
|
|
|
|
},
|
|
|
|
preview() {
|
|
|
|
Animator.showDefaultPose(true);
|
|
|
|
|
|
|
|
Group.all.forEach(group => {
|
2019-07-18 00:02:07 +08:00
|
|
|
Animator.animations.forEach(animation => {
|
|
|
|
if (animation.playing) {
|
2020-04-26 02:25:07 +08:00
|
|
|
animation.getBoneAnimator(group).displayFrame()
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
|
|
|
})
|
2020-03-11 05:19:17 +08:00
|
|
|
group.mesh.updateMatrixWorld()
|
2019-07-18 00:02:07 +08:00
|
|
|
})
|
2019-08-18 00:26:14 +08:00
|
|
|
|
|
|
|
Animator.animations.forEach(animation => {
|
|
|
|
if (animation.playing) {
|
|
|
|
if (animation.animators.effects) {
|
|
|
|
animation.animators.effects.displayFrame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-07-18 00:02:07 +08:00
|
|
|
if (Group.selected) {
|
|
|
|
Transformer.center()
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
2019-07-18 00:02:07 +08:00
|
|
|
Blockbench.dispatchEvent('display_animation_frame')
|
2018-11-12 04:19:08 +08:00
|
|
|
},
|
2019-07-18 00:02:07 +08:00
|
|
|
loadFile(file) {
|
2018-10-24 03:49:04 +08:00
|
|
|
var json = autoParseJSON(file.content)
|
|
|
|
if (json && typeof json.animations === 'object') {
|
|
|
|
for (var ani_name in json.animations) {
|
2018-11-12 04:19:08 +08:00
|
|
|
//Animation
|
2018-10-24 03:49:04 +08:00
|
|
|
var a = json.animations[ani_name]
|
|
|
|
var animation = new Animation({
|
|
|
|
name: ani_name,
|
2020-07-16 15:32:59 +08:00
|
|
|
loop: a.loop && (a.loop == 'hold_on_last_frame' ? 'hold' : 'loop'),
|
2018-10-24 03:49:04 +08:00
|
|
|
override: a.override_previous_animation,
|
2018-11-12 04:19:08 +08:00
|
|
|
anim_time_update: a.anim_time_update,
|
2018-10-24 03:49:04 +08:00
|
|
|
length: a.animation_length,
|
2019-07-22 05:17:36 +08:00
|
|
|
blend_weight: a.blend_weight,
|
2019-08-18 00:26:14 +08:00
|
|
|
//particle_effects: a.particle_effects,
|
|
|
|
//sound_effects: a.sound_effects,
|
2018-10-24 03:49:04 +08:00
|
|
|
}).add()
|
2018-11-12 04:19:08 +08:00
|
|
|
//Bones
|
2019-08-18 00:26:14 +08:00
|
|
|
if (a.bones) {
|
|
|
|
for (var bone_name in a.bones) {
|
|
|
|
var b = a.bones[bone_name]
|
2020-07-16 15:32:59 +08:00
|
|
|
bone_name = bone_name.toLowerCase();
|
|
|
|
var group = Group.all.find(group => group.name.toLowerCase() == bone_name)
|
2019-08-18 00:26:14 +08:00
|
|
|
if (group) {
|
|
|
|
var ba = new BoneAnimator(group.uuid, animation);
|
|
|
|
animation.animators[group.uuid] = ba;
|
|
|
|
//Channels
|
|
|
|
for (var channel in b) {
|
|
|
|
if (Animator.possible_channels[channel]) {
|
|
|
|
if (typeof b[channel] === 'string' || typeof b[channel] === 'number' || b[channel] instanceof Array) {
|
|
|
|
ba.addKeyframe({
|
|
|
|
time: 0,
|
|
|
|
channel,
|
|
|
|
values: b[channel],
|
|
|
|
})
|
|
|
|
} else if (typeof b[channel] === 'object') {
|
|
|
|
for (var timestamp in b[channel]) {
|
|
|
|
ba.addKeyframe({
|
|
|
|
time: parseFloat(timestamp),
|
|
|
|
channel,
|
|
|
|
values: b[channel][timestamp],
|
|
|
|
});
|
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
if (a.sound_effects) {
|
|
|
|
if (!animation.animators.effects) {
|
|
|
|
animation.animators.effects = new EffectAnimator(animation);
|
|
|
|
}
|
|
|
|
for (var timestamp in a.sound_effects) {
|
|
|
|
var sound = a.sound_effects[timestamp];
|
|
|
|
if (sound instanceof Array) sound = sound[0];
|
|
|
|
animation.animators.effects.addKeyframe({
|
|
|
|
channel: 'sound',
|
|
|
|
time: parseFloat(timestamp),
|
|
|
|
effect: sound.effect,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (a.particle_effects) {
|
|
|
|
if (!animation.animators.effects) {
|
|
|
|
animation.animators.effects = new EffectAnimator(animation);
|
|
|
|
}
|
|
|
|
for (var timestamp in a.particle_effects) {
|
|
|
|
var particle = a.particle_effects[timestamp];
|
|
|
|
if (particle instanceof Array) particle = particle[0];
|
|
|
|
animation.animators.effects.addKeyframe({
|
|
|
|
channel: 'particle',
|
|
|
|
time: parseFloat(timestamp),
|
|
|
|
effect: particle.effect,
|
|
|
|
locator: particle.locator,
|
2020-01-24 01:53:36 +08:00
|
|
|
script: particle.pre_effect_script,
|
2019-08-18 00:26:14 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-12-16 03:04:31 +08:00
|
|
|
if (a.timeline) {
|
|
|
|
if (!animation.animators.effects) {
|
|
|
|
animation.animators.effects = new EffectAnimator(animation);
|
|
|
|
}
|
|
|
|
for (var timestamp in a.timeline) {
|
|
|
|
var entry = a.timeline[timestamp];
|
|
|
|
var instructions = entry.join('\n');
|
|
|
|
animation.animators.effects.addKeyframe({
|
|
|
|
channel: 'timeline',
|
|
|
|
time: parseFloat(timestamp),
|
|
|
|
instructions
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2018-12-27 21:03:04 +08:00
|
|
|
if (!Animator.selected) {
|
|
|
|
animation.select()
|
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
2018-12-16 23:18:20 +08:00
|
|
|
if (isApp && file.path) {
|
2019-07-18 00:02:07 +08:00
|
|
|
ModelMeta.animation_path = file.path
|
2018-12-16 23:18:20 +08:00
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
|
|
|
},
|
2019-07-18 00:02:07 +08:00
|
|
|
buildFile(options) {
|
2018-10-24 03:49:04 +08:00
|
|
|
if (typeof options !== 'object') {
|
2019-04-08 00:53:33 +08:00
|
|
|
options = false
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
|
|
|
var animations = {}
|
|
|
|
Animator.animations.forEach(function(a) {
|
2019-12-16 03:04:31 +08:00
|
|
|
var ani_tag = animations[a.name] = {};
|
2020-07-16 15:32:59 +08:00
|
|
|
|
|
|
|
if (a.loop == 'hold') {
|
|
|
|
ani_tag.loop = 'hold_on_last_frame';
|
|
|
|
} else if (a.loop == 'loop' || a.getMaxLength() == 0) {
|
|
|
|
ani_tag.loop = true;
|
|
|
|
}
|
|
|
|
|
2019-12-16 03:04:31 +08:00
|
|
|
if (a.length) ani_tag.animation_length = a.length;
|
|
|
|
if (a.override) ani_tag.override_previous_animation = true;
|
|
|
|
if (a.anim_time_update) ani_tag.anim_time_update = a.anim_time_update;
|
|
|
|
ani_tag.bones = {};
|
2019-08-18 00:26:14 +08:00
|
|
|
|
|
|
|
for (var uuid in a.animators) {
|
|
|
|
var animator = a.animators[uuid];
|
|
|
|
if (animator instanceof EffectAnimator) {
|
2018-11-12 04:19:08 +08:00
|
|
|
|
2019-08-18 00:26:14 +08:00
|
|
|
animator.sound.forEach(kf => {
|
|
|
|
if (!ani_tag.sound_effects) ani_tag.sound_effects = {};
|
|
|
|
let timecode = Math.clamp(trimFloatNumber(Math.round(kf.time*60)/60), 0) + '';
|
|
|
|
if (!timecode.includes('.')) {
|
|
|
|
timecode += '.0';
|
|
|
|
}
|
|
|
|
ani_tag.sound_effects[timecode] = {
|
|
|
|
effect: kf.effect
|
2019-12-16 03:04:31 +08:00
|
|
|
};
|
2019-08-18 00:26:14 +08:00
|
|
|
})
|
|
|
|
animator.particle.forEach(kf => {
|
|
|
|
if (!ani_tag.particle_effects) ani_tag.particle_effects = {};
|
|
|
|
let timecode = Math.clamp(trimFloatNumber(Math.round(kf.time*60)/60), 0) + '';
|
|
|
|
if (!timecode.includes('.')) {
|
|
|
|
timecode += '.0';
|
|
|
|
}
|
2020-01-24 01:53:36 +08:00
|
|
|
let script = kf.script || undefined;
|
|
|
|
if (script && !script.match(/;$/)) script += ';';
|
2019-08-18 00:26:14 +08:00
|
|
|
ani_tag.particle_effects[timecode] = {
|
|
|
|
effect: kf.effect,
|
2020-01-24 01:53:36 +08:00
|
|
|
locator: kf.locator || undefined,
|
|
|
|
pre_effect_script: kf.script || undefined
|
2019-12-16 03:04:31 +08:00
|
|
|
};
|
|
|
|
})
|
|
|
|
animator.timeline.forEach(kf => {
|
|
|
|
if (!ani_tag.timeline) ani_tag.timeline = {};
|
|
|
|
let timecode = Math.clamp(trimFloatNumber(Math.round(kf.time*60)/60), 0) + '';
|
|
|
|
if (!timecode.includes('.')) {
|
|
|
|
timecode += '.0';
|
2019-08-18 00:26:14 +08:00
|
|
|
}
|
2019-12-16 03:04:31 +08:00
|
|
|
ani_tag.timeline[timecode] = kf.instructions.split('\n');
|
2019-08-18 00:26:14 +08:00
|
|
|
})
|
|
|
|
|
2020-04-26 02:25:07 +08:00
|
|
|
} else if (a.animators[uuid].keyframes.length && a.animators[uuid].getGroup()) {
|
2019-08-18 00:26:14 +08:00
|
|
|
|
|
|
|
var group = a.animators[uuid].group;
|
2019-12-16 03:04:31 +08:00
|
|
|
var bone_tag = ani_tag.bones[group.name] = {};
|
|
|
|
var channels = {};
|
2018-11-12 04:19:08 +08:00
|
|
|
//Saving Keyframes
|
2019-08-18 00:26:14 +08:00
|
|
|
a.animators[uuid].keyframes.forEach(function(kf) {
|
2018-11-12 04:19:08 +08:00
|
|
|
if (!channels[kf.channel]) {
|
2019-12-16 03:04:31 +08:00
|
|
|
channels[kf.channel] = {};
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
2019-08-01 06:01:47 +08:00
|
|
|
let timecode = Math.clamp(trimFloatNumber(Math.round(kf.time*60)/60), 0) + '';
|
2018-11-12 04:19:08 +08:00
|
|
|
if (!timecode.includes('.')) {
|
2019-12-16 03:04:31 +08:00
|
|
|
timecode = timecode + '.0';
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
|
|
|
channels[kf.channel][timecode] = kf.getArray()
|
|
|
|
})
|
|
|
|
//Sorting keyframes
|
|
|
|
for (var channel in Animator.possible_channels) {
|
|
|
|
if (channels[channel]) {
|
|
|
|
let timecodes = Object.keys(channels[channel])
|
|
|
|
if (timecodes.length === 1) {
|
|
|
|
bone_tag[channel] = channels[channel][timecodes[0]]
|
2020-04-26 02:25:07 +08:00
|
|
|
if (channel == 'scale' &&
|
|
|
|
channels[channel][timecodes[0]] instanceof Array &&
|
|
|
|
channels[channel][timecodes[0]].allEqual(channels[channel][timecodes[0]][0])
|
|
|
|
) {
|
|
|
|
bone_tag[channel] = channels[channel][timecodes[0]][0];
|
|
|
|
}
|
2018-11-12 04:19:08 +08:00
|
|
|
} else {
|
|
|
|
timecodes.sort().forEach((time) => {
|
|
|
|
if (!bone_tag[channel]) {
|
|
|
|
bone_tag[channel] = {}
|
|
|
|
}
|
|
|
|
bone_tag[channel][time] = channels[channel][time]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
if (Object.keys(ani_tag.bones).length == 0) {
|
|
|
|
delete ani_tag.bones;
|
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
})
|
|
|
|
return {
|
2018-11-12 04:19:08 +08:00
|
|
|
format_version: '1.8.0',
|
2018-10-24 03:49:04 +08:00
|
|
|
animations: animations
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const Timeline = {
|
2019-08-18 00:26:14 +08:00
|
|
|
animators: [],
|
2018-10-24 03:49:04 +08:00
|
|
|
selected: [],//frames
|
2020-01-24 01:53:36 +08:00
|
|
|
playing_sounds: [],
|
2019-03-10 05:06:35 +08:00
|
|
|
playback_speed: 100,
|
2019-08-18 00:26:14 +08:00
|
|
|
time: 0,
|
|
|
|
get second() {return Timeline.time},
|
2020-04-26 02:25:07 +08:00
|
|
|
get animation_length() {return Animator.selected ? Animator.selected.length : 0;},
|
2018-12-03 02:37:06 +08:00
|
|
|
playing: false,
|
2019-08-18 00:26:14 +08:00
|
|
|
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') &&
|
|
|
|
e.target.id !== 'timeline_body_inner'
|
|
|
|
)) {
|
|
|
|
return
|
|
|
|
};
|
2019-12-16 03:04:31 +08:00
|
|
|
|
2020-01-24 01:53:36 +08:00
|
|
|
Timeline.selector.interval = setInterval(Timeline.selector.move, 1000/60);
|
2019-12-16 03:04:31 +08:00
|
|
|
document.addEventListener('mouseup', Timeline.selector.end, false);
|
|
|
|
|
2019-08-18 00:26:14 +08:00
|
|
|
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],
|
|
|
|
]
|
|
|
|
if (e.shiftKey) {
|
|
|
|
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,
|
|
|
|
]
|
2020-01-24 01:53:36 +08:00
|
|
|
var rect = getRectangle(R.start[0], R.start[1], mouse_pos.x - R.panel_offset[0], mouse_pos.y - R.panel_offset[1])
|
2019-08-18 00:26:14 +08:00
|
|
|
$('#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;
|
|
|
|
var focus = Timeline.vue._data.focus_channel;
|
|
|
|
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;
|
|
|
|
|
2020-04-26 02:25:07 +08:00
|
|
|
Timeline.selected.empty()
|
2019-08-18 00:26:14 +08:00
|
|
|
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-05-31 21:54:04 +08:00
|
|
|
(kf.channel == focus || !focus || focus == 'used')
|
2019-08-18 00:26:14 +08:00
|
|
|
) {
|
|
|
|
var channel_index = focus ? 0 : animator.channels.indexOf(kf.channel);
|
2020-05-31 21:54:04 +08:00
|
|
|
if (focus == 'used') {
|
|
|
|
for (var channel of animator.channels) {
|
|
|
|
if (kf.channel == channel) break;
|
|
|
|
channel_index++;
|
|
|
|
}
|
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
height = offset + channel_index*24 + 36;
|
|
|
|
if (height > rect.ay && height < rect.by) {
|
|
|
|
kf.selected = true;
|
|
|
|
Timeline.selected.push(kf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-16 03:04:31 +08:00
|
|
|
//Scroll body
|
|
|
|
var body = $('#timeline_body').get(0)
|
|
|
|
var body_inner = $('#timeline_body_inner').get(0)
|
|
|
|
|
2020-01-24 01:53:36 +08:00
|
|
|
var top = mouse_pos.y - R.panel_offset[1] - body.scrollTop;
|
|
|
|
var bot = body.scrollTop + body.clientHeight - (mouse_pos.y - R.panel_offset[1]);
|
|
|
|
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);
|
2019-12-16 03:04:31 +08:00
|
|
|
|
2020-07-16 15:32:59 +08:00
|
|
|
let speed = 15;
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (lef < 0) body.scrollLeft = body.scrollLeft - speed;
|
|
|
|
if (rig < 0) body.scrollLeft = Math.clamp(body.scrollLeft + speed, 0, body_inner.clientWidth - body.clientWidth);
|
2019-08-18 00:26:14 +08:00
|
|
|
},
|
|
|
|
end(e) {
|
|
|
|
if (!Timeline.selector.selecting) return false;
|
2019-12-16 03:04:31 +08:00
|
|
|
e.stopPropagation();
|
|
|
|
document.removeEventListener('mousemove', Timeline.selector.move);
|
2020-01-24 01:53:36 +08:00
|
|
|
clearInterval(Timeline.selector.interval);
|
2019-12-16 03:04:31 +08:00
|
|
|
document.removeEventListener('mouseup', Timeline.selector.end);
|
|
|
|
|
|
|
|
updateKeyframeSelection()
|
2019-08-18 00:26:14 +08:00
|
|
|
Timeline.selector.selected_before.empty();
|
|
|
|
Timeline.selector.selecting = false;
|
|
|
|
$('#timeline_selector')
|
|
|
|
.css('width', 0)
|
|
|
|
.css('height', 0)
|
|
|
|
.hide()
|
|
|
|
},
|
|
|
|
},
|
2019-07-18 00:02:07 +08:00
|
|
|
setTime(seconds, editing) {
|
2018-11-12 04:19:08 +08:00
|
|
|
seconds = limitNumber(seconds, 0, 1000)
|
2020-01-24 01:53:36 +08:00
|
|
|
Timeline.vue._data.playhead = seconds
|
2019-08-18 00:26:14 +08:00
|
|
|
Timeline.time = seconds
|
2018-12-27 21:03:04 +08:00
|
|
|
if (!editing) {
|
|
|
|
Timeline.setTimecode(seconds)
|
|
|
|
}
|
2020-04-26 02:25:07 +08:00
|
|
|
if (Timeline.getMaxLength() !== Timeline.vue._data.length) {
|
|
|
|
Timeline.updateSize()
|
|
|
|
}
|
|
|
|
Timeline.revealTime(seconds)
|
|
|
|
},
|
|
|
|
revealTime(time) {
|
2019-08-18 00:26:14 +08:00
|
|
|
var scroll = $('#timeline_body').scrollLeft()
|
2020-04-26 02:25:07 +08:00
|
|
|
var playhead = time * Timeline.vue._data.size + 8
|
2020-01-24 01:53:36 +08:00
|
|
|
if (playhead < scroll || playhead > scroll + $('#timeline_body').width() - Timeline.vue._data.head_width) {
|
|
|
|
$('#timeline_body').scrollLeft(playhead-16)
|
2018-12-27 21:03:04 +08:00
|
|
|
}
|
2018-11-12 04:19:08 +08:00
|
|
|
},
|
2019-07-18 00:02:07 +08:00
|
|
|
setTimecode(time) {
|
2018-11-12 04:19:08 +08:00
|
|
|
let m = Math.floor(time/60)
|
|
|
|
let s = Math.floor(time%60)
|
2019-04-08 00:53:33 +08:00
|
|
|
let f = Math.floor((time%1) * 100)
|
2018-11-12 04:19:08 +08:00
|
|
|
if ((s+'').length === 1) {s = '0'+s}
|
|
|
|
if ((f+'').length === 1) {f = '0'+f}
|
|
|
|
$('#timeline_corner').text(m + ':' + s + ':' + f)
|
|
|
|
},
|
2019-07-18 00:02:07 +08:00
|
|
|
snapTime(time) {
|
|
|
|
//return time;
|
|
|
|
if (time == undefined || isNaN(time)) {
|
2019-08-18 00:26:14 +08:00
|
|
|
time = Timeline.time;
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
2019-07-19 23:31:22 +08:00
|
|
|
var fps = Math.clamp(settings.animation_snap.value, 1, 120);
|
2019-07-18 00:02:07 +08:00
|
|
|
return Math.clamp(Math.round(time*fps)/fps, 0);
|
|
|
|
},
|
2020-01-24 01:53:36 +08:00
|
|
|
getStep() {
|
|
|
|
return 1/Math.clamp(settings.animation_snap.value, 1, 120);
|
|
|
|
},
|
2019-07-18 00:02:07 +08:00
|
|
|
setup() {
|
2019-12-16 03:04:31 +08:00
|
|
|
$('#timeline_body').mousedown(Timeline.selector.down)
|
2019-08-18 00:26:14 +08:00
|
|
|
|
2020-01-24 01:53:36 +08:00
|
|
|
$('#timeline_time').on('mousedown touchstart', e => {
|
|
|
|
if (e.which !== 1 && !event.changedTouches) return;
|
|
|
|
if (e.target.classList.contains('timeline_marker')) return;
|
2020-04-26 02:25:07 +08:00
|
|
|
|
|
|
|
if (e.target.id == 'timeline_endbracket') {
|
|
|
|
|
2020-07-16 15:32:59 +08:00
|
|
|
if (Animator.selected) {
|
|
|
|
Timeline.dragging_endbracket = true;
|
|
|
|
Undo.initEdit({animations: [Animator.selected]});
|
|
|
|
} else {
|
|
|
|
Blockbench.showQuickMessage('message.no_animation_selected');
|
|
|
|
}
|
2020-04-26 02:25:07 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
convertTouchEvent(e);
|
|
|
|
Timeline.dragging_playhead = true;
|
2020-07-16 15:32:59 +08:00
|
|
|
|
|
|
|
let offset = e.clientX - $('#timeline_time').offset().left;
|
|
|
|
let time = Timeline.snapTime(offset / Timeline.vue._data.size);
|
|
|
|
Timeline.setTime(time);
|
|
|
|
Animator.preview();
|
2020-04-26 02:25:07 +08:00
|
|
|
}
|
2018-11-12 04:19:08 +08:00
|
|
|
})
|
2020-01-24 01:53:36 +08:00
|
|
|
$(document).on('mousemove touchmove', e => {
|
|
|
|
if (Timeline.dragging_playhead) {
|
2020-04-26 02:25:07 +08:00
|
|
|
|
2020-01-24 01:53:36 +08:00
|
|
|
convertTouchEvent(e);
|
|
|
|
let offset = e.clientX - $('#timeline_time').offset().left;
|
2019-08-18 00:26:14 +08:00
|
|
|
let time = Timeline.snapTime(offset / Timeline.vue._data.size)
|
|
|
|
if (Timeline.time != time) {
|
|
|
|
Timeline.setTime(time)
|
|
|
|
Animator.preview()
|
|
|
|
}
|
2020-04-26 02:25:07 +08:00
|
|
|
} else if (Timeline.dragging_endbracket) {
|
|
|
|
|
|
|
|
convertTouchEvent(e);
|
|
|
|
let offset = e.clientX - $('#timeline_time').offset().left;
|
|
|
|
let time = Timeline.snapTime(offset / Timeline.vue._data.size)
|
|
|
|
|
|
|
|
Animator.selected.setLength(time)
|
|
|
|
Timeline.revealTime(time)
|
|
|
|
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
|
|
|
})
|
2020-01-24 01:53:36 +08:00
|
|
|
.on('mouseup touchend', e => {
|
|
|
|
if (Timeline.dragging_playhead) {
|
|
|
|
delete Timeline.dragging_playhead
|
|
|
|
Timeline.pause();
|
2020-04-26 02:25:07 +08:00
|
|
|
|
|
|
|
} else if (Timeline.dragging_endbracket) {
|
|
|
|
|
|
|
|
Undo.finishEdit('Change Animation Length')
|
|
|
|
delete Timeline.dragging_endbracket
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
|
|
|
})
|
2019-01-09 22:54:35 +08:00
|
|
|
//Keyframe inputs
|
2018-12-03 02:37:06 +08:00
|
|
|
$('.keyframe_input').click(e => {
|
2019-12-16 03:04:31 +08:00
|
|
|
Undo.initEdit({keyframes: Timeline.selected})
|
2018-12-03 02:37:06 +08:00
|
|
|
}).focusout(e => {
|
|
|
|
Undo.finishEdit('edit keyframe')
|
|
|
|
})
|
2019-01-09 22:54:35 +08:00
|
|
|
//Enter Time
|
2018-12-27 21:03:04 +08:00
|
|
|
$('#timeline_corner').click(e => {
|
|
|
|
if ($('#timeline_corner').attr('contenteditable') == 'true') return;
|
|
|
|
|
|
|
|
$('#timeline_corner').attr('contenteditable', true).focus().select()
|
|
|
|
var times = $('#timeline_corner').text().split(':')
|
|
|
|
while (times.length < 3) {
|
|
|
|
times.push('00')
|
|
|
|
}
|
|
|
|
var node = $('#timeline_corner').get(0).childNodes[0]
|
|
|
|
var selection = window.getSelection();
|
|
|
|
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)) {
|
|
|
|
$('#timeline_corner').attr('contenteditable', false)
|
2019-08-18 00:26:14 +08:00
|
|
|
Timeline.setTimecode(Timeline.time)
|
2018-12-27 21:03:04 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.on('keyup', e => {
|
|
|
|
var times = $('#timeline_corner').text().split(':')
|
|
|
|
times.forEach((t, i) => {
|
|
|
|
times[i] = parseInt(t)
|
|
|
|
if (isNaN(times[i])) {
|
|
|
|
times[i] = 0
|
|
|
|
}
|
|
|
|
})
|
|
|
|
while (times.length < 3) {
|
|
|
|
times.push(0)
|
|
|
|
}
|
|
|
|
var seconds
|
|
|
|
= times[0]*60
|
|
|
|
+ limitNumber(times[1], 0, 59)
|
2019-04-08 00:53:33 +08:00
|
|
|
+ limitNumber(times[2]/100, 0, 99)
|
2019-08-18 00:26:14 +08:00
|
|
|
if (Math.abs(seconds-Timeline.time) > 1e-3 ) {
|
2018-12-27 21:03:04 +08:00
|
|
|
Timeline.setTime(seconds, true)
|
2019-04-13 00:44:18 +08:00
|
|
|
Animator.preview()
|
2018-12-27 21:03:04 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-04-26 02:25:07 +08:00
|
|
|
$('#timeline_vue').on('mousewheel scroll', function(e) {
|
|
|
|
e.preventDefault()
|
2019-08-18 00:26:14 +08:00
|
|
|
var body = $('#timeline_body').get(0)
|
|
|
|
if (event.shiftKey) {
|
|
|
|
body.scrollLeft += event.deltaY/4
|
2020-04-26 02:25:07 +08:00
|
|
|
|
2019-08-18 00:26:14 +08:00
|
|
|
} else if (event.ctrlOrCmd) {
|
2020-04-26 02:25:07 +08:00
|
|
|
|
|
|
|
let mouse_pos = event.clientX - $(this).offset().left;
|
|
|
|
|
|
|
|
var zoom = 1 - event.deltaY/600
|
|
|
|
let original_size = Timeline.vue._data.size
|
|
|
|
Timeline.vue._data.size = limitNumber(Timeline.vue._data.size * zoom, 10, 1000)
|
|
|
|
//let val = ((body.scrollLeft + mouse_pos) * (Timeline.vue._data.size - original_size) ) / 128
|
|
|
|
|
|
|
|
let size_ratio = Timeline.vue._data.size / original_size
|
|
|
|
let offset = mouse_pos - body.scrollLeft - 180
|
|
|
|
let val = (size_ratio-1) * offset;
|
|
|
|
// todo: optimize zooming in
|
|
|
|
body.scrollLeft += val
|
|
|
|
/*
|
|
|
|
Timeline.vue._data.size = limitNumber(Timeline.vue._data.size * zoom, 10, 1000)
|
|
|
|
body.scrollLeft *= zoom
|
2019-08-18 00:26:14 +08:00
|
|
|
let l = (event.offsetX / body.clientWidth) * 500 * (event.deltaY<0?1:-0.2)
|
|
|
|
body.scrollLeft += l
|
2020-04-26 02:25:07 +08:00
|
|
|
*/
|
|
|
|
|
2019-04-08 00:53:33 +08:00
|
|
|
} else {
|
2019-08-18 00:26:14 +08:00
|
|
|
body.scrollTop += event.deltaY/6.25
|
2019-04-08 00:53:33 +08:00
|
|
|
}
|
|
|
|
Timeline.updateSize()
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
2019-08-18 00:26:14 +08:00
|
|
|
$('#timeline_body').on('scroll', e => {
|
|
|
|
Timeline.vue._data.scroll_left = $('#timeline_body').scrollLeft()||0;
|
|
|
|
})
|
2019-04-08 00:53:33 +08:00
|
|
|
|
2019-03-10 05:06:35 +08:00
|
|
|
BarItems.slider_animation_speed.update()
|
2018-11-12 04:19:08 +08:00
|
|
|
Timeline.is_setup = true
|
2018-12-27 21:03:04 +08:00
|
|
|
Timeline.setTime(0)
|
2018-11-12 04:19:08 +08:00
|
|
|
},
|
2019-07-18 00:02:07 +08:00
|
|
|
update() {
|
2018-11-12 04:19:08 +08:00
|
|
|
//Draggable
|
2019-08-18 00:26:14 +08:00
|
|
|
$('#timeline_body .keyframe:not(.ui-draggable)').draggable({
|
2018-10-24 03:49:04 +08:00
|
|
|
axis: 'x',
|
2019-04-08 00:53:33 +08:00
|
|
|
distance: 4,
|
2019-07-19 23:31:22 +08:00
|
|
|
helper: () => $('<div></div>'),
|
2018-11-12 04:19:08 +08:00
|
|
|
start: function(event, ui) {
|
2019-04-08 00:53:33 +08:00
|
|
|
|
2019-08-18 00:26:14 +08:00
|
|
|
var id = $(event.target).attr('id');
|
|
|
|
var clicked = Timeline.keyframes.findInArray('uuid', id)
|
|
|
|
|
|
|
|
if (!$(event.target).hasClass('selected') && !event.shiftKey && Timeline.selected.length != 0) {
|
2019-04-08 00:53:33 +08:00
|
|
|
clicked.select()
|
2019-08-18 00:26:14 +08:00
|
|
|
} else if (clicked && !clicked.selected) {
|
|
|
|
clicked.select({shiftKey: true})
|
2019-04-08 00:53:33 +08:00
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
|
2019-12-16 03:04:31 +08:00
|
|
|
Undo.initEdit({keyframes: Timeline.selected})
|
2019-08-18 00:26:14 +08:00
|
|
|
Timeline.dragging_keyframes = true;
|
2019-04-08 00:53:33 +08:00
|
|
|
|
2018-11-12 04:19:08 +08:00
|
|
|
var i = 0;
|
2019-08-18 00:26:14 +08:00
|
|
|
for (var kf of Timeline.selected) {
|
|
|
|
kf.time_before = kf.time
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
drag: function(event, ui) {
|
|
|
|
var difference = (ui.position.left - ui.originalPosition.left - 8) / Timeline.vue._data.size;
|
2018-10-24 03:49:04 +08:00
|
|
|
var id = $(ui.helper).attr('id')
|
2018-12-03 02:37:06 +08:00
|
|
|
|
2019-08-18 00:26:14 +08:00
|
|
|
for (var kf of Timeline.selected) {
|
|
|
|
var t = limitNumber(kf.time_before + difference, 0, 256)
|
|
|
|
if (kf.uuid === id) {
|
|
|
|
ui.position.left = t * Timeline.vue._data.size + 8
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
kf.time = Timeline.snapTime(t);
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
2018-11-12 04:19:08 +08:00
|
|
|
BarItems.slider_keyframe_time.update()
|
|
|
|
Animator.preview()
|
|
|
|
},
|
|
|
|
stop: function(event, ui) {
|
2019-08-18 00:26:14 +08:00
|
|
|
var deleted = []
|
|
|
|
for (var kf of Timeline.selected) {
|
|
|
|
delete kf.time_before;
|
|
|
|
kf.replaceOthers(deleted);
|
|
|
|
}
|
|
|
|
Undo.addKeyframeCasualties(deleted);
|
2018-12-03 02:37:06 +08:00
|
|
|
Undo.finishEdit('drag keyframes')
|
2020-04-26 02:25:07 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
Timeline.dragging_keyframes = false;
|
|
|
|
}, 20)
|
2020-01-24 01:53:36 +08:00
|
|
|
}
|
|
|
|
})
|
2018-11-12 04:19:08 +08:00
|
|
|
},
|
2020-04-26 02:25:07 +08:00
|
|
|
getMaxLength() {
|
2019-08-18 00:26:14 +08:00
|
|
|
var max_length = ($('#timeline_body').width()-8) / Timeline.vue._data.size;
|
|
|
|
Timeline.keyframes.forEach((kf) => {
|
2018-11-12 04:19:08 +08:00
|
|
|
max_length = Math.max(max_length, kf.time)
|
|
|
|
})
|
2019-08-18 00:26:14 +08:00
|
|
|
max_length = Math.max(max_length, Timeline.time) + 50/Timeline.vue._data.size
|
2020-04-26 02:25:07 +08:00
|
|
|
return max_length;
|
|
|
|
},
|
|
|
|
updateSize() {
|
|
|
|
let size = Timeline.vue._data.size
|
|
|
|
Timeline.vue._data.length = Timeline.getMaxLength()
|
|
|
|
Timeline.vue._data.timecodes.empty()
|
2018-11-12 04:19:08 +08:00
|
|
|
|
|
|
|
var step = 1
|
|
|
|
if (size < 1) {step = 1}
|
|
|
|
else if (size < 20) {step = 4}
|
|
|
|
else if (size < 40) {step = 2}
|
2020-04-26 02:25:07 +08:00
|
|
|
else if (size < 100) {step = 1}
|
|
|
|
else if (size < 256) {step = 0.5}
|
|
|
|
else if (size < 520) {step = 0.25}
|
|
|
|
else if (size < 660) {step = 0.2}
|
|
|
|
else if (size < 860) {step = 0.1}
|
2018-11-12 04:19:08 +08:00
|
|
|
else {step = 0.05}
|
|
|
|
|
2020-04-26 02:25:07 +08:00
|
|
|
|
2019-07-18 00:02:07 +08:00
|
|
|
if (step < 1) {
|
2020-01-24 01:53:36 +08:00
|
|
|
var FPS = Timeline.getStep();
|
2019-07-18 00:02:07 +08:00
|
|
|
step = Math.round(step/FPS) * FPS
|
2020-04-26 02:25:07 +08:00
|
|
|
//step = 1/Math.round(1/step)
|
|
|
|
}
|
|
|
|
|
|
|
|
let substeps = step / Timeline.getStep()
|
|
|
|
while (substeps > 8) {
|
|
|
|
substeps /= 2;
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
2020-04-26 02:25:07 +08:00
|
|
|
//substeps = Math.round(substeps)
|
|
|
|
|
2018-11-12 04:19:08 +08:00
|
|
|
|
|
|
|
var i = 0;
|
|
|
|
while (i < Timeline.vue._data.length) {
|
|
|
|
Timeline.vue._data.timecodes.push({
|
|
|
|
time: i,
|
2020-04-26 02:25:07 +08:00
|
|
|
width: step,
|
|
|
|
substeps: substeps,
|
2018-11-12 04:19:08 +08:00
|
|
|
text: Math.round(i*100)/100
|
|
|
|
})
|
|
|
|
i += step;
|
|
|
|
}
|
|
|
|
},
|
2019-08-18 00:26:14 +08:00
|
|
|
updateScroll(e) {
|
|
|
|
$('.channel_head').css('left', scroll_amount+'px')
|
|
|
|
$('#timeline_time').css('left', -scroll_amount+'px')
|
|
|
|
},
|
2019-07-18 00:02:07 +08:00
|
|
|
unselect(e) {
|
2018-11-12 04:19:08 +08:00
|
|
|
if (!Animator.selected) return;
|
|
|
|
Timeline.keyframes.forEach((kf) => {
|
|
|
|
if (kf.selected) {
|
|
|
|
Timeline.selected.remove(kf)
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
2018-11-12 04:19:08 +08:00
|
|
|
kf.selected = false
|
2018-10-24 03:49:04 +08:00
|
|
|
})
|
2019-09-06 06:16:54 +08:00
|
|
|
TickUpdates.keyframe_selection = true;
|
2018-10-24 03:49:04 +08:00
|
|
|
},
|
2019-07-18 00:02:07 +08:00
|
|
|
start() {
|
2018-11-12 04:19:08 +08:00
|
|
|
if (!Animator.selected) return;
|
|
|
|
Animator.selected.getMaxLength()
|
2018-10-24 03:49:04 +08:00
|
|
|
Timeline.pause()
|
2018-12-03 02:37:06 +08:00
|
|
|
Timeline.playing = true
|
2018-11-12 04:19:08 +08:00
|
|
|
BarItems.play_animation.setIcon('pause')
|
2020-07-16 15:32:59 +08:00
|
|
|
Timeline.interval = setInterval(Timeline.loop, 100/6)
|
2018-10-24 03:49:04 +08:00
|
|
|
Timeline.loop()
|
|
|
|
},
|
2019-07-18 00:02:07 +08:00
|
|
|
loop() {
|
2019-02-04 04:09:35 +08:00
|
|
|
Animator.preview()
|
2019-08-18 00:26:14 +08:00
|
|
|
if (Animator.selected && Timeline.time < (Animator.selected.length||1e3)) {
|
2019-03-10 05:06:35 +08:00
|
|
|
|
2019-08-18 00:26:14 +08:00
|
|
|
Timeline.setTime(Timeline.time + (1/60) * (Timeline.playback_speed/100))
|
2018-10-24 03:49:04 +08:00
|
|
|
} else {
|
2020-07-16 15:32:59 +08:00
|
|
|
if (Animator.selected.loop == 'once') {
|
|
|
|
Timeline.setTime(0)
|
2018-11-12 04:19:08 +08:00
|
|
|
Timeline.pause()
|
2020-03-05 03:56:17 +08:00
|
|
|
Animator.preview()
|
2020-07-16 15:32:59 +08:00
|
|
|
} else if (Animator.selected.loop == 'hold') {
|
|
|
|
Timeline.pause()
|
|
|
|
} else {
|
|
|
|
Timeline.setTime(0)
|
|
|
|
Timeline.start()
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
|
|
|
},
|
2019-07-18 00:02:07 +08:00
|
|
|
pause() {
|
2018-12-03 02:37:06 +08:00
|
|
|
Timeline.playing = false;
|
2018-11-12 04:19:08 +08:00
|
|
|
BarItems.play_animation.setIcon('play_arrow')
|
2020-07-16 15:32:59 +08:00
|
|
|
if (Timeline.interval) {
|
|
|
|
clearInterval(Timeline.interval)
|
|
|
|
Timeline.interval = false
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
2020-01-24 01:53:36 +08:00
|
|
|
Timeline.playing_sounds.forEach(media => {
|
|
|
|
if (!media.paused) {
|
|
|
|
media.pause();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
Timeline.playing_sounds.empty();
|
2018-11-12 04:19:08 +08:00
|
|
|
},
|
2019-08-18 00:26:14 +08:00
|
|
|
get keyframes() {
|
|
|
|
var keyframes = [];
|
2019-12-16 03:04:31 +08:00
|
|
|
Timeline.animators.forEach(animator => {
|
2019-08-18 00:26:14 +08:00
|
|
|
keyframes = [...keyframes, ...animator.keyframes]
|
|
|
|
})
|
|
|
|
return keyframes;
|
2018-11-12 04:19:08 +08:00
|
|
|
},
|
2019-07-18 00:02:07 +08:00
|
|
|
showMenu(event) {
|
2019-12-16 03:04:31 +08:00
|
|
|
if (event.target.nodeName == 'KEYFRAME' || event.target.parentElement.nodeName == 'KEYFRAME') return;
|
|
|
|
Timeline.menu.open(event, event);
|
2018-11-12 04:19:08 +08:00
|
|
|
},
|
|
|
|
menu: new Menu([
|
2019-08-18 00:26:14 +08:00
|
|
|
'paste',
|
2019-12-16 03:04:31 +08:00
|
|
|
'_',
|
|
|
|
'select_all',
|
|
|
|
'bring_up_all_animations',
|
2020-04-26 02:25:07 +08:00
|
|
|
'fold_all_animations',
|
2019-12-16 03:04:31 +08:00
|
|
|
'clear_timeline',
|
2018-11-12 04:19:08 +08:00
|
|
|
])
|
2018-10-24 03:49:04 +08:00
|
|
|
}
|
2019-07-18 00:02:07 +08:00
|
|
|
Molang.global_variables = {
|
|
|
|
'true': 1,
|
|
|
|
'false': 0,
|
|
|
|
get 'query.anim_time'() {
|
2019-08-18 00:26:14 +08:00
|
|
|
return Timeline.time;
|
2019-07-18 00:02:07 +08:00
|
|
|
},
|
2019-07-26 19:33:29 +08:00
|
|
|
get 'query.life_time'() {
|
2019-08-18 00:26:14 +08:00
|
|
|
return Timeline.time;
|
2019-07-18 00:02:07 +08:00
|
|
|
},
|
2019-07-26 19:33:29 +08:00
|
|
|
get 'time'() {
|
2019-08-18 00:26:14 +08:00
|
|
|
return Timeline.time;
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Molang.variableHandler = function (variable) {
|
|
|
|
var inputs = $('#var_placeholder_area').val().split('\n')
|
|
|
|
var i = 0;
|
|
|
|
while (i < inputs.length) {
|
|
|
|
let key, val;
|
|
|
|
[key, val] = inputs[i].replace(/[\s;]/g, '').split('=')
|
|
|
|
if (key === variable) {
|
|
|
|
return Molang.parse(val)
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2018-10-24 03:49:04 +08:00
|
|
|
|
2019-02-04 04:09:35 +08:00
|
|
|
onVueSetup(function() {
|
|
|
|
Animator.vue = new Vue({
|
|
|
|
el: '#animations_list',
|
|
|
|
data: {
|
|
|
|
animations: Animator.animations
|
2019-08-18 00:26:14 +08:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
sort(event) {
|
|
|
|
var item = Animator.animations.splice(event.oldIndex, 1)[0];
|
|
|
|
Animator.animations.splice(event.newIndex, 0, item);
|
|
|
|
}
|
2019-02-04 04:09:35 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
Timeline.vue = new Vue({
|
2019-08-18 00:26:14 +08:00
|
|
|
el: '#timeline_vue',
|
2019-02-04 04:09:35 +08:00
|
|
|
data: {
|
|
|
|
size: 150,
|
|
|
|
length: 10,
|
2020-04-26 02:25:07 +08:00
|
|
|
animation_length: 0,
|
2019-08-18 00:26:14 +08:00
|
|
|
scroll_left: 0,
|
2020-04-26 02:25:07 +08:00
|
|
|
head_width: 180,
|
2019-02-04 04:09:35 +08:00
|
|
|
timecodes: [],
|
2019-08-18 00:26:14 +08:00
|
|
|
animators: Timeline.animators,
|
2020-01-24 01:53:36 +08:00
|
|
|
markers: [],
|
2019-08-18 00:26:14 +08:00
|
|
|
focus_channel: null,
|
2020-01-24 01:53:36 +08:00
|
|
|
playhead: Timeline.time
|
2019-08-18 00:26:14 +08:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
toggleAnimator(animator) {
|
|
|
|
animator.expanded = !animator.expanded;
|
|
|
|
},
|
|
|
|
removeAnimator(animator) {
|
|
|
|
Timeline.animators.remove(animator);
|
|
|
|
}
|
2019-02-04 04:09:35 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2019-12-16 03:04:31 +08:00
|
|
|
Blockbench.addDragHandler('animation', {
|
|
|
|
extensions: ['animation.json'],
|
|
|
|
readtype: 'text',
|
2020-01-24 01:53:36 +08:00
|
|
|
condition: {modes: ['animate']},
|
2019-12-16 03:04:31 +08:00
|
|
|
}, function(files) {
|
|
|
|
Animator.loadFile(files[0])
|
|
|
|
})
|
2019-02-04 04:09:35 +08:00
|
|
|
|
2018-11-12 04:19:08 +08:00
|
|
|
BARS.defineActions(function() {
|
2019-08-18 00:26:14 +08:00
|
|
|
new Action('add_animation', {
|
2018-11-12 04:19:08 +08:00
|
|
|
icon: 'fa-plus-circle',
|
|
|
|
category: 'animation',
|
2020-01-24 01:53:36 +08:00
|
|
|
condition: {modes: ['animate']},
|
2018-11-12 04:19:08 +08:00
|
|
|
click: function () {
|
|
|
|
var animation = new Animation({
|
2019-07-18 00:02:07 +08:00
|
|
|
name: 'animation.' + (Project.geometry_name||'model') + '.new'
|
2019-04-08 00:53:33 +08:00
|
|
|
}).add(true).rename()
|
2018-10-24 03:49:04 +08:00
|
|
|
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
|
|
|
})
|
2019-08-18 00:26:14 +08:00
|
|
|
new Action('load_animation_file', {
|
2019-07-18 00:02:07 +08:00
|
|
|
icon: 'fa-file-video',
|
2018-11-12 04:19:08 +08:00
|
|
|
category: 'animation',
|
2020-01-24 01:53:36 +08:00
|
|
|
condition: {modes: ['animate']},
|
2018-11-12 04:19:08 +08:00
|
|
|
click: function () {
|
2019-07-18 00:02:07 +08:00
|
|
|
var path = ModelMeta.export_path
|
2018-11-12 04:19:08 +08:00
|
|
|
if (isApp) {
|
|
|
|
var exp = new RegExp(osfs.replace('\\', '\\\\')+'models'+osfs.replace('\\', '\\\\'))
|
|
|
|
var m_index = path.search(exp)
|
|
|
|
if (m_index > 3) {
|
2019-07-18 00:02:07 +08:00
|
|
|
path = path.substr(0, m_index) + osfs + 'animations' + osfs + pathToName(ModelMeta.export_path).replace(/\.geo/, '.animation')
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Blockbench.import({
|
2020-04-26 02:25:07 +08:00
|
|
|
resource_id: 'animation',
|
2018-11-12 04:19:08 +08:00
|
|
|
extensions: ['json'],
|
|
|
|
type: 'JSON Animation',
|
|
|
|
startpath: path
|
|
|
|
}, function(files) {
|
|
|
|
Animator.loadFile(files[0])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2019-08-18 00:26:14 +08:00
|
|
|
new Action('export_animation_file', {
|
2018-11-12 04:19:08 +08:00
|
|
|
icon: 'save',
|
|
|
|
category: 'animation',
|
|
|
|
click: function () {
|
|
|
|
var content = autoStringify(Animator.buildFile())
|
2019-07-18 00:02:07 +08:00
|
|
|
var path = ModelMeta.animation_path
|
2018-12-16 23:18:20 +08:00
|
|
|
|
|
|
|
if (isApp && !path) {
|
2019-07-18 00:02:07 +08:00
|
|
|
path = ModelMeta.export_path
|
2018-11-12 04:19:08 +08:00
|
|
|
var exp = new RegExp(osfs.replace('\\', '\\\\')+'models'+osfs.replace('\\', '\\\\'))
|
|
|
|
var m_index = path.search(exp)
|
|
|
|
if (m_index > 3) {
|
2019-07-18 00:02:07 +08:00
|
|
|
path = path.substr(0, m_index) + osfs + 'animations' + osfs + pathToName(ModelMeta.export_path, true)
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
2019-09-06 06:16:54 +08:00
|
|
|
if (path.match(/\.geo\.json$/)) {
|
|
|
|
path = path.replace(/\.geo\.json$/, '.animation.json')
|
|
|
|
} else {
|
|
|
|
path = path.replace(/\.json$/, '.animation.json')
|
|
|
|
}
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
|
|
|
Blockbench.export({
|
2020-04-26 02:25:07 +08:00
|
|
|
resource_id: 'animation',
|
2018-11-12 04:19:08 +08:00
|
|
|
type: 'JSON Animation',
|
|
|
|
extensions: ['json'],
|
2019-09-06 06:16:54 +08:00
|
|
|
name: (Project.geometry_name||'model')+'.animation',
|
2018-11-12 04:19:08 +08:00
|
|
|
startpath: path,
|
2019-09-04 15:37:38 +08:00
|
|
|
content: content,
|
|
|
|
}, (real_path) => {
|
|
|
|
ModelMeta.animation_path = real_path;
|
2018-11-12 04:19:08 +08:00
|
|
|
})
|
2018-10-24 03:49:04 +08:00
|
|
|
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
|
|
|
})
|
2019-08-18 00:26:14 +08:00
|
|
|
new Action('play_animation', {
|
2018-11-12 04:19:08 +08:00
|
|
|
icon: 'play_arrow',
|
|
|
|
category: 'animation',
|
|
|
|
keybind: new Keybind({key: 32}),
|
2019-12-16 03:04:31 +08:00
|
|
|
condition: {modes: ['animate']},
|
2018-11-12 04:19:08 +08:00
|
|
|
click: function () {
|
|
|
|
|
2018-12-27 21:03:04 +08:00
|
|
|
if (!Animator.selected) {
|
|
|
|
Blockbench.showQuickMessage('message.no_animation_selected')
|
|
|
|
return;
|
|
|
|
}
|
2018-12-03 02:37:06 +08:00
|
|
|
if (Timeline.playing) {
|
2018-11-12 04:19:08 +08:00
|
|
|
Timeline.pause()
|
|
|
|
} else {
|
|
|
|
Timeline.start()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2019-08-18 00:26:14 +08:00
|
|
|
new NumSlider('slider_animation_length', {
|
2018-11-12 04:19:08 +08:00
|
|
|
category: 'animation',
|
|
|
|
condition: () => Animator.open && Animator.selected,
|
2020-03-05 03:56:17 +08:00
|
|
|
getInterval(event) {
|
|
|
|
if (event && event.shiftKey) return 1;
|
|
|
|
return 1/Math.clamp(settings.animation_snap.value, 1, 120)
|
|
|
|
},
|
2018-11-12 04:19:08 +08:00
|
|
|
get: function() {
|
|
|
|
return Animator.selected.length
|
|
|
|
},
|
2019-12-16 03:04:31 +08:00
|
|
|
change: function(modify) {
|
2020-04-26 02:25:07 +08:00
|
|
|
Animator.selected.setLength(limitNumber(modify(Animator.selected.length), 0, 1e4))
|
|
|
|
},
|
|
|
|
onBefore: function() {
|
|
|
|
Undo.initEdit({animations: [Animator.selected]});
|
|
|
|
},
|
|
|
|
onAfter: function() {
|
|
|
|
Undo.finishEdit('Change Animation Length')
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
|
|
|
})
|
2019-08-18 00:26:14 +08:00
|
|
|
new NumSlider('slider_animation_speed', {
|
2019-03-10 05:06:35 +08:00
|
|
|
category: 'animation',
|
2020-01-24 01:53:36 +08:00
|
|
|
condition: {modes: ['animate']},
|
2019-03-10 05:06:35 +08:00
|
|
|
get: function() {
|
|
|
|
return Timeline.playback_speed;
|
|
|
|
},
|
2019-12-16 03:04:31 +08:00
|
|
|
change: function(modify) {
|
|
|
|
Timeline.playback_speed = limitNumber(modify(Timeline.playback_speed), 0, 10000)
|
2019-03-10 05:06:35 +08:00
|
|
|
},
|
|
|
|
getInterval: (e) => {
|
|
|
|
var val = BarItems.slider_animation_speed.get()
|
|
|
|
if (e.shiftKey) {
|
|
|
|
if (val < 50) {
|
|
|
|
return 10;
|
|
|
|
} else {
|
|
|
|
return 50;
|
|
|
|
}
|
|
|
|
}
|
2019-08-18 00:26:14 +08:00
|
|
|
if (e.ctrlOrCmd) {
|
2019-03-10 05:06:35 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2019-08-18 00:26:14 +08:00
|
|
|
new NumSlider('slider_keyframe_time', {
|
2018-11-12 04:19:08 +08:00
|
|
|
category: 'animation',
|
|
|
|
condition: () => Animator.open && Timeline.selected.length,
|
2020-03-05 03:56:17 +08:00
|
|
|
getInterval(event) {
|
|
|
|
if (event && event.shiftKey) return 1;
|
|
|
|
return 1/Math.clamp(settings.animation_snap.value, 1, 120)
|
|
|
|
},
|
2018-11-12 04:19:08 +08:00
|
|
|
get: function() {
|
|
|
|
return Timeline.selected[0] ? Timeline.selected[0].time : 0
|
|
|
|
},
|
2019-12-16 03:04:31 +08:00
|
|
|
change: function(modify) {
|
2018-11-12 04:19:08 +08:00
|
|
|
Timeline.selected.forEach((kf) => {
|
2019-12-16 03:04:31 +08:00
|
|
|
kf.time = Timeline.snapTime(limitNumber(modify(kf.time), 0, 1e4))
|
2018-11-12 04:19:08 +08:00
|
|
|
})
|
|
|
|
Animator.preview()
|
2018-12-03 02:37:06 +08:00
|
|
|
},
|
|
|
|
onBefore: function() {
|
2019-12-16 03:04:31 +08:00
|
|
|
Undo.initEdit({keyframes: Timeline.selected})
|
2018-12-03 02:37:06 +08:00
|
|
|
},
|
|
|
|
onAfter: function() {
|
2019-04-08 00:53:33 +08:00
|
|
|
Undo.finishEdit('move keyframes')
|
|
|
|
}
|
|
|
|
})
|
2019-08-18 00:26:14 +08:00
|
|
|
new Action('reset_keyframe', {
|
2019-04-08 00:53:33 +08:00
|
|
|
icon: 'replay',
|
|
|
|
category: 'animation',
|
2019-04-13 00:44:18 +08:00
|
|
|
condition: () => Animator.open && Timeline.selected.length,
|
2019-04-08 00:53:33 +08:00
|
|
|
click: function () {
|
2019-08-18 00:26:14 +08:00
|
|
|
Undo.initEdit({keyframes: Timeline.selected})
|
2019-04-08 00:53:33 +08:00
|
|
|
Timeline.selected.forEach((kf) => {
|
2020-07-16 15:32:59 +08:00
|
|
|
var n = kf.channel === 'scale' ? '1' : '0';
|
2019-04-08 00:53:33 +08:00
|
|
|
kf.extend({
|
|
|
|
x: n,
|
|
|
|
y: n,
|
|
|
|
z: n,
|
|
|
|
w: kf.isQuaternion ? 0 : undefined
|
|
|
|
})
|
|
|
|
})
|
|
|
|
Undo.finishEdit('reset keyframes')
|
2019-07-18 00:02:07 +08:00
|
|
|
updateKeyframeSelection()
|
2019-04-08 00:53:33 +08:00
|
|
|
Animator.preview()
|
2018-11-12 04:19:08 +08:00
|
|
|
}
|
|
|
|
})
|
2020-04-26 02:25:07 +08:00
|
|
|
new Action('resolve_keyframe_expressions', {
|
|
|
|
icon: 'functions',
|
|
|
|
category: 'animation',
|
|
|
|
condition: () => Animator.open && Timeline.selected.length,
|
|
|
|
click: function () {
|
|
|
|
Undo.initEdit({keyframes: Timeline.selected})
|
2020-07-16 15:32:59 +08:00
|
|
|
let time_before = Timeline.time;
|
2020-04-26 02:25:07 +08:00
|
|
|
Timeline.selected.forEach((kf) => {
|
|
|
|
if (kf.animator.fillValues) {
|
2020-07-16 15:32:59 +08:00
|
|
|
Timeline.time = kf.time;
|
2020-04-26 02:25:07 +08:00
|
|
|
kf.animator.fillValues(kf, null, false);
|
|
|
|
}
|
|
|
|
})
|
2020-07-16 15:32:59 +08:00
|
|
|
Timeline.time = time_before;
|
2020-04-26 02:25:07 +08:00
|
|
|
Undo.finishEdit('reset keyframes')
|
|
|
|
updateKeyframeSelection()
|
|
|
|
}
|
|
|
|
})
|
2019-08-18 00:26:14 +08:00
|
|
|
new Action('change_keyframe_file', {
|
|
|
|
icon: 'fa-file-audio',
|
|
|
|
category: 'animation',
|
|
|
|
condition: () => (Animator.open && Timeline.selected.length && Timeline.selected[0].channel == 'sound' && isApp),
|
|
|
|
click: function () {
|
|
|
|
Blockbench.import({
|
2020-04-26 02:25:07 +08:00
|
|
|
resource_id: 'animation_audio',
|
2019-08-18 00:26:14 +08:00
|
|
|
extensions: ['ogg'],
|
|
|
|
type: 'Audio File',
|
|
|
|
startpath: Timeline.selected[0].file
|
|
|
|
}, function(files) {
|
|
|
|
|
|
|
|
Undo.initEdit({keyframes: Timeline.selected})
|
|
|
|
Timeline.selected.forEach((kf) => {
|
|
|
|
if (kf.channel == 'sound') {
|
|
|
|
kf.file = files[0].path;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
Undo.finishEdit('changed keyframe audio file')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
new Action('reverse_keyframes', {
|
|
|
|
icon: 'swap_horizontal_circle',
|
|
|
|
category: 'animation',
|
|
|
|
condition: () => Animator.open && Timeline.selected.length,
|
|
|
|
click: function () {
|
|
|
|
var start = 1e9;
|
|
|
|
var end = 0;
|
|
|
|
Timeline.selected.forEach((kf) => {
|
|
|
|
start = Math.min(start, kf.time);
|
|
|
|
end = Math.max(end, kf.time);
|
|
|
|
})
|
|
|
|
Undo.initEdit({keyframes: Timeline.selected})
|
|
|
|
Timeline.selected.forEach((kf) => {
|
|
|
|
kf.time = end + start - kf.time;
|
|
|
|
})
|
|
|
|
Undo.finishEdit('reverse keyframes')
|
|
|
|
updateKeyframeSelection()
|
|
|
|
Animator.preview()
|
|
|
|
}
|
|
|
|
})
|
2019-03-10 05:06:35 +08:00
|
|
|
|
2019-08-18 00:26:14 +08:00
|
|
|
new Action('previous_keyframe', {
|
2019-03-10 05:06:35 +08:00
|
|
|
icon: 'fa-arrow-circle-left',
|
|
|
|
category: 'animation',
|
2020-01-24 01:53:36 +08:00
|
|
|
condition: {modes: ['animate']},
|
2019-03-10 05:06:35 +08:00
|
|
|
click: function () {
|
|
|
|
|
2019-08-18 00:26:14 +08:00
|
|
|
var time = Timeline.time;
|
2019-03-10 05:06:35 +08:00
|
|
|
function getDelta(kf, abs) {
|
|
|
|
return kf.time - time
|
|
|
|
}
|
2020-01-24 01:53:36 +08:00
|
|
|
let animator = Timeline.selected_animator
|
|
|
|
|| (Timeline.selected[0] && Timeline.selected[0].animator)
|
|
|
|
|| Timeline.animators[0];
|
|
|
|
let channel = Timeline.selected[0] ? Timeline.selected[0].channel : (animator && animator.channels[0]);
|
|
|
|
|
2019-03-10 05:06:35 +08:00
|
|
|
var matches = []
|
2019-08-18 00:26:14 +08:00
|
|
|
for (var kf of Timeline.keyframes) {
|
2020-01-24 01:53:36 +08:00
|
|
|
if ((!animator || animator == kf.animator) && (!channel || channel == kf.channel)) {
|
|
|
|
let delta = getDelta(kf)
|
|
|
|
if (delta < 0) {
|
|
|
|
matches.push(kf)
|
|
|
|
}
|
2019-03-10 05:06:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
matches.sort((a, b) => {
|
|
|
|
return Math.abs(getDelta(a)) - Math.abs(getDelta(b))
|
|
|
|
})
|
|
|
|
var kf = matches[0]
|
|
|
|
if (kf) {
|
2020-01-24 01:53:36 +08:00
|
|
|
kf.select().callPlayhead()
|
2019-03-10 05:06:35 +08:00
|
|
|
} else {
|
|
|
|
if (Timeline.selected.length) {
|
|
|
|
selectAllKeyframes()
|
|
|
|
selectAllKeyframes()
|
|
|
|
}
|
|
|
|
Timeline.setTime(0)
|
|
|
|
Animator.preview()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2019-08-18 00:26:14 +08:00
|
|
|
new Action('next_keyframe', {
|
2019-03-10 05:06:35 +08:00
|
|
|
icon: 'fa-arrow-circle-right',
|
|
|
|
category: 'animation',
|
2020-01-24 01:53:36 +08:00
|
|
|
condition: {modes: ['animate']},
|
2019-03-10 05:06:35 +08:00
|
|
|
click: function () {
|
|
|
|
|
2019-08-18 00:26:14 +08:00
|
|
|
var time = Timeline.time;
|
2019-03-10 05:06:35 +08:00
|
|
|
function getDelta(kf, abs) {
|
|
|
|
return kf.time - time
|
|
|
|
}
|
2020-01-24 01:53:36 +08:00
|
|
|
let animator = Timeline.selected_animator
|
|
|
|
|| (Timeline.selected[0] && Timeline.selected[0].animator)
|
|
|
|
|| Timeline.animators[0];
|
|
|
|
let channel = Timeline.selected[0] ? Timeline.selected[0].channel : (animator && animator.channels[0]);
|
|
|
|
|
2019-03-10 05:06:35 +08:00
|
|
|
var matches = []
|
2019-08-18 00:26:14 +08:00
|
|
|
for (var kf of Timeline.keyframes) {
|
2020-01-24 01:53:36 +08:00
|
|
|
if ((!animator || animator == kf.animator) && (!channel || channel == kf.channel)) {
|
|
|
|
let delta = getDelta(kf)
|
|
|
|
if (delta > 0) {
|
|
|
|
matches.push(kf)
|
|
|
|
}
|
2019-03-10 05:06:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
matches.sort((a, b) => {
|
|
|
|
return Math.abs(getDelta(a)) - Math.abs(getDelta(b))
|
|
|
|
})
|
|
|
|
var kf = matches[0]
|
|
|
|
if (kf) {
|
2020-01-24 01:53:36 +08:00
|
|
|
kf.select().callPlayhead()
|
2019-03-10 05:06:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-07-16 15:32:59 +08:00
|
|
|
new Action('jump_to_timeline_start', {
|
|
|
|
icon: 'skip_previous',
|
|
|
|
category: 'animation',
|
|
|
|
condition: {modes: ['animate']},
|
|
|
|
keybind: new Keybind({key: 36}),
|
|
|
|
click: function () {
|
|
|
|
Timeline.setTime(0)
|
|
|
|
Animator.preview()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
new Action('jump_to_timeline_end', {
|
|
|
|
icon: 'skip_next',
|
|
|
|
category: 'animation',
|
|
|
|
condition: {modes: ['animate']},
|
|
|
|
keybind: new Keybind({key: 35}),
|
|
|
|
click: function () {
|
|
|
|
Timeline.setTime(Animator.selected ? Animator.selected.length : 0)
|
|
|
|
Animator.preview()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-01-24 01:53:36 +08:00
|
|
|
new Action('move_keyframe_back', {
|
|
|
|
icon: 'arrow_back',
|
|
|
|
category: 'transform',
|
|
|
|
condition: {modes: ['animate'], method: () => (!open_menu && Timeline.selected.length)},
|
|
|
|
keybind: new Keybind({key: 37}),
|
|
|
|
click: function (e) {
|
|
|
|
Undo.initEdit({keyframes: Timeline.selected})
|
|
|
|
Timeline.selected.forEach((kf) => {
|
|
|
|
kf.time = Timeline.snapTime(limitNumber(kf.time - Timeline.getStep(), 0, 1e4))
|
|
|
|
})
|
|
|
|
Animator.preview()
|
|
|
|
Undo.finishEdit('move keyframes')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
new Action('move_keyframe_forth', {
|
|
|
|
icon: 'arrow_forward',
|
|
|
|
category: 'transform',
|
|
|
|
condition: {modes: ['animate'], method: () => (!open_menu && Timeline.selected.length)},
|
|
|
|
keybind: new Keybind({key: 39}),
|
|
|
|
click: function (e) {
|
|
|
|
Undo.initEdit({keyframes: Timeline.selected})
|
|
|
|
Timeline.selected.forEach((kf) => {
|
|
|
|
kf.time = Timeline.snapTime(limitNumber(kf.time + Timeline.getStep(), 0, 1e4))
|
|
|
|
})
|
|
|
|
Animator.preview()
|
|
|
|
Undo.finishEdit('move keyframes')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-12-16 03:04:31 +08:00
|
|
|
new Action('add_keyframe', {
|
|
|
|
icon: 'add_circle',
|
|
|
|
category: 'animation',
|
2020-01-24 01:53:36 +08:00
|
|
|
condition: {modes: ['animate']},
|
2019-12-16 03:04:31 +08:00
|
|
|
keybind: new Keybind({key: 81, shift: null}),
|
|
|
|
click: function (event) {
|
|
|
|
var animator = Timeline.selected_animator;
|
|
|
|
if (!animator) return;
|
|
|
|
var channel = animator.channels[0];
|
|
|
|
if (Toolbox.selected.id == 'rotate_tool' && animator.channels.includes('rotation')) channel = 'rotation';
|
|
|
|
if (Toolbox.selected.id == 'move_tool' && animator.channels.includes('position')) channel = 'position';
|
|
|
|
if (Toolbox.selected.id == 'resize_tool' && animator.channels.includes('scale')) channel = 'scale';
|
|
|
|
animator.createKeyframe((event && event.shiftKey) ? {} : null, Timeline.time, channel, true);
|
|
|
|
if (event && event.shiftKey) {
|
|
|
|
Animator.preview();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2019-03-10 05:06:35 +08:00
|
|
|
|
2020-01-24 01:53:36 +08:00
|
|
|
new Action('add_marker', {
|
|
|
|
icon: 'flag',
|
|
|
|
category: 'animation',
|
|
|
|
condition: {modes: ['animate']},
|
2020-03-05 03:56:17 +08:00
|
|
|
keybind: new Keybind({ctrl: true, key: 77}),
|
2020-01-24 01:53:36 +08:00
|
|
|
click: function (event) {
|
|
|
|
if (!Animator.selected) {
|
|
|
|
Blockbench.showQuickMessage('message.no_animation_selected')
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var time = Timeline.snapTime();
|
|
|
|
var original_marker;
|
|
|
|
for (var m of Animator.selected.markers) {
|
|
|
|
if (Math.abs(m.time - time) < 0.01) {
|
|
|
|
original_marker = m;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (original_marker) {
|
|
|
|
Animator.selected.markers.remove(original_marker);
|
|
|
|
} else {
|
|
|
|
let marker = new TimelineMarker({time});
|
|
|
|
Animator.selected.markers.push(marker);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-12-16 03:04:31 +08:00
|
|
|
new Action('bring_up_all_animations', {
|
|
|
|
icon: 'fa-sort-amount-up',
|
2018-11-12 04:19:08 +08:00
|
|
|
category: 'animation',
|
2020-01-24 01:53:36 +08:00
|
|
|
condition: {modes: ['animate']},
|
2019-12-16 03:04:31 +08:00
|
|
|
click: function () {
|
2020-04-26 02:25:07 +08:00
|
|
|
if (!Animator.selected) return;
|
2019-12-16 03:04:31 +08:00
|
|
|
for (var uuid in Animator.selected.animators) {
|
|
|
|
var ba = Animator.selected.animators[uuid]
|
|
|
|
if (ba && ba.keyframes.length) {
|
|
|
|
ba.addToTimeline();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-11-12 04:19:08 +08:00
|
|
|
})
|
2020-04-26 02:25:07 +08:00
|
|
|
new Action('fold_all_animations', {
|
|
|
|
icon: 'format_indent_decrease',
|
|
|
|
category: 'animation',
|
|
|
|
condition: {modes: ['animate']},
|
|
|
|
click: function () {
|
|
|
|
for (var animator of Timeline.animators) {
|
|
|
|
animator.expanded = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
2019-08-18 00:26:14 +08:00
|
|
|
new Action('clear_timeline', {
|
|
|
|
icon: 'clear_all',
|
|
|
|
category: 'animation',
|
2020-01-24 01:53:36 +08:00
|
|
|
condition: {modes: ['animate']},
|
2019-08-18 00:26:14 +08:00
|
|
|
click: function () {
|
|
|
|
Timeline.vue._data.animators.purge();
|
2019-12-16 03:04:31 +08:00
|
|
|
unselectAll();
|
2019-08-18 00:26:14 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
new Action('select_effect_animator', {
|
|
|
|
icon: 'fa-magic',
|
|
|
|
category: 'animation',
|
2020-01-24 01:53:36 +08:00
|
|
|
condition: {modes: ['animate']},
|
2019-08-18 00:26:14 +08:00
|
|
|
click: function () {
|
|
|
|
if (!Animator.selected) return;
|
|
|
|
if (!Animator.selected.animators.effects) {
|
|
|
|
var ea = Animator.selected.animators.effects = new EffectAnimator(Animator.selected);
|
|
|
|
}
|
|
|
|
Animator.selected.animators.effects.select()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
new BarSelect('timeline_focus', {
|
|
|
|
options: {
|
|
|
|
all: true,
|
2020-04-26 02:25:07 +08:00
|
|
|
used: true,
|
2019-08-18 00:26:14 +08:00
|
|
|
rotation: tl('timeline.rotation'),
|
|
|
|
position: tl('timeline.position'),
|
|
|
|
scale: tl('timeline.scale'),
|
|
|
|
},
|
|
|
|
onChange: function(slider) {
|
|
|
|
var val = slider.get();
|
|
|
|
Timeline.vue._data.focus_channel = val != 'all' ? val : null;
|
|
|
|
}
|
|
|
|
})
|
2019-12-16 03:04:31 +08:00
|
|
|
/*
|
|
|
|
//Inverse Kinematics
|
|
|
|
new Action('ik_enabled', {
|
|
|
|
icon: 'check_box_outline_blank',
|
|
|
|
category: 'animation',
|
|
|
|
click: function () {
|
|
|
|
Group.selected.ik_enabled = !Group.selected.ik_enabled;
|
|
|
|
updateNslideValues();
|
|
|
|
Transformer.updateSelection();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
new NumSlider('slider_ik_chain_length', {
|
|
|
|
category: 'animation',
|
|
|
|
condition: () => Animator.open && Group.selected,
|
|
|
|
get: function() {
|
|
|
|
return Group.selected.ik_chain_length||0;
|
|
|
|
},
|
|
|
|
settings: {
|
|
|
|
min: 0, max: 64, default: 0,
|
|
|
|
interval: function(event) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
change: function(modify) {
|
|
|
|
Group.selected.ik_chain_length = modify(Group.selected.ik_chain_length);
|
|
|
|
},
|
|
|
|
onBefore: function() {
|
|
|
|
Undo.initEdit({keyframes: Timeline.selected})
|
|
|
|
},
|
|
|
|
onAfter: function() {
|
|
|
|
Undo.finishEdit('move keyframes')
|
|
|
|
}
|
|
|
|
})*/
|
|
|
|
|
2019-02-04 04:09:35 +08:00
|
|
|
})
|