Fix #1860 playback of loop modes in anim controllers

Fix error when saving timeline setup
Support "context.is_first_person" for attachables
This commit is contained in:
JannisX11 2023-05-05 19:46:42 +02:00
parent da328a0751
commit 680db62587
5 changed files with 18 additions and 4 deletions

View File

@ -477,7 +477,13 @@ class Animation extends AnimationItem {
}
}
get time() {
return (this.length && this.loop === 'loop') ? ((Timeline.time - 0.001) % this.length) + 0.001 : Timeline.time;
if (!this.length || this.loop == 'once') {
return Timeline.time;
} else if (this.loop === 'loop') {
return ((Timeline.time - 0.001) % this.length) + 0.001;
} else if (this.loop === 'hold') {
return Math.min(Timeline.time, this.length);
}
}
createUniqueName(arr) {
var scope = this;
@ -1116,6 +1122,9 @@ const Animator = {
if (!node.constructor.animator) return;
Animator.resetLastValues();
animations.forEach(animation => {
if (animation.loop == 'once' && Timeline.time > animation.length && animation.length) {
return;
}
let multiplier = animation.blend_weight ? Math.clamp(Animator.MolangParser.parse(animation.blend_weight), 0, Infinity) : 1;
if (typeof controller_blend_values[animation.uuid] == 'number') multiplier *= controller_blend_values[animation.uuid];
animation.getBoneAnimator(node).displayFrame(multiplier);

View File

@ -1,4 +1,4 @@
Animator.MolangParser.context = {};
Animator.MolangParser.global_variables = {
'true': 1,
'false': 0,
@ -8,7 +8,7 @@ Animator.MolangParser.global_variables = {
return Math.clamp(time, 0, 0.1);
},
get 'query.anim_time'() {
return Animation.selected ? Animation.selected.time : Timeline.time;
return Animator.MolangParser.context.animation ? Animator.MolangParser.context.animation.time : Timeline.time;
},
get 'query.life_time'() {
return Timeline.time;
@ -69,6 +69,9 @@ Animator.MolangParser.global_variables = {
get 'query.is_first_person'() {
return Project.bedrock_animation_mode == 'attachable_first' ? 1 : 0;
},
get 'context.is_first_person'() {
return Project.bedrock_animation_mode == 'attachable_first' ? 1 : 0;
},
get 'time'() {
return Timeline.time;
}

View File

@ -444,6 +444,7 @@ class BoneAnimator extends GeneralAnimator {
displayFrame(multiplier = 1) {
if (!this.doRender()) return;
this.getGroup()
Animator.MolangParser.context.animation = this.animation;
if (!this.muted.rotation) this.displayRotation(this.interpolate('rotation'), multiplier)
if (!this.muted.position) this.displayPosition(this.interpolate('position'), multiplier)

View File

@ -202,7 +202,7 @@ const Blockbench = {
text: {full_width: true, placeholder, value}
},
onConfirm({text}) {
callback(text);
if (callback) callback(text);
resolve(text);
},
onOpen() {

View File

@ -301,6 +301,7 @@ class ModelProject {
if (TextureAnimator.isPlaying) TextureAnimator.stop();
this.selected = false;
Painter.current = {};
Animator.MolangParser.context = {};
scene.remove(this.model_3d);
OutlinerNode.uuids = {};
Format = 0;