mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-20 09:01:20 -08:00
Mobile QOL + Improve autimatic set detection
This commit is contained in:
1 parent
28bbb53fb7
commit
910fe5cf71
6 files changed
+155
-99
No files matched your search
@@ -16,10 +16,9 @@ import { TogglePill, TogglePillOption } from '@/components/commons/TogglePill';
|
||||
import { TrackerPartCard } from '@/components/tracker/TrackerPartCard';
|
||||
import { PartCardRenderer } from './parts/PartCard';
|
||||
import {
|
||||
ASSIGNMENT_MODES,
|
||||
BodyPartError,
|
||||
COMMONS,
|
||||
useAssignMode,
|
||||
useSuggestedBodyParts,
|
||||
} from '@/hooks/tracker-picker';
|
||||
import { PersonFrontIcon, SIDES } from '@/components/commons/PersonFrontIcon';
|
||||
import { useAtomValue } from 'jotai';
|
||||
@@ -121,7 +120,7 @@ export function BodyAssignment({
|
||||
dotProps?: (part: BodyPart) => HTMLAttributes<HTMLDivElement>;
|
||||
activeParts?: BodyPart[];
|
||||
}) {
|
||||
const assignMode = useAssignMode();
|
||||
const suggestedBodyParts = useSuggestedBodyParts();
|
||||
const assignedRoles = useAtomValue(assignedRolesAtom);
|
||||
const trackerByPart = useAtomValue(trackerByBodyPartAtom);
|
||||
|
||||
@@ -148,8 +147,10 @@ export function BodyAssignment({
|
||||
|
||||
const hasBodyPart = useCallback(
|
||||
(part: BodyPart) =>
|
||||
COMMONS.includes(part) || ASSIGNMENT_MODES[assignMode].includes(part),
|
||||
[assignMode]
|
||||
COMMONS.includes(part) ||
|
||||
suggestedBodyParts.includes(part) ||
|
||||
assignedRoles.includes(part),
|
||||
[suggestedBodyParts, assignedRoles]
|
||||
);
|
||||
|
||||
const card: PartCardRenderer =
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { FluentVariable } from '@fluent/bundle';
|
||||
import { useLocalization } from '@fluent/react';
|
||||
import classNames from 'classnames';
|
||||
import { ReactNode, useMemo } from 'react';
|
||||
import { CSSProperties, ReactNode, useMemo } from 'react';
|
||||
import { BodyPart } from 'solarxr-protocol';
|
||||
import { Button } from '@/components/commons/Button';
|
||||
import { ProgressBar } from '@/components/commons/ProgressBar';
|
||||
@@ -10,9 +10,14 @@ import {
|
||||
ArrowDownIcon,
|
||||
ArrowUpIcon,
|
||||
} from '@/components/commons/icon/ArrowIcons';
|
||||
import { WarningIcon } from '@/components/commons/icon/WarningIcon';
|
||||
import { ShowAllPartsToggle } from '@/components/onboarding/BodyAssignment';
|
||||
import { useOnboarding } from '@/hooks/onboarding';
|
||||
import { getTrackerName } from '@/hooks/tracker';
|
||||
import {
|
||||
getTrackerName,
|
||||
useTrackersVelocity,
|
||||
velocityGlowStyle,
|
||||
} from '@/hooks/tracker';
|
||||
import {
|
||||
FlatDeviceTracker,
|
||||
groupTrackersByConnection,
|
||||
@@ -33,9 +38,11 @@ function MobileAssignPanel({
|
||||
onBackdropPress,
|
||||
title,
|
||||
description,
|
||||
warning,
|
||||
headerAction,
|
||||
progress,
|
||||
footer,
|
||||
style,
|
||||
children,
|
||||
}: {
|
||||
open: boolean;
|
||||
@@ -44,9 +51,11 @@ function MobileAssignPanel({
|
||||
onBackdropPress: () => void;
|
||||
title: ReactNode;
|
||||
description: ReactNode;
|
||||
warning?: ReactNode;
|
||||
headerAction?: ReactNode;
|
||||
progress: number;
|
||||
footer?: ReactNode;
|
||||
style?: CSSProperties;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const headerRow = (
|
||||
@@ -58,6 +67,16 @@ function MobileAssignPanel({
|
||||
>
|
||||
{title}
|
||||
{description}
|
||||
{warning && (
|
||||
<div className="mt-1 flex items-start gap-1 fill-status-warning text-status-warning">
|
||||
<div className="shrink-0 scale-75 -mt-0.5">
|
||||
<WarningIcon />
|
||||
</div>
|
||||
<Typography variant="standard" color="text-status-warning">
|
||||
{warning}
|
||||
</Typography>
|
||||
</div>
|
||||
)}
|
||||
</button>
|
||||
{headerAction}
|
||||
<button
|
||||
@@ -96,6 +115,7 @@ function MobileAssignPanel({
|
||||
? 'w-[calc(100%-var(--navbar-w)-var(--page-margin)*3)] left-[calc(var(--navbar-w)+var(--page-margin))] bottom-[calc(var(--navbar-h)+var(--page-margin))] -mb-1'
|
||||
: 'bottom-1 w-full'
|
||||
)}
|
||||
style={style}
|
||||
>
|
||||
{headerRow}
|
||||
|
||||
@@ -139,7 +159,21 @@ export function MobileTrackerAssign() {
|
||||
() => groupTrackersByConnection(flatTrackers, dongles),
|
||||
[flatTrackers, dongles]
|
||||
);
|
||||
const unassignedTrackers = useMemo(
|
||||
() =>
|
||||
flatTrackers.filter(
|
||||
({ tracker }) => tracker.info?.bodyPart === BodyPart.NONE
|
||||
),
|
||||
[flatTrackers]
|
||||
);
|
||||
const unassignedTrackerData = useMemo(
|
||||
() => unassignedTrackers.map(({ tracker }) => tracker),
|
||||
[unassignedTrackers]
|
||||
);
|
||||
const unassignedCount = flatTrackers.length - assignedTrackers.length;
|
||||
const panelVelocity = useTrackersVelocity(unassignedTrackerData);
|
||||
const panelStyle =
|
||||
panelVelocity > 0 ? velocityGlowStyle(panelVelocity) : undefined;
|
||||
|
||||
const selectedTracker =
|
||||
pendingTrackerId != null
|
||||
@@ -248,6 +282,7 @@ export function MobileTrackerAssign() {
|
||||
vars={header.descVars}
|
||||
/>
|
||||
}
|
||||
warning={assignment.firstError?.label}
|
||||
headerAction={
|
||||
armedPart !== BodyPart.NONE && armedTracker ? (
|
||||
<Button
|
||||
@@ -258,6 +293,7 @@ export function MobileTrackerAssign() {
|
||||
/>
|
||||
) : undefined
|
||||
}
|
||||
style={panelStyle}
|
||||
progress={
|
||||
assignment.expectedTrackersCount
|
||||
? assignment.assignedPartsCount / assignment.expectedTrackersCount
|
||||
|
||||
@@ -13,7 +13,7 @@ import { NumberSelector } from '@/components/commons/NumberSelector';
|
||||
import { Typography } from '@/components/commons/Typography';
|
||||
import { CheckBox } from '@/components/commons/Checkbox';
|
||||
import { Dropdown } from '@/components/commons/Dropdown';
|
||||
import { ASSIGNMENT_MODES } from '@/hooks/tracker-picker';
|
||||
import { TAP_DETECTION_BODY_PARTS } from '@/hooks/tracker-picker';
|
||||
import { atom, useAtomValue, useSetAtom } from 'jotai';
|
||||
import { isEqual } from '@react-hookz/deep-equal';
|
||||
import { selectAtom } from 'jotai/utils';
|
||||
@@ -74,7 +74,7 @@ export function TapDetectionSettings() {
|
||||
|
||||
const bodyParts: { value: string; label: string }[] = Object.values(BodyPart)
|
||||
.filter((v): v is BodyPart => typeof v === 'number')
|
||||
.filter((v) => ASSIGNMENT_MODES['full-body'].includes(v as BodyPart))
|
||||
.filter((v) => TAP_DETECTION_BODY_PARTS.includes(v as BodyPart))
|
||||
.map((value) => ({
|
||||
value: String(value),
|
||||
label: l10n.getString(`body_part-${BodyPart[value]}`),
|
||||
|
||||
@@ -13,14 +13,6 @@ export interface WindowConfig {
|
||||
y: number;
|
||||
}
|
||||
|
||||
export enum AssignMode {
|
||||
LowerBody = 'lower-body',
|
||||
Core = 'core',
|
||||
EnhancedCore = 'enhanced-core',
|
||||
FullBody = 'full-body',
|
||||
All = 'all',
|
||||
}
|
||||
|
||||
export interface DeveloperModeConfig {
|
||||
highContrast: boolean;
|
||||
preciseRotation: boolean;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useLocalization } from '@fluent/react';
|
||||
import { createContext, useContext, useMemo, useState } from 'react';
|
||||
import { BodyPart } from 'solarxr-protocol';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { AssignMode, useConfig } from './config';
|
||||
import { useConfig } from './config';
|
||||
import {
|
||||
assignedRolesAtom,
|
||||
assignedTrackersAtom,
|
||||
@@ -62,69 +62,66 @@ export const ASSIGNMENT_RULES: Partial<Record<BodyPart, (BodyPart | BodyPart[])[
|
||||
|
||||
export const COMMONS = [BodyPart.HEAD, ...HANDS_PARTS];
|
||||
|
||||
export const ASSIGNMENT_MODES: Record<AssignMode, BodyPart[]> = {
|
||||
// x5
|
||||
[AssignMode.LowerBody]: [BodyPart.CHEST, ...LEGS_PARTS],
|
||||
// x6 (5 + 1)
|
||||
[AssignMode.Core]: [BodyPart.CHEST, BodyPart.HIP, ...LEGS_PARTS],
|
||||
// x8 (5 + 3)
|
||||
[AssignMode.EnhancedCore]: [
|
||||
BodyPart.CHEST,
|
||||
BodyPart.HIP,
|
||||
...LEGS_PARTS,
|
||||
BodyPart.LEFT_FOOT,
|
||||
BodyPart.RIGHT_FOOT,
|
||||
],
|
||||
// x10 (7 + 3)
|
||||
[AssignMode.FullBody]: [
|
||||
BodyPart.CHEST,
|
||||
BodyPart.HIP,
|
||||
BodyPart.LEFT_UPPER_ARM,
|
||||
BodyPart.RIGHT_UPPER_ARM,
|
||||
...LEGS_PARTS,
|
||||
BodyPart.LEFT_FOOT,
|
||||
BodyPart.RIGHT_FOOT,
|
||||
],
|
||||
// special case with all body parts
|
||||
[AssignMode.All]: [
|
||||
BodyPart.HEAD,
|
||||
BodyPart.NECK,
|
||||
BodyPart.LEFT_SHOULDER,
|
||||
BodyPart.RIGHT_SHOULDER,
|
||||
BodyPart.LEFT_HAND,
|
||||
BodyPart.RIGHT_HAND,
|
||||
BodyPart.LEFT_FOOT,
|
||||
BodyPart.RIGHT_FOOT,
|
||||
...SPINE_PARTS,
|
||||
...ARMS_PARTS,
|
||||
...LEGS_PARTS,
|
||||
],
|
||||
export const ALL_ASSIGNABLE_PARTS = [
|
||||
BodyPart.HEAD,
|
||||
BodyPart.NECK,
|
||||
BodyPart.LEFT_SHOULDER,
|
||||
BodyPart.RIGHT_SHOULDER,
|
||||
BodyPart.LEFT_HAND,
|
||||
BodyPart.RIGHT_HAND,
|
||||
BodyPart.LEFT_FOOT,
|
||||
BodyPart.RIGHT_FOOT,
|
||||
...SPINE_PARTS,
|
||||
...ARMS_PARTS,
|
||||
...LEGS_PARTS,
|
||||
];
|
||||
|
||||
export const TAP_DETECTION_BODY_PARTS = [
|
||||
BodyPart.CHEST,
|
||||
BodyPart.HIP,
|
||||
BodyPart.LEFT_UPPER_ARM,
|
||||
BodyPart.RIGHT_UPPER_ARM,
|
||||
...LEGS_PARTS,
|
||||
BodyPart.LEFT_FOOT,
|
||||
BodyPart.RIGHT_FOOT,
|
||||
];
|
||||
|
||||
const addParts = (parts: Set<BodyPart>, roles: BodyPart[]) => {
|
||||
roles.forEach((role) => parts.add(role));
|
||||
};
|
||||
|
||||
export const ASSIGN_MODE_OPTIONS: Record<AssignMode, number> = [
|
||||
AssignMode.LowerBody,
|
||||
AssignMode.Core,
|
||||
AssignMode.EnhancedCore,
|
||||
AssignMode.FullBody,
|
||||
AssignMode.All,
|
||||
].reduce(
|
||||
(opts, mode) => ({ ...opts, [mode]: ASSIGNMENT_MODES[mode].length }),
|
||||
{} as Record<AssignMode, number>
|
||||
);
|
||||
export const getSuggestedBodyParts = (
|
||||
connectedIMUTrackersCount: number
|
||||
): BodyPart[] => {
|
||||
const parts = new Set<BodyPart>();
|
||||
|
||||
export const getPreferredAssignMode = (connectedIMUTrackersCount: number): AssignMode =>
|
||||
(Object.entries(ASSIGN_MODE_OPTIONS).find(
|
||||
([, count]) => count >= connectedIMUTrackersCount
|
||||
)?.[0] as AssignMode) ?? AssignMode.All;
|
||||
addParts(parts, [BodyPart.CHEST, ...LEGS_PARTS]);
|
||||
if (connectedIMUTrackersCount >= 6) parts.add(BodyPart.HIP);
|
||||
if (connectedIMUTrackersCount === 7) parts.add(BodyPart.WAIST);
|
||||
if (connectedIMUTrackersCount >= 8) {
|
||||
addParts(parts, [BodyPart.LEFT_FOOT, BodyPart.RIGHT_FOOT]);
|
||||
}
|
||||
if (connectedIMUTrackersCount >= 9) parts.add(BodyPart.WAIST);
|
||||
if (connectedIMUTrackersCount >= 10) {
|
||||
addParts(parts, [BodyPart.LEFT_UPPER_ARM, BodyPart.RIGHT_UPPER_ARM]);
|
||||
}
|
||||
if (connectedIMUTrackersCount >= 12) {
|
||||
addParts(parts, [BodyPart.LEFT_SHOULDER, BodyPart.RIGHT_SHOULDER]);
|
||||
}
|
||||
if (connectedIMUTrackersCount >= 14) parts.add(BodyPart.UPPER_CHEST);
|
||||
if (connectedIMUTrackersCount >= 15) parts.add(BodyPart.NECK);
|
||||
|
||||
/** Which set of body parts to offer: what the user asked for, or a guess from their trackers */
|
||||
export function useAssignMode(): AssignMode {
|
||||
return [...parts];
|
||||
};
|
||||
|
||||
/** Which body parts to offer: what the user asked for, or a guess from their trackers */
|
||||
export function useSuggestedBodyParts(): BodyPart[] {
|
||||
const { config } = useConfig();
|
||||
const connectedIMUTrackers = useAtomValue(connectedIMUTrackersAtom);
|
||||
|
||||
return config?.assignShowAllBodyParts
|
||||
? AssignMode.All
|
||||
: getPreferredAssignMode(connectedIMUTrackers.length);
|
||||
? ALL_ASSIGNABLE_PARTS
|
||||
: getSuggestedBodyParts(connectedIMUTrackers.length);
|
||||
}
|
||||
|
||||
export type PickerTab = 'body' | 'fingers' | 'toes';
|
||||
@@ -170,14 +167,12 @@ export function usePickerShell() {
|
||||
const flatTrackers = useAtomValue(flatTrackersAtom);
|
||||
const assignedRoles = useAtomValue(assignedRolesAtom);
|
||||
|
||||
const currentAssignMode = useAssignMode();
|
||||
const expectedTrackersCount = ASSIGN_MODE_OPTIONS[currentAssignMode];
|
||||
const suggestedBodyParts = useSuggestedBodyParts();
|
||||
const expectedTrackersCount = flatTrackers.length;
|
||||
|
||||
const assignedPartsCount = useMemo(
|
||||
() =>
|
||||
ASSIGNMENT_MODES[currentAssignMode].filter((part) => assignedRoles.includes(part))
|
||||
.length,
|
||||
[currentAssignMode, assignedRoles]
|
||||
() => suggestedBodyParts.filter((part) => assignedRoles.includes(part)).length,
|
||||
[suggestedBodyParts, assignedRoles]
|
||||
);
|
||||
|
||||
const rolesWithErrors = useMemo(() => {
|
||||
@@ -240,6 +235,7 @@ export function usePickerShell() {
|
||||
assignedTrackers,
|
||||
trackerByPart,
|
||||
flatTrackers,
|
||||
suggestedBodyParts,
|
||||
expectedTrackersCount,
|
||||
assignedPartsCount,
|
||||
rolesWithErrors,
|
||||
|
||||
@@ -55,19 +55,49 @@ export const useTracker = (tracker: TrackerDataT) => {
|
||||
};
|
||||
|
||||
export const useVelocity = (tracker?: TrackerDataT): number => {
|
||||
const trackers = useMemo(() => (tracker ? [tracker] : []), [tracker]);
|
||||
|
||||
return useTrackersVelocity(trackers);
|
||||
};
|
||||
|
||||
export const useTrackersVelocity = (trackers: TrackerDataT[]): number => {
|
||||
const { feedMaxTps } = useDataFeedConfig();
|
||||
const previousRot = useRef<Quaternion>(QuaternionFromQuatT(tracker?.rotation));
|
||||
const previousAcc = useRef<Vector3>(Vector3FromVec3fT(tracker?.linearAcceleration));
|
||||
const previous = useRef<
|
||||
Record<
|
||||
number,
|
||||
{
|
||||
rot: Quaternion;
|
||||
acc: Vector3;
|
||||
deltas: number[];
|
||||
}
|
||||
>
|
||||
>({});
|
||||
const [velocity, setVelocity] = useState<number>(0);
|
||||
const [deltas] = useState<number[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
if (tracker?.rotation) {
|
||||
const trackerIds = new Set(trackers.map((tracker) => tracker.trackerId));
|
||||
Object.keys(previous.current).forEach((trackerId) => {
|
||||
if (!trackerIds.has(Number(trackerId))) {
|
||||
delete previous.current[Number(trackerId)];
|
||||
}
|
||||
});
|
||||
|
||||
const velocities = trackers.map((tracker) => {
|
||||
if (!tracker.rotation) return 0;
|
||||
|
||||
const trackerId = tracker.trackerId;
|
||||
previous.current[trackerId] ??= {
|
||||
rot: QuaternionFromQuatT(tracker.rotation),
|
||||
acc: Vector3FromVec3fT(tracker.linearAcceleration),
|
||||
deltas: [],
|
||||
};
|
||||
const trackerPrevious = previous.current[trackerId];
|
||||
|
||||
const rot = QuaternionFromQuatT(tracker.rotation).multiply(
|
||||
previousRot.current.clone().invert()
|
||||
trackerPrevious.rot.clone().invert()
|
||||
);
|
||||
const acc = Vector3FromVec3fT(tracker.linearAcceleration).sub(
|
||||
previousAcc.current
|
||||
trackerPrevious.acc
|
||||
);
|
||||
const dif = Math.min(
|
||||
1,
|
||||
@@ -76,23 +106,24 @@ export const useVelocity = (tracker?: TrackerDataT): number => {
|
||||
);
|
||||
// Use sum of the rotation and acceleration delta vector lengths over 0.3sec
|
||||
// for smoother movement and better detection of slow movement.
|
||||
if (deltas.length >= 0.5 * feedMaxTps) {
|
||||
deltas.shift();
|
||||
if (trackerPrevious.deltas.length >= 0.5 * feedMaxTps) {
|
||||
trackerPrevious.deltas.shift();
|
||||
}
|
||||
deltas.push(dif);
|
||||
setVelocity(
|
||||
Math.min(
|
||||
1,
|
||||
Math.max(
|
||||
0,
|
||||
deltas.reduce((a, b) => a + b)
|
||||
)
|
||||
trackerPrevious.deltas.push(dif);
|
||||
trackerPrevious.rot = QuaternionFromQuatT(tracker.rotation);
|
||||
trackerPrevious.acc = Vector3FromVec3fT(tracker.linearAcceleration);
|
||||
|
||||
return Math.min(
|
||||
1,
|
||||
Math.max(
|
||||
0,
|
||||
trackerPrevious.deltas.reduce((a, b) => a + b, 0)
|
||||
)
|
||||
);
|
||||
previousRot.current = QuaternionFromQuatT(tracker.rotation);
|
||||
previousAcc.current = Vector3FromVec3fT(tracker.linearAcceleration);
|
||||
}
|
||||
}, [tracker?.rotation]);
|
||||
});
|
||||
|
||||
setVelocity(Math.max(0, ...velocities));
|
||||
}, [trackers, feedMaxTps]);
|
||||
|
||||
return velocity;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user