mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-12-06 08:42:32 -08:00
Tracker-Bone Offset
This commit is contained in:
1 parent
8e9558fcee
commit
388bcb33a1
22 files changed
+119
-44
No files matched your search
@@ -4,6 +4,7 @@ import dev.slimevr.context.Behaviour
|
||||
import dev.slimevr.context.Context
|
||||
import dev.slimevr.skeleton.inputprocessors.DEFAULT_SPINE_UPPER_LOWER
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.cancelAndJoin
|
||||
@@ -32,6 +33,7 @@ data class TrackerConfig(
|
||||
@Serializable(with = QuaternionSerializer::class)
|
||||
val mountingResetOrientation: Quaternion? = null,
|
||||
val magEnabled: Boolean? = null,
|
||||
val boneOffsets: Map<BodyPart, Vector3> = emptyMap(),
|
||||
)
|
||||
|
||||
@Serializable
|
||||
|
||||
@@ -79,6 +79,7 @@ class YouSpinMeRightRoundBehaviour(val inputHz: Int = 1) : SkeletonBehaviour {
|
||||
receiver.context.dispatch(
|
||||
SkeletonActions.SetBonePose(
|
||||
BodyPart.LOWER_CHEST,
|
||||
Vector3.ZERO,
|
||||
inputHz.toUShort(),
|
||||
Quaternion.fromRotationVector(Vector3(cos(elapsed), sin(elapsed), 0f)),
|
||||
Vector3.ZERO,
|
||||
@@ -88,6 +89,7 @@ class YouSpinMeRightRoundBehaviour(val inputHz: Int = 1) : SkeletonBehaviour {
|
||||
receiver.context.dispatch(
|
||||
SkeletonActions.SetBonePose(
|
||||
BodyPart.LEFT_LOWER_LEG,
|
||||
Vector3.ZERO,
|
||||
inputHz.toUShort(),
|
||||
Quaternion.fromRotationVector(Vector3(cos(elapsed + 1000), sin(elapsed + 1000), 0f)),
|
||||
Vector3.ZERO,
|
||||
@@ -102,6 +104,7 @@ class YouSpinMeRightRoundBehaviour(val inputHz: Int = 1) : SkeletonBehaviour {
|
||||
receiver.context.dispatch(
|
||||
SkeletonActions.SetBonePose(
|
||||
BodyPart.HEAD,
|
||||
Vector3.ZERO,
|
||||
inputHz.toUShort(),
|
||||
Quaternion.IDENTITY,
|
||||
Vector3.ZERO,
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package dev.slimevr.skeleton.inputprocessors
|
||||
|
||||
import dev.slimevr.skeleton.InputSkeleton
|
||||
import dev.slimevr.skeleton.SkeletonInputProcessor
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
|
||||
/**
|
||||
* Handles tracker offset. For example, an HMD's rotation will be about 10cm in front of the head bone.
|
||||
*/
|
||||
class TrackerOffsetInputProcessor : SkeletonInputProcessor {
|
||||
override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) {
|
||||
mutableInputSkeleton.forEach { (part, input) ->
|
||||
if (input.trackerOffset == Vector3.ZERO) return@forEach
|
||||
val localOffset = input.rotation.sandwich(input.trackerOffset)
|
||||
mutableInputSkeleton[part] = input.copy(position = input.position?.plus(localOffset))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import dev.slimevr.skeleton.inputprocessors.PredictionInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.SmoothingInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.SpineInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.ToeActiveLinkInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.TrackerOffsetInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.UpperLegsRollAlignInputProcessor
|
||||
import dev.slimevr.skeleton.targetprocessors.FloorClipTargetProcessor
|
||||
import dev.slimevr.skeleton.targetprocessors.PositionalTargetProcessor
|
||||
@@ -46,6 +47,7 @@ data class BoneInput(
|
||||
val bodyPart: BodyPart,
|
||||
val headOffset: Vector3,
|
||||
val offset: Vector3,
|
||||
val trackerOffset: Vector3,
|
||||
val expectedTps: UShort?,
|
||||
val rotation: Quaternion,
|
||||
val acceleration: Vector3,
|
||||
@@ -61,6 +63,7 @@ data class BoneState(
|
||||
val bodyPart: BodyPart,
|
||||
val headOffset: Vector3,
|
||||
val offset: Vector3,
|
||||
val trackerOffset: Vector3,
|
||||
val rotation: Quaternion,
|
||||
val acceleration: Vector3,
|
||||
val headPosition: Vector3,
|
||||
@@ -110,6 +113,7 @@ val DEFAULT_BONE_INPUT = BoneInput(
|
||||
bodyPart = BodyPart.NONE,
|
||||
headOffset = Vector3.ZERO,
|
||||
offset = Vector3.ZERO,
|
||||
trackerOffset = Vector3.ZERO,
|
||||
expectedTps = null,
|
||||
rotation = Quaternion.IDENTITY,
|
||||
acceleration = Vector3.ZERO,
|
||||
@@ -145,6 +149,7 @@ fun buildBone(bone: BoneInput, parentBone: BoneState?, velocity: Velocity = ZERO
|
||||
bodyPart = bone.bodyPart,
|
||||
headOffset = bone.headOffset,
|
||||
offset = bone.offset,
|
||||
trackerOffset = bone.trackerOffset,
|
||||
rotation = bone.rotation,
|
||||
acceleration = bone.acceleration,
|
||||
headPosition = headPosition,
|
||||
@@ -172,7 +177,7 @@ fun buildBones(boneInputs: InputSkeleton, changedParts: Set<BodyPart> = headPart
|
||||
}
|
||||
|
||||
sealed interface SkeletonActions {
|
||||
data class SetBonePose(val bodyPart: BodyPart, val expectedTps: UShort, val rotation: Quaternion, val acceleration: Vector3, val position: Vector3?) : SkeletonActions
|
||||
data class SetBonePose(val bodyPart: BodyPart, val trackerOffset: Vector3, val expectedTps: UShort, val rotation: Quaternion, val acceleration: Vector3, val position: Vector3?) : SkeletonActions
|
||||
data class DisableBone(val bodyPart: BodyPart) : SkeletonActions
|
||||
data class SetProportions(val lengths: Map<SkeletonBone, Float>) : SkeletonActions
|
||||
data class PauseTracking(val pause: Boolean) : SkeletonActions
|
||||
@@ -257,6 +262,7 @@ class Skeleton(
|
||||
hz = hz,
|
||||
waiter = waiter,
|
||||
inputProcessors = listOf(
|
||||
TrackerOffsetInputProcessor(),
|
||||
PredictionInputProcessor(settings),
|
||||
SmoothingInputProcessor(settings),
|
||||
HeadPositionFallbackProcessor(settings),
|
||||
|
||||
@@ -9,7 +9,6 @@ import kotlin.collections.plus
|
||||
|
||||
// TODO : Placeholder, move this to config defaults somehow
|
||||
val DEFAULT_PROPORTIONS = mapOf(
|
||||
SkeletonBone.HEAD to 0.1f,
|
||||
SkeletonBone.NECK to 0.1f,
|
||||
SkeletonBone.UPPER_CHEST to 0.16f,
|
||||
SkeletonBone.LOWER_CHEST to 0.16f,
|
||||
@@ -43,7 +42,6 @@ private val HEIGHT_CONTRIBUTING_BONES: Set<SkeletonBone> = setOf(
|
||||
|
||||
// Maps each SolarXR SkeletonBone to the BodyPart(s) it controls in the skeleton with vectors for offset directions.
|
||||
private val BONE_VALUE_TO_OFFSETS: Map<SkeletonBone, BodyPartMap<Vector3>> = mapOf(
|
||||
SkeletonBone.HEAD to BodyPartMap(mapOf(BodyPart.HEAD to Vector3.POS_Z)),
|
||||
SkeletonBone.NECK to BodyPartMap(mapOf(BodyPart.NECK to Vector3.NEG_Y)),
|
||||
SkeletonBone.UPPER_CHEST to BodyPartMap(mapOf(BodyPart.UPPER_CHEST to Vector3.NEG_Y)),
|
||||
SkeletonBone.LOWER_CHEST to BodyPartMap(mapOf(BodyPart.LOWER_CHEST to Vector3.NEG_Y)),
|
||||
@@ -117,6 +115,9 @@ data class BoneOffsets(
|
||||
fun toBoneOffsets(lengths: Map<SkeletonBone, Float>): BoneOffsets {
|
||||
val tail = bodyPartMap<Vector3>()
|
||||
val head = bodyPartMap<Vector3>()
|
||||
|
||||
// Set offsets (lengths) and head offsets
|
||||
tail[BodyPart.HEAD] = Vector3.ZERO // Head has no length
|
||||
for ((cfg, length) in lengths) {
|
||||
BONE_VALUE_TO_OFFSETS[cfg]?.let { for ((bone, vec) in it) tail[bone] = (tail[bone] ?: Vector3.ZERO) + length * vec }
|
||||
BONE_VALUE_TO_HEAD_OFFSETS[cfg]?.let { for ((bone, vec) in it) head[bone] = (head[bone] ?: Vector3.ZERO) + length * vec }
|
||||
|
||||
@@ -10,6 +10,7 @@ fun reduce(state: SkeletonState, action: SkeletonActions): SkeletonState = when
|
||||
state.copy(
|
||||
boneInputs = state.boneInputs.mutateCopy {
|
||||
it[action.bodyPart] = bone.copy(
|
||||
trackerOffset = action.trackerOffset,
|
||||
expectedTps = bone.expectedTps,
|
||||
rotation = action.rotation,
|
||||
isRotationActive = true,
|
||||
@@ -27,6 +28,7 @@ fun reduce(state: SkeletonState, action: SkeletonActions): SkeletonState = when
|
||||
state.copy(
|
||||
boneInputs = state.boneInputs.mutateCopy {
|
||||
it[action.bodyPart] = bone.copy(
|
||||
trackerOffset = Vector3.ZERO,
|
||||
expectedTps = null,
|
||||
rotation = Quaternion.IDENTITY,
|
||||
acceleration = Vector3.ZERO,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package dev.slimevr.solarxr
|
||||
|
||||
import dev.slimevr.skeleton.BoneState
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
import solarxr_protocol.datatypes.BoneMask
|
||||
import solarxr_protocol.datatypes.math.Quat
|
||||
@@ -9,10 +11,19 @@ import solarxr_protocol.datatypes.math.Vec3f
|
||||
fun createBone(bone: BoneState, mask: BoneMask): solarxr_protocol.datatypes.Bone = solarxr_protocol.datatypes.Bone(
|
||||
bodyPart = if (mask.bodyPart) bone.bodyPart else BodyPart.NONE,
|
||||
boneLength = if (mask.boneLength) bone.offset.len() else 0f,
|
||||
rotation = if (mask.rotation) bone.rotation.let { Quat(it.x, it.y, it.z, it.w) } else null,
|
||||
orientation = if (mask.orientation) bone.orientation.let { Quat(it.x, it.y, it.z, it.w) } else null,
|
||||
headPosition = if (mask.headPosition) bone.headPosition.let { Vec3f(it.x, it.y, it.z) } else null,
|
||||
tailPosition = if (mask.tailPosition) bone.tailPosition.let { Vec3f(it.x, it.y, it.z) } else null,
|
||||
linearVelocity = if (mask.linearVelocity) bone.velocity.linear.let { Vec3f(it.x, it.y, it.z) } else null,
|
||||
angularVelocity = if (mask.angularVelocity) bone.velocity.angular.let { Vec3f(it.x, it.y, it.z) } else null,
|
||||
rotation = if (mask.rotation) bone.rotation.toQuat() else null,
|
||||
orientation = if (mask.orientation) bone.orientation.toQuat() else null,
|
||||
headPosition = if (mask.headPosition) bone.headPosition.toVec3f() else null,
|
||||
tailPosition = if (mask.tailPosition) bone.tailPosition.toVec3f() else null,
|
||||
linearVelocity = if (mask.linearVelocity) bone.velocity.linear.toVec3f() else null,
|
||||
angularVelocity = if (mask.angularVelocity) bone.velocity.angular.toVec3f() else null,
|
||||
trackerOffset = if (mask.trackerOffset) bone.trackerOffset.toVec3f() else null,
|
||||
)
|
||||
|
||||
fun Quat.toQuaternion() = Quaternion(w, x, y, z)
|
||||
|
||||
fun Quaternion.toQuat() = Quat(x, y, z, w)
|
||||
|
||||
fun Vec3f.toVector3() = Vector3(x, y, z)
|
||||
|
||||
fun Vector3.toVec3f() = Vec3f(x, y, z)
|
||||
@@ -12,9 +12,12 @@ import dev.slimevr.solarxr.SolarXRBridge
|
||||
import dev.slimevr.solarxr.SolarXRBridgeActions
|
||||
import dev.slimevr.solarxr.SolarXRBridgeBehaviour
|
||||
import dev.slimevr.solarxr.createBone
|
||||
import dev.slimevr.solarxr.toQuat
|
||||
import dev.slimevr.solarxr.toVec3f
|
||||
import dev.slimevr.tracker.Motion
|
||||
import dev.slimevr.tracker.TrackerState
|
||||
import dev.slimevr.util.stripIpAddressPort
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
import kotlinx.coroutines.cancelAndJoin
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.isActive
|
||||
@@ -39,8 +42,6 @@ import solarxr_protocol.datatypes.TrackerStatus
|
||||
import solarxr_protocol.datatypes.hardware_info.HardwareInfo
|
||||
import solarxr_protocol.datatypes.hardware_info.HardwareStatus
|
||||
import solarxr_protocol.datatypes.hardware_info.ImuType
|
||||
import solarxr_protocol.datatypes.math.Quat
|
||||
import solarxr_protocol.datatypes.math.Vec3f
|
||||
import kotlin.time.Duration
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
import kotlin.time.TimeSource
|
||||
@@ -58,32 +59,33 @@ private fun createTracker(device: DeviceState, tracker: TrackerState, trackerMas
|
||||
deviceId = device.id.toUShort(),
|
||||
trackerId = tracker.id.toUShort(),
|
||||
status = if (trackerMask.status) tracker.status else TrackerStatus.NONE,
|
||||
rotation = if (trackerMask.rotation) tracker.rawRotation.let { Quat(it.x, it.y, it.z, it.w) } else null,
|
||||
position = if (trackerMask.position && tracker.position != null) tracker.position.let { Vec3f(it.x, it.y, it.z) } else null,
|
||||
rotation = if (trackerMask.rotation) tracker.rawRotation.toQuat() else null,
|
||||
position = if (trackerMask.position && tracker.position != null) tracker.position.toVec3f() else null,
|
||||
info = if (trackerMask.info) {
|
||||
TrackerInfo(
|
||||
isImu = tracker.imuType != null,
|
||||
imuType = tracker.imuType ?: ImuType.UNKNOWN,
|
||||
bodyPart = tracker.bodyPart ?: BodyPart.NONE,
|
||||
intendedBodyPart = tracker.intendedBodyPart ?: BodyPart.NONE,
|
||||
mountingOrientation = tracker.mountingOrientation.let { Quat(it.x, it.y, it.z, it.w) },
|
||||
mountingResetOrientation = tracker.sessionCalibration.headingAlignment.let { Quat(it.x, it.y, it.z, it.w) },
|
||||
mountingOrientation = tracker.mountingOrientation.toQuat(),
|
||||
mountingResetOrientation = tracker.sessionCalibration.headingAlignment.toQuat(),
|
||||
displayName = tracker.name,
|
||||
customName = tracker.customName,
|
||||
lastMountingMethod = tracker.lastMountingMethod,
|
||||
magnetometer = tracker.magStatus,
|
||||
dataType = tracker.trackerDataType,
|
||||
boneOffset = (tracker.boneOffsets[tracker.bodyPart] ?: Vector3.ZERO).toVec3f(),
|
||||
)
|
||||
} else {
|
||||
null
|
||||
},
|
||||
tps = if (trackerMask.tps) tracker.tps else null,
|
||||
temp = if (trackerMask.temp && tracker.imuTemp != null) tracker.imuTemp else null,
|
||||
rawAcceleration = if (trackerMask.rawAcceleration) tracker.rawAcceleration.let { Vec3f(it.x, it.y, it.z) } else null,
|
||||
linearAcceleration = if (trackerMask.linearAcceleration) tracker.acceleration.let { Vec3f(it.x, it.y, it.z) } else null,
|
||||
rotationReferenceAdjusted = if (trackerMask.rotationReferenceAdjusted) tracker.rotation.let { Quat(it.x, it.y, it.z, it.w) } else null,
|
||||
rotationIdentityAdjusted = if (trackerMask.rotationIdentityAdjusted) tracker.rotation.let { Quat(it.x, it.y, it.z, it.w) } else null, // FIXME: uses reference adjusted
|
||||
rawMagneticVector = if (trackerMask.rawMagneticVector && tracker.magStatus == MagnetometerStatus.ENABLED) tracker.rawMagnetometer.let { Vec3f(it.x, it.y, it.z) } else null,
|
||||
rawAcceleration = if (trackerMask.rawAcceleration) tracker.rawAcceleration.toVec3f() else null,
|
||||
linearAcceleration = if (trackerMask.linearAcceleration) tracker.acceleration.toVec3f() else null,
|
||||
rotationReferenceAdjusted = if (trackerMask.rotationReferenceAdjusted) tracker.rotation.toQuat() else null,
|
||||
rotationIdentityAdjusted = if (trackerMask.rotationIdentityAdjusted) tracker.rotation.toQuat() else null, // FIXME: uses reference adjusted
|
||||
rawMagneticVector = if (trackerMask.rawMagneticVector && tracker.magStatus == MagnetometerStatus.ENABLED) tracker.rawMagnetometer.toVec3f() else null,
|
||||
stayAligned = if (trackerMask.stayAligned) StayAlignedTracker(tracker.stayAlignedData.yawCorrection.toDeg(), tracker.motion == Motion.RESTING) else null,
|
||||
origin = if (trackerMask.origin) tracker.origin else null,
|
||||
)
|
||||
|
||||
@@ -6,10 +6,12 @@ import dev.slimevr.device.Device
|
||||
import dev.slimevr.device.DeviceActions
|
||||
import dev.slimevr.solarxr.SolarXRBridge
|
||||
import dev.slimevr.solarxr.SolarXRBridgeBehaviour
|
||||
import dev.slimevr.solarxr.toQuaternion
|
||||
import dev.slimevr.solarxr.toVector3
|
||||
import dev.slimevr.tracker.Tracker
|
||||
import dev.slimevr.tracker.TrackerActions
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
import solarxr_protocol.datatypes.DeviceOrigin
|
||||
import solarxr_protocol.driver_protocol.AddTrackerRequest
|
||||
import solarxr_protocol.driver_protocol.AddTrackerResponse
|
||||
@@ -17,6 +19,21 @@ import solarxr_protocol.driver_protocol.AddTrackerStatus
|
||||
import solarxr_protocol.driver_protocol.UpdateTrackerBattery
|
||||
import solarxr_protocol.driver_protocol.UpdateTrackerPosition
|
||||
import solarxr_protocol.driver_protocol.UpdateTrackerStatus
|
||||
import kotlin.to
|
||||
|
||||
// TODO add more devices and retest Knuckles
|
||||
private val DISPLAY_NAME_TO_INTENDED_OFFSET = mapOf(
|
||||
"Beyond" to Vector3(0f, 0f, 0.1f),
|
||||
"Knuckles Left" to Vector3(0f, 0.11f, 0.08f),
|
||||
"Knuckles Right" to Vector3(0f, 0.11f, 0.08f),
|
||||
)
|
||||
|
||||
// Used as fallback when map above doesn't contain the entry
|
||||
private val BODY_PART_TO_INTENDED_OFFSET = mapOf(
|
||||
BodyPart.HEAD to Vector3(0f, 0f, 0.1f),
|
||||
BodyPart.LEFT_HAND to Vector3(0f, 0.11f, 0.08f),
|
||||
BodyPart.RIGHT_HAND to Vector3(0f, 0.11f, 0.08f),
|
||||
)
|
||||
|
||||
class DriverIncomingTrackersBehaviour(
|
||||
private val appContext: AppContextProvider,
|
||||
@@ -75,6 +92,7 @@ class DriverIncomingTrackersBehaviour(
|
||||
name = req.displayName ?: "Tracker #$trackerId",
|
||||
bodyPart = req.bodyPart,
|
||||
intendedBodyPart = req.bodyPart,
|
||||
intendedBoneOffset = DISPLAY_NAME_TO_INTENDED_OFFSET[req.displayName] ?: BODY_PART_TO_INTENDED_OFFSET[req.bodyPart],
|
||||
deviceId = deviceId,
|
||||
hardwareId = hardwareId,
|
||||
origin = DeviceOrigin.DRIVER,
|
||||
@@ -119,8 +137,8 @@ class DriverIncomingTrackersBehaviour(
|
||||
// TODO: receive velocity, mapping to accel?
|
||||
server.getTracker(trackerId)?.context?.dispatch(
|
||||
TrackerActions.SetRotation(
|
||||
rotation = event.rotation?.let { Quaternion(it.w, it.x, it.y, it.z) },
|
||||
position = event.position?.let { Vector3(it.x, it.y, it.z) },
|
||||
rotation = event.rotation?.toQuaternion(),
|
||||
position = event.position?.toVector3(),
|
||||
),
|
||||
)
|
||||
}.launchIn(receiver.context.scope)
|
||||
|
||||
@@ -4,28 +4,30 @@ import dev.slimevr.VRServer
|
||||
import dev.slimevr.skeleton.bodyPartMap
|
||||
import dev.slimevr.solarxr.SolarXRBridge
|
||||
import dev.slimevr.solarxr.SolarXRBridgeBehaviour
|
||||
import dev.slimevr.solarxr.toVector3
|
||||
import dev.slimevr.tracker.Tracker
|
||||
import dev.slimevr.tracker.TrackerActions
|
||||
import dev.slimevr.util.isActive
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
import solarxr_protocol.rpc.AssignTrackerRequest
|
||||
import solarxr_protocol.rpc.ResetTrackerAssignments
|
||||
import solarxr_protocol.rpc.UpdateTrackerRequest
|
||||
|
||||
class AssignTrackerBehaviour(
|
||||
private val server: VRServer,
|
||||
) : SolarXRBridgeBehaviour {
|
||||
override fun observe(receiver: SolarXRBridge) {
|
||||
receiver.rpcDispatcher.on<AssignTrackerRequest> { req ->
|
||||
receiver.rpcDispatcher.on<UpdateTrackerRequest> { req ->
|
||||
val id = req.trackerId
|
||||
val tracker = server.getTracker(id.toInt())
|
||||
?: return@on
|
||||
|
||||
val bodyPart = req.bodyPosition.takeIf { it != BodyPart.NONE }
|
||||
if (bodyPart != null) {
|
||||
// Unassign other trackers with the same bodyPart
|
||||
server.context.state.value.trackers.values.filter {
|
||||
val state = it.context.state.value
|
||||
state.id != id.toInt() &&
|
||||
it != tracker &&
|
||||
state.bodyPart == bodyPart &&
|
||||
state.status.isActive()
|
||||
}.forEach {
|
||||
@@ -39,6 +41,11 @@ class AssignTrackerBehaviour(
|
||||
copy(
|
||||
bodyPart = bodyPart,
|
||||
customName = req.displayName ?: customName,
|
||||
boneOffsets = bodyPart?.let { part ->
|
||||
req.boneOffset?.let { offset ->
|
||||
boneOffsets.toMutableMap().apply { put(part, offset.toVector3()) }
|
||||
}
|
||||
} ?: boneOffsets,
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -51,6 +51,7 @@ class TrackerConfigBehaviour(
|
||||
false -> MagnetometerStatus.DISABLED
|
||||
null -> state.magStatus
|
||||
},
|
||||
boneOffsets = state.boneOffsets + config.boneOffsets,
|
||||
)
|
||||
|
||||
private fun applyStateToConfig(config: TrackerConfig, state: TrackerState, saveMountingReset: Boolean) = config.copy(
|
||||
@@ -63,6 +64,7 @@ class TrackerConfigBehaviour(
|
||||
MagnetometerStatus.DISABLED -> false
|
||||
MagnetometerStatus.NOT_SUPPORTED -> config.magEnabled
|
||||
},
|
||||
boneOffsets = state.boneOffsets,
|
||||
)
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -17,9 +17,10 @@ class TrackerDefaultMountingOrientationBehaviour : TrackerBehaviour {
|
||||
* Returns the default mounting orientation for the body part
|
||||
*/
|
||||
private fun defaultMountingForBodyPart(bodyPart: BodyPart?): Quaternion = when (bodyPart) {
|
||||
// Spine mounted on the back (TODO: hip too? Test if spine is fine)
|
||||
// Spine mounted on the back
|
||||
BodyPart.UPPER_CHEST, BodyPart.LOWER_CHEST,
|
||||
BodyPart.UPPER_WAIST, BodyPart.LOWER_WAIST,
|
||||
BodyPart.HIP,
|
||||
-> Quaternion.SLIMEVR.BACK
|
||||
|
||||
// Left lower arm mounted left
|
||||
|
||||
@@ -5,6 +5,7 @@ import dev.slimevr.tracker.Tracker
|
||||
import dev.slimevr.tracker.TrackerActions
|
||||
import dev.slimevr.tracker.TrackerBehaviour
|
||||
import dev.slimevr.util.isActive
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.filter
|
||||
@@ -45,6 +46,7 @@ class TrackerToSkeletonBehaviour : TrackerBehaviour {
|
||||
val pendingResets = trackerState.pendingSkeletonResets
|
||||
val bonePoseActions = SkeletonActions.SetBonePose(
|
||||
bodyPart,
|
||||
trackerState.boneOffsets[bodyPart] ?: Vector3.ZERO,
|
||||
trackerState.expectedTps ?: trackerState.tps,
|
||||
trackerState.rotation,
|
||||
trackerState.acceleration,
|
||||
|
||||
@@ -64,6 +64,7 @@ data class TrackerState(
|
||||
val bodyPart: BodyPart?,
|
||||
/** The default body part given by e.g. driver, VMC, etc. */
|
||||
val intendedBodyPart: BodyPart?,
|
||||
val boneOffsets: Map<BodyPart, Vector3>,
|
||||
val customName: String?,
|
||||
val trackerDataType: TrackerDataType, // TODO
|
||||
val lastMountingMethod: MountingMethod,
|
||||
@@ -91,9 +92,10 @@ data class TrackerState(
|
||||
val pendingSkeletonResets: List<ResetType> = emptyList(),
|
||||
) {
|
||||
private val isHmd = origin == DeviceOrigin.DRIVER && intendedBodyPart == BodyPart.HEAD
|
||||
private val isController = origin == DeviceOrigin.DRIVER && (intendedBodyPart == BodyPart.LEFT_HAND || intendedBodyPart == BodyPart.RIGHT_HAND)
|
||||
|
||||
/** Indicates if the tracker is a reliable reference for aligning other trackers. */
|
||||
val isReliableReference = isHmd
|
||||
val isReliableReference = isHmd || isController
|
||||
val isAssignedReliableReference = isReliableReference && bodyPart == intendedBodyPart
|
||||
}
|
||||
|
||||
@@ -137,6 +139,7 @@ class Tracker(
|
||||
name: String = "Tracker #$id",
|
||||
bodyPart: BodyPart? = null,
|
||||
intendedBodyPart: BodyPart? = null,
|
||||
intendedBoneOffset: Vector3? = null,
|
||||
deviceId: Int,
|
||||
imuType: ImuType? = null,
|
||||
hardwareId: String,
|
||||
@@ -158,6 +161,7 @@ class Tracker(
|
||||
imuType = imuType,
|
||||
bodyPart = bodyPart,
|
||||
intendedBodyPart = intendedBodyPart,
|
||||
boneOffsets = intendedBodyPart?.let { part -> intendedBoneOffset?.let { offset -> mapOf(part to offset) } } ?: emptyMap(),
|
||||
stayAlignedData = DEFAULT_STATE.stayAlignedData.copy(enabled = settings.context.state.value.data.stayAlignedConfig.enabled),
|
||||
expectedTps = expectedTps,
|
||||
)
|
||||
@@ -202,6 +206,7 @@ class Tracker(
|
||||
imuType = null,
|
||||
bodyPart = null,
|
||||
intendedBodyPart = null,
|
||||
boneOffsets = emptyMap(),
|
||||
customName = null,
|
||||
trackerDataType = TrackerDataType.ROTATION,
|
||||
lastMountingMethod = MountingMethod.MANUAL,
|
||||
|
||||
@@ -87,7 +87,7 @@ fun reduce(
|
||||
)
|
||||
|
||||
is TrackerActions.FullReset -> {
|
||||
val alignAttitude = !state.isAssignedReliableReference || action.resetReliableReferenceAttitude
|
||||
val alignAttitude = !state.isAssignedReliableReference || (action.resetReliableReferenceAttitude && action.referenceRotation == null)
|
||||
val correctHeading = action.referenceRotation != null
|
||||
val alignHeading = state.position != null && action.referenceRotation != null
|
||||
|
||||
|
||||
Reference in new issue
Block a user