Catmull rom interpolation preview

This commit is contained in:
JannisX11 2020-09-27 10:52:31 +02:00
parent 992f42e3a0
commit 03f6a726fb
2 changed files with 44 additions and 14 deletions

View File

@ -878,17 +878,30 @@ class BoneAnimator extends GeneralAnimator {
} else if (!before && !after) {
//
} else {
let alpha = Math.lerp(before.time, after.time, time)
if (Blockbench.hasFlag('no_interpolations')) {
alpha = Math.round(alpha)
}
result = [
before.getLerp(after, 'x', alpha, allow_expression),
before.getLerp(after, 'y', alpha, allow_expression),
before.getLerp(after, 'z', alpha, allow_expression)
]
if (before.isQuaternion && after.isQuaternion) {
result[3] = before.getLerp(after, 'q', alpha, allow_expression)
let no_interpolations = Blockbench.hasFlag('no_interpolations')
if (no_interpolations || (before.interpolation == Keyframe.interpolation.linear && after.interpolation == Keyframe.interpolation.linear)) {
let alpha = Math.lerp(before.time, after.time, time)
if (no_interpolations) {
alpha = Math.round(alpha)
}
result = [
before.getLerp(after, 'x', alpha, allow_expression),
before.getLerp(after, 'y', alpha, allow_expression),
before.getLerp(after, 'z', alpha, allow_expression)
]
} else {
let sorted = this[channel].slice().sort((kf1, kf2) => (kf1.time - kf2.time));
let before_index = sorted.indexOf(before);
let before_plus = sorted[before_index-1];
let after_plus = sorted[before_index+2];
result = [
before.getCatmullromLerp(before_plus, before, after, after_plus, 'x'),
before.getCatmullromLerp(before_plus, before, after, after_plus, 'y'),
before.getCatmullromLerp(before_plus, before, after, after_plus, 'z'),
]
}
}
if (result && result.type === 'keyframe') {

View File

@ -30,19 +30,19 @@ class KeyframeDataPoint {
if (this.instructions != undefined) Merge.string(this, data, 'instructions')
}
get x_string() {
return typeof this.x == 'number' ? trimFloatNumber(this.x) : this.x;
return typeof this.x == 'number' ? trimFloatNumber(this.x) || '0' : this.x;
}
set x_string(val) {
this.x = val;
}
get y_string() {
return typeof this.y == 'number' ? trimFloatNumber(this.y) : this.y;
return typeof this.y == 'number' ? trimFloatNumber(this.y) || '0' : this.y;
}
set y_string(val) {
this.y = val;
}
get z_string() {
return typeof this.z == 'number' ? trimFloatNumber(this.z) : this.z;
return typeof this.z == 'number' ? trimFloatNumber(this.z) || '0' : this.z;
}
set z_string(val) {
this.z = val;
@ -173,6 +173,19 @@ class Keyframe {
return calc + (other.calc(axis, other_data_point) - calc) * amount;
}
}
getCatmullromLerp(before_plus, before, after, after_plus, axis) {
var vectors = [];
if (before_plus) vectors.push(new THREE.Vector2(before_plus.time, before_plus.calc(axis, 0)))
if (before) vectors.push(new THREE.Vector2(before.time, before.calc(axis, 0)))
if (after) vectors.push(new THREE.Vector2(after.time, after.calc(axis, 0)))
if (after_plus) vectors.push(new THREE.Vector2(after_plus.time, after_plus.calc(axis, 0)))
var curve = new THREE.SplineCurve(vectors);
let time = Math.lerp(vectors[0].x, vectors.last().x, Timeline.time)
return curve.getPoint(time).y;
}
getArray(data_point = 0) {
var arr = [
this.get('x', data_point),
@ -403,6 +416,10 @@ class Keyframe {
new Property(Keyframe, 'number', 'color', {default: -1})
new Property(Keyframe, 'string', 'interpolation', {default: 'linear'})
Keyframe.selected = [];
Keyframe.interpolation = {
linear: 'linear',
catmullrom: 'catmullrom',
}
// Misc Functions
function updateKeyframeValue(axis, value, data_point) {