2020-09-26 23:56:14 +08:00
|
|
|
class KeyframeDataPoint {
|
|
|
|
constructor(keyframe) {
|
2020-10-01 19:07:45 +08:00
|
|
|
this.keyframe = keyframe;
|
|
|
|
for (var key in KeyframeDataPoint.properties) {
|
|
|
|
KeyframeDataPoint.properties[key].reset(this);
|
2020-09-26 23:56:14 +08:00
|
|
|
}
|
|
|
|
}
|
2020-09-27 04:20:19 +08:00
|
|
|
extend(data) {
|
|
|
|
if (data.values) {
|
2020-10-01 19:07:45 +08:00
|
|
|
Object.assign(data, data.values)
|
|
|
|
}
|
|
|
|
for (var key in KeyframeDataPoint.properties) {
|
|
|
|
KeyframeDataPoint.properties[key].merge(this, data)
|
|
|
|
}
|
2020-09-26 23:56:14 +08:00
|
|
|
}
|
2020-10-01 19:07:45 +08:00
|
|
|
getUndoCopy() {
|
|
|
|
var copy = {}
|
|
|
|
for (var key in KeyframeDataPoint.properties) {
|
|
|
|
KeyframeDataPoint.properties[key].copy(this, copy)
|
|
|
|
}
|
|
|
|
return copy;
|
2020-09-26 23:56:14 +08:00
|
|
|
}
|
|
|
|
}
|
2020-10-12 20:40:42 +08:00
|
|
|
new Property(KeyframeDataPoint, 'molang', 'x', { label: 'X', condition: point => point.keyframe.transform, default: point => (point && point.keyframe.channel == 'scale' ? '1' : '0') });
|
|
|
|
new Property(KeyframeDataPoint, 'molang', 'y', { label: 'Y', condition: point => point.keyframe.transform, default: point => (point && point.keyframe.channel == 'scale' ? '1' : '0') });
|
|
|
|
new Property(KeyframeDataPoint, 'molang', 'z', { label: 'Z', condition: point => point.keyframe.transform, default: point => (point && point.keyframe.channel == 'scale' ? '1' : '0') });
|
2020-10-08 04:00:06 +08:00
|
|
|
new Property(KeyframeDataPoint, 'string', 'effect', {label: tl('data.effect'), condition: point => ['particle', 'sound'].includes(point.keyframe.channel)});
|
|
|
|
new Property(KeyframeDataPoint, 'string', 'locator',{label: tl('data.locator'), condition: point => 'particle' == point.keyframe.channel});
|
|
|
|
new Property(KeyframeDataPoint, 'molang', 'script', {label: tl('timeline.pre_effect_script'), condition: point => ['particle', 'timeline'].includes(point.keyframe.channel), default: ''});
|
|
|
|
new Property(KeyframeDataPoint, 'string', 'file', {exposed: false, condition: point => ['particle', 'sound'].includes(point.keyframe.channel)});
|
2020-10-01 19:07:45 +08:00
|
|
|
|
2020-09-09 00:40:22 +08:00
|
|
|
class Keyframe {
|
2022-07-09 22:08:59 +08:00
|
|
|
constructor(data, uuid, animator) {
|
2020-09-09 00:40:22 +08:00
|
|
|
this.type = 'keyframe'
|
2020-09-26 22:05:23 +08:00
|
|
|
this.uuid = (uuid && isUUID(uuid)) ? uuid : guid();
|
|
|
|
this.channel == 'rotation'
|
2020-09-09 00:40:22 +08:00
|
|
|
this.selected = 0;
|
2020-09-26 22:05:23 +08:00
|
|
|
this.data_points = []
|
2020-09-23 01:17:28 +08:00
|
|
|
|
2022-06-18 18:56:46 +08:00
|
|
|
if (typeof data === 'object') {
|
|
|
|
Merge.string(this, data, 'channel')
|
2022-07-09 22:08:59 +08:00
|
|
|
this.animator = animator;
|
|
|
|
this.transform = !!(this.animator.channels[this.channel]).transform;
|
2022-06-18 18:56:46 +08:00
|
|
|
this.data_points.push(new KeyframeDataPoint(this));
|
|
|
|
}
|
|
|
|
|
2020-09-23 01:17:28 +08:00
|
|
|
for (var key in Keyframe.properties) {
|
|
|
|
Keyframe.properties[key].reset(this);
|
|
|
|
}
|
2020-09-26 20:03:09 +08:00
|
|
|
|
2020-09-09 00:40:22 +08:00
|
|
|
if (typeof data === 'object') {
|
|
|
|
this.extend(data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
extend(data) {
|
2020-09-23 01:17:28 +08:00
|
|
|
for (var key in Keyframe.properties) {
|
|
|
|
Keyframe.properties[key].merge(this, data)
|
|
|
|
}
|
2020-09-26 19:57:58 +08:00
|
|
|
if (data.data_points && data.data_points.length) {
|
2020-09-27 05:29:28 +08:00
|
|
|
this.data_points.splice(data.data_points.length);
|
2020-09-26 19:57:58 +08:00
|
|
|
data.data_points.forEach((point, i) => {
|
2020-09-26 22:05:23 +08:00
|
|
|
if (!this.data_points[i]) {
|
2020-09-26 23:56:14 +08:00
|
|
|
this.data_points.push(new KeyframeDataPoint(this));
|
2020-09-26 22:05:23 +08:00
|
|
|
}
|
2020-09-26 19:57:58 +08:00
|
|
|
let this_point = this.data_points[i];
|
2020-09-27 04:20:19 +08:00
|
|
|
this_point.extend(point)
|
2020-09-26 19:57:58 +08:00
|
|
|
})
|
2020-10-22 00:40:07 +08:00
|
|
|
} else {
|
|
|
|
// Direct extending
|
|
|
|
for (var key in KeyframeDataPoint.properties) {
|
|
|
|
KeyframeDataPoint.properties[key].merge(this.data_points[0], data)
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
2020-09-26 19:57:58 +08:00
|
|
|
get(axis, data_point = 0) {
|
2020-10-18 04:46:42 +08:00
|
|
|
if (data_point) data_point = Math.clamp(data_point, 0, this.data_points.length-1);
|
2020-09-26 19:57:58 +08:00
|
|
|
data_point = this.data_points[data_point];
|
|
|
|
if (!data_point || !data_point[axis]) {
|
2020-09-09 00:40:22 +08:00
|
|
|
return this.transform ? 0 : '';
|
2020-09-26 19:57:58 +08:00
|
|
|
} else if (!isNaN(data_point[axis])) {
|
|
|
|
let num = parseFloat(data_point[axis]);
|
2020-09-09 00:40:22 +08:00
|
|
|
return isNaN(num) ? 0 : num;
|
|
|
|
} else {
|
2020-09-26 19:57:58 +08:00
|
|
|
return data_point[axis]
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
|
|
|
}
|
2020-09-26 19:57:58 +08:00
|
|
|
calc(axis, data_point = 0) {
|
2020-10-18 04:46:42 +08:00
|
|
|
if (data_point) data_point = Math.clamp(data_point, 0, this.data_points.length-1);
|
2020-09-26 19:57:58 +08:00
|
|
|
data_point = this.data_points[data_point];
|
2022-01-03 01:54:20 +08:00
|
|
|
let last_value = Animator._last_values[this.channel] && Animator._last_values[this.channel][axis];
|
2022-05-20 01:00:40 +08:00
|
|
|
let result = Animator.MolangParser.parse(data_point && data_point[axis], {
|
|
|
|
'this': last_value,
|
|
|
|
'query.anim_time': this.animator.animation.time
|
|
|
|
});
|
2021-05-22 15:51:37 +08:00
|
|
|
return result;
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
2020-09-21 05:03:28 +08:00
|
|
|
set(axis, value, data_point = 0) {
|
2020-10-18 04:46:42 +08:00
|
|
|
if (data_point) data_point = Math.clamp(data_point, 0, this.data_points.length-1);
|
2020-09-21 05:03:28 +08:00
|
|
|
if (this.data_points[data_point]) {
|
2021-08-12 05:46:19 +08:00
|
|
|
if (this.uniform) {
|
|
|
|
this.data_points[data_point].x = value;
|
|
|
|
this.data_points[data_point].y = value;
|
|
|
|
this.data_points[data_point].z = value;
|
|
|
|
} else {
|
|
|
|
this.data_points[data_point][axis] = value;
|
|
|
|
}
|
2020-09-21 05:03:28 +08:00
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
return this;
|
|
|
|
}
|
2020-09-21 05:03:28 +08:00
|
|
|
offset(axis, amount, data_point = 0) {
|
2020-10-18 04:46:42 +08:00
|
|
|
if (data_point) data_point = Math.clamp(data_point, 0, this.data_points.length-1);
|
2020-09-09 00:40:22 +08:00
|
|
|
var value = this.get(axis)
|
|
|
|
if (!value || value === '0') {
|
2020-09-21 05:03:28 +08:00
|
|
|
this.set(axis, amount, data_point)
|
2020-09-09 00:40:22 +08:00
|
|
|
return amount;
|
|
|
|
}
|
|
|
|
if (typeof value === 'number') {
|
2020-09-21 05:03:28 +08:00
|
|
|
this.set(axis, value+amount, data_point)
|
2020-09-09 00:40:22 +08:00
|
|
|
return value+amount
|
|
|
|
}
|
2020-09-29 23:14:26 +08:00
|
|
|
var start = value.match(/^-?\s*\d+(\.\d+)?\s*(\+|-)/)
|
2020-09-09 00:40:22 +08:00
|
|
|
if (start) {
|
2021-02-14 01:41:55 +08:00
|
|
|
var number = parseFloat( start[0].substr(0, start[0].length-1) ) + amount;
|
|
|
|
if (number == 0) {
|
|
|
|
value = value.substr(start[0].length + (value[start[0].length-1] == '+' ? 0 : -1));
|
2022-06-25 17:14:23 +08:00
|
|
|
value = value.trim();
|
2021-02-14 01:41:55 +08:00
|
|
|
} else {
|
|
|
|
value = trimFloatNumber(number) + (start[0].substr(-2, 1) == ' ' ? ' ' : '') + value.substr(start[0].length-1);
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
} else {
|
|
|
|
|
|
|
|
var end = value.match(/(\+|-)\s*\d*(\.\d+)?\s*$/)
|
|
|
|
if (end) {
|
|
|
|
var number = (parseFloat( end[0] ) + amount)
|
|
|
|
value = value.substr(0, end.index) + ((number.toString()).substr(0,1)=='-'?'':'+') + trimFloatNumber(number)
|
|
|
|
} else {
|
|
|
|
value = trimFloatNumber(amount) +(value.substr(0,1)=='-'?'':'+')+ value
|
|
|
|
}
|
|
|
|
}
|
2020-09-21 05:03:28 +08:00
|
|
|
this.set(axis, value, data_point)
|
2020-09-09 00:40:22 +08:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
flip(axis) {
|
2020-09-26 19:57:58 +08:00
|
|
|
if (!this.transform || this.channel == 'scale') return this;
|
2020-09-09 00:40:22 +08:00
|
|
|
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})`;
|
|
|
|
}
|
|
|
|
}
|
2020-09-26 19:57:58 +08:00
|
|
|
this.data_points.forEach((data_point, data_point_i) => {
|
|
|
|
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, data_point_i)), data_point_i)
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
2020-09-26 19:57:58 +08:00
|
|
|
} else if (this.channel == 'position') {
|
|
|
|
let l = getAxisLetter(axis)
|
|
|
|
this.set(l, negate(this.get(l, data_point_i)), data_point_i)
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
2020-09-26 19:57:58 +08:00
|
|
|
})
|
2020-09-09 00:40:22 +08:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
getLerp(other, axis, amount, allow_expression) {
|
2020-09-26 22:05:23 +08:00
|
|
|
let this_data_point = (this.data_points.length > 1 && this.time < other.time) ? 1 : 0;
|
|
|
|
let other_data_point = (other.data_points.length > 1 && this.time > other.time) ? 1 : 0;
|
|
|
|
if (allow_expression && this.get(axis, this_data_point) === other.get(axis, other_data_point)) {
|
2022-02-12 02:29:44 +08:00
|
|
|
return this.get(axis, this_data_point);
|
2020-09-09 00:40:22 +08:00
|
|
|
} else {
|
2020-09-26 22:05:23 +08:00
|
|
|
let calc = this.calc(axis, this_data_point);
|
|
|
|
return calc + (other.calc(axis, other_data_point) - calc) * amount;
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
|
|
|
}
|
2020-09-27 19:01:51 +08:00
|
|
|
getCatmullromLerp(before_plus, before, after, after_plus, axis, alpha) {
|
2020-09-27 16:52:31 +08:00
|
|
|
var vectors = [];
|
|
|
|
|
2020-10-18 04:46:42 +08:00
|
|
|
if (before_plus && before.data_points.length == 1) vectors.push(new THREE.Vector2(before_plus.time, before_plus.calc(axis, 1)))
|
|
|
|
if (before) vectors.push(new THREE.Vector2(before.time, before.calc(axis, 1)))
|
2020-09-27 16:52:31 +08:00
|
|
|
if (after) vectors.push(new THREE.Vector2(after.time, after.calc(axis, 0)))
|
2020-10-18 04:46:42 +08:00
|
|
|
if (after_plus && after.data_points.length == 1) vectors.push(new THREE.Vector2(after_plus.time, after_plus.calc(axis, 0)))
|
2020-09-27 16:52:31 +08:00
|
|
|
|
|
|
|
var curve = new THREE.SplineCurve(vectors);
|
2020-09-27 19:01:51 +08:00
|
|
|
let time = (alpha + (before_plus ? 1 : 0)) / (vectors.length-1);
|
2020-09-27 16:52:31 +08:00
|
|
|
|
|
|
|
return curve.getPoint(time).y;
|
|
|
|
}
|
2020-09-26 22:05:23 +08:00
|
|
|
getArray(data_point = 0) {
|
2020-09-09 00:40:22 +08:00
|
|
|
var arr = [
|
2020-09-26 22:05:23 +08:00
|
|
|
this.get('x', data_point),
|
|
|
|
this.get('y', data_point),
|
|
|
|
this.get('z', data_point),
|
2020-09-09 00:40:22 +08:00
|
|
|
]
|
2020-09-15 17:27:49 +08:00
|
|
|
arr.forEach((n, i) => {
|
|
|
|
if (n.replace) arr[i] = n.replace(/\n/g, '');
|
|
|
|
})
|
2020-09-09 00:40:22 +08:00
|
|
|
return arr;
|
|
|
|
}
|
2021-12-02 04:11:41 +08:00
|
|
|
getFixed(data_point = 0, do_quaternion = true) {
|
2020-09-09 00:40:22 +08:00
|
|
|
if (this.channel === 'rotation') {
|
|
|
|
let fix = this.animator.group.mesh.fix_rotation;
|
2021-12-02 04:11:41 +08:00
|
|
|
let euler = new THREE.Euler(
|
2022-07-02 04:47:29 +08:00
|
|
|
(fix.x||0) - Math.degToRad(this.calc('x', data_point)),
|
|
|
|
(fix.y||0) - Math.degToRad(this.calc('y', data_point)),
|
|
|
|
(fix.z||0) + Math.degToRad(this.calc('z', data_point)),
|
2020-09-09 00:40:22 +08:00
|
|
|
'ZYX'
|
2021-12-02 04:11:41 +08:00
|
|
|
)
|
|
|
|
return do_quaternion ? new THREE.Quaternion().setFromEuler(euler) : euler;
|
2020-09-09 00:40:22 +08:00
|
|
|
} else if (this.channel === 'position') {
|
|
|
|
let fix = this.animator.group.mesh.fix_position;
|
|
|
|
return new THREE.Vector3(
|
2020-09-26 22:05:23 +08:00
|
|
|
fix.x - this.calc('x', data_point),
|
|
|
|
fix.y + this.calc('y', data_point),
|
|
|
|
fix.z + this.calc('z', data_point)
|
2020-09-09 00:40:22 +08:00
|
|
|
)
|
|
|
|
} else if (this.channel === 'scale') {
|
|
|
|
return new THREE.Vector3(
|
2020-09-26 22:05:23 +08:00
|
|
|
this.calc('x', data_point),
|
|
|
|
this.calc('y', data_point),
|
|
|
|
this.calc('z', data_point)
|
2020-09-09 00:40:22 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getTimecodeString() {
|
2020-09-14 18:44:43 +08:00
|
|
|
let timecode = trimFloatNumber(Timeline.snapTime(this.time, this.animator.animation)).toString();
|
2020-09-09 00:40:22 +08:00
|
|
|
if (!timecode.includes('.')) {
|
|
|
|
timecode += '.0';
|
|
|
|
}
|
|
|
|
return timecode;
|
|
|
|
}
|
2021-12-05 22:39:42 +08:00
|
|
|
getPreviousKeyframe() {
|
|
|
|
let keyframes = this.animator[this.channel].filter(kf => kf.time < this.time);
|
|
|
|
keyframes.sort((a, b) => b.time - a.time);
|
|
|
|
return keyframes[0];
|
|
|
|
}
|
2020-09-26 22:05:23 +08:00
|
|
|
compileBedrockKeyframe() {
|
|
|
|
if (this.transform) {
|
2021-12-05 22:39:42 +08:00
|
|
|
|
|
|
|
if (this.interpolation != 'linear' && this.interpolation != 'step') {
|
2022-05-20 23:00:28 +08:00
|
|
|
let previous = this.getPreviousKeyframe();
|
|
|
|
let include_pre = (!previous && this.time > 0) || (previous && previous.interpolation != 'catmullrom')
|
2021-03-05 19:55:49 +08:00
|
|
|
return {
|
2022-05-20 23:00:28 +08:00
|
|
|
pre: include_pre ? this.getArray(0) : undefined,
|
|
|
|
post: this.getArray(include_pre ? 1 : 0),
|
2021-03-05 19:55:49 +08:00
|
|
|
lerp_mode: this.interpolation,
|
|
|
|
}
|
|
|
|
} else if (this.data_points.length == 1) {
|
2021-12-05 22:39:42 +08:00
|
|
|
let previous = this.getPreviousKeyframe();
|
|
|
|
if (previous && previous.interpolation == 'step') {
|
|
|
|
return new oneLiner({
|
|
|
|
pre: previous.getArray(1),
|
|
|
|
post: this.getArray(),
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
return this.getArray();
|
|
|
|
}
|
2020-09-26 22:05:23 +08:00
|
|
|
} else {
|
2021-02-09 06:31:20 +08:00
|
|
|
return new oneLiner({
|
2020-09-26 22:05:23 +08:00
|
|
|
pre: this.getArray(0),
|
2020-09-27 05:07:44 +08:00
|
|
|
post: this.getArray(1),
|
2021-02-09 06:31:20 +08:00
|
|
|
})
|
2020-09-26 22:05:23 +08:00
|
|
|
}
|
|
|
|
} else if (this.channel == 'timeline') {
|
2020-10-01 19:07:45 +08:00
|
|
|
let scripts = [];
|
2020-09-27 05:07:44 +08:00
|
|
|
this.data_points.forEach(data_point => {
|
2020-10-01 19:07:45 +08:00
|
|
|
if (data_point.script) {
|
|
|
|
scripts.push(...data_point.script.split('\n'));
|
2020-09-27 05:07:44 +08:00
|
|
|
}
|
|
|
|
})
|
2022-06-25 17:14:23 +08:00
|
|
|
scripts = scripts.filter(script => !!script.replace(/[\n\s;.]+/g, ''));
|
|
|
|
scripts = scripts.map(line => line.match(/;\s*$/) ? line : (line+';'));
|
2020-10-01 19:07:45 +08:00
|
|
|
return scripts.length <= 1 ? scripts[0] : scripts;
|
2020-09-26 22:05:23 +08:00
|
|
|
} else {
|
|
|
|
let points = [];
|
|
|
|
this.data_points.forEach(data_point => {
|
2020-09-27 05:07:44 +08:00
|
|
|
if (data_point.effect) {
|
2022-02-02 03:28:51 +08:00
|
|
|
let script = data_point.script || undefined;
|
2022-02-05 22:39:11 +08:00
|
|
|
if (script && !script.replace(/[\n\s;.]+/g, '')) script = undefined;
|
2020-09-27 05:07:44 +08:00
|
|
|
if (script && !script.match(/;$/)) script += ';';
|
|
|
|
points.push({
|
|
|
|
effect: data_point.effect,
|
|
|
|
locator: data_point.locator || undefined,
|
|
|
|
pre_effect_script: script,
|
|
|
|
})
|
2020-09-26 22:05:23 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
return points.length <= 1 ? points[0] : points;
|
|
|
|
}
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
replaceOthers(save) {
|
|
|
|
var scope = this;
|
|
|
|
var arr = this.animator[this.channel];
|
|
|
|
arr.forEach(kf => {
|
|
|
|
if (kf != scope && Math.abs(kf.time - scope.time) < 0.0001) {
|
|
|
|
save.push(kf);
|
|
|
|
kf.remove();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
select(event) {
|
|
|
|
var scope = this;
|
|
|
|
if (Timeline.dragging_keyframes) {
|
|
|
|
Timeline.dragging_keyframes = false
|
|
|
|
return this;
|
|
|
|
}
|
2021-08-03 17:04:40 +08:00
|
|
|
if (!event || (!event.shiftKey && !event.ctrlOrCmd && !Pressing.overrides.ctrl && !Pressing.overrides.shift)) {
|
2020-09-09 00:40:22 +08:00
|
|
|
Timeline.selected.forEach(function(kf) {
|
|
|
|
kf.selected = false
|
|
|
|
})
|
|
|
|
Timeline.selected.empty()
|
|
|
|
}
|
2021-08-03 17:04:40 +08:00
|
|
|
if (event && (event.shiftKey || Pressing.overrides.shift) && Timeline.selected.length) {
|
2020-09-09 00:40:22 +08:00
|
|
|
var last = Timeline.selected[Timeline.selected.length-1]
|
|
|
|
if (last && last.channel === scope.channel && last.animator == scope.animator) {
|
|
|
|
Timeline.keyframes.forEach((kf) => {
|
|
|
|
if (kf.channel === scope.channel &&
|
|
|
|
kf.animator === scope.animator &&
|
|
|
|
Math.isBetween(kf.time, last.time, scope.time) &&
|
|
|
|
!kf.selected
|
|
|
|
) {
|
|
|
|
kf.selected = true
|
|
|
|
Timeline.selected.push(kf)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Timeline.selected.safePush(this);
|
2020-09-15 23:14:37 +08:00
|
|
|
if (Timeline.selected.length == 1 && Timeline.selected[0].animator.selected == false) {
|
2020-09-09 00:40:22 +08:00
|
|
|
Timeline.selected[0].animator.select()
|
|
|
|
}
|
2021-02-09 06:31:20 +08:00
|
|
|
this.selected = true
|
|
|
|
TickUpdates.keyframe_selection = true;
|
|
|
|
|
|
|
|
if (this.transform) Timeline.vue.graph_editor_channel = this.channel;
|
2020-09-09 00:40:22 +08:00
|
|
|
|
|
|
|
var select_tool = true;
|
|
|
|
Timeline.selected.forEach(kf => {
|
|
|
|
if (kf.channel != scope.channel) select_tool = false;
|
|
|
|
})
|
|
|
|
if (select_tool) {
|
|
|
|
switch (this.channel) {
|
|
|
|
case 'rotation': BarItems.rotate_tool.select(); break;
|
|
|
|
case 'position': BarItems.move_tool.select(); break;
|
|
|
|
case 'scale': BarItems.resize_tool.select(); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
callPlayhead() {
|
|
|
|
Timeline.setTime(this.time)
|
|
|
|
Animator.preview()
|
|
|
|
return this;
|
|
|
|
}
|
2022-08-23 06:19:57 +08:00
|
|
|
|
|
|
|
showInTimeline() {
|
|
|
|
if (!this.animator.animation.selected) {
|
|
|
|
this.animator.animation.select();
|
|
|
|
}
|
|
|
|
this.animator.addToTimeline();
|
|
|
|
this.select();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
let element = $(`.keyframe#${this.uuid}`);
|
|
|
|
let offset = element.offset();
|
|
|
|
if (!offset) return;
|
|
|
|
|
|
|
|
let body = document.getElementById('timeline_body');
|
|
|
|
let body_offset = $(body).offset();
|
|
|
|
|
|
|
|
$(body).animate({
|
|
|
|
scrollLeft: (offset.left - body_offset.left - 300),
|
|
|
|
scrollTop: (offset.top - body_offset.top - 120)
|
|
|
|
}, 200);
|
|
|
|
})
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
showContextMenu(event) {
|
|
|
|
if (!this.selected) {
|
|
|
|
this.select();
|
2020-10-17 01:44:58 +08:00
|
|
|
updateKeyframeSelection();
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
|
|
|
this.menu.open(event, this);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
remove() {
|
|
|
|
if (this.animator) {
|
|
|
|
this.animator[this.channel].remove(this)
|
|
|
|
}
|
|
|
|
Timeline.selected.remove(this)
|
|
|
|
}
|
2020-09-12 22:55:32 +08:00
|
|
|
forSelected(fc, undo_tag) {
|
|
|
|
if (Timeline.selected.length <= 1 || !Timeline.selected.includes(this)) {
|
|
|
|
var edited = [this]
|
|
|
|
} else {
|
|
|
|
var edited = Timeline.selected
|
|
|
|
}
|
|
|
|
if (undo_tag) {
|
|
|
|
Undo.initEdit({keyframes: edited})
|
|
|
|
}
|
|
|
|
for (var i = 0; i < edited.length; i++) {
|
|
|
|
fc(edited[i])
|
|
|
|
}
|
|
|
|
if (undo_tag) {
|
|
|
|
Undo.finishEdit(undo_tag)
|
|
|
|
}
|
|
|
|
return edited;
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
getUndoCopy(save) {
|
|
|
|
var copy = {
|
|
|
|
animator: save ? undefined : this.animator && this.animator.uuid,
|
|
|
|
channel: this.channel,
|
2020-09-26 22:05:23 +08:00
|
|
|
data_points: []
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
2021-02-27 22:38:49 +08:00
|
|
|
if (!save && this.animator instanceof EffectAnimator) {
|
|
|
|
copy.animator = 'effects';
|
|
|
|
}
|
2020-09-27 23:03:28 +08:00
|
|
|
if (save) copy.uuid = this.uuid;
|
2020-09-23 01:17:28 +08:00
|
|
|
for (var key in Keyframe.properties) {
|
2020-09-23 03:54:31 +08:00
|
|
|
Keyframe.properties[key].copy(this, copy)
|
2020-09-23 01:17:28 +08:00
|
|
|
}
|
2020-09-26 22:05:23 +08:00
|
|
|
this.data_points.forEach(data_point => {
|
2020-10-01 19:07:45 +08:00
|
|
|
copy.data_points.push(data_point.getUndoCopy())
|
2020-09-26 22:05:23 +08:00
|
|
|
})
|
2020-09-09 00:40:22 +08:00
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Keyframe.prototype.menu = new Menu([
|
|
|
|
'change_keyframe_file',
|
|
|
|
'_',
|
2021-08-12 05:46:19 +08:00
|
|
|
'keyframe_uniform',
|
2020-09-27 16:01:39 +08:00
|
|
|
'keyframe_interpolation',
|
2022-06-25 22:43:11 +08:00
|
|
|
{name: 'menu.cube.color', icon: 'color_lens', children() {
|
|
|
|
return [
|
|
|
|
{icon: 'bubble_chart', name: 'generic.unset', click: function(kf) {kf.forSelected(kf2 => {kf2.color = -1}, 'change color')}},
|
|
|
|
...markerColors.map((color, i) => {return {
|
|
|
|
icon: 'bubble_chart',
|
|
|
|
color: color.standard,
|
|
|
|
name: color.name || 'cube.color.'+color.id,
|
|
|
|
click(kf) {
|
|
|
|
kf.forSelected(function(kf2){kf2.color = i}, 'change color')
|
|
|
|
}
|
|
|
|
}})
|
|
|
|
];
|
|
|
|
}},
|
2020-09-09 00:40:22 +08:00
|
|
|
'copy',
|
|
|
|
'delete',
|
|
|
|
])
|
2020-09-23 01:17:28 +08:00
|
|
|
new Property(Keyframe, 'number', 'time')
|
|
|
|
new Property(Keyframe, 'number', 'color', {default: -1})
|
2022-08-04 03:47:43 +08:00
|
|
|
new Property(Keyframe, 'boolean', 'uniform', {condition: keyframe => keyframe.channel == 'scale', default: settings.uniform_keyframe.value})
|
2020-09-27 16:01:39 +08:00
|
|
|
new Property(Keyframe, 'string', 'interpolation', {default: 'linear'})
|
2020-09-26 04:06:03 +08:00
|
|
|
Keyframe.selected = [];
|
2020-09-27 16:52:31 +08:00
|
|
|
Keyframe.interpolation = {
|
|
|
|
linear: 'linear',
|
|
|
|
catmullrom: 'catmullrom',
|
2021-12-05 22:39:42 +08:00
|
|
|
step: 'step',
|
2020-09-27 16:52:31 +08:00
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
|
|
|
|
// Misc Functions
|
2020-09-21 05:03:28 +08:00
|
|
|
function updateKeyframeValue(axis, value, data_point) {
|
2020-09-09 00:40:22 +08:00
|
|
|
Timeline.selected.forEach(function(kf) {
|
2021-08-12 05:46:19 +08:00
|
|
|
if (axis == 'uniform' && kf.channel == 'scale') kf.uniform = true;
|
2020-09-21 05:03:28 +08:00
|
|
|
kf.set(axis, value, data_point);
|
2020-09-09 00:40:22 +08:00
|
|
|
})
|
|
|
|
if (!['effect', 'locator', 'script'].includes(axis)) {
|
|
|
|
Animator.preview();
|
2021-02-13 21:32:31 +08:00
|
|
|
updateKeyframeSelection();
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
function updateKeyframeSelection() {
|
2020-09-14 00:31:46 +08:00
|
|
|
Timeline.keyframes.forEach(kf => {
|
|
|
|
if (kf.selected && !Timeline.selected.includes(kf)) {
|
|
|
|
kf.selected = false;
|
|
|
|
}
|
|
|
|
})
|
2020-09-13 21:34:12 +08:00
|
|
|
if (Timeline.selected.length) {
|
2020-09-09 00:40:22 +08:00
|
|
|
BarItems.slider_keyframe_time.update()
|
2020-09-27 16:01:39 +08:00
|
|
|
BarItems.keyframe_interpolation.set(Timeline.selected[0].interpolation)
|
2021-08-12 05:46:19 +08:00
|
|
|
if (BarItems.keyframe_uniform.value != !!Timeline.selected[0].uniform) {
|
|
|
|
BarItems.keyframe_uniform.value = !!Timeline.selected[0].uniform;
|
|
|
|
BarItems.keyframe_uniform.updateEnabledState();
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
2022-07-09 22:08:59 +08:00
|
|
|
if (settings.motion_trails.value && Modes.animate && Animation.selected && (Group.selected || (Outliner.selected[0] && Outliner.selected[0].constructor.animator) || Project.motion_trail_lock)) {
|
2020-10-10 21:17:43 +08:00
|
|
|
Animator.showMotionTrail();
|
2020-10-14 01:56:55 +08:00
|
|
|
} else if (Animator.motion_trail.parent) {
|
|
|
|
Animator.motion_trail.children.forEachReverse(child => {
|
|
|
|
Animator.motion_trail.remove(child);
|
|
|
|
})
|
2020-10-10 21:17:43 +08:00
|
|
|
}
|
2021-11-30 06:50:51 +08:00
|
|
|
if (Timeline.selected.length >= 2) {
|
|
|
|
Interface.addSuggestedModifierKey('ctrl', 'modifier_actions.stretch_keyframes');
|
|
|
|
} else {
|
|
|
|
Interface.removeSuggestedModifierKey('ctrl', 'modifier_actions.stretch_keyframes');
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
BARS.updateConditions()
|
|
|
|
Blockbench.dispatchEvent('update_keyframe_selection');
|
|
|
|
}
|
|
|
|
function selectAllKeyframes() {
|
2020-09-15 20:21:04 +08:00
|
|
|
if (!Animation.selected) return;
|
2020-09-09 00:40:22 +08:00
|
|
|
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
|
|
|
|
})
|
|
|
|
updateKeyframeSelection()
|
|
|
|
}
|
2022-06-25 17:14:23 +08:00
|
|
|
function unselectAllKeyframes() {
|
|
|
|
if (!Animation.selected) return;
|
|
|
|
Timeline.keyframes.forEach((kf) => {
|
|
|
|
Timeline.selected.remove(kf)
|
|
|
|
kf.selected = false;
|
|
|
|
})
|
|
|
|
updateKeyframeSelection()
|
|
|
|
}
|
2020-09-09 00:40:22 +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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateKeyframeSelection()
|
|
|
|
Animator.preview()
|
2021-06-06 15:28:22 +08:00
|
|
|
Undo.finishEdit('Remove keyframes')
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
|
|
|
|
2021-11-21 19:07:43 +08:00
|
|
|
//Clipbench
|
|
|
|
Object.assign(Clipbench, {
|
|
|
|
setKeyframes() {
|
|
|
|
|
|
|
|
var keyframes = Timeline.selected;
|
|
|
|
|
|
|
|
Clipbench.keyframes = []
|
|
|
|
if (!keyframes || keyframes.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var first = keyframes[0];
|
|
|
|
var single_animator;
|
|
|
|
keyframes.forEach(function(kf) {
|
|
|
|
if (kf.time < first.time) {
|
|
|
|
first = kf
|
|
|
|
}
|
|
|
|
if (single_animator && single_animator !== kf.animator.uuid) {
|
|
|
|
single_animator = false;
|
|
|
|
} else if (single_animator == undefined) {
|
|
|
|
single_animator = kf.animator.uuid;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
if (isApp) {
|
|
|
|
clipboard.writeHTML(JSON.stringify({type: 'keyframes', content: Clipbench.keyframes}))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
pasteKeyframes() {
|
|
|
|
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 (!Animation.selected) return;
|
|
|
|
var keyframes = [];
|
|
|
|
Undo.initEdit({keyframes});
|
|
|
|
Timeline.selected.empty();
|
|
|
|
Timeline.keyframes.forEach((kf) => {
|
|
|
|
kf.selected = false;
|
|
|
|
})
|
|
|
|
Clipbench.keyframes.forEach(function(data, i) {
|
|
|
|
|
|
|
|
if (data.animator) {
|
|
|
|
var animator = Animation.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)
|
|
|
|
if (!kf) return;
|
|
|
|
keyframes.push(kf);
|
|
|
|
kf.selected = true;
|
2022-05-07 05:43:50 +08:00
|
|
|
Property.resetUniqueValues(Keyframe, kf);
|
2021-11-21 19:07:43 +08:00
|
|
|
Timeline.selected.push(kf);
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
TickUpdates.keyframe_selection = true;
|
|
|
|
Animator.preview()
|
|
|
|
Undo.finishEdit('Paste keyframes');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-09-09 00:40:22 +08:00
|
|
|
BARS.defineActions(function() {
|
|
|
|
new Action('add_keyframe', {
|
|
|
|
icon: 'add_circle',
|
|
|
|
category: 'animation',
|
|
|
|
condition: {modes: ['animate']},
|
2021-02-13 21:32:31 +08:00
|
|
|
keybind: new Keybind({key: 'q', shift: null}),
|
2020-09-09 00:40:22 +08:00
|
|
|
click: function (event) {
|
|
|
|
var animator = Timeline.selected_animator;
|
|
|
|
if (!animator) return;
|
2021-11-20 02:36:19 +08:00
|
|
|
var channel = Object.keys(animator.channels)[0];
|
|
|
|
if (Toolbox.selected.id == 'rotate_tool' && animator.channels['rotation']) channel = 'rotation';
|
|
|
|
if (Toolbox.selected.id == 'move_tool' && animator.channels['position']) channel = 'position';
|
|
|
|
if (Toolbox.selected.id == 'resize_tool' && animator.channels['scale']) channel = 'scale';
|
|
|
|
if (Timeline.vue.graph_editor_open && Prop.active_panel == 'timeline' && animator.channels[Timeline.vue.graph_editor_channel]) {
|
|
|
|
channel = Timeline.vue.graph_editor_channel;
|
|
|
|
}
|
2021-08-03 17:04:40 +08:00
|
|
|
animator.createKeyframe((event && (event.shiftKey || Pressing.overrides.shift)) ? {} : null, Timeline.time, channel, true);
|
|
|
|
if (event && (event.shiftKey || Pressing.overrides.shift)) {
|
2020-09-09 00:40:22 +08:00
|
|
|
Animator.preview();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
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()
|
2021-04-12 02:53:30 +08:00
|
|
|
BarItems.slider_keyframe_time.update()
|
2021-06-06 15:28:22 +08:00
|
|
|
Undo.finishEdit('Move keyframes back')
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
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))
|
|
|
|
})
|
2021-11-20 02:36:19 +08:00
|
|
|
Animation.selected.setLength();
|
2020-09-09 00:40:22 +08:00
|
|
|
Animator.preview()
|
2021-04-12 02:53:30 +08:00
|
|
|
BarItems.slider_keyframe_time.update()
|
2021-06-06 15:28:22 +08:00
|
|
|
Undo.finishEdit('Move keyframes forwards')
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
new Action('previous_keyframe', {
|
|
|
|
icon: 'fa-arrow-circle-left',
|
|
|
|
category: 'animation',
|
|
|
|
condition: {modes: ['animate']},
|
|
|
|
click: function () {
|
|
|
|
|
|
|
|
var time = Timeline.time;
|
|
|
|
function getDelta(kf, abs) {
|
|
|
|
return kf.time - time
|
|
|
|
}
|
|
|
|
let animator = Timeline.selected_animator
|
|
|
|
|| (Timeline.selected[0] && Timeline.selected[0].animator)
|
|
|
|
|| Timeline.animators[0];
|
2021-11-20 02:36:19 +08:00
|
|
|
let channel = Timeline.selected[0] ? Timeline.selected[0].channel : (animator && Object.keys(animator.channels)[0]);
|
2020-09-09 00:40:22 +08:00
|
|
|
|
|
|
|
var matches = []
|
|
|
|
for (var kf of Timeline.keyframes) {
|
|
|
|
if ((!animator || animator == kf.animator) && (!channel || channel == kf.channel)) {
|
|
|
|
let delta = getDelta(kf)
|
|
|
|
if (delta < 0) {
|
|
|
|
matches.push(kf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
matches.sort((a, b) => {
|
|
|
|
return Math.abs(getDelta(a)) - Math.abs(getDelta(b))
|
|
|
|
})
|
|
|
|
var kf = matches[0]
|
|
|
|
if (kf) {
|
|
|
|
kf.select().callPlayhead()
|
|
|
|
} else {
|
|
|
|
if (Timeline.selected.length) {
|
|
|
|
selectAllKeyframes()
|
|
|
|
selectAllKeyframes()
|
|
|
|
}
|
|
|
|
Timeline.setTime(0)
|
|
|
|
Animator.preview()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
new Action('next_keyframe', {
|
|
|
|
icon: 'fa-arrow-circle-right',
|
|
|
|
category: 'animation',
|
|
|
|
condition: {modes: ['animate']},
|
|
|
|
click: function () {
|
|
|
|
|
|
|
|
var time = Timeline.time;
|
|
|
|
function getDelta(kf, abs) {
|
|
|
|
return kf.time - time
|
|
|
|
}
|
|
|
|
let animator = Timeline.selected_animator
|
|
|
|
|| (Timeline.selected[0] && Timeline.selected[0].animator)
|
|
|
|
|| Timeline.animators[0];
|
2021-11-20 02:36:19 +08:00
|
|
|
let channel = Timeline.selected[0] ? Timeline.selected[0].channel : (animator && Object.keys(animator.channels)[0]);
|
2020-09-09 00:40:22 +08:00
|
|
|
|
|
|
|
var matches = []
|
|
|
|
for (var kf of Timeline.keyframes) {
|
|
|
|
if ((!animator || animator == kf.animator) && (!channel || channel == kf.channel)) {
|
|
|
|
let delta = getDelta(kf)
|
|
|
|
if (delta > 0) {
|
|
|
|
matches.push(kf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
matches.sort((a, b) => {
|
|
|
|
return Math.abs(getDelta(a)) - Math.abs(getDelta(b))
|
|
|
|
})
|
|
|
|
var kf = matches[0]
|
|
|
|
if (kf) {
|
|
|
|
kf.select().callPlayhead()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
new NumSlider('slider_keyframe_time', {
|
|
|
|
category: 'animation',
|
|
|
|
condition: () => Animator.open && Timeline.selected.length,
|
|
|
|
getInterval(event) {
|
2021-05-29 05:42:35 +08:00
|
|
|
if ((event && event.shiftKey) || Pressing.overrides.shift) return 1;
|
2020-09-14 18:44:43 +08:00
|
|
|
return Timeline.getStep()
|
2020-09-09 00:40:22 +08:00
|
|
|
},
|
|
|
|
get: function() {
|
|
|
|
return Timeline.selected[0] ? Timeline.selected[0].time : 0
|
|
|
|
},
|
|
|
|
change: function(modify) {
|
|
|
|
Timeline.selected.forEach((kf) => {
|
|
|
|
kf.time = Timeline.snapTime(limitNumber(modify(kf.time), 0, 1e4))
|
|
|
|
})
|
|
|
|
Animator.preview()
|
|
|
|
},
|
|
|
|
onBefore: function() {
|
|
|
|
Undo.initEdit({keyframes: Timeline.selected})
|
|
|
|
},
|
|
|
|
onAfter: function() {
|
2021-07-04 21:41:42 +08:00
|
|
|
Animation.selected.setLength();
|
2021-06-06 15:28:22 +08:00
|
|
|
Undo.finishEdit('Change keyframe time')
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
|
|
|
})
|
2021-08-12 05:46:19 +08:00
|
|
|
new Toggle('keyframe_uniform', {
|
|
|
|
icon: 'link',
|
|
|
|
category: 'animation',
|
|
|
|
condition: () => Animator.open && Timeline.selected.length && !Timeline.selected.find(kf => kf.channel !== 'scale'),
|
|
|
|
onChange(value) {
|
|
|
|
let keyframes = Timeline.selected;
|
|
|
|
Undo.initEdit({keyframes})
|
|
|
|
keyframes.forEach((kf) => {
|
|
|
|
kf.uniform = value;
|
|
|
|
})
|
|
|
|
Undo.finishEdit('Change keyframes uniform setting')
|
2021-08-22 21:50:46 +08:00
|
|
|
Interface.Panels.keyframe.inside_vue.$forceUpdate();
|
2021-08-12 05:46:19 +08:00
|
|
|
updateKeyframeSelection();
|
|
|
|
}
|
|
|
|
})
|
2020-09-27 16:01:39 +08:00
|
|
|
new BarSelect('keyframe_interpolation', {
|
|
|
|
category: 'animation',
|
2020-09-27 23:03:28 +08:00
|
|
|
condition: () => Animator.open && Timeline.selected.length && Timeline.selected.find(kf => kf.transform),
|
2020-09-27 16:01:39 +08:00
|
|
|
options: {
|
|
|
|
linear: true,
|
|
|
|
catmullrom: true,
|
2021-12-05 22:39:42 +08:00
|
|
|
step: true,
|
2020-09-27 16:01:39 +08:00
|
|
|
},
|
|
|
|
onChange: function(sel, event) {
|
|
|
|
Undo.initEdit({keyframes: Timeline.selected})
|
|
|
|
Timeline.selected.forEach((kf) => {
|
2020-09-27 23:03:28 +08:00
|
|
|
if (kf.transform) kf.interpolation = sel.value;
|
2020-09-27 16:01:39 +08:00
|
|
|
})
|
2021-06-06 15:28:22 +08:00
|
|
|
Undo.finishEdit('Change keyframes interpolation')
|
2020-10-11 00:31:56 +08:00
|
|
|
updateKeyframeSelection();
|
2020-09-27 16:01:39 +08:00
|
|
|
}
|
|
|
|
})
|
2020-09-09 00:40:22 +08:00
|
|
|
new Action('reset_keyframe', {
|
|
|
|
icon: 'replay',
|
|
|
|
category: 'animation',
|
|
|
|
condition: () => Animator.open && Timeline.selected.length,
|
|
|
|
click: function () {
|
|
|
|
Undo.initEdit({keyframes: Timeline.selected})
|
|
|
|
Timeline.selected.forEach((kf) => {
|
2020-09-26 23:56:14 +08:00
|
|
|
kf.data_points.replace([new KeyframeDataPoint(kf)]);
|
2020-09-09 00:40:22 +08:00
|
|
|
})
|
2021-06-06 15:28:22 +08:00
|
|
|
Undo.finishEdit('Reset keyframes')
|
2020-09-09 00:40:22 +08:00
|
|
|
updateKeyframeSelection()
|
|
|
|
Animator.preview()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
new Action('resolve_keyframe_expressions', {
|
|
|
|
icon: 'functions',
|
|
|
|
category: 'animation',
|
|
|
|
condition: () => Animator.open && Timeline.selected.length,
|
|
|
|
click: function () {
|
|
|
|
Undo.initEdit({keyframes: Timeline.selected})
|
|
|
|
let time_before = Timeline.time;
|
|
|
|
Timeline.selected.forEach((kf) => {
|
|
|
|
if (kf.animator.fillValues) {
|
|
|
|
Timeline.time = kf.time;
|
2021-02-17 06:30:33 +08:00
|
|
|
kf.animator.fillValues(kf, null, false, false);
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
Timeline.time = time_before;
|
2021-06-06 15:28:22 +08:00
|
|
|
Undo.finishEdit('Resolve keyframes')
|
2020-09-09 00:40:22 +08:00
|
|
|
updateKeyframeSelection()
|
|
|
|
}
|
|
|
|
})
|
2022-06-26 23:22:10 +08:00
|
|
|
/*new Action('change_keyframe_file', {
|
2020-10-17 21:17:27 +08:00
|
|
|
icon: 'fa-file',
|
2020-09-09 00:40:22 +08:00
|
|
|
category: 'animation',
|
2021-11-15 05:00:17 +08:00
|
|
|
condition: () => (Animator.open && Timeline.selected.length && ['sound', 'particle'].includes(Timeline.selected[0].channel)),
|
2020-09-09 00:40:22 +08:00
|
|
|
click: function () {
|
|
|
|
|
2020-10-07 03:23:13 +08:00
|
|
|
if (Timeline.selected[0].channel == 'particle') {
|
|
|
|
Blockbench.import({
|
|
|
|
resource_id: 'animation_particle',
|
|
|
|
extensions: ['json'],
|
|
|
|
type: 'Bedrock Particle',
|
2020-10-27 02:56:00 +08:00
|
|
|
startpath: Timeline.selected[0].data_points[0].file
|
2020-10-07 03:23:13 +08:00
|
|
|
}, function(files) {
|
|
|
|
|
|
|
|
let {path} = files[0];
|
|
|
|
Undo.initEdit({keyframes: Timeline.selected})
|
|
|
|
Timeline.selected.forEach((kf) => {
|
|
|
|
if (kf.channel == 'particle') {
|
|
|
|
kf.data_points.forEach(data_point => {
|
|
|
|
data_point.file = path;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2020-10-09 20:10:48 +08:00
|
|
|
Animator.loadParticleEmitter(path, files[0].content);
|
2021-06-06 15:28:22 +08:00
|
|
|
Undo.finishEdit('Change keyframe particle file')
|
2020-10-07 03:23:13 +08:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
Blockbench.import({
|
|
|
|
resource_id: 'animation_audio',
|
2021-06-13 18:26:56 +08:00
|
|
|
extensions: ['ogg', 'wav', 'mp3'],
|
2020-10-07 03:23:13 +08:00
|
|
|
type: 'Audio File',
|
2020-10-27 02:56:00 +08:00
|
|
|
startpath: Timeline.selected[0].data_points[0].file
|
2020-10-07 03:23:13 +08:00
|
|
|
}, function(files) {
|
|
|
|
|
2021-11-15 05:00:17 +08:00
|
|
|
let path = isApp
|
|
|
|
? files[0].path
|
|
|
|
: URL.createObjectURL(files[0].browser_file);
|
|
|
|
|
2020-10-07 03:23:13 +08:00
|
|
|
Undo.initEdit({keyframes: Timeline.selected})
|
|
|
|
Timeline.selected.forEach((kf) => {
|
|
|
|
if (kf.channel == 'sound') {
|
|
|
|
kf.data_points.forEach(data_point => {
|
|
|
|
data_point.file = path;
|
2021-11-15 05:00:17 +08:00
|
|
|
if (!data_point.effect) data_point.effect = files[0].name.toLowerCase().replace(/\.[a-z]+$/, '').replace(/[^a-z0-9._]+/g, '');
|
2020-10-07 03:23:13 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
Timeline.visualizeAudioFile(path);
|
2021-06-06 15:28:22 +08:00
|
|
|
Undo.finishEdit('Change keyframe audio file')
|
2020-09-09 00:40:22 +08:00
|
|
|
})
|
2020-10-07 03:23:13 +08:00
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
}
|
2022-06-26 23:22:10 +08:00
|
|
|
})*/
|
2020-09-09 00:40:22 +08:00
|
|
|
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;
|
2021-02-09 06:31:20 +08:00
|
|
|
if (kf.transform && kf.data_points.length > 1) {
|
|
|
|
kf.data_points.reverse();
|
|
|
|
}
|
2020-09-09 00:40:22 +08:00
|
|
|
})
|
2021-06-06 15:28:22 +08:00
|
|
|
Undo.finishEdit('Reverse keyframes')
|
2020-09-09 00:40:22 +08:00
|
|
|
updateKeyframeSelection()
|
|
|
|
Animator.preview()
|
|
|
|
}
|
|
|
|
})
|
2022-06-27 00:12:53 +08:00
|
|
|
let channels = ['rotation', 'position', 'scale']
|
|
|
|
new Action('keyframe_column_create', {
|
|
|
|
icon: 'add_road',
|
|
|
|
category: 'animation',
|
|
|
|
condition: () => Animator.open,
|
|
|
|
click() {
|
|
|
|
Timeline.selected.empty();
|
|
|
|
let new_keyframes = [];
|
|
|
|
Undo.initEdit({keyframes: new_keyframes})
|
|
|
|
Timeline.animators.forEach(animator => {
|
|
|
|
if (animator instanceof BoneAnimator == false) return;
|
|
|
|
channels.forEach(channel => {
|
|
|
|
if (Timeline.vue.channels[channel] !== false && animator[channel] && animator[channel].length) {
|
2022-08-17 01:21:06 +08:00
|
|
|
let kf = animator[channel].find(kf => Math.epsilon(kf.time, Timeline.time, 1e-5));
|
|
|
|
if (!kf) {
|
|
|
|
kf = animator.createKeyframe(null, Timeline.time, channel, false, false);
|
|
|
|
new_keyframes.push(kf)
|
|
|
|
}
|
2022-06-27 00:12:53 +08:00
|
|
|
Timeline.selected.push(kf);
|
|
|
|
kf.selected = true;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
updateKeyframeSelection();
|
|
|
|
Undo.finishEdit('Create keyframe column');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
new Action('keyframe_column_select', {
|
|
|
|
icon: 'unfold_more_double',
|
|
|
|
category: 'animation',
|
|
|
|
condition: () => Animator.open,
|
|
|
|
click() {
|
|
|
|
Timeline.selected.empty();
|
|
|
|
Timeline.animators.forEach(animator => {
|
|
|
|
if (animator instanceof BoneAnimator == false) return;
|
|
|
|
channels.forEach(channel => {
|
|
|
|
if (Timeline.vue.channels[channel] !== false && animator[channel] && animator[channel].length) {
|
|
|
|
animator[channel].forEach(kf => {
|
|
|
|
if (Math.epsilon(kf.time, Timeline.time, 1e-5) && Timeline.vue.channels[kf.channel] !== false) {
|
|
|
|
Timeline.selected.push(kf);
|
|
|
|
kf.selected = true;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
updateKeyframeSelection();
|
|
|
|
}
|
|
|
|
})
|
2021-05-08 00:31:26 +08:00
|
|
|
|
|
|
|
flip_action = new Action('flip_animation', {
|
|
|
|
icon: 'transfer_within_a_station',
|
|
|
|
category: 'animation',
|
2021-06-22 21:14:44 +08:00
|
|
|
condition: {modes: ['animate'], method: () => Animation.selected},
|
2021-05-08 00:31:26 +08:00
|
|
|
click() {
|
|
|
|
|
|
|
|
if (!Animation.selected) {
|
|
|
|
Blockbench.showQuickMessage('message.no_animation_selected')
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let original_keyframes = (Timeline.selected.length ? Timeline.selected : Timeline.keyframes).slice();
|
|
|
|
if (!original_keyframes.length) return;
|
|
|
|
|
|
|
|
new Dialog({
|
|
|
|
id: 'flip_animation',
|
|
|
|
title: 'action.flip_animation',
|
|
|
|
form: {
|
|
|
|
info: {type: 'info', text: 'dialog.flip_animation.info'},
|
|
|
|
offset: {label: 'dialog.flip_animation.offset', type: 'checkbox', value: false},
|
2022-08-16 05:31:51 +08:00
|
|
|
show_in_timeline: {label: 'dialog.flip_animation.show_in_timeline', type: 'checkbox', value: true},
|
2021-05-08 00:31:26 +08:00
|
|
|
},
|
|
|
|
onConfirm(formResult) {
|
|
|
|
this.hide()
|
|
|
|
|
|
|
|
let new_keyframes = [];
|
|
|
|
Undo.initEdit({keyframes: new_keyframes});
|
|
|
|
let animators = [];
|
|
|
|
original_keyframes.forEach(kf => animators.safePush(kf.animator));
|
|
|
|
let channels = ['rotation', 'position', 'scale'];
|
|
|
|
|
|
|
|
animators.forEach(animator => {
|
2022-08-16 05:31:51 +08:00
|
|
|
let opposite_animator;
|
2021-05-08 00:31:26 +08:00
|
|
|
channels.forEach(channel => {
|
|
|
|
if (!animator[channel]) return;
|
|
|
|
let kfs = original_keyframes.filter(kf => kf.channel == channel && kf.animator == animator);
|
|
|
|
if (!kfs.length) return;
|
2022-08-16 05:31:51 +08:00
|
|
|
if (!opposite_animator) {
|
|
|
|
let name = animator.name.toLowerCase().replace(/left/g, '%LX').replace(/right/g, 'left').replace(/%LX/g, 'right');
|
|
|
|
let opposite_bone = Group.all.find(g => g.name.toLowerCase() == name);
|
|
|
|
if (!opposite_bone) {
|
|
|
|
console.log(`Animation Flipping: Unable to find opposite bone for ${animator.name}`)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
opposite_animator = Animation.selected.getBoneAnimator(opposite_bone);
|
2021-05-08 00:31:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
kfs.forEach(old_kf => {
|
|
|
|
let time = old_kf.time;
|
|
|
|
if (formResult.offset) {
|
|
|
|
time = (time + Animation.selected.length/2) % (Animation.selected.length + 0.001);
|
|
|
|
}
|
|
|
|
let new_kf = opposite_animator.createKeyframe(old_kf, Timeline.snapTime(time), channel, false, false)
|
|
|
|
if (new_kf) {
|
|
|
|
new_kf.flip(0);
|
|
|
|
new_keyframes.push(new_kf);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2022-08-16 05:31:51 +08:00
|
|
|
if (formResult.show_in_timeline && opposite_animator) {
|
|
|
|
opposite_animator.addToTimeline();
|
|
|
|
}
|
2021-05-08 00:31:26 +08:00
|
|
|
})
|
|
|
|
TickUpdates.keyframes = true;
|
|
|
|
Animator.preview();
|
|
|
|
|
2021-06-06 15:28:22 +08:00
|
|
|
Undo.finishEdit('Copy and flip keyframes');
|
2021-05-08 00:31:26 +08:00
|
|
|
}
|
|
|
|
}).show()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
MenuBar.addAction(flip_action, 'animation')
|
2020-09-09 00:40:22 +08:00
|
|
|
})
|
2020-09-22 05:23:42 +08:00
|
|
|
|
|
|
|
Interface.definePanels(function() {
|
2020-10-09 01:57:48 +08:00
|
|
|
|
2021-01-31 19:51:10 +08:00
|
|
|
let locator_suggestion_list = $('<datalist id="locator_suggestion_list" hidden></datalist>').get(0);
|
|
|
|
document.body.append(locator_suggestion_list);
|
2020-09-22 05:23:42 +08:00
|
|
|
|
2022-02-23 01:12:27 +08:00
|
|
|
new Panel('keyframe', {
|
2022-03-07 21:37:19 +08:00
|
|
|
icon: 'icon-keyframe',
|
2020-09-22 05:23:42 +08:00
|
|
|
condition: {modes: ['animate']},
|
2022-03-04 04:13:30 +08:00
|
|
|
default_position: {
|
|
|
|
slot: 'left_bar',
|
|
|
|
float_position: [0, 0],
|
|
|
|
float_size: [300, 400],
|
|
|
|
height: 400
|
|
|
|
},
|
2020-09-22 05:23:42 +08:00
|
|
|
toolbars: {
|
|
|
|
head: Toolbars.keyframe
|
|
|
|
},
|
|
|
|
component: {
|
|
|
|
name: 'panel-keyframe',
|
|
|
|
components: {VuePrismEditor},
|
|
|
|
data() { return {
|
2020-10-01 19:07:45 +08:00
|
|
|
keyframes: Timeline.selected,
|
|
|
|
channel_colors: {
|
|
|
|
x: 'color_x',
|
|
|
|
y: 'color_y',
|
|
|
|
z: 'color_z',
|
|
|
|
}
|
2020-09-22 05:23:42 +08:00
|
|
|
}},
|
|
|
|
methods: {
|
2020-09-26 23:56:14 +08:00
|
|
|
updateInput(axis, value, data_point) {
|
2021-08-12 05:46:19 +08:00
|
|
|
updateKeyframeValue(axis, value, data_point);
|
2020-09-22 05:23:42 +08:00
|
|
|
},
|
|
|
|
getKeyframeInfos() {
|
|
|
|
let list = [tl('timeline.'+this.channel)];
|
|
|
|
if (this.keyframes.length > 1) list.push(this.keyframes.length);
|
|
|
|
return list.join(', ')
|
2020-09-27 04:20:19 +08:00
|
|
|
},
|
|
|
|
addDataPoint() {
|
|
|
|
Undo.initEdit({keyframes: Timeline.selected})
|
|
|
|
Timeline.selected.forEach(kf => {
|
2021-11-20 02:36:19 +08:00
|
|
|
if (kf.data_points.length < kf.animator.channels[kf.channel].max_data_points) {
|
2020-09-27 04:20:19 +08:00
|
|
|
kf.data_points.push(new KeyframeDataPoint(kf))
|
|
|
|
kf.data_points.last().extend(kf.data_points[0])
|
|
|
|
}
|
|
|
|
})
|
|
|
|
Animator.preview()
|
2021-06-06 15:28:22 +08:00
|
|
|
Undo.finishEdit('Add keyframe data point')
|
2020-09-27 04:20:19 +08:00
|
|
|
},
|
2022-02-05 22:39:11 +08:00
|
|
|
removeDataPoint(data_point_index) {
|
2020-09-27 04:20:19 +08:00
|
|
|
Undo.initEdit({keyframes: Timeline.selected})
|
|
|
|
Timeline.selected.forEach(kf => {
|
|
|
|
if (kf.data_points.length >= 2) {
|
2022-02-05 22:39:11 +08:00
|
|
|
kf.data_points.splice(data_point_index, 1);
|
2020-09-27 04:20:19 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
Animator.preview()
|
2021-06-06 15:28:22 +08:00
|
|
|
Undo.finishEdit('Remove keyframe data point')
|
2020-10-09 01:57:48 +08:00
|
|
|
},
|
|
|
|
updateLocatorSuggestionList() {
|
2021-02-10 04:21:57 +08:00
|
|
|
locator_suggestion_list.innerHTML = '';
|
2020-10-09 01:57:48 +08:00
|
|
|
Locator.all.forEach(locator => {
|
2021-02-17 06:37:45 +08:00
|
|
|
let option = document.createElement('option');
|
|
|
|
option.value = locator.name;
|
|
|
|
locator_suggestion_list.append(option);
|
2020-10-09 01:57:48 +08:00
|
|
|
})
|
2021-01-22 00:33:43 +08:00
|
|
|
},
|
|
|
|
focusAxis(axis) {
|
2022-02-12 02:29:44 +08:00
|
|
|
if ('xyz'.includes(axis)) {
|
2021-01-22 00:33:43 +08:00
|
|
|
Timeline.vue.graph_editor_axis = axis;
|
|
|
|
}
|
2021-09-21 17:20:10 +08:00
|
|
|
},
|
2022-02-14 04:12:38 +08:00
|
|
|
slideValue(axis, e1) {
|
|
|
|
convertTouchEvent(e1);
|
|
|
|
let last_event = e1;
|
|
|
|
let started = false;
|
|
|
|
let move_calls = 0;
|
|
|
|
let last_val = 0;
|
|
|
|
let total = 0;
|
|
|
|
let clientX = e1.clientX;
|
|
|
|
function start() {
|
|
|
|
started = true;
|
|
|
|
if (!e1.touches && last_event == e1 && e1.target.requestPointerLock) e1.target.requestPointerLock();
|
|
|
|
Undo.initEdit({keyframes: Keyframe.selected});
|
|
|
|
}
|
|
|
|
|
|
|
|
function move(e2) {
|
|
|
|
convertTouchEvent(e2);
|
|
|
|
if (!started && Math.abs(e2.clientX - e1.clientX) > 5) {
|
|
|
|
start()
|
|
|
|
}
|
|
|
|
if (started) {
|
|
|
|
if (e1.touches) {
|
|
|
|
clientX = e2.clientX;
|
|
|
|
} else {
|
|
|
|
let limit = move_calls <= 2 ? 1 : 100;
|
|
|
|
clientX += Math.clamp(e2.movementX, -limit, limit);
|
|
|
|
}
|
2022-04-20 19:27:36 +08:00
|
|
|
let val = Math.round((clientX - e1.clientX) / 40);
|
2022-02-14 04:12:38 +08:00
|
|
|
let difference = (val - last_val);
|
|
|
|
if (!difference) return;
|
|
|
|
if (Toolbox.selected.id === 'rotate_tool') {
|
|
|
|
difference *= getRotationInterval(e2);
|
|
|
|
} else {
|
|
|
|
difference *= canvasGridSize(e2.shiftKey || Pressing.overrides.shift, e2.ctrlOrCmd || Pressing.overrides.ctrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
Keyframe.selected.forEach(kf => {
|
|
|
|
kf.offset(axis, difference);
|
|
|
|
})
|
|
|
|
|
|
|
|
last_val = val;
|
|
|
|
last_event = e2;
|
|
|
|
total += difference;
|
|
|
|
move_calls++;
|
|
|
|
|
|
|
|
Animator.preview()
|
|
|
|
Blockbench.setStatusBarText(trimFloatNumber(total));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function off(e2) {
|
|
|
|
if (document.exitPointerLock) document.exitPointerLock()
|
|
|
|
removeEventListeners(document, 'mousemove touchmove', move);
|
|
|
|
removeEventListeners(document, 'mouseup touchend', off);
|
|
|
|
if (total) {
|
|
|
|
Undo.finishEdit('Slide keyframe');
|
|
|
|
} else {
|
|
|
|
Undo.cancelEdit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addEventListeners(document, 'mouseup touchend', off);
|
|
|
|
addEventListeners(document, 'mousemove touchmove', move);
|
|
|
|
},
|
2022-06-26 23:22:10 +08:00
|
|
|
changeKeyframeFile(data_point, keyframe) {
|
|
|
|
if (keyframe.channel == 'particle') {
|
|
|
|
Blockbench.import({
|
|
|
|
resource_id: 'animation_particle',
|
|
|
|
extensions: ['json'],
|
|
|
|
type: 'Bedrock Particle',
|
|
|
|
startpath: keyframe.data_points[0].file
|
|
|
|
}, function(files) {
|
|
|
|
|
|
|
|
let {path} = files[0];
|
|
|
|
Undo.initEdit({keyframes: [keyframe]})
|
|
|
|
data_point.file = path;
|
2022-07-20 18:52:49 +08:00
|
|
|
let effect = Animator.loadParticleEmitter(path, files[0].content);
|
2022-07-26 02:59:50 +08:00
|
|
|
delete effect.config.preview_texture;
|
2022-07-20 18:52:49 +08:00
|
|
|
Undo.finishEdit('Change keyframe particle file');
|
|
|
|
|
2022-07-26 02:59:50 +08:00
|
|
|
if (!isApp || effect.config.texture.image.src.match(/^data:/)) {
|
2022-07-20 18:52:49 +08:00
|
|
|
Blockbench.import({
|
|
|
|
extensions: ['png'],
|
|
|
|
type: 'Particle Texture',
|
|
|
|
readtype: 'image',
|
|
|
|
startpath: effect.config.preview_texture || path
|
|
|
|
}, function(files) {
|
|
|
|
effect.config.preview_texture = isApp ? files[0].path : files[0].content;
|
|
|
|
if (isApp) effect.config.updateTexture();
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2022-06-26 23:22:10 +08:00
|
|
|
} else {
|
|
|
|
Blockbench.import({
|
|
|
|
resource_id: 'animation_audio',
|
|
|
|
extensions: ['ogg', 'wav', 'mp3'],
|
|
|
|
type: 'Audio File',
|
|
|
|
startpath: keyframe.data_points[0].file
|
|
|
|
}, function(files) {
|
|
|
|
|
|
|
|
let path = isApp
|
|
|
|
? files[0].path
|
|
|
|
: URL.createObjectURL(files[0].browser_file);
|
|
|
|
|
|
|
|
Undo.initEdit({keyframes: [keyframe]})
|
|
|
|
data_point.file = path;
|
|
|
|
if (!data_point.effect) data_point.effect = files[0].name.toLowerCase().replace(/\.[a-z]+$/, '').replace(/[^a-z0-9._]+/g, '');
|
|
|
|
Timeline.visualizeAudioFile(path);
|
|
|
|
Undo.finishEdit('Change keyframe audio file')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2021-09-21 17:20:10 +08:00
|
|
|
tl,
|
|
|
|
Condition
|
2020-09-22 05:23:42 +08:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
channel() {
|
|
|
|
var channel = false;
|
|
|
|
for (var kf of this.keyframes) {
|
|
|
|
if (channel === false) {
|
|
|
|
channel = kf.channel
|
|
|
|
} else if (channel !== kf.channel) {
|
|
|
|
channel = false
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<div>
|
|
|
|
<div class="toolbar_wrapper keyframe"></div>
|
|
|
|
|
|
|
|
<template v-if="channel != false">
|
|
|
|
|
2020-09-27 04:20:19 +08:00
|
|
|
<div id="keyframe_type_label">
|
|
|
|
<label>{{ tl('panel.keyframe.type', [getKeyframeInfos()]) }}</label>
|
|
|
|
<div
|
|
|
|
class="in_list_button"
|
2022-05-20 23:00:28 +08:00
|
|
|
v-if="keyframes[0].animator.channels[channel] && keyframes[0].data_points.length < keyframes[0].animator.channels[channel].max_data_points && keyframes[0].interpolation !== 'catmullrom'"
|
2020-09-27 04:20:19 +08:00
|
|
|
v-on:click.stop="addDataPoint()"
|
2022-06-26 23:22:10 +08:00
|
|
|
title="${ tl('panel.keyframe.change_effect_file') }"
|
2020-09-27 04:20:19 +08:00
|
|
|
>
|
|
|
|
<i class="material-icons">add</i>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2020-09-27 05:07:44 +08:00
|
|
|
<ul class="list">
|
|
|
|
|
|
|
|
<div v-for="(data_point, data_point_i) of keyframes[0].data_points" class="keyframe_data_point">
|
2020-09-26 23:56:14 +08:00
|
|
|
|
2020-09-27 05:07:44 +08:00
|
|
|
<div class="keyframe_data_point_header" v-if="keyframes[0].data_points.length > 1">
|
|
|
|
<label>{{ keyframes[0].transform ? tl('panel.keyframe.' + (data_point_i ? 'post' : 'pre')) : (data_point_i + 1) }}</label>
|
|
|
|
<div class="flex_fill_line"></div>
|
2022-02-05 22:39:11 +08:00
|
|
|
<div class="in_list_button" v-on:click.stop="removeDataPoint(data_point_i)" title="${ tl('panel.keyframe.remove_data_point') }">
|
2020-09-27 05:07:44 +08:00
|
|
|
<i class="material-icons">clear</i>
|
|
|
|
</div>
|
2020-09-27 04:20:19 +08:00
|
|
|
</div>
|
2020-09-22 05:23:42 +08:00
|
|
|
|
2021-08-12 05:46:19 +08:00
|
|
|
<template v-if="channel == 'scale' && keyframes[0].uniform && data_point.x_string == data_point.y_string && data_point.y_string == data_point.z_string">
|
2021-06-09 02:44:51 +08:00
|
|
|
<div
|
|
|
|
class="bar flex"
|
|
|
|
id="keyframe_bar_uniform_scale"
|
|
|
|
>
|
|
|
|
<label>${ tl('generic.all') }</label>
|
|
|
|
<vue-prism-editor
|
|
|
|
class="molang_input dark_bordered keyframe_input tab_target"
|
|
|
|
v-model="data_point['x_string']"
|
|
|
|
@change="updateInput('uniform', $event, data_point_i)"
|
|
|
|
language="molang"
|
2021-09-21 17:20:10 +08:00
|
|
|
:ignoreTabKey="true"
|
2021-06-09 02:44:51 +08:00
|
|
|
:line-numbers="false"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<template v-else>
|
|
|
|
<div
|
|
|
|
v-for="(property, key) in data_point.constructor.properties"
|
|
|
|
v-if="property.exposed != false && Condition(property.condition, data_point)"
|
|
|
|
class="bar flex"
|
|
|
|
:id="'keyframe_bar_' + property.name"
|
|
|
|
>
|
2022-02-14 04:12:38 +08:00
|
|
|
<label :class="{[channel_colors[key]]: true, slidable_input: property.type == 'molang'}" :style="{'font-weight': channel_colors[key] ? 'bolder' : 'unset'}" @mousedown="slideValue(key, $event)" @touchstart="slideValue(key, $event)">{{ property.label }}</label>
|
2021-06-09 02:44:51 +08:00
|
|
|
<vue-prism-editor
|
|
|
|
v-if="property.type == 'molang'"
|
|
|
|
class="molang_input dark_bordered keyframe_input tab_target"
|
|
|
|
v-model="data_point[key+'_string']"
|
|
|
|
@change="updateInput(key, $event, data_point_i)"
|
|
|
|
@focus="focusAxis(key)"
|
|
|
|
language="molang"
|
2021-09-21 17:20:10 +08:00
|
|
|
:ignoreTabKey="true"
|
2021-06-09 02:44:51 +08:00
|
|
|
:line-numbers="false"
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
v-else
|
|
|
|
type="text"
|
|
|
|
class="dark_bordered code keyframe_input tab_target"
|
|
|
|
v-model="data_point[key]"
|
|
|
|
:list="key == 'locator' && 'locator_suggestion_list'"
|
|
|
|
@focus="key == 'locator' && updateLocatorSuggestionList()"
|
|
|
|
@input="updateInput(key, $event.target.value, data_point_i)"
|
|
|
|
/>
|
2022-06-26 23:22:10 +08:00
|
|
|
<div class="tool" v-if="key == 'effect'" title="${tl('action.change_keyframe_file')}" @click="changeKeyframeFile(data_point, keyframes[0])">
|
|
|
|
<i class="material-icons">upload_file</i>
|
|
|
|
</div>
|
2021-06-09 02:44:51 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
2020-09-26 20:03:09 +08:00
|
|
|
</div>
|
2020-09-27 05:07:44 +08:00
|
|
|
</ul>
|
2020-09-22 05:23:42 +08:00
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
}
|
|
|
|
})
|
2021-02-27 22:38:49 +08:00
|
|
|
|
|
|
|
let keyframe_edit_value;
|
|
|
|
function isTarget(target) {
|
2021-03-08 19:57:31 +08:00
|
|
|
return target && target.classList && (target.classList.contains('keyframe_input') || (target.parentElement && target.parentElement.classList.contains('keyframe_input')));
|
2021-02-27 22:38:49 +08:00
|
|
|
}
|
|
|
|
document.addEventListener('focus', event => {
|
|
|
|
if (isTarget(event.target)) {
|
|
|
|
|
|
|
|
keyframe_edit_value = event.target.value || event.target.innerText;
|
|
|
|
Undo.initEdit({keyframes: Timeline.selected.slice()})
|
|
|
|
}
|
|
|
|
}, true)
|
|
|
|
document.addEventListener('focusout', event => {
|
|
|
|
if (isTarget(event.target)) {
|
|
|
|
|
|
|
|
let val = event.target.value || event.target.innerText;
|
|
|
|
if (val != keyframe_edit_value) {
|
2021-06-06 15:28:22 +08:00
|
|
|
Undo.finishEdit('Edit keyframe');
|
2021-02-27 22:38:49 +08:00
|
|
|
} else {
|
|
|
|
Undo.cancelEdit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2020-09-22 05:23:42 +08:00
|
|
|
})
|