diff --git a/gui/app/src/components/commons/BodyPartIcon.tsx b/gui/app/src/components/commons/BodyPartIcon.tsx
index 219e68e72..ff86eaef8 100644
--- a/gui/app/src/components/commons/BodyPartIcon.tsx
+++ b/gui/app/src/components/commons/BodyPartIcon.tsx
@@ -75,8 +75,6 @@ export const mapPart: Record<
[BodyPart.CHEST]: ({ width }) => ,
[BodyPart.HEAD]: ({ width }) => ,
[BodyPart.HIP]: ({ width }) => ,
- [BodyPart.LEFT_HIP]: ({ width }) => , // Unused
- [BodyPart.RIGHT_HIP]: ({ width }) => , // Unused
[BodyPart.LEFT_FOOT]: ({ width, currentLocales }) =>
currentLocales.includes('en-x-owo') ? (
diff --git a/gui/app/src/hooks/body-parts.ts b/gui/app/src/hooks/body-parts.ts
index 7c391de7f..93add9328 100644
--- a/gui/app/src/hooks/body-parts.ts
+++ b/gui/app/src/hooks/body-parts.ts
@@ -84,7 +84,5 @@ export const ALL_BODY_PARTS = [
...SPINE_BODY_PARTS,
...LEG_BODY_PARTS,
...ARM_BODY_PARTS,
- BodyPart.LEFT_HIP,
- BodyPart.RIGHT_HIP,
...FINGER_BODY_PARTS,
];
diff --git a/gui/app/src/utils/skeletonHelper.ts b/gui/app/src/utils/skeletonHelper.ts
index cfdc24355..072dc5180 100644
--- a/gui/app/src/utils/skeletonHelper.ts
+++ b/gui/app/src/utils/skeletonHelper.ts
@@ -39,8 +39,6 @@ const BONE_COLOR_GROUPS: [BodyPart[], string][] = [
export function getBoneColor(bodyPart: BodyPart) {
if (
- bodyPart === BodyPart.LEFT_HIP ||
- bodyPart === BodyPart.RIGHT_HIP ||
FINGER_BODY_PARTS.includes(bodyPart) ||
TOE_BODY_PARTS.includes(bodyPart)
) {
diff --git a/gui/app/src/utils/skeletonParts.ts b/gui/app/src/utils/skeletonParts.ts
index 91871546a..09890656f 100644
--- a/gui/app/src/utils/skeletonParts.ts
+++ b/gui/app/src/utils/skeletonParts.ts
@@ -278,19 +278,6 @@ export const SKELETON_PART_PRESETS: Record = {
}),
{ trackerOffset: HIP_TRACKER_OFFSET }
),
- [BodyPart.LEFT_HIP]: part(
- model('hip_ball', {
- scale: spanBone({ girthFrom: 'hips', length: 0.6 }),
- offset: inBoneLengths({ depth: 0.8, length: -0.8 }),
- })
- ),
- [BodyPart.RIGHT_HIP]: part(
- model('hip_ball', {
- scale: spanBone({ girthFrom: 'hips', length: 0.6 }),
- offset: inBoneLengths({ depth: 0.8, length: -0.8 }),
- })
- ),
-
[BodyPart.LEFT_SHOULDER]: part(
model('shoulder', {
scale: shoulderScale,
diff --git a/gui/app/src/utils/skeletonProportions.ts b/gui/app/src/utils/skeletonProportions.ts
index e19d51361..2790718b1 100644
--- a/gui/app/src/utils/skeletonProportions.ts
+++ b/gui/app/src/utils/skeletonProportions.ts
@@ -59,8 +59,8 @@ export function computeHeadYOffset(bones: Map) {
/**
* Derives the few body measurements the mesh preview needs from the skeleton.
*
- * `BoneT` only carries lengths, so girths have to come from the bones that
- * happen to run sideways: the shoulder and hip bones.
+ * Shoulder girth comes from the sideways-running shoulder bones. Hip girth is the
+ * gap between the two upper-leg heads, which the hip width spreads apart.
*/
export function deriveSkeletonProportions(
bones: Map
@@ -70,7 +70,17 @@ export function deriveSkeletonProportions(
const shoulderWidth =
sumBoneLengths(bones, [BodyPart.LEFT_SHOULDER, BodyPart.RIGHT_SHOULDER]) ?? 0;
- const hipWidth = sumBoneLengths(bones, [BodyPart.LEFT_HIP, BodyPart.RIGHT_HIP]) ?? 0;
+
+ const leftLegHead = bones.get(BodyPart.LEFT_UPPER_LEG)?.headPosition;
+ const rightLegHead = bones.get(BodyPart.RIGHT_UPPER_LEG)?.headPosition;
+ const hipWidth =
+ leftLegHead && rightLegHead
+ ? Math.hypot(
+ leftLegHead.x - rightLegHead.x,
+ leftLegHead.y - rightLegHead.y,
+ leftLegHead.z - rightLegHead.z
+ )
+ : 0;
return {
bodyScale,
diff --git a/server/core/src/main/java/dev/slimevr/bvh/stream.kt b/server/core/src/main/java/dev/slimevr/bvh/stream.kt
index 9f3c79fc1..5c946c970 100644
--- a/server/core/src/main/java/dev/slimevr/bvh/stream.kt
+++ b/server/core/src/main/java/dev/slimevr/bvh/stream.kt
@@ -95,9 +95,12 @@ class BvhStream(
return intervalString.padEnd(9)
}
- private fun getBvhOffset(parentPart: BodyPart, bones: ComputedSkeleton): Vector3 {
- val offset = bones[parentPart]?.offset ?: return Vector3.ZERO
- return offset * OFFSET_SCALE
+ // A joint's BVH OFFSET is the vector from the parent joint's origin to this joint's, in the
+ // parent's frame: the parent's own head->tail offset plus this bone's head displacement.
+ private fun getBvhOffset(childPart: BodyPart, parentPart: BodyPart, bones: ComputedSkeleton): Vector3 {
+ val parentOffset = bones[parentPart]?.offset ?: Vector3.ZERO
+ val childHeadOffset = bones[childPart]?.headOffset ?: Vector3.ZERO
+ return (parentOffset + childHeadOffset) * OFFSET_SCALE
}
private suspend fun writeRotations(part: BodyPart, bones: ComputedSkeleton) {
@@ -118,7 +121,7 @@ class BvhStream(
file.write("${childIndent}OFFSET 0.0 0.0 0.0\n")
file.write("${childIndent}CHANNELS 6 Xposition Yposition Zposition Zrotation Xrotation Yrotation\n")
} else {
- val offset = getBvhOffset(parent, bones)
+ val offset = getBvhOffset(part, parent, bones)
file.write("${childIndent}OFFSET ${offset.x} ${offset.y} ${offset.z}\n")
file.write("${childIndent}CHANNELS 3 Zrotation Xrotation Yrotation\n")
}
diff --git a/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt b/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt
index 69a2e1a38..ac63d5354 100644
--- a/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt
+++ b/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt
@@ -19,6 +19,7 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import solarxr_protocol.datatypes.BodyPart
+import solarxr_protocol.rpc.ResetType
import java.util.EnumMap
import java.util.concurrent.Executors
import kotlin.math.cos
@@ -36,6 +37,7 @@ class ProportionsBehaviour(private val userConfig: UserConfig) : SkeletonBehavio
.onEach { proportions ->
if (proportions.isNotEmpty()) {
receiver.context.dispatch(SkeletonActions.SetProportions(configToBoneValues(proportions)))
+ receiver.resetProcessors(ResetType.FULL)
}
}
.launchIn(receiver.context.scope)
diff --git a/server/core/src/main/java/dev/slimevr/skeleton/bodypart-constraints.kt b/server/core/src/main/java/dev/slimevr/skeleton/bodypart-constraints.kt
index 84be9fe03..60df2ed16 100644
--- a/server/core/src/main/java/dev/slimevr/skeleton/bodypart-constraints.kt
+++ b/server/core/src/main/java/dev/slimevr/skeleton/bodypart-constraints.kt
@@ -60,10 +60,6 @@ val BODY_PART_CONSTRAINT_MAP: BodyPartMap = BodyPartMap(
120f * FastMath.DEG_TO_RAD,
),
- BodyPart.LEFT_HIP to TwistSwingConstraint(
- 0f * FastMath.DEG_TO_RAD,
- 15f * FastMath.DEG_TO_RAD,
- ),
BodyPart.LEFT_UPPER_LEG to TwistSwingConstraint(
120f * FastMath.DEG_TO_RAD,
180f * FastMath.DEG_TO_RAD,
@@ -78,10 +74,6 @@ val BODY_PART_CONSTRAINT_MAP: BodyPartMap = BodyPartMap(
60f * FastMath.DEG_TO_RAD,
),
- BodyPart.RIGHT_HIP to TwistSwingConstraint(
- 0f * FastMath.DEG_TO_RAD,
- 15f * FastMath.DEG_TO_RAD,
- ),
BodyPart.RIGHT_UPPER_LEG to TwistSwingConstraint(
120f * FastMath.DEG_TO_RAD,
180f * FastMath.DEG_TO_RAD,
diff --git a/server/core/src/main/java/dev/slimevr/skeleton/bodypart-structure.kt b/server/core/src/main/java/dev/slimevr/skeleton/bodypart-structure.kt
index 01c154acd..c812fec5d 100644
--- a/server/core/src/main/java/dev/slimevr/skeleton/bodypart-structure.kt
+++ b/server/core/src/main/java/dev/slimevr/skeleton/bodypart-structure.kt
@@ -54,13 +54,11 @@ val BODY_PART_HIERARCHY_MAP: BodyPartMap> = BodyPartMap(
BodyPart.UPPER_CHEST to arrayOf(BodyPart.CHEST),
BodyPart.CHEST to arrayOf(BodyPart.WAIST),
BodyPart.WAIST to arrayOf(BodyPart.HIP),
- BodyPart.HIP to arrayOf(BodyPart.LEFT_HIP, BodyPart.RIGHT_HIP),
+ BodyPart.HIP to arrayOf(BodyPart.LEFT_UPPER_LEG, BodyPart.RIGHT_UPPER_LEG),
- BodyPart.LEFT_HIP to arrayOf(BodyPart.LEFT_UPPER_LEG),
BodyPart.LEFT_UPPER_LEG to arrayOf(BodyPart.LEFT_LOWER_LEG),
BodyPart.LEFT_LOWER_LEG to arrayOf(BodyPart.LEFT_FOOT),
- BodyPart.RIGHT_HIP to arrayOf(BodyPart.RIGHT_UPPER_LEG),
BodyPart.RIGHT_UPPER_LEG to arrayOf(BodyPart.RIGHT_LOWER_LEG),
BodyPart.RIGHT_LOWER_LEG to arrayOf(BodyPart.RIGHT_FOOT),
diff --git a/server/core/src/main/java/dev/slimevr/skeleton/ik.kt b/server/core/src/main/java/dev/slimevr/skeleton/ik.kt
index 104714215..38b7a1b9f 100644
--- a/server/core/src/main/java/dev/slimevr/skeleton/ik.kt
+++ b/server/core/src/main/java/dev/slimevr/skeleton/ik.kt
@@ -21,20 +21,6 @@ fun chainDistanceFromTarget(
return (target - chainTail).len()
}
-fun chainCanReach(
- bones: ComputedSkeleton,
- chain: IKChain,
- target: Vector3,
-): Boolean {
- val chainHead = requireBone(bones, chain.first()).headPosition
-
- val chainLength = chain.fold(0f) { acc, bodyPart ->
- val boneLength = requireBone(bones, bodyPart).offset.len()
- acc + boneLength
- }
- return (target - chainHead).len() <= chainLength
-}
-
private val oppositeRotation = Quaternion.rotationAroundZAxis(FastMath.PI)
fun fromChainToTarget(
bodyPart: BodyPart,
diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-direct-link.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-direct-link.kt
index 250958c1c..1554036e1 100644
--- a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-direct-link.kt
+++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/bone-direct-link.kt
@@ -17,9 +17,6 @@ class BoneDirectLinkInputProcessor : SkeletonInputProcessor {
BodyPart.HEAD to BodyPart.NECK,
BodyPart.NECK to BodyPart.HEAD,
- BodyPart.LEFT_HIP to BodyPart.HIP,
- BodyPart.RIGHT_HIP to BodyPart.HIP,
-
BodyPart.LEFT_FOOT to BodyPart.LEFT_LOWER_LEG,
BodyPart.RIGHT_FOOT to BodyPart.RIGHT_LOWER_LEG,
diff --git a/server/core/src/main/java/dev/slimevr/skeleton/module.kt b/server/core/src/main/java/dev/slimevr/skeleton/module.kt
index bf600aa86..dd285b19a 100644
--- a/server/core/src/main/java/dev/slimevr/skeleton/module.kt
+++ b/server/core/src/main/java/dev/slimevr/skeleton/module.kt
@@ -41,6 +41,7 @@ val ZERO_VELOCITY = Velocity(Vector3.ZERO, Vector3.ZERO)
/** Pre-FK */
data class BoneInput(
val bodyPart: BodyPart,
+ val headOffset: Vector3,
val offset: Vector3,
val rotation: Quaternion,
val acceleration: Vector3,
@@ -54,6 +55,7 @@ data class BoneInput(
data class BoneState(
val parentBone: BoneState?,
val bodyPart: BodyPart,
+ val headOffset: Vector3,
val offset: Vector3,
val rotation: Quaternion,
val acceleration: Vector3,
@@ -93,6 +95,7 @@ data class SkeletonState(
val DEFAULT_BONE_INPUT = BoneInput(
bodyPart = BodyPart.NONE,
+ headOffset = Vector3.ZERO,
offset = Vector3.ZERO,
rotation = Quaternion.IDENTITY,
acceleration = Vector3.ZERO,
@@ -102,25 +105,31 @@ val DEFAULT_BONE_INPUT = BoneInput(
isPositionActive = false,
)
-val DEFAULT_SKELETON_STATE = SkeletonState(
- boneInputs = DEFAULT_PROPORTIONS.toBoneOffsets().mapValues { bodyPart, tailOffset ->
- DEFAULT_BONE_INPUT.copy(
- bodyPart = bodyPart,
- offset = tailOffset,
- )
- },
- skeletonHeight = DEFAULT_HEIGHT,
- floorLevel = 0f,
- paused = false,
- pausedProcessedBoneInputs = null,
-)
+val DEFAULT_SKELETON_STATE = run {
+ val offsets = toBoneOffsets(DEFAULT_PROPORTIONS)
+ SkeletonState(
+ boneInputs = offsets.tail.mapValues { bodyPart, tailOffset ->
+ DEFAULT_BONE_INPUT.copy(
+ bodyPart = bodyPart,
+ headOffset = offsets.head[bodyPart] ?: Vector3.ZERO,
+ offset = tailOffset,
+ )
+ },
+ skeletonHeight = DEFAULT_HEIGHT,
+ floorLevel = 0f,
+ paused = false,
+ pausedProcessedBoneInputs = null,
+ )
+}
fun buildBone(bone: BoneInput, parentBone: BoneState?, velocity: Velocity = ZERO_VELOCITY): BoneState {
// Raw position of the bone input is used for BodyPart.HEAD since it has no parent
- val headPosition = parentBone?.tailPosition ?: bone.position ?: Vector3.ZERO
+ val headPosition = parentBone?.let { it.tailPosition + it.rotation.sandwich(bone.headOffset) }
+ ?: bone.position ?: Vector3.ZERO
return BoneState(
parentBone = parentBone,
bodyPart = bone.bodyPart,
+ headOffset = bone.headOffset,
offset = bone.offset,
rotation = bone.rotation,
acceleration = bone.acceleration,
diff --git a/server/core/src/main/java/dev/slimevr/skeleton/proportions.kt b/server/core/src/main/java/dev/slimevr/skeleton/proportions.kt
index bf8bb0e29..fae7f06de 100644
--- a/server/core/src/main/java/dev/slimevr/skeleton/proportions.kt
+++ b/server/core/src/main/java/dev/slimevr/skeleton/proportions.kt
@@ -48,7 +48,6 @@ private val BONE_VALUE_TO_OFFSETS: Map> = map
SkeletonBone.CHEST to BodyPartMap(mapOf(BodyPart.CHEST to Vector3.NEG_Y)),
SkeletonBone.WAIST to BodyPartMap(mapOf(BodyPart.WAIST to Vector3.NEG_Y)),
SkeletonBone.HIP to BodyPartMap(mapOf(BodyPart.HIP to Vector3.NEG_Y)),
- SkeletonBone.HIPS_WIDTH to BodyPartMap(mapOf(BodyPart.LEFT_HIP to Vector3.NEG_X / 2f, BodyPart.RIGHT_HIP to Vector3.POS_X / 2f)),
SkeletonBone.UPPER_LEG to BodyPartMap(mapOf(BodyPart.LEFT_UPPER_LEG to Vector3.NEG_Y, BodyPart.RIGHT_UPPER_LEG to Vector3.NEG_Y)),
SkeletonBone.LOWER_LEG to BodyPartMap(mapOf(BodyPart.LEFT_LOWER_LEG to Vector3.NEG_Y, BodyPart.RIGHT_LOWER_LEG to Vector3.NEG_Y)),
SkeletonBone.FOOT_LENGTH to BodyPartMap(mapOf(BodyPart.LEFT_FOOT to Vector3.NEG_Z, BodyPart.RIGHT_FOOT to Vector3.NEG_Z)),
@@ -61,22 +60,21 @@ private val BONE_VALUE_TO_OFFSETS: Map> = map
SkeletonBone.HAND_Z to BodyPartMap(mapOf(BodyPart.LEFT_HAND to Vector3.NEG_Z, BodyPart.RIGHT_HAND to Vector3.NEG_Z)),
)
-private val BONE_OFFSET_TO_VALUES: BodyPartMap