Import a 3D Model and automatically assign and export animations
TypeScript
if target is using a Mesh2Motion rig, no need to use bones. Show that messaging
Scott Petrovicf0fa42ef9b42
diff --git a/src/retarget/RetargetUtils.ts b/src/retarget/RetargetUtils.tsindex 83eaa20..e4d81f5 100644--- a/src/retarget/RetargetUtils.ts+++ b/src/retarget/RetargetUtils.ts@@ -22,7 +22,7 @@ export class RetargetUtils {* Validates that the retargetable model contains SkinnedMeshes with bones* @returns true if valid SkinnedMeshes are found, false otherwise*/- static validate_skinned_mesh_has_bones (retargetable_model: Scene): boolean {+ static validate_skinned_mesh_has_bones (retargetable_model: Scene, show_error: boolean = true): boolean {// Collect all SkinnedMesheslet has_skinned_mesh_with_bones = falseretargetable_model.traverse((child) => {@@ -33,7 +33,9 @@ export class RetargetUtils {// Check if we have any SkinnedMeshesif (!has_skinned_mesh_with_bones) {- new ModalDialog('No SkinnedMeshes found in file', 'Error opening file').show()+ if (show_error) {+ new ModalDialog('No SkinnedMeshes found in file', 'Error opening file').show()+ }return false}@@ -41,6 +43,39 @@ export class RetargetUtils {return true}+ /**+ * Determines if our target rig is a perfect match to the source rig (M2M) by comparing bone names+ * When this happens, we don't need any bone mapping since we have a 1:1 match+ * @param source_armature Always a Mesh2Motion rig+ * @param target_armature user-uploaded rig+ * @returns boolean indicating if the bone names are identical+ */+ static are_source_and_target_bones_identical (source_armature: Group, target_armature: Scene): boolean {+ // if there is no target armature at all, return false+ if (!this.validate_skinned_mesh_has_bones(target_armature, false)) {+ return false+ }++ // collect all bones from source+ const source_bone_names: Set<string> = new Set<string>()+ source_armature.traverse((child) => {+ if (child.type === 'Bone') {+ source_bone_names.add(child.name)+ }+ })++ let all_bones_match = true+ target_armature.traverse((child) => {+ if (child.type === 'Bone') {+ if (!source_bone_names.has(child.name)) {+ all_bones_match = false+ }+ }+ })++ return all_bones_match+ }+/*** Get the animation file path based on skeleton type*/diff --git a/src/retarget/index.html b/src/retarget/index.htmlindex 6b80d86..4c0e5f2 100644--- a/src/retarget/index.html+++ b/src/retarget/index.html@@ -91,10 +91,14 @@<button id="clear-mappings-button" class="secondary-button" style="display: none;">Clear Mappings</button></div>- <p>Bones List <span id="target-bone-count">(0)</span></p>- <div id="target-bones-list">- <p style="color: var(--text-secondary);">No target skeleton loaded</p>- </div>+ <span id="target-bones-list-container">+ <p>Bones List <span id="target-bone-count">(0)</span></p>+ <div id="target-bones-list">+ <p style="color: var(--text-secondary);">No target skeleton loaded</p>+ </div>+ </span>+ <span id="no-bone-mapping-needed-message" style="display: none;">No bone mapping needed. The uploaded model is using a Mesh2Motion rig. The bone names of this match the source skeleton exactly.</span>+</div></div>diff --git a/src/retarget/retarget.css b/src/retarget/retarget.cssindex ada04b6..92fa3d8 100644--- a/src/retarget/retarget.css+++ b/src/retarget/retarget.css@@ -127,4 +127,10 @@ h1 {padding: 0.2rem 0.4rem;border-radius: 0.25rem;display: none;+}++#no-bone-mapping-needed-message {+ max-width: 13rem;+ margin-top: 2rem;+ font-style: italic;}\ No newline at end of filediff --git a/src/retarget/retarget.ts b/src/retarget/retarget.tsindex 6041279..c54016f 100644--- a/src/retarget/retarget.ts+++ b/src/retarget/retarget.ts@@ -7,6 +7,7 @@ import { RetargetAnimationPreview } from './RetargetAnimationPreview.ts'import { RetargetAnimationListing } from './RetargetAnimationListing.ts'import { AnimationRetargetService } from './AnimationRetargetService'import { type SkeletonType } from '../lib/enums/SkeletonType.ts'+import { RetargetUtils } from './RetargetUtils.ts'class RetargetModule {private readonly mesh2motion_engine: Mesh2MotionEngine@@ -85,6 +86,11 @@ class RetargetModule {// animation service keeps track of shared data across classesAnimationRetargetService.getInstance().set_source_armature(source_armature)AnimationRetargetService.getInstance().set_skeleton_type(skeleton_type)++ console.log('Source skeleton loaded:', skeleton_type)++ this.check_for_mesh2motion_retarget()+this.step_bone_mapping.source_armature_updated()})@@ -99,11 +105,14 @@ class RetargetModule {AnimationRetargetService.getInstance().set_target_armature(temp_target_armature)+ // if the uploaded model is a M2M rig, we don't need to do any bone mapping+ // hide the bones list and show a message+ this.check_for_mesh2motion_retarget()+// hide the skeleton helper since we are on that stepthis.step_load_source_skeleton.show_skeleton_helper(false)- // Set target skeleton data in bone mapping (uploaded mesh)- this.step_bone_mapping.target_armature_updated()+this.start_live_preview()// Show "Continue" button to proceed to animation listing@@ -136,6 +145,32 @@ class RetargetModule {}}+ private check_for_mesh2motion_retarget (): void {+ // if the source and target is identical, no need to do bone mapping step+ const identical_bones: boolean = RetargetUtils.are_source_and_target_bones_identical(+ AnimationRetargetService.getInstance().get_source_armature(),+ AnimationRetargetService.getInstance().get_target_armature()+ )++ console.log('Are source and target bones identical (no mapping needed)?', identical_bones)++ const target_bones_list_container = document.getElementById('target-bones-list-container')+ const no_bone_mapping_needed_message = document.getElementById('no-bone-mapping-needed-message')++ if (target_bones_list_container !== null) {+ target_bones_list_container.style.display = identical_bones ? 'none' : 'block'+ }++ if (no_bone_mapping_needed_message !== null) {+ no_bone_mapping_needed_message.style.display = identical_bones ? 'inline-flex' : 'none'+ }++ // bones are not the same...so we need to do bone mapping+ if (!identical_bones) {+ this.step_bone_mapping.target_armature_updated()+ }+ }+private start_live_preview (): void {// Start preview when both skeletons are loadedif (this.step_bone_mapping.has_both_skeletons()) {