Import a 3D Model and automatically assign and export animations
TypeScript
Start adding UI indicator when there is a skeleton match
Scott Petrovic3c9f70987c79
diff --git a/src/retarget/bone-automap/BoneAutoMapper.ts b/src/retarget/bone-automap/BoneAutoMapper.tsindex cbdf21e..288398f 100644--- a/src/retarget/bone-automap/BoneAutoMapper.ts+++ b/src/retarget/bone-automap/BoneAutoMapper.ts@@ -51,10 +51,7 @@ export class BoneAutoMapper {* @param target_armature - Target skeleton armature (uploaded mesh)* @returns Map of target bone name -> source bone name*/- public static auto_map_bones (- target_armature: Scene,- target_bone_mapping_type: TargetBoneMappingType- ): Map<string, string> {+ public static auto_map_bones (): Map<string, string> {// mappings: final output mapping of target bone name to source bone namelet mappings = new Map<string, string>()@@ -84,7 +81,7 @@ export class BoneAutoMapper {// if the target is a mixamo rig and our skeleton type is human, we can do a direct name mapping// without worrying about guessing- if (target_bone_mapping_type === TargetBoneMappingType.Mixamo) {+ if (retarget_service.get_target_mapping_type() === TargetBoneMappingType.Mixamo) {console.log('Target skeleton appears to be a Mixamo rig, performing direct name mapping...')mappings = MixamoMapper.map_mixamo_bones(source_bones_meta, target_bones_meta)return mappingsdiff --git a/src/retarget/index.html b/src/retarget/index.htmlindex 3bf726c..fc1ce20 100644--- a/src/retarget/index.html+++ b/src/retarget/index.html@@ -75,7 +75,10 @@<!-- imported 3d skinned mesh (target) - drop zone for bones --><div class="bone-map-section">- <p class="bone-map-heading">Your 3D Rig Model (Target)</p>+ <p class="bone-map-heading">+ Your 3D Rig Model (Target)+ <span id="auto-bone-map-match">✨Mixamo</span>+ </p><div class="bone-map-content"><div style="display: flex; gap: 0.5rem;"><!-- there are some issues going on with scaling the skeleton for FBX and other formats so we will start simple for now with just GLB files -->diff --git a/src/retarget/retarget.css b/src/retarget/retarget.cssindex 8987dd9..8ef4126 100644--- a/src/retarget/retarget.css+++ b/src/retarget/retarget.css@@ -119,4 +119,12 @@ h1 {#animation-listing-count {top: 1.4rem;+}++#auto-bone-map-match {+ font-size: 0.9rem;+ border: 2px solid var(--bg-tertiary);+ padding: 0.2rem 0.4rem;+ border-radius: 0.25rem;+ display: none;}\ No newline at end of filediff --git a/src/retarget/steps/StepBoneMapping.ts b/src/retarget/steps/StepBoneMapping.tsindex d352845..52e9b7d 100644--- a/src/retarget/steps/StepBoneMapping.ts+++ b/src/retarget/steps/StepBoneMapping.ts@@ -20,6 +20,7 @@ export class StepBoneMapping extends EventTarget {private auto_map_button: HTMLButtonElement | null = nullprivate source_bone_count: HTMLSpanElement | null = nullprivate target_bone_count: HTMLSpanElement | null = null+ private auto_bone_map_match_display: HTMLSpanElement | null = null// Bone mapping: target bone name (uploaded mesh) -> source bone name (Mesh2Motion skeleton)// private bone_mapping = new Map<string, string>()@@ -34,6 +35,9 @@ export class StepBoneMapping extends EventTarget {this.clear_mappings_button = document.getElementById('clear-mappings-button') as HTMLButtonElementthis.auto_map_button = document.getElementById('auto-map-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+// for display only on the bones list for referencethis.source_bone_count = document.getElementById('source-bone-count') as HTMLSpanElementthis.target_bone_count = document.getElementById('target-bone-count') as HTMLSpanElement@@ -318,6 +322,23 @@ export class StepBoneMapping extends EventTarget {this.clear_mappings_button.style.display = this.has_bone_mappings() ? 'block' : 'none'}+ // Show what type of auto-mapping match we got on the UI+ private update_bone_match_type_display (): void {+ if (this.auto_bone_map_match_display === null) return++ const mapping_type: TargetBoneMappingType = AnimationRetargetService.getInstance().get_target_mapping_type()++ if (mapping_type === TargetBoneMappingType.Mixamo) {+ this.auto_bone_map_match_display.style.display = 'inline-flex'+ this.auto_bone_map_match_display.textContent = '✨Mixamo'+ } else if (mapping_type === TargetBoneMappingType.Mesh2Motion) {+ this.auto_bone_map_match_display.style.display = 'inline-flex'+ this.auto_bone_map_match_display.textContent = '🚀Mesh2Motion'+ } else {+ this.auto_bone_map_match_display.style.display = 'none'+ }+ }+// Update visibility of auto-map buttonprivate update_auto_map_button_visibility (): void {if (this.auto_map_button === null) return@@ -331,6 +352,7 @@ export class StepBoneMapping extends EventTarget {this.update_target_bones_list()this.update_clear_button_visibility()+ this.update_bone_match_type_display()this.dispatchEvent(new CustomEvent('bone-mappings-changed'))}@@ -341,6 +363,7 @@ export class StepBoneMapping extends EventTarget {this.update_target_bones_list()this.update_clear_button_visibility()+ this.update_bone_match_type_display()this.dispatchEvent(new CustomEvent('bone-mappings-changed'))}@@ -364,10 +387,7 @@ export class StepBoneMapping extends EventTarget {}// Use BoneAutoMapper to generate mappings- const auto_mappings = BoneAutoMapper.auto_map_bones(- retarget_service.get_target_armature(),- retarget_service.get_target_mapping_type()- )+ const auto_mappings = BoneAutoMapper.auto_map_bones()// Apply the auto-generated mappingsretarget_service.set_bone_mappings(auto_mappings)@@ -376,6 +396,7 @@ export class StepBoneMapping extends EventTarget {// Update UIthis.update_target_bones_list()this.update_clear_button_visibility()+ this.update_bone_match_type_display()this.dispatchEvent(new CustomEvent('bone-mappings-changed'))}}