mirror of
https://github.com/JannisX11/blockbench.git
synced 2024-11-27 04:21:46 +08:00
Add option to bake IK
Fix detecging small keyframe values as molang
This commit is contained in:
parent
cc391c937d
commit
236693aa43
@ -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',
|
||||
|
@ -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',
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user