Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

move rotation back to bone mapping area for now

Scott Petrovice3fc40105627
diff --git a/src/retarget/RetargetAnimationListing.ts b/src/retarget/RetargetAnimationListing.ts
index e773cca..72da041 100644
--- a/src/retarget/RetargetAnimationListing.ts
+++ b/src/retarget/RetargetAnimationListing.ts
@@ -32,10 +32,6 @@ export class RetargetAnimationListing extends EventTarget {
private export_button: HTMLButtonElement | null = null
- // tracks which animation is currently playing so we can re-play it when
- // settings (like the root rotation correction) change
- private current_playing_index: number = -1
-
constructor (theme_manager: ThemeManager, download_settings: DownloadSettings) {
super()
this.theme_manager = theme_manager
@@ -203,8 +199,6 @@ export class RetargetAnimationListing extends EventTarget {
const animation_pair = this.animation_clips_loaded[index]
const display_clip = animation_pair.display_animation_clip
- this.current_playing_index = index
-
// Stop all current actions
this.animation_mixer.stopAllAction()
@@ -260,19 +254,6 @@ export class RetargetAnimationListing extends EventTarget {
})
})
- // global rig rotation correction. stored on the shared service so the
- // retargeter picks it up when clips are retargeted for playback/export,
- // then re-play the current animation so the change is visible immediately
- const root_rotation_correction_select = document.getElementById('root-rotation-correction-select') as HTMLSelectElement
- root_rotation_correction_select?.addEventListener('change', () => {
- const degrees: number = Number(root_rotation_correction_select.value ?? 0)
- AnimationRetargetService.getInstance().set_root_correction_x_degrees(degrees)
-
- if (this.current_playing_index >= 0) {
- this.play_animation(this.current_playing_index)
- }
- })
-
// event listener for select all / deselect all button
const toggle_select_all_button = document.querySelector('#toggle-select-all-animations')
toggle_select_all_button?.addEventListener('click', () => {
diff --git a/src/retarget/index.html b/src/retarget/index.html
index 76f1333..69af31e 100644
--- a/src/retarget/index.html
+++ b/src/retarget/index.html
@@ -114,6 +114,8 @@
<button id="auto-map-button" class="secondary-button" style="display: none;">Auto-Map</button>
<button id="clear-mappings-button" class="secondary-button" style="display: none;">Clear Mappings</button>
+ <button id="root-rotation-correction-button" class="secondary-button"
+ data-tippy-content="Cycle the global X-axis correction for tilted rigs. Useful when the imported rig has no root bone above the pelvis.">Fix Tilt: 0°</button>
</div>
<span id="target-bones-list-container" >
@@ -176,16 +178,6 @@
<button id="toggle-select-all-animations" class="secondary-button">Select All</button>
- <!-- global rig rotation correction for tilted rigs -->
- <select id="root-rotation-correction-select" class="button"
- data-tippy-content="If the retargeted animation is tilted (for example the character face plants), apply a global X-axis rotation to the whole rig. Useful for rigs that have no root bone above the pelvis.">
- <option value="0" selected>X Rotation: 0°</option>
- <option value="90">X Rotation: 90°</option>
- <option value="-90">X Rotation: -90°</option>
- <option value="180">X Rotation: 180°</option>
- </select>
-
-
<div id="animation-listing-count" style="white-space: nowrap;">0 animations</div>
</div>
diff --git a/src/retarget/steps/StepBoneMapping.ts b/src/retarget/steps/StepBoneMapping.ts
index 281fdeb..8480f30 100644
--- a/src/retarget/steps/StepBoneMapping.ts
+++ b/src/retarget/steps/StepBoneMapping.ts
@@ -24,6 +24,9 @@ export class StepBoneMapping extends EventTarget {
private clear_mappings_button: HTMLButtonElement | null = null
private auto_map_button: HTMLButtonElement | null = null
private view_bone_tree_button: HTMLButtonElement | null = null
+ private root_rotation_correction_button: HTMLButtonElement | null = null
+ private readonly root_rotation_correction_degrees: number[] = [0, 90, -90, 180]
+ private root_rotation_correction_index: number = 0
private source_bone_count: HTMLSpanElement | null = null
private target_bone_count: HTMLSpanElement | null = null
private auto_bone_map_match_display: HTMLSpanElement | null = null
@@ -43,6 +46,7 @@ export class StepBoneMapping extends EventTarget {
this.clear_mappings_button = document.getElementById('clear-mappings-button') as HTMLButtonElement
this.auto_map_button = document.getElementById('auto-map-button') as HTMLButtonElement
this.view_bone_tree_button = document.getElementById('view-bone-tree-button') as HTMLButtonElement
+ this.root_rotation_correction_button = document.getElementById('root-rotation-correction-button') as HTMLButtonElement
// if we get a match, show what type of match we got on the UI for feedback
this.auto_bone_map_match_display = document.getElementById('auto-bone-map-match') as HTMLSpanElement
@@ -73,6 +77,14 @@ export class StepBoneMapping extends EventTarget {
this.auto_map_bones()
})
+ this.root_rotation_correction_button?.addEventListener('click', () => {
+ this.root_rotation_correction_index = (this.root_rotation_correction_index + 1) % this.root_rotation_correction_degrees.length
+ const degrees: number = this.root_rotation_correction_degrees[this.root_rotation_correction_index]
+ AnimationRetargetService.getInstance().set_root_correction_x_degrees(degrees)
+ this.update_root_rotation_correction_button()
+ this.dispatchEvent(new CustomEvent('bone-mappings-changed'))
+ })
+
// Filter source bones as user types
this.source_bones_filter?.addEventListener('input', () => {
this.update_source_bones_list()
@@ -383,6 +395,14 @@ export class StepBoneMapping extends EventTarget {
this.auto_map_button.style.display = this.has_both_skeletons() ? 'block' : 'none'
}
+ private update_root_rotation_correction_button (): void {
+ if (this.root_rotation_correction_button === null) return
+
+ const degrees: number = this.root_rotation_correction_degrees[this.root_rotation_correction_index]
+ this.root_rotation_correction_button.textContent = `Fix Tilt: ${degrees}°`
+ this.root_rotation_correction_button.setAttribute('aria-label', `Set root X rotation correction to ${degrees} degrees`)
+ }
+
private update_view_bone_tree_button_visibility (): void {
if (this.view_bone_tree_button === null) return
this.view_bone_tree_button.style.display = this.has_target_skeleton() ? 'inline-flex' : 'none'