Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Add one more option for a single hand bone

Scott Petrovicb12a74561a4f
diff --git a/src/index.html b/src/index.html
index d986ab7..4bd6380 100644
--- a/src/index.html
+++ b/src/index.html
@@ -122,15 +122,16 @@
Hand Options:
<div class="tooltip" style="display: inline-block; margin-left: 0.5rem;">
<span class="material-symbols-outlined" style="font-size: 16px;">help</span>
- <span class="tooltiptext">Variations on which finger bones you want to keep. </span>
+ <span class="tooltiptext">Variations on which finger bones you want to keep. Single Hand Bone removes all fingers and keeps only the hand bone.</span>
</div>
</span>
<select id="hand-skeleton-selection">
<option value="all-fingers">All Fingers</option>
<option value="thumb-and-index">Thumb + Main Finger</option>
- <option value="simplified-hand">Simplified Hand</option>
- </select>
+ <option value="simplified-hand">All Fingers - Simplified</option>
+ <option value="single-bone">Single Hand Bone</option>
+ </select>
</div>
<!-- <hr /> -->
diff --git a/src/lib/enums/SkeletonType.ts b/src/lib/enums/SkeletonType.ts
index 322d8b2..3409e3c 100644
--- a/src/lib/enums/SkeletonType.ts
+++ b/src/lib/enums/SkeletonType.ts
@@ -10,5 +10,6 @@ export enum SkeletonType {
export enum HandSkeletonType {
AllFingers = 'all-fingers',
ThumbAndIndex = 'thumb-and-index',
- SimplifiedHand = 'simplified-hand'
+ SimplifiedHand = 'simplified-hand',
+ SingleBone = 'single-bone'
}
diff --git a/src/lib/processes/StepLoadSkeleton.ts b/src/lib/processes/StepLoadSkeleton.ts
index 03a4573..38712cb 100644
--- a/src/lib/processes/StepLoadSkeleton.ts
+++ b/src/lib/processes/StepLoadSkeleton.ts
@@ -146,12 +146,17 @@ export class StepLoadSkeleton extends EventTarget {
const bone = child
const bone_name = (bone.name ?? '').toLowerCase() as string
+ // bone is not part of hand, we can just skip it
+ // we also always keep the palm of the hand
+ if (!this.is_hand_bone(bone_name) || this.is_palm_bone(bone_name)) {
+ return
+ }
+
// remove bones on mesh based on hand type selected on UI
switch (hand_type) {
case HandSkeletonType.ThumbAndIndex:
// Remove all finger bones except thumb and index finger
- if (this.is_finger_bone(bone_name) &&
- !this.is_thumb_bone(bone_name) &&
+ if (!this.is_thumb_bone(bone_name) &&
!this.is_middle_finger_bone(bone_name)) {
bones_to_remove.push(bone)
}
@@ -168,6 +173,20 @@ export class StepLoadSkeleton extends EventTarget {
bones_to_remove.push(bone)
}
break
+
+ case HandSkeletonType.SingleBone:
+ // Remove all non-middle finger bones, keeping one line of bones
+ if (!this.is_middle_finger_bone(bone_name)) {
+ bones_to_remove.push(bone)
+ break
+ }
+
+ // remove all tip bones
+ if (this.is_end_tip_bone(bone_name) || bone_name.includes('03') || bone_name.includes('04') || bone_name.includes('02')) {
+ bones_to_remove.push(bone)
+ }
+
+ break
}
}
})
@@ -182,17 +201,18 @@ export class StepLoadSkeleton extends EventTarget {
console.log(`Modified hand skeleton: ${hand_type}, removed ${bones_to_remove.length} bones`)
}
- private is_finger_bone (bone_name: string): boolean {
- const finger_patterns = ['finger', 'thumb', 'index', 'middle', 'ring', 'pinky']
- return finger_patterns.some(pattern => bone_name.includes(pattern))
+ private is_hand_bone (bone_name: string): boolean {
+ const hand_patterns = ['hand', 'finger', 'thumb', 'index', 'middle', 'ring', 'pinky']
+ return hand_patterns.some(pattern => bone_name.includes(pattern))
}
- private is_thumb_bone (bone_name: string): boolean {
- return bone_name.includes('thumb')
+ private is_palm_bone (bone_name: string): boolean {
+ const hand_patterns = ['hand']
+ return hand_patterns.some(pattern => bone_name.includes(pattern))
}
- private is_index_finger_bone (bone_name: string): boolean {
- return bone_name.includes('index')
+ private is_thumb_bone (bone_name: string): boolean {
+ return bone_name.includes('thumb')
}
private is_middle_finger_bone (bone_name: string): boolean {