mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-12-03 07:12:43 -08:00
Don't use getValue in skeleton
This commit is contained in:
1 parent
f6084e398e
commit
f9c08e5ec7
12 files changed
+15
-15
No files matched your search
@@ -140,11 +140,11 @@ class ComputedSkeletonBehaviour(
|
||||
val newInputs = processor.process(inputs, fk, targetState.floorLevel)
|
||||
if (newInputs != inputs) {
|
||||
// Inputs changed; re-run FK
|
||||
val changedParts = newInputs.filter { (part, boneInput) -> boneInput != inputs.getValue(part) }.keys
|
||||
fk = buildBones(newInputs, changedParts, fk)
|
||||
val changedInputs = newInputs.filter { (part, boneInput) -> boneInput != inputs[part] }
|
||||
fk = buildBones(newInputs, changedInputs.keys, fk)
|
||||
|
||||
// For bones with inactive position, update their input's position in state (needed for Localizer)
|
||||
val changedPositionInputs = newInputs.filter { (part, boneInput) -> boneInput.rawPosition != inputs.getValue(part).rawPosition }
|
||||
val changedPositionInputs = changedInputs.filter { (part, boneInput) -> boneInput.rawPosition != inputs[part]?.rawPosition }
|
||||
for (input in changedPositionInputs) {
|
||||
receiver.context.dispatch(SkeletonActions.SetBonePosition(input.key, input.value.rawPosition, false))
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import solarxr_protocol.datatypes.BodyPart
|
||||
|
||||
class LocalizerFkProcessor(val settings: Settings) : SkeletonFkProcessor {
|
||||
override fun process(inputSkeleton: InputSkeleton, fk: ComputedSkeleton, floorLevel: Float): InputSkeleton {
|
||||
val headInput = inputSkeleton.getValue(BodyPart.HEAD)
|
||||
val headInput = inputSkeleton[BodyPart.HEAD] ?: return inputSkeleton
|
||||
if (headInput.isPositionActive || !settings.context.state.value.data.skeletonConfig.toggles.mocapMode) {
|
||||
return inputSkeleton
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ fun ccdIkIteration(
|
||||
rotateChain(boneInputs, chain, constrainedOffset)
|
||||
|
||||
// Only build bones for inputs that were changed
|
||||
val changedParts = boneInputs.filter { (part, boneInput) -> boneInput != lastBoneInputs.getValue(part) }.keys
|
||||
val changedParts = boneInputs.filter { (part, boneInput) -> boneInput != lastBoneInputs[part] }.keys
|
||||
return buildBones(boneInputs, changedParts, bones)
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class BoneActiveLinkInputProcessor : SkeletonInputProcessor {
|
||||
|
||||
override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float): InputSkeleton = inputSkeleton.mutateCopy { updated ->
|
||||
for ((bodyPart, sources) in linkedToSources) {
|
||||
val bone = inputSkeleton.getValue(bodyPart)
|
||||
val bone = inputSkeleton[bodyPart] ?: continue
|
||||
if (bone.isRotationActive) continue
|
||||
|
||||
val closestActiveBone = sources.firstNotNullOfOrNull { part ->
|
||||
|
||||
@@ -39,7 +39,7 @@ class BoneDirectLinkInputProcessor : SkeletonInputProcessor {
|
||||
|
||||
override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float): InputSkeleton = inputSkeleton.mutateCopy { updated ->
|
||||
for ((bodyPart, source) in linkedToSource) {
|
||||
val bone = updated.getValue(bodyPart)
|
||||
val bone = updated[bodyPart] ?: continue
|
||||
if (bone.isRotationActive) continue
|
||||
|
||||
val sourceBone = updated[source]
|
||||
|
||||
@@ -19,7 +19,7 @@ class BoneYawFallbackInputProcessor : SkeletonInputProcessor {
|
||||
val children = iterateBodyPartHierarchy(parentPart, true)
|
||||
|
||||
for (childPart in children) {
|
||||
val childBone = inputSkeleton.getValue(childPart.second)
|
||||
val childBone = inputSkeleton[childPart.second] ?: continue
|
||||
if (childBone.isRotationActive) continue // Child needs to be inactive
|
||||
|
||||
updated[childPart.second] = childBone.copy(rawRotation = parentBone.rawRotation.project(Vector3.POS_Y).unit())
|
||||
|
||||
@@ -50,7 +50,7 @@ class FingerImputeInputProcessor : SkeletonInputProcessor {
|
||||
// TODO : There's more math to do here. Reference the original code.
|
||||
override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float): InputSkeleton = inputSkeleton.mutateCopy { updated ->
|
||||
for ((bodyPart, source) in fingerToSource) {
|
||||
val bone = updated.getValue(bodyPart)
|
||||
val bone = updated[bodyPart] ?: continue
|
||||
if (bone.isRotationActive) continue
|
||||
|
||||
val sourceBone = updated[source]
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import solarxr_protocol.datatypes.BodyPart
|
||||
*/
|
||||
class HeadPositionFallbackProcessor(val settings: Settings) : SkeletonInputProcessor {
|
||||
override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float): InputSkeleton {
|
||||
val headBone = inputSkeleton.getValue(BodyPart.HEAD)
|
||||
val headBone = inputSkeleton[BodyPart.HEAD] ?: return inputSkeleton
|
||||
if (headBone.rawPosition != null) return inputSkeleton
|
||||
|
||||
// Set the head position to the be standing up at the origin
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ class HipYawRollAlignInputProcessor(val settings: Settings) : SkeletonInputProce
|
||||
val source = arrayOf(BodyPart.LEFT_UPPER_LEG, BodyPart.RIGHT_UPPER_LEG)
|
||||
|
||||
override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float): InputSkeleton {
|
||||
val hipBone = inputSkeleton.getValue(BodyPart.HIP)
|
||||
val hipBone = inputSkeleton[BodyPart.HIP] ?: return inputSkeleton
|
||||
if (hipBone.isRotationActive) return inputSkeleton
|
||||
|
||||
return inputSkeleton.mutateCopy { updated ->
|
||||
|
||||
@@ -51,7 +51,7 @@ class SpineImputeInputProcessor(val settings: Settings) : SkeletonInputProcessor
|
||||
|
||||
return inputSkeleton.mutateCopy { updated ->
|
||||
for ((chainIndex, bodyPart) in missingSpineParts.withIndex()) {
|
||||
val bone = inputSkeleton.getValue(bodyPart)
|
||||
val bone = inputSkeleton[bodyPart] ?: continue
|
||||
|
||||
// Get the first active bones above and below this one in the chain
|
||||
val (fromSource, toSource) = when (bodyPart) {
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ class ToeDirectLinkInputProcessor : SkeletonInputProcessor {
|
||||
|
||||
override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float): InputSkeleton = inputSkeleton.mutateCopy { updated ->
|
||||
for ((bodyPart, source) in toesToSource) {
|
||||
val bone = updated.getValue(bodyPart)
|
||||
val bone = updated[bodyPart] ?: continue
|
||||
if (bone.isRotationActive) continue
|
||||
val sourceBone = updated[source]
|
||||
updated[bodyPart] =
|
||||
|
||||
+2
-2
@@ -27,10 +27,10 @@ class UpperLegsRollAlignInputProcessor(val settings: Settings) : SkeletonInputPr
|
||||
|
||||
return inputSkeleton.mutateCopy { updated ->
|
||||
for (bodyPartToSource in bodyPartToSources) {
|
||||
val bone = inputSkeleton.getValue(bodyPartToSource.first)
|
||||
val bone = inputSkeleton[bodyPartToSource.first] ?: continue
|
||||
if (!bone.isRotationActive) continue
|
||||
|
||||
val sourceRotation = inputSkeleton.getValue(bodyPartToSource.second).rawRotation
|
||||
val sourceRotation = inputSkeleton[bodyPartToSource.second]?.rawRotation ?: continue
|
||||
val alignedRotation = alignRoll(bone.rawRotation, sourceRotation)
|
||||
updated[bodyPartToSource.first] = bone.copy(rawRotation = bone.rawRotation.interpQ(alignedRotation, ratio))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user