Skip to content

Commit

Permalink
Merge pull request #804 from galacean/fix/time-accuracy
Browse files Browse the repository at this point in the history
fix: message item triggering issue caused by time accuracy
  • Loading branch information
yiiqii authored Dec 26, 2024
2 parents d76b791 + 6013f96 commit 3074284
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/effects-core/src/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ export class Composition extends EventEmitter<CompositionEvent<Composition>> imp
return;
}

const dt = this.getUpdateTime(deltaTime * this.speed);
const dt = parseFloat(this.getUpdateTime(deltaTime * this.speed).toFixed(0));

this.updateRootComposition(dt / 1000);
this.updateVideo();
Expand Down
12 changes: 3 additions & 9 deletions packages/effects-core/src/plugins/interact/interact-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ export class InteractComponent extends RendererComponent {
const composition = this.item.composition;
const { type, showPreview } = this.interactData.options as spec.ClickInteractOption;

this.item.composition?.on('goto', () => {
if (this.item.time > 0) {
this.duringPlay = true;

}
});
if (type === spec.InteractType.CLICK) {
this.clickable = true;
if (showPreview && env === PLAYER_OPTIONS_ENV_EDITOR) {
Expand Down Expand Up @@ -131,13 +125,13 @@ export class InteractComponent extends RendererComponent {
}

override onUpdate (dt: number): void {
this.duringPlay = true;

// trigger messageBegin when item enter
if (this.item.time > 0 && !this.duringPlay) {
if (this.item.time > 0 && this.item.time - dt / 1000 <= 0) {
const options = this.item.props.content.options as spec.DragInteractOption;

this.item.composition?.addInteractiveItem(this.item, options.type);
this.duringPlay = true;

}

this.previewContent?.updateMesh();
Expand Down
2 changes: 1 addition & 1 deletion packages/effects-core/src/plugins/timeline/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class RuntimeClip {
}
this.parentMixer.setInputWeight(this.playable, weight);

const clipTime = clip.toLocalTime(localTime);
const clipTime = parseFloat(clip.toLocalTime(localTime).toFixed(3));

this.playable.setTime(clipTime);

Expand Down

0 comments on commit 3074284

Please sign in to comment.