mirror of
https://github.com/JannisX11/blockbench.git
synced 2024-11-27 04:21:46 +08:00
Keep bones that don't exist in the current model
This commit is contained in:
parent
973322478f
commit
3068f6b55d
@ -35,7 +35,7 @@ class Animation {
|
|||||||
if (data.animators instanceof Object) {
|
if (data.animators instanceof Object) {
|
||||||
for (var key in data.animators) {
|
for (var key in data.animators) {
|
||||||
var group = Group.all.findInArray( isUUID(key) ? 'uuid' : 'name', key )
|
var group = Group.all.findInArray( isUUID(key) ? 'uuid' : 'name', key )
|
||||||
if (group) {
|
if (group) { // todo
|
||||||
var ba = this.getBoneAnimator(group)
|
var ba = this.getBoneAnimator(group)
|
||||||
var kfs = data.animators[key]
|
var kfs = data.animators[key]
|
||||||
if (kfs && ba) {
|
if (kfs && ba) {
|
||||||
@ -57,7 +57,6 @@ class Animation {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
getUndoCopy(options, save) {
|
getUndoCopy(options, save) {
|
||||||
var scope = this;
|
|
||||||
var copy = {
|
var copy = {
|
||||||
uuid: this.uuid,
|
uuid: this.uuid,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
@ -77,7 +76,7 @@ class Animation {
|
|||||||
if (kfs && kfs.length) {
|
if (kfs && kfs.length) {
|
||||||
if (options && options.bone_names && this.animators[uuid] instanceof BoneAnimator) {
|
if (options && options.bone_names && this.animators[uuid] instanceof BoneAnimator) {
|
||||||
var group = this.animators[uuid].getGroup();
|
var group = this.animators[uuid].getGroup();
|
||||||
uuid = group ? group.name : '';
|
uuid = group ? group.name : this.animators[uuid].name;
|
||||||
}
|
}
|
||||||
copy.animators[uuid] = [];
|
copy.animators[uuid] = [];
|
||||||
kfs.forEach(kf => {
|
kfs.forEach(kf => {
|
||||||
@ -91,19 +90,19 @@ class Animation {
|
|||||||
compileBedrockAnimation() {
|
compileBedrockAnimation() {
|
||||||
let ani_tag = {};
|
let ani_tag = {};
|
||||||
|
|
||||||
if (a.loop == 'hold') {
|
if (this.loop == 'hold') {
|
||||||
ani_tag.loop = 'hold_on_last_frame';
|
ani_tag.loop = 'hold_on_last_frame';
|
||||||
} else if (a.loop == 'loop' || a.getMaxLength() == 0) {
|
} else if (this.loop == 'loop' || this.getMaxLength() == 0) {
|
||||||
ani_tag.loop = true;
|
ani_tag.loop = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a.length) ani_tag.animation_length = a.length;
|
if (this.length) ani_tag.animation_length = this.length;
|
||||||
if (a.override) ani_tag.override_previous_animation = true;
|
if (this.override) ani_tag.override_previous_animation = true;
|
||||||
if (a.anim_time_update) ani_tag.anim_time_update = a.anim_time_update;
|
if (this.anim_time_update) ani_tag.anim_time_update = this.anim_time_update;
|
||||||
ani_tag.bones = {};
|
ani_tag.bones = {};
|
||||||
|
|
||||||
for (var uuid in a.animators) {
|
for (var uuid in this.animators) {
|
||||||
var animator = a.animators[uuid];
|
var animator = this.animators[uuid];
|
||||||
if (animator instanceof EffectAnimator) {
|
if (animator instanceof EffectAnimator) {
|
||||||
|
|
||||||
animator.sound.forEach(kf => {
|
animator.sound.forEach(kf => {
|
||||||
@ -130,13 +129,13 @@ class Animation {
|
|||||||
ani_tag.timeline[timecode] = kf.instructions.split('\n');
|
ani_tag.timeline[timecode] = kf.instructions.split('\n');
|
||||||
})
|
})
|
||||||
|
|
||||||
} else if (a.animators[uuid].keyframes.length && a.animators[uuid].getGroup()) {
|
} else if (animator.keyframes.length) {
|
||||||
|
|
||||||
var group = a.animators[uuid].group;
|
var group = animator.getGroup();
|
||||||
var bone_tag = ani_tag.bones[group.name] = {};
|
var bone_tag = ani_tag.bones[group ? group.name : animator.name] = {};
|
||||||
var channels = {};
|
var channels = {};
|
||||||
//Saving Keyframes
|
//Saving Keyframes
|
||||||
a.animators[uuid].keyframes.forEach(function(kf) {
|
animator.keyframes.forEach(function(kf) {
|
||||||
if (!channels[kf.channel]) {
|
if (!channels[kf.channel]) {
|
||||||
channels[kf.channel] = {};
|
channels[kf.channel] = {};
|
||||||
}
|
}
|
||||||
@ -531,9 +530,10 @@ class GeneralAnimator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
class BoneAnimator extends GeneralAnimator {
|
class BoneAnimator extends GeneralAnimator {
|
||||||
constructor(uuid, animation) {
|
constructor(uuid, animation, name) {
|
||||||
super(uuid, animation);
|
super(uuid, animation);
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
|
this._name = name;
|
||||||
|
|
||||||
this.rotation = [];
|
this.rotation = [];
|
||||||
this.position = [];
|
this.position = [];
|
||||||
@ -542,7 +542,10 @@ class BoneAnimator extends GeneralAnimator {
|
|||||||
get name() {
|
get name() {
|
||||||
var group = this.getGroup();
|
var group = this.getGroup();
|
||||||
if (group) return group.name;
|
if (group) return group.name;
|
||||||
return '';
|
return this._name;
|
||||||
|
}
|
||||||
|
set name(name) {
|
||||||
|
this._name = name;
|
||||||
}
|
}
|
||||||
get keyframes() {
|
get keyframes() {
|
||||||
return [...this.rotation, ...this.position, ...this.scale];
|
return [...this.rotation, ...this.position, ...this.scale];
|
||||||
@ -550,7 +553,6 @@ class BoneAnimator extends GeneralAnimator {
|
|||||||
getGroup() {
|
getGroup() {
|
||||||
this.group = Group.all.findInArray('uuid', this.uuid)
|
this.group = Group.all.findInArray('uuid', this.uuid)
|
||||||
if (!this.group) {
|
if (!this.group) {
|
||||||
console.log('no group found for '+this.uuid)
|
|
||||||
if (this.animation && this.animation.animators[this.uuid] && this.animation.animators[this.uuid].type == 'bone') {
|
if (this.animation && this.animation.animators[this.uuid] && this.animation.animators[this.uuid].type == 'bone') {
|
||||||
delete this.animation.bones[this.uuid];
|
delete this.animation.bones[this.uuid];
|
||||||
}
|
}
|
||||||
@ -1006,11 +1008,12 @@ const Animator = {
|
|||||||
if (a.bones) {
|
if (a.bones) {
|
||||||
for (var bone_name in a.bones) {
|
for (var bone_name in a.bones) {
|
||||||
var b = a.bones[bone_name]
|
var b = a.bones[bone_name]
|
||||||
bone_name = bone_name.toLowerCase();
|
let lowercase_bone_name = bone_name.toLowerCase();
|
||||||
var group = Group.all.find(group => group.name.toLowerCase() == bone_name)
|
var group = Group.all.find(group => group.name.toLowerCase() == lowercase_bone_name)
|
||||||
if (group) {
|
let uuid = group ? group.uuid : guid();
|
||||||
var ba = new BoneAnimator(group.uuid, animation);
|
|
||||||
animation.animators[group.uuid] = ba;
|
var ba = new BoneAnimator(uuid, animation, bone_name);
|
||||||
|
animation.animators[uuid] = ba;
|
||||||
//Channels
|
//Channels
|
||||||
for (var channel in b) {
|
for (var channel in b) {
|
||||||
if (Animator.possible_channels[channel]) {
|
if (Animator.possible_channels[channel]) {
|
||||||
@ -1033,7 +1036,6 @@ const Animator = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (a.sound_effects) {
|
if (a.sound_effects) {
|
||||||
if (!animation.animators.effects) {
|
if (!animation.animators.effects) {
|
||||||
animation.animators.effects = new EffectAnimator(animation);
|
animation.animators.effects = new EffectAnimator(animation);
|
||||||
|
Loading…
Reference in New Issue
Block a user