add hand tracking source debug switch
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
import { useSceneMode } from "@/hooks/debug/useSceneMode";
|
import { useSceneMode } from "@/hooks/debug/useSceneMode";
|
||||||
|
import { useDebugStore } from "@/hooks/debug/useDebugStore";
|
||||||
import { useInteraction } from "@/hooks/interaction/useInteraction";
|
import { useInteraction } from "@/hooks/interaction/useInteraction";
|
||||||
import {
|
import {
|
||||||
HAND_TRACKING_IDLE_SNAPSHOT,
|
HAND_TRACKING_IDLE_SNAPSHOT,
|
||||||
HandTrackingContext,
|
HandTrackingContext,
|
||||||
} from "@/hooks/handTracking/useHandTrackingSnapshot";
|
} from "@/hooks/handTracking/useHandTrackingSnapshot";
|
||||||
|
import { useBrowserHandTracking } from "@/hooks/handTracking/useBrowserHandTracking";
|
||||||
import { useRemoteHandTracking } from "@/hooks/handTracking/useRemoteHandTracking";
|
import { useRemoteHandTracking } from "@/hooks/handTracking/useRemoteHandTracking";
|
||||||
|
|
||||||
export function HandTrackingProvider({
|
export function HandTrackingProvider({
|
||||||
@@ -13,9 +15,19 @@ export function HandTrackingProvider({
|
|||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
}): React.JSX.Element {
|
}): React.JSX.Element {
|
||||||
const sceneMode = useSceneMode();
|
const sceneMode = useSceneMode();
|
||||||
|
const handTrackingSource = useDebugStore((debug) =>
|
||||||
|
debug.getHandTrackingSource(),
|
||||||
|
);
|
||||||
const { nearby, holding, handHolding } = useInteraction();
|
const { nearby, holding, handHolding } = useInteraction();
|
||||||
const enabled = sceneMode === "physics" && (nearby || holding || handHolding);
|
const enabled = sceneMode === "physics" && (nearby || holding || handHolding);
|
||||||
const snapshot = useRemoteHandTracking({ enabled });
|
const backendSnapshot = useRemoteHandTracking({
|
||||||
|
enabled: enabled && handTrackingSource === "backend",
|
||||||
|
});
|
||||||
|
const browserSnapshot = useBrowserHandTracking({
|
||||||
|
enabled: enabled && handTrackingSource === "browser",
|
||||||
|
});
|
||||||
|
const snapshot =
|
||||||
|
handTrackingSource === "browser" ? browserSnapshot : backendSnapshot;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<HandTrackingContext
|
<HandTrackingContext
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import GUI from "lil-gui";
|
import GUI from "lil-gui";
|
||||||
import type { CameraMode, SceneMode } from "@/types/debug/debug";
|
import type { CameraMode, SceneMode } from "@/types/debug/debug";
|
||||||
|
import type { HandTrackingSource } from "@/types/handTracking/handTracking";
|
||||||
import { isDebugEnabled } from "@/utils/debug/isDebugEnabled";
|
import { isDebugEnabled } from "@/utils/debug/isDebugEnabled";
|
||||||
|
|
||||||
const DEBUG_CONTROLS_STORAGE_KEY = "la-fabrik-debug-controls";
|
const DEBUG_CONTROLS_STORAGE_KEY = "la-fabrik-debug-controls";
|
||||||
@@ -52,6 +53,7 @@ export class Debug {
|
|||||||
private readonly listeners = new Set<() => void>();
|
private readonly listeners = new Set<() => void>();
|
||||||
private readonly controls: {
|
private readonly controls: {
|
||||||
cameraMode: CameraMode;
|
cameraMode: CameraMode;
|
||||||
|
handTrackingSource: HandTrackingSource;
|
||||||
showDebugOverlay: boolean;
|
showDebugOverlay: boolean;
|
||||||
showHandTrackingSvg: boolean;
|
showHandTrackingSvg: boolean;
|
||||||
showInteractionSpheres: boolean;
|
showInteractionSpheres: boolean;
|
||||||
@@ -73,6 +75,7 @@ export class Debug {
|
|||||||
|
|
||||||
this.controls = {
|
this.controls = {
|
||||||
cameraMode: storedControls.cameraMode ?? "player",
|
cameraMode: storedControls.cameraMode ?? "player",
|
||||||
|
handTrackingSource: "backend",
|
||||||
showDebugOverlay: true,
|
showDebugOverlay: true,
|
||||||
showHandTrackingSvg: false,
|
showHandTrackingSvg: false,
|
||||||
showInteractionSpheres: false,
|
showInteractionSpheres: false,
|
||||||
@@ -123,11 +126,22 @@ export class Debug {
|
|||||||
|
|
||||||
handTrackingFolder
|
handTrackingFolder
|
||||||
?.add(this.controls, "showHandTrackingSvg")
|
?.add(this.controls, "showHandTrackingSvg")
|
||||||
.name("Afficher SVG")
|
.name("Show SVG")
|
||||||
.onChange((value: boolean) => {
|
.onChange((value: boolean) => {
|
||||||
this.controls.showHandTrackingSvg = value;
|
this.controls.showHandTrackingSvg = value;
|
||||||
this.emit();
|
this.emit();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
handTrackingFolder
|
||||||
|
?.add(this.controls, "handTrackingSource", {
|
||||||
|
Backend: "backend",
|
||||||
|
"Browser JS": "browser",
|
||||||
|
})
|
||||||
|
.name("Source")
|
||||||
|
.onChange((value: HandTrackingSource) => {
|
||||||
|
this.controls.handTrackingSource = value;
|
||||||
|
this.emit();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,6 +201,10 @@ export class Debug {
|
|||||||
return this.active && this.controls.showDebugOverlay;
|
return this.active && this.controls.showDebugOverlay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getHandTrackingSource(): HandTrackingSource {
|
||||||
|
return this.controls.handTrackingSource;
|
||||||
|
}
|
||||||
|
|
||||||
getShowInteractionSpheres(): boolean {
|
getShowInteractionSpheres(): boolean {
|
||||||
return this.controls.showInteractionSpheres;
|
return this.controls.showInteractionSpheres;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user