Add option to bake animation into model

Fix animation save issue
This commit is contained in:
JannisX11 2021-12-07 20:22:34 +01:00
parent 86b4797e91
commit 95195a63c7
4 changed files with 53 additions and 10 deletions

View File

@ -1469,6 +1469,56 @@ BARS.defineActions(function() {
}
}
})
new Action('bake_animation_into_model', {
icon: 'transfer_within_a_station',
category: 'animation',
condition: {modes: ['animate']},
click: function () {
let elements = Outliner.elements;
Undo.initEdit({elements, outliner: true});
[...Group.all, ...NullObject.all].forEach(node => {
let offset_rotation = [0, 0, 0];
let offset_position = [0, 0, 0];
Animator.animations.forEach(animation => {
if (animation.playing) {
let animator = animation.getBoneAnimator(node);
let multiplier = animation.blend_weight ? Math.clamp(Animator.MolangParser.parse(animation.blend_weight), 0, Infinity) : 1;
if (node instanceof Group) {
console.log(animator, animator.interpolate('rotation'))
let rotation = animator.interpolate('rotation');
let position = animator.interpolate('position');
if (rotation instanceof Array) offset_rotation.V3_add(rotation.map(v => v * multiplier));
if (position instanceof Array) offset_position.V3_add(position.map(v => v * multiplier));
}
}
})
// Rotation
if (node.rotatable) {
node.rotation[0] -= offset_rotation[0];
node.rotation[1] -= offset_rotation[1];
node.rotation[2] += offset_rotation[2];
}
// Position
function offset(node) {
if (node instanceof Group) {
node.origin.V3_add(offset_position);
node.children.forEach(offset);
} else {
if (node.from) node.from.V3_add(offset_position);
if (node.to) node.to.V3_add(offset_position);
if (node.origin && node.origin !== node.from) node.origin.V3_add(offset_position);
}
}
offset(node);
});
Modes.options.edit.select()
Undo.finishEdit('Bake animation into model')
}
})
})
Interface.definePanels(function() {

View File

@ -159,11 +159,6 @@ class BoneAnimator extends GeneralAnimator {
}
getGroup() {
this.group = OutlinerNode.uuids[this.uuid];
if (!this.group) {
if (this.animation && this.animation.animators[this.uuid] && this.animation.animators[this.uuid].type == 'bone') {
delete this.animation.bones[this.uuid];
}
}
return this.group
}
select(group_is_selected) {
@ -425,11 +420,6 @@ class NullObjectAnimator extends BoneAnimator {
}
getElement() {
this.element = OutlinerNode.uuids[this.uuid];
if (!this.element) {
if (this.animation && this.animation.animators[this.uuid] && this.animation.animators[this.uuid].type == 'bone') {
delete this.animation.bones[this.uuid];
}
}
return this.element
}
select(element_is_selected) {

View File

@ -740,6 +740,7 @@ const MenuBar = {
'lock_motion_trail',
'_',
'select_effect_animator',
'bake_animation_into_model',
'_',
'load_animation_file',
'save_all_animations',

View File

@ -1223,6 +1223,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_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",
"action.slider_animation_length.desc": "Change the length of the selected animation",
"action.set_animation_end": "Set Animation End",