Catmullrom keyframe validation

This commit is contained in:
JannisX11 2022-08-09 23:14:03 +02:00
parent 3a603ce152
commit 7f047e8f37
2 changed files with 41 additions and 7 deletions

View File

@ -366,15 +366,16 @@ const Blockbench = {
//Events
dispatchEvent(event_name, data) {
let list = this.events[event_name];
if (!list) return;
let results = [];
for (let i = 0; i < list.length; i++) {
if (typeof list[i] === 'function') {
let result = list[i](data);
results.push(result);
let results;
if (list) {
results = [];
for (let i = 0; i < list.length; i++) {
if (typeof list[i] === 'function') {
let result = list[i](data);
results.push(result);
}
}
}
console.log(event_name, Validator.triggers.includes(event_name))
if (Validator.triggers.includes(event_name)) {
Validator.validate(event_name);
}

View File

@ -149,3 +149,36 @@ new ValidatorCheck('texture_names', {
})
}
})
new ValidatorCheck('catmullrom_keyframes', {
condition: {features: ['animation_files']},
update_triggers: ['update_keyframe_selection'],
run() {
Animation.all.forEach(animation => {
for (let key in animation.animators) {
let animator = animation.animators[key];
if (animator instanceof BoneAnimator) {
for (let channel in animator.channels) {
if (!animator[channel] || !animator[channel].find(kf => kf.interpolation == 'catmullrom')) continue;
let keyframes = animator[channel].slice().sort((a, b) => a.time - b.time);
keyframes.forEach((kf, i) => {
if (kf.interpolation == 'catmullrom') {
if (kf.data_points.find(dp => isNaN(dp.x) || isNaN(dp.y) || isNaN(dp.z))) {
this.fail({
message: `${animator.channels[channel].name} keyframe at ${kf.time.toFixed(2)} on "${animator.name}" in "${animation.name}" contains non-numeric value. Smooth keyframes cannot contain math expressions.`
})
}
if ((!keyframes[i-1] || keyframes[i-1].interpolation != 'catmullrom') && (!keyframes[i+1] || keyframes[i+1].interpolation != 'catmullrom')) {
this.warn({
message: `${animator.channels[channel].name} keyframe at ${kf.time.toFixed(2)} on "${animator.name}" in "${animation.name}" is not surrounted by smooth keyframes. Multiple smooth keyframes are required to create a smooth spline.`
})
}
}
})
}
}
}
})
}
})