Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Show the animation player when on retargeting animation listing. hide the skeleton helper when on animation listing

Scott Petrovica795e6ac2452
diff --git a/src/Mesh2MotionEngine.ts b/src/Mesh2MotionEngine.ts
index 0a7277a..bcac6c6 100644
--- a/src/Mesh2MotionEngine.ts
+++ b/src/Mesh2MotionEngine.ts
@@ -269,6 +269,21 @@ export class Mesh2MotionEngine {
}
}
+ // the retargeting functionality also uses, so expose this out publicly
+ public show_animation_player (show: boolean): void {
+ if (this.ui.dom_animation_player === null) {
+ console.error('Cannot find animation player DOM element to show/hide')
+ return
+ }
+
+ if (show) {
+ this.ui.dom_animation_player.style.display = 'flex'
+ return
+ }
+
+ this.ui.dom_animation_player.style.display = 'none'
+ }
+
public process_step_changed (process_step: ProcessStep): ProcessStep {
// we will have the current step turn on the UI elements it needs
this.ui.hide_all_elements()
@@ -281,12 +296,10 @@ export class Mesh2MotionEngine {
this.load_skeleton_step.dispose()
// only show animation player on the animation listing page
- if (this.ui.dom_animation_player !== null) {
- this.ui.dom_animation_player.style.display = 'none'
-
- if (process_step === ProcessStep.AnimationsListing) {
- this.ui.dom_animation_player.style.display = 'flex'
- }
+ if (process_step === ProcessStep.AnimationsListing) {
+ this.show_animation_player(true)
+ } else {
+ this.show_animation_player(false)
}
/**********
diff --git a/src/retarget/RetargetAnimationListing.ts b/src/retarget/RetargetAnimationListing.ts
index dc19a1e..39cbac6 100644
--- a/src/retarget/RetargetAnimationListing.ts
+++ b/src/retarget/RetargetAnimationListing.ts
@@ -208,11 +208,6 @@ export class RetargetAnimationListing extends EventTarget {
return this.animation_search?.get_selected_animation_indices() ?? []
}
- // public frame_change (delta_time: number): void {
- // this.mixer().update(delta_time)
- // this.animation_player.update(delta_time)
- // }
-
private setup_animation_loop (): void {
let last_time = performance.now()
const animate = (): void => {
diff --git a/src/retarget/index.html b/src/retarget/index.html
index 07560cf..6dd6a11 100644
--- a/src/retarget/index.html
+++ b/src/retarget/index.html
@@ -8,6 +8,7 @@
<!-- Stylesheets-->
<link href="../styles.css" rel="stylesheet" crossorigin="anonymous" />
+ <link rel="stylesheet" href="../animation-player.css" crossorigin="anonymous" />
<link rel="stylesheet" href="./retarget.css" crossorigin="anonymous" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0" />
diff --git a/src/retarget/retarget.ts b/src/retarget/retarget.ts
index dc5f319..ddd0e69 100644
--- a/src/retarget/retarget.ts
+++ b/src/retarget/retarget.ts
@@ -66,21 +66,25 @@ class RetargetModule {
bone_mapping_step.style.display = 'inline'
}
+ // show the skeleton helper again since we hid it while on the animation listing step
+ this.step_load_source_skeleton.show_skeleton_helper(true)
+
// stop the animation listing step
if (this.animation_listing_step !== null) {
this.animation_listing_step.stop_preview()
}
- // start the live preview again
+ // start the live preview again and hide the animation player
this.start_live_preview()
+ this.mesh2motion_engine.show_animation_player(false)
}
// Listen for source skeleton (Mesh2Motion) loaded
this.step_load_source_skeleton.addEventListener('skeleton-loaded', () => {
const source_armature = this.step_load_source_skeleton.get_loaded_source_armature()
const skeleton_type = this.step_load_source_skeleton.get_skeleton_type()
+
this.step_bone_mapping.set_source_skeleton_data(source_armature, skeleton_type)
- this.start_live_preview()
})
// Listen for target model (user-uploaded) loaded
@@ -103,6 +107,9 @@ class RetargetModule {
animation_export_options.style.display = 'inline'
}
+ // hide the skeleton helper that is offset since we have committed and are continuing
+ this.step_load_source_skeleton.show_skeleton_helper(false)
+
// stop the live preview step from playing its animation
this.retarget_animation_preview.stop_preview()
@@ -112,6 +119,7 @@ class RetargetModule {
this.step_bone_mapping
)
this.animation_listing_step.begin(this.step_load_source_skeleton.get_skeleton_type())
+ this.mesh2motion_engine.show_animation_player(true)
const retargetable_meshes: Scene | null = this.step_load_target_model.get_retargetable_meshes()
diff --git a/src/retarget/steps/StepLoadSourceSkeleton.ts b/src/retarget/steps/StepLoadSourceSkeleton.ts
index 87fbac3..ca8606c 100644
--- a/src/retarget/steps/StepLoadSourceSkeleton.ts
+++ b/src/retarget/steps/StepLoadSourceSkeleton.ts
@@ -146,6 +146,12 @@ export class StepLoadSourceSkeleton extends EventTarget {
return has_bones
}
+ public show_skeleton_helper (visible: boolean): void {
+ if (this.skeleton_helper !== null) {
+ this.skeleton_helper.visible = visible
+ }
+ }
+
private add_skeleton_and_helper_to_scene (): void {
// Add the source skeleton to the scene
this._main_scene.add(this.loaded_source_armature)