mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-04-12 17:41:57 +08:00
Add copy/paste/duplicate/save support for anim controllers
Fix prompt for memory animations opening when loading model
This commit is contained in:
parent
10f17b4dcb
commit
b255db0192
@ -916,6 +916,16 @@ const Animator = {
|
||||
if (isApp && (Format.id == 'bedrock' || Format.id == 'bedrock_old') && !Project.BedrockEntityManager.initialized_animations) {
|
||||
Project.BedrockEntityManager.initAnimations();
|
||||
}
|
||||
if (isApp && Project.memory_animation_files_to_load) {
|
||||
let paths = Project.memory_animation_files_to_load.filter(path => !Animation.all.find(a => a.path == path));
|
||||
if (paths.length) {
|
||||
Blockbench.read(paths, {}, files => {
|
||||
files.forEach(file => {
|
||||
Animator.importFile(file);
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Animator.open = true;
|
||||
Canvas.updateAllBones();
|
||||
@ -1675,8 +1685,8 @@ Blockbench.on('reset_project', () => {
|
||||
})
|
||||
|
||||
Clipbench.setAnimation = function() {
|
||||
if (!Animation.selected) return;
|
||||
Clipbench.animation = Animation.selected.getUndoCopy();
|
||||
if (!Animation.selected && !AnimationController.selected) return;
|
||||
Clipbench.animation = AnimationItem.selected.getUndoCopy();
|
||||
|
||||
if (isApp) {
|
||||
clipboard.writeHTML(JSON.stringify({type: 'animation', content: Clipbench.animation}));
|
||||
@ -1692,15 +1702,26 @@ Clipbench.pasteAnimation = function() {
|
||||
}
|
||||
} catch (err) {}
|
||||
}
|
||||
if (!Clipbench.animation) return;
|
||||
if (!Clipbench.animation || !Format.animation_mode) return;
|
||||
|
||||
let animations = [];
|
||||
Undo.initEdit({animations});
|
||||
let animation = new Animation(Clipbench.animation).add(false);
|
||||
animation.createUniqueName();
|
||||
animation.select().propertiesDialog();
|
||||
animations.push(animation);
|
||||
Undo.finishEdit('Paste animation')
|
||||
if (Clipbench.animation.type == 'animation_controller') {
|
||||
let animation_controllers = [];
|
||||
Undo.initEdit({animation_controllers});
|
||||
let animation_controller = new AnimationController(Clipbench.animation).add(false);
|
||||
animation_controller.createUniqueName();
|
||||
animation_controller.select().propertiesDialog();
|
||||
animation_controllers.push(animation_controller);
|
||||
Undo.finishEdit('Paste animation controller')
|
||||
|
||||
} else {
|
||||
let animations = [];
|
||||
Undo.initEdit({animations});
|
||||
let animation = new Animation(Clipbench.animation).add(false);
|
||||
animation.createUniqueName();
|
||||
animation.select().propertiesDialog();
|
||||
animations.push(animation);
|
||||
Undo.finishEdit('Paste animation')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -453,6 +453,7 @@ class AnimationController extends AnimationItem {
|
||||
this.states.push(state);
|
||||
} else {
|
||||
state = new AnimationControllerState(this, template);
|
||||
if (template.uuid) state.uuid = template.uuid;
|
||||
}
|
||||
})
|
||||
} else if (typeof data.states === 'object') {
|
||||
@ -485,6 +486,7 @@ class AnimationController extends AnimationItem {
|
||||
getUndoCopy(options = 0, save) {
|
||||
var copy = {
|
||||
uuid: this.uuid,
|
||||
type: 'animation_controller',
|
||||
name: this.name,
|
||||
selected: this.selected,
|
||||
selected_state: this.selected_state ? this.selected_state.uuid : null
|
||||
|
@ -286,12 +286,7 @@ function loadDataFromModelMemory() {
|
||||
})
|
||||
}
|
||||
if (project.animation_files && Format.animation_files) {
|
||||
let files = project.animation_files.filter(path => !Animation.all.find(a => a.path == path));
|
||||
Blockbench.read(files, {}, files => {
|
||||
files.forEach(file => {
|
||||
Animator.importFile(file);
|
||||
})
|
||||
})
|
||||
Project.memory_animation_files_to_load = project.animation_files;
|
||||
}
|
||||
Blockbench.dispatchEvent('load_from_recent_project_data', {data: project});
|
||||
}
|
||||
|
@ -1849,6 +1849,15 @@ const BARS = {
|
||||
Animator.animations.splice(Animator.animations.indexOf(Animation.selected)+1, 0, animation)
|
||||
animation.saved = false;
|
||||
animation.add(true).select();
|
||||
|
||||
} else if (AnimationController.selected && Prop.active_panel == 'animations') {
|
||||
var copy = AnimationController.selected.getUndoCopy();
|
||||
var controller = new AnimationController(copy);
|
||||
Property.resetUniqueValues(AnimationController, controller);
|
||||
controller.createUniqueName();
|
||||
AnimationController.all.splice(AnimationController.all.indexOf(AnimationController.selected)+1, 0, controller)
|
||||
controller.saved = false;
|
||||
controller.add(true).select();
|
||||
|
||||
} else if (Prop.active_panel == 'animation_controllers' && AnimationController.selected?.selected_state) {
|
||||
Undo.initEdit({animation_controllers: [AnimationController.selected]});
|
||||
|
@ -178,12 +178,18 @@ var codec = new Codec('project', {
|
||||
model.textures.push(t);
|
||||
})
|
||||
|
||||
if (Animator.animations.length) {
|
||||
if (Animation.all.length) {
|
||||
model.animations = [];
|
||||
Animator.animations.forEach(a => {
|
||||
Animation.all.forEach(a => {
|
||||
model.animations.push(a.getUndoCopy({bone_names: true, absolute_paths: options.absolute_paths}, true))
|
||||
})
|
||||
}
|
||||
if (AnimationController.all.length) {
|
||||
model.animation_controllers = [];
|
||||
AnimationController.all.forEach(a => {
|
||||
model.animation_controllers.push(a.getUndoCopy());
|
||||
})
|
||||
}
|
||||
if (Interface.Panels.variable_placeholders.inside_vue._data.text) {
|
||||
model.animation_variable_placeholders = Interface.Panels.variable_placeholders.inside_vue._data.text;
|
||||
}
|
||||
@ -339,6 +345,16 @@ var codec = new Codec('project', {
|
||||
}
|
||||
})
|
||||
}
|
||||
if (model.animation_controllers) {
|
||||
model.animation_controllers.forEach(ani => {
|
||||
var base_ani = new AnimationController()
|
||||
base_ani.uuid = ani.uuid;
|
||||
base_ani.extend(ani).add();
|
||||
if (isApp && Format.animation_files) {
|
||||
base_ani.saved_name = base_ani.name;
|
||||
}
|
||||
})
|
||||
}
|
||||
if (model.animation_variable_placeholders) {
|
||||
Interface.Panels.variable_placeholders.inside_vue._data.text = model.animation_variable_placeholders;
|
||||
}
|
||||
@ -570,6 +586,19 @@ var codec = new Codec('project', {
|
||||
new_animations.push(base_ani);
|
||||
})
|
||||
}
|
||||
if (model.animation_controllers) {
|
||||
model.animation_controllers.forEach(ani => {
|
||||
var base_ani = new AnimationController()
|
||||
if (AnimationController.all.find(a => a.uuid == ani.uuid)) {
|
||||
ani.uuid = guid();
|
||||
}
|
||||
base_ani.uuid = ani.uuid;
|
||||
base_ani.extend(ani).add();
|
||||
if (isApp && Format.animation_files) {
|
||||
base_ani.saved_name = base_ani.name;
|
||||
}
|
||||
})
|
||||
}
|
||||
if (Format.bone_rig) {
|
||||
Group.all.forEachReverse(group => group.createUniqueName());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user