@sage-rsc/talking-head-react 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -2
- package/dist/index.js +777 -772
- package/package.json +1 -1
- package/src/lib/talkinghead.mjs +34 -28
package/package.json
CHANGED
package/src/lib/talkinghead.mjs
CHANGED
|
@@ -1667,32 +1667,28 @@ class TalkingHead {
|
|
|
1667
1667
|
const tempEuler = new THREE.Euler();
|
|
1668
1668
|
const tempQuaternion = new THREE.Quaternion();
|
|
1669
1669
|
|
|
1670
|
-
//
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
//
|
|
1674
|
-
//
|
|
1675
|
-
//
|
|
1676
|
-
// High shoulders: X rotation > 0.8 radians
|
|
1677
|
-
// We reduce high rotations by 40-50% to bring them down while maintaining arm relationships
|
|
1678
|
-
const reductionFactor = isFBXPlaying ? 0.5 : 0.6; // Reduce by 50% during FBX, 40% otherwise
|
|
1679
|
-
const maxAllowedX = 0.7; // Maximum allowed X rotation
|
|
1670
|
+
// Research-based relaxed shoulder rotation values
|
|
1671
|
+
// Natural relaxed shoulders: X rotation ~0.5-0.7 radians (much lower for natural look)
|
|
1672
|
+
// High/stiff shoulders: X rotation ~1.5-1.8 radians
|
|
1673
|
+
// We aggressively clamp to a very relaxed position
|
|
1674
|
+
const targetX = 0.6; // Target X rotation for relaxed, natural shoulders (radians) - lowered significantly
|
|
1675
|
+
const maxX = 0.7; // Maximum allowed X rotation - lowered significantly
|
|
1680
1676
|
|
|
1681
1677
|
// Adjust left shoulder bone directly
|
|
1682
1678
|
if (leftShoulderBone.quaternion) {
|
|
1683
1679
|
tempEuler.setFromQuaternion(leftShoulderBone.quaternion, 'XYZ');
|
|
1684
1680
|
const originalX = tempEuler.x;
|
|
1685
1681
|
|
|
1686
|
-
//
|
|
1687
|
-
if (tempEuler.x >
|
|
1688
|
-
//
|
|
1689
|
-
tempEuler.x =
|
|
1690
|
-
} else if (tempEuler.x >
|
|
1691
|
-
//
|
|
1692
|
-
tempEuler.x = tempEuler.x
|
|
1682
|
+
// Aggressively clamp X rotation to relaxed position
|
|
1683
|
+
if (tempEuler.x > maxX) {
|
|
1684
|
+
// Force to target relaxed position
|
|
1685
|
+
tempEuler.x = targetX;
|
|
1686
|
+
} else if (tempEuler.x > targetX) {
|
|
1687
|
+
// Smoothly reduce if slightly above target
|
|
1688
|
+
tempEuler.x = targetX + (tempEuler.x - targetX) * 0.2; // More aggressive reduction
|
|
1693
1689
|
}
|
|
1694
1690
|
|
|
1695
|
-
// Only update if we changed something
|
|
1691
|
+
// Only update if we actually changed something
|
|
1696
1692
|
if (Math.abs(tempEuler.x - originalX) > 0.01) {
|
|
1697
1693
|
tempQuaternion.setFromEuler(tempEuler, 'XYZ');
|
|
1698
1694
|
leftShoulderBone.quaternion.copy(tempQuaternion);
|
|
@@ -1705,16 +1701,16 @@ class TalkingHead {
|
|
|
1705
1701
|
tempEuler.setFromQuaternion(rightShoulderBone.quaternion, 'XYZ');
|
|
1706
1702
|
const originalX = tempEuler.x;
|
|
1707
1703
|
|
|
1708
|
-
//
|
|
1709
|
-
if (tempEuler.x >
|
|
1710
|
-
//
|
|
1711
|
-
tempEuler.x =
|
|
1712
|
-
} else if (tempEuler.x >
|
|
1713
|
-
//
|
|
1714
|
-
tempEuler.x = tempEuler.x
|
|
1704
|
+
// Aggressively clamp X rotation to relaxed position
|
|
1705
|
+
if (tempEuler.x > maxX) {
|
|
1706
|
+
// Force to target relaxed position
|
|
1707
|
+
tempEuler.x = targetX;
|
|
1708
|
+
} else if (tempEuler.x > targetX) {
|
|
1709
|
+
// Smoothly reduce if slightly above target
|
|
1710
|
+
tempEuler.x = targetX + (tempEuler.x - targetX) * 0.2; // More aggressive reduction
|
|
1715
1711
|
}
|
|
1716
1712
|
|
|
1717
|
-
// Only update if we changed something
|
|
1713
|
+
// Only update if we actually changed something
|
|
1718
1714
|
if (Math.abs(tempEuler.x - originalX) > 0.01) {
|
|
1719
1715
|
tempQuaternion.setFromEuler(tempEuler, 'XYZ');
|
|
1720
1716
|
rightShoulderBone.quaternion.copy(tempQuaternion);
|
|
@@ -5764,6 +5760,7 @@ class TalkingHead {
|
|
|
5764
5760
|
// Filter and map animation tracks
|
|
5765
5761
|
const mappedTracks = [];
|
|
5766
5762
|
const unmappedBones = new Set();
|
|
5763
|
+
let filteredShoulderTracks = 0;
|
|
5767
5764
|
anim.tracks.forEach(track => {
|
|
5768
5765
|
// Remove mixamorig prefix first
|
|
5769
5766
|
let trackName = track.name.replaceAll('mixamorig', '');
|
|
@@ -5774,8 +5771,13 @@ class TalkingHead {
|
|
|
5774
5771
|
// Map bone name to avatar skeleton
|
|
5775
5772
|
const mappedBoneName = mapBoneName(fbxBoneName);
|
|
5776
5773
|
|
|
5777
|
-
//
|
|
5778
|
-
|
|
5774
|
+
// Filter out shoulder rotation tracks - we'll control shoulders manually
|
|
5775
|
+
if (mappedBoneName && (mappedBoneName === 'LeftShoulder' || mappedBoneName === 'RightShoulder')) {
|
|
5776
|
+
if (property === 'quaternion' || property === 'rotation') {
|
|
5777
|
+
filteredShoulderTracks++;
|
|
5778
|
+
return; // Skip this track - don't add it to mappedTracks
|
|
5779
|
+
}
|
|
5780
|
+
}
|
|
5779
5781
|
|
|
5780
5782
|
if (mappedBoneName && property) {
|
|
5781
5783
|
// Create new track with mapped bone name
|
|
@@ -5804,6 +5806,10 @@ class TalkingHead {
|
|
|
5804
5806
|
}
|
|
5805
5807
|
});
|
|
5806
5808
|
|
|
5809
|
+
if (filteredShoulderTracks > 0) {
|
|
5810
|
+
console.log(`✓ Filtered out ${filteredShoulderTracks} shoulder rotation track(s) to prevent high shoulders`);
|
|
5811
|
+
}
|
|
5812
|
+
|
|
5807
5813
|
if (unmappedBones.size > 0) {
|
|
5808
5814
|
console.warn(`⚠️ ${unmappedBones.size} bone(s) could not be mapped:`, Array.from(unmappedBones).sort().join(', '));
|
|
5809
5815
|
}
|