mirror of
https://github.com/JannisX11/blockbench.git
synced 2024-11-21 01:13:37 +08:00
Fix importing old bbmodel animations
Fix preview of discontinuous keyframes
This commit is contained in:
parent
c0adfdb484
commit
a436f6d08e
@ -45,15 +45,19 @@ class Animation {
|
||||
keyframes: animator_blueprint
|
||||
}
|
||||
}
|
||||
var kfs = animator_blueprint.keyframes;
|
||||
|
||||
|
||||
var kfs = animator_blueprint.keyframes;
|
||||
var animator;
|
||||
if (!this.animators[key]) {
|
||||
if (key == 'effects') {
|
||||
animator = this.animators[key] = new EffectAnimator(this);
|
||||
} else {
|
||||
animator = this.animators[key] = new BoneAnimator(isUUID(key) ? key : guid(), this, animator_blueprint.name)
|
||||
let uuid = isUUID(key) && key;
|
||||
if (!uuid) {
|
||||
let lowercase_bone_name = key.toLowerCase();
|
||||
uuid = Group.all.find(group => group.name.toLowerCase() == lowercase_bone_name)?.uuid;
|
||||
if (!uuid) uuid = guid();
|
||||
}
|
||||
animator = this.animators[uuid] = new BoneAnimator(uuid, this, animator_blueprint.name)
|
||||
}
|
||||
} else {
|
||||
animator = this.animators[key];
|
||||
@ -873,10 +877,10 @@ class BoneAnimator extends GeneralAnimator {
|
||||
}
|
||||
interpolate(channel, allow_expression) {
|
||||
let time = Timeline.time;
|
||||
var i = 0;
|
||||
var before = false
|
||||
var after = false
|
||||
var result = false
|
||||
let epsilon = 1/1200;
|
||||
for (var keyframe of this[channel]) {
|
||||
|
||||
if (keyframe.time < time) {
|
||||
@ -890,9 +894,9 @@ class BoneAnimator extends GeneralAnimator {
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (before && Math.abs(before.time - time) < 1/1200) {
|
||||
if (before && Math.epsilon(before.time, time, epsilon)) {
|
||||
result = before
|
||||
} else if (after && Math.abs(after.time - time) < 1/1200) {
|
||||
} else if (after && Math.epsilon(after.time, time, epsilon)) {
|
||||
result = after
|
||||
} else if (before && !after) {
|
||||
result = before
|
||||
@ -927,17 +931,15 @@ class BoneAnimator extends GeneralAnimator {
|
||||
]
|
||||
}
|
||||
}
|
||||
if (result && result.type === 'keyframe') {
|
||||
if (result && result instanceof Keyframe) {
|
||||
let keyframe = result
|
||||
let method = allow_expression ? 'get' : 'calc'
|
||||
let dp_index = (keyframe.time > time || Math.epsilon(keyframe.time, time, epsilon)) ? 0 : keyframe.data_points.length-1;
|
||||
result = [
|
||||
keyframe[method]('x'),
|
||||
keyframe[method]('y'),
|
||||
keyframe[method]('z')
|
||||
keyframe[method]('x', dp_index),
|
||||
keyframe[method]('y', dp_index),
|
||||
keyframe[method]('z', dp_index)
|
||||
]
|
||||
if (keyframe.isQuaternion) {
|
||||
result[3] = keyframe[method]('w')
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ class Keyframe {
|
||||
return this;
|
||||
}
|
||||
get(axis, data_point = 0) {
|
||||
if (data_point) data_point = Math.clamp(data_point, 0, this.data_points.length-1);
|
||||
data_point = this.data_points[data_point];
|
||||
if (!data_point || !data_point[axis]) {
|
||||
return this.transform ? 0 : '';
|
||||
@ -76,16 +77,19 @@ class Keyframe {
|
||||
}
|
||||
}
|
||||
calc(axis, data_point = 0) {
|
||||
if (data_point) data_point = Math.clamp(data_point, 0, this.data_points.length-1);
|
||||
data_point = this.data_points[data_point];
|
||||
return Animator.MolangParser.parse(data_point && data_point[axis])
|
||||
}
|
||||
set(axis, value, data_point = 0) {
|
||||
if (data_point) data_point = Math.clamp(data_point, 0, this.data_points.length-1);
|
||||
if (this.data_points[data_point]) {
|
||||
this.data_points[data_point][axis] = value;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
offset(axis, amount, data_point = 0) {
|
||||
if (data_point) data_point = Math.clamp(data_point, 0, this.data_points.length-1);
|
||||
var value = this.get(axis)
|
||||
if (!value || value === '0') {
|
||||
this.set(axis, amount, data_point)
|
||||
@ -157,10 +161,10 @@ class Keyframe {
|
||||
getCatmullromLerp(before_plus, before, after, after_plus, axis, alpha) {
|
||||
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 (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)))
|
||||
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)))
|
||||
if (after_plus && after.data_points.length == 1) vectors.push(new THREE.Vector2(after_plus.time, after_plus.calc(axis, 0)))
|
||||
|
||||
var curve = new THREE.SplineCurve(vectors);
|
||||
let time = (alpha + (before_plus ? 1 : 0)) / (vectors.length-1);
|
||||
|
Loading…
Reference in New Issue
Block a user