Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Add if skeleton is a match with Mesh2Motion

Scott Petrovic5e8b89bfb2ec
diff --git a/src/retarget/bone-automap/Mesh2MotionMapper.ts b/src/retarget/bone-automap/Mesh2MotionMapper.ts
new file mode 100644
index 0000000..09d3802
--- /dev/null
+++ b/src/retarget/bone-automap/Mesh2MotionMapper.ts
@@ -0,0 +1,12 @@
+export class Mesh2MotionMapper {
+ /**
+ * Check if the given skeleton is a Mesh2Motion skeleton
+ * All the source bones are Mesh2Motion, so we really just need
+ * to check if the target bones match the source bones
+ * @param bones - Bones to check
+ * @returns True if all the bones match
+ */
+ static is_source_bones_same_as_target (source_bone_names: string[], target_bone_names: string[]): boolean {
+ return source_bone_names.every(name => target_bone_names.includes(name))
+ }
+}
\ No newline at end of file
diff --git a/src/retarget/index.html b/src/retarget/index.html
index fc1ce20..f473556 100644
--- a/src/retarget/index.html
+++ b/src/retarget/index.html
@@ -50,7 +50,9 @@
<div style="display: flex; flex-direction: row; gap: 1rem; margin-top: 1rem;">
<!-- Mesh2Motion skeleton (source) - draggable bones -->
<div class="bone-map-section">
- <h2 class="bone-map-heading">Mesh2Motion Skeleton (Source)</h2>
+ <h2 class="bone-map-heading">
+ <span>Mesh2Motion Skeleton (Source)</span>
+ </h2>
<div class="bone-map-content">
<div id="skeleton-selection-container" >
<select id="skeleton-type-select" class="button">
@@ -76,7 +78,7 @@
<!-- imported 3d skinned mesh (target) - drop zone for bones -->
<div class="bone-map-section">
<p class="bone-map-heading">
- Your 3D Rig Model (Target)
+ <span>Your 3D Rig Model (Target)</span>
<span id="auto-bone-map-match">✨Mixamo</span>
</p>
<div class="bone-map-content">
diff --git a/src/retarget/retarget.css b/src/retarget/retarget.css
index 8ef4126..ada04b6 100644
--- a/src/retarget/retarget.css
+++ b/src/retarget/retarget.css
@@ -10,14 +10,14 @@ h1 {
}
.bone-map-heading {
- font-size: 1.1rem;
+ display: inline-block;
color: var(--text-primary);
margin: 0;
- padding: 0.5rem;
+ padding: 1rem;
background: var(--bg-alternate);
- text-align: center;
margin-bottom: 1rem;
}
+
.bone-map-content {
padding: 1rem;
padding-top: 0;
@@ -123,7 +123,7 @@ h1 {
#auto-bone-map-match {
font-size: 0.9rem;
- border: 2px solid var(--bg-tertiary);
+ border: 3px solid var(--bg-tertiary);
padding: 0.2rem 0.4rem;
border-radius: 0.25rem;
display: none;
diff --git a/src/retarget/steps/StepBoneMapping.ts b/src/retarget/steps/StepBoneMapping.ts
index 52e9b7d..65eebc7 100644
--- a/src/retarget/steps/StepBoneMapping.ts
+++ b/src/retarget/steps/StepBoneMapping.ts
@@ -2,6 +2,7 @@ import { type Scene, type SkinnedMesh } from 'three'
import { BoneAutoMapper } from '../bone-automap/BoneAutoMapper.ts'
import { MixamoMapper } from '../bone-automap/MixamoMapper.ts'
import { AnimationRetargetService } from '../AnimationRetargetService.ts'
+import { Mesh2MotionMapper } from '../bone-automap/Mesh2MotionMapper.ts'
// when we are auto-mapping, keep track of what rig type we matched target against
export enum TargetBoneMappingType {
@@ -329,11 +330,11 @@ export class StepBoneMapping extends EventTarget {
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'
+ this.auto_bone_map_match_display.style.display = 'inline'
+ 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'
+ this.auto_bone_map_match_display.style.display = 'inline'
+ this.auto_bone_map_match_display.textContent = '✨ Mesh2Motion'
} else {
this.auto_bone_map_match_display.style.display = 'none'
}
@@ -382,6 +383,11 @@ export class StepBoneMapping extends EventTarget {
// see if target bones follow a known template
if (MixamoMapper.is_target_valid_skeleton(this.get_target_bone_names())) {
retarget_service.set_target_mapping_type(TargetBoneMappingType.Mixamo)
+ } else if (Mesh2MotionMapper.is_source_bones_same_as_target(
+ this.get_source_bone_names(),
+ this.get_target_bone_names()
+ )) {
+ retarget_service.set_target_mapping_type(TargetBoneMappingType.Mesh2Motion)
} else {
retarget_service.set_target_mapping_type(TargetBoneMappingType.Custom)
}