Add option to bake IK

Fix detecging small keyframe values as molang
This commit is contained in:
JannisX11 2023-11-04 22:36:28 +01:00
parent cc391c937d
commit 236693aa43
4 changed files with 38 additions and 1 deletions

View File

@ -1078,6 +1078,40 @@ BARS.defineActions(function() {
}
})
new Action('bake_ik_animation', {
icon: 'precision_manufacturing',
category: 'animation',
condition: () => Modes.animate && NullObject.all.findIndex(n => n.ik_target) != -1,
click() {
let animation = Animation.selected;
let ik_samples = animation.sampleIK(animation.snapping);
let keyframes = [];
Undo.initEdit({keyframes});
for (let uuid in ik_samples) {
let animator = animation.animators[uuid];
ik_samples[uuid].forEach(({array}) => {
array[0] = Math.roundTo(array[0], 4);
array[1] = Math.roundTo(array[1], 4);
array[2] = Math.roundTo(array[2], 4);
})
ik_samples[uuid].forEach(({array}, i) => {
let before = ik_samples[uuid][i-1];
let after = ik_samples[uuid][i+1];
if ((!before || before.array.equals(array)) && (!after || after.array.equals(array))) return;
let time = Timeline.snapTime(i / animation.snapping, animation);
let values = {x: array[0], y: array[1], z: array[2]};
let kf = animator.createKeyframe(values, time, 'rotation', false, false);
keyframes.push(kf);
})
animator.addToTimeline();
}
Undo.finishEdit('Bake IK rotations');
}
})
new Action('bake_animation_into_model', {
icon: 'directions_run',
category: 'animation',

View File

@ -336,6 +336,7 @@ const MenuBar = {
'add_marker',
'select_effect_animator',
'flip_animation',
'bake_ik_animation',
'bake_animation_into_model',
new MenuSeparator('file'),
'load_animation_file',

View File

@ -136,5 +136,5 @@ function getAxisNumber(letter) {
}
let string_num_regex = /^-?\d+(\.\d+f?)?$/;
function isStringNumber(string) {
return string_num_regex.test(string);
return typeof string == 'number' || string_num_regex.test(string);
}

View File

@ -1649,6 +1649,8 @@
"action.save_all_animations.desc": "Save all currently loaded animations",
"action.export_animation_file": "Export Animations...",
"action.export_animation_file.desc": "Export a selection of animations into a new file",
"action.bake_ik_animation": "Bake Inverse Kinematics",
"action.bake_ik_animation.desc": "Bake the rotations applied by inverse kinematics into the selected animation",
"action.bake_animation_into_model": "Bake Animation into Model",
"action.bake_animation_into_model.desc": "Bake the currently displayed animation frame into the model. Only applies rotation and position, scale is ignored.",
"action.slider_animation_length": "Animation Length",