From e0b59a7b5352795eaede793fbf043b9ed7664fd6 Mon Sep 17 00:00:00 2001 From: Miles Ryan <75916236+Quicksticks-oss@users.noreply.github.com> Date: Mon, 29 Jul 2024 14:29:35 -0400 Subject: [PATCH] Feature/bugfix mmd (#655) --- app/pages/PageEnigma/Editor/scene.ts | 4 ++++ app/pages/PageEnigma/Editor/timeline.ts | 13 ++----------- .../datastructures/clips/animation_clip.ts | 18 ++++++++++-------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/app/pages/PageEnigma/Editor/scene.ts b/app/pages/PageEnigma/Editor/scene.ts index 365dbc8352..276435b069 100644 --- a/app/pages/PageEnigma/Editor/scene.ts +++ b/app/pages/PageEnigma/Editor/scene.ts @@ -667,6 +667,10 @@ class Scene { media_url: string, progress: (event: ProgressEvent) => void, ): Promise { + + // TODO: When converted to ts remove this and make ammo await instead. + await this.delay_mmd(100); + console.log('Load MMD') const scriptModule = document.createElement('script'); scriptModule.type = 'module'; diff --git a/app/pages/PageEnigma/Editor/timeline.ts b/app/pages/PageEnigma/Editor/timeline.ts index f8055b410a..32054e32f7 100644 --- a/app/pages/PageEnigma/Editor/timeline.ts +++ b/app/pages/PageEnigma/Editor/timeline.ts @@ -835,11 +835,6 @@ export class TimeLine { this.is_playing, this.scrubber_frame_position, // Double FPS for best result. ); - let mmdDelta = delta_time; - if(mmdDelta == 0){ - mmdDelta = 0.001; - } - this.scene.helper.update(mmdDelta); //this.animation_engine.clips[object.uuid + element.media_id].update_bones(); } } else if (element.type === ClipType.EXPRESSION) { @@ -849,15 +844,11 @@ export class TimeLine { ].step(this.scrubber_frame_position - element.offset, object); } } - //this.timelineItems = this.timelineItems.filter(item => item !== element) } } - // if(isRendering === false){ - // for (const video_plane of this.scene.video_planes) { - // video_plane.pause(); - // } - // } + + this.scene.helper.update(0.1); if ( this.scrubber_frame_position >= this.timeline_limit && diff --git a/app/pages/PageEnigma/datastructures/clips/animation_clip.ts b/app/pages/PageEnigma/datastructures/clips/animation_clip.ts index 0ce5d9557d..a3fb922c6b 100644 --- a/app/pages/PageEnigma/datastructures/clips/animation_clip.ts +++ b/app/pages/PageEnigma/datastructures/clips/animation_clip.ts @@ -1,6 +1,6 @@ import * as THREE from "three"; import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js"; -import { FBXLoader, MMDAnimationHelper } from "three/examples/jsm/Addons.js"; +import { FBXLoader, MMDAnimationHelper, MMDAnimationHelperMixer } from "three/examples/jsm/Addons.js"; import { MMDLoader } from "three/addons/loaders/MMDLoader.js"; import { MoveAIResult, Retarget } from "../../Editor/retargeting"; @@ -23,6 +23,7 @@ export class AnimationClip { last_frame: number; private isMMD: boolean = false; + private obj: MMDAnimationHelperMixer | undefined; constructor( version: number, @@ -132,13 +133,6 @@ export class AnimationClip { this.clip_action = this.mixer?.clipAction(anim_clip); if (this.clip_action) { if (this.clip_action?.isRunning() == false) { - if(this.isMMD) { - const helper: MMDAnimationHelper = object.parent?.userData["helper"]; - const obj = helper.objects.get((object as THREE.SkinnedMesh)); - if(obj) { - obj.mixer = this.mixer; - } - } this.clip_action.play(); } } @@ -202,6 +196,14 @@ export class AnimationClip { } animate(deltatime: number) { + if(this.isMMD && this.mixer) { + const helper: MMDAnimationHelper = this.mixer?.getRoot().parent?.userData["helper"]; + this.obj = helper.objects.get((this.mixer?.getRoot() as THREE.SkinnedMesh)); + if(this.obj && this.obj.mixer !== this.mixer) { + this.obj.mixer = this.mixer; + } + } + this.mixer?.setTime(deltatime); this.update_bones(); }