Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(office): a camera drag never clicks, the wheel zooms by how far it turns, first person stays clear
rubenluetke10-beepb67b735b0bd8
diff --git a/jarvis/ui/web/frontend/src/components/society/office/GigiFlyer.tsx b/jarvis/ui/web/frontend/src/components/society/office/GigiFlyer.tsxindex d8d2c03ce2..d9052ab19b 100644--- a/jarvis/ui/web/frontend/src/components/society/office/GigiFlyer.tsx+++ b/jarvis/ui/web/frontend/src/components/society/office/GigiFlyer.tsx@@ -16,6 +16,7 @@ import {import { CompanionModel } from "../companion/AgentFollower";import { defaultCompanion } from "../companion/appearance";import { createGigiFlight, createGigiPose, followAnchor, stepGigiFlight, type GigiFlightMode } from "./gigiFlight";+import { cameraView } from "./officeStore";/** Gigi's on-screen height in the office. */export const GIGI_OFFICE_SIZE_M = 0.5;@@ -29,6 +30,8 @@ const TRAIL_SIZE = 24;const TRAIL_LIFE_S = 0.8;const TRAIL_RATE = 30;const MOVING_SPEED = 0.05;+/** Closer than this to a first-person camera, Gigi would fill the view. */+const FIRST_PERSON_CLEARANCE_M = 2.5;/** Local effect colours; the diorama keeps one palette in light and dark mode. */const GLOW_WARM = new Color("#ffd98a");@@ -155,6 +158,11 @@ export function GigiFlyer({ owner, mode, speaking, paused, reduced, clear }: {targetX, targetZ, moving, mode, speaking, t: clock.current, dt, heading: m.heading, reduced, clear,}, pose);+ // Gigi hovers at head height beside the person: seated in first person that is right in+ // front of the eyes, so close by it steps out of the picture until the person stands up.+ const hidden = cameraView.firstPerson && Math.hypot(pose.x - cameraView.x, pose.z - cameraView.z) < FIRST_PERSON_CLEARANCE_M;+ if (root.current) root.current.visible = !hidden;+ if (shadow.current) shadow.current.visible = !hidden;if (root.current) root.current.position.set(pose.x, pose.y, pose.z);if (body.current) {body.current.rotation.set(pose.pitch, pose.yaw, pose.roll, "YXZ");diff --git a/jarvis/ui/web/frontend/src/components/society/office/OfficeCameraRig.tsx b/jarvis/ui/web/frontend/src/components/society/office/OfficeCameraRig.tsxindex f036d2b1a6..ace8f61874 100644--- a/jarvis/ui/web/frontend/src/components/society/office/OfficeCameraRig.tsx+++ b/jarvis/ui/web/frontend/src/components/society/office/OfficeCameraRig.tsx@@ -5,17 +5,21 @@* mode switch. A right-drag pan or a fly-to leaves follow mode; moving the* character re-enters it. Seated at Mission Control's desk the camera glides* into the character's eyes (first person onto the monitors) and back out- * when it stands up.+ * when it stands up; asking for the overview or a fly-to stands it up.+ *+ * A press that turned the camera never ends in a click, and the wheel zooms+ * by how far it turned (see officeCamera.ts).*/import { useEffect, useRef } from "react";import { OrbitControls } from "@react-three/drei";import { useFrame, useThree } from "@react-three/fiber";import { MOUSE, Vector3, type PerspectiveCamera } from "three";import type { OrbitControls as OrbitControlsImpl } from "three-stdlib";-import { cameraHome, CAMERA_LIMITS, HOME_PITCH_RAD, HOME_YAW_RAD } from "./officeCamera";+import { cameraHome, CAMERA_LIMITS, DRAG_CLICK_PX, HOME_PITCH_RAD, HOME_YAW_RAD, wheelZoomSpeed } from "./officeCamera";import { seatOf, type OfficeLayout } from "./officeLayout";import { useLeadSeat } from "./leadSeat";import { cameraView, officeSession, player, useOfficeStore } from "./officeStore";+import "./officeCameraRig.css";/** Where the camera starts: close behind the character, south-east, looking down. */export const FOLLOW_DISTANCE = 15;@@ -43,6 +47,8 @@ export function OfficeCameraRig({ layout, overview }: { layout: OfficeLayout; ovconst size = useThree((s) => s.size);const gl = useThree((s) => s.gl);const scene = useThree((s) => s.scene);+ // The element R3F and the orbit controls listen on (the canvas wrapper, which also holds the <Html> labels).+ const connected = useThree((s) => s.events.connected) as HTMLElement | undefined;const lastFocus = useRef(0);const lastZoom = useRef(0);const backOff = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);@@ -55,15 +61,55 @@ export function OfficeCameraRig({ layout, overview }: { layout: OfficeLayout; ovconst eye = useRef(new Vector3());const look = useRef(new Vector3());const delta = useRef(new Vector3());+ const shownFirstPerson = useRef(false);- // Remember the view when leaving: the pose before a dive, never the inside of a monitor.+ // First person for the rest of the scene: Gigi steps aside (cameraView), and the floating labels+ // of the rest of the floor hide over the monitors (officeCameraRig.css keys on the attribute).+ const publishFirstPerson = (on: boolean) => {+ cameraView.firstPerson = on;+ if (shownFirstPerson.current === on) return;+ shownFirstPerson.current = on;+ const viewport = gl.domElement.closest(".office-viewport");+ if (on) viewport?.setAttribute("data-first-person", "");+ else viewport?.removeAttribute("data-first-person");+ };+ useEffect(() => () => {+ cameraView.firstPerson = false;+ gl.domElement.closest(".office-viewport")?.removeAttribute("data-first-person");+ }, [gl]);++ // Out of first person at once, back to the view it left: the person asked for another view.+ const leaveFirstPerson = () => {+ const c = controls.current;+ const fp = seated.current;+ const desk = layout.command;+ if (desk && useLeadSeat.getState().seated === desk.id) useLeadSeat.getState().set({ seated: null, standUp: true });+ const lensCam = camera as PerspectiveCamera;+ if (fp.before) {+ camera.position.copy(fp.before.position);+ c?.target.copy(fp.before.target);+ lensCam.fov = fp.before.fov;+ lensCam.updateProjectionMatrix();+ }+ fp.before = null;+ fp.blend = 0;+ if (c) { c.enabled = true; c.update(); }+ };++ // Remember the view when leaving: the pose before a dive, never the inside of a monitor,+ // and the view before sitting down, never the character's eyes.const preDive = useRef<{ position: [number, number, number]; target: [number, number, number] } | null>(null);useEffect(() => () => {const c = controls.current;- officeSession.camera = preDive.current ?? (c+ const beforeSeat = seated.current.before;+ officeSession.camera = beforeSeat+ ? { position: beforeSeat.position.toArray() as [number, number, number], target: beforeSeat.target.toArray() as [number, number, number] }+ : preDive.current ?? (c? { position: camera.position.toArray() as [number, number, number], target: c.target.toArray() as [number, number, number] }: null);officeSession.follow = useOfficeStore.getState().follow;+ // The camera belongs to the canvas and can outlive this rig: hand it back with its own lens.+ if (beforeSeat) { (camera as PerspectiveCamera).fov = beforeSeat.fov; (camera as PerspectiveCamera).updateProjectionMatrix(); }}, [camera]);// Start where the last visit left off, or close to the character.@@ -89,6 +135,8 @@ export function OfficeCameraRig({ layout, overview }: { layout: OfficeLayout; ov// "Overview": frame the whole floor and stop following.useEffect(() => {if (overview === 0) return;+ // Seated in first person the glide would keep the camera in the chair: stand up first.+ if (seated.current.blend > 0 || (layout.command && useLeadSeat.getState().seated === layout.command.id)) leaveFirstPerson();const home = cameraHome(layout.bounds, size.width / Math.max(1, size.height));flight.current = null;useOfficeStore.getState().setFollow(false);@@ -116,6 +164,49 @@ export function OfficeCameraRig({ layout, overview }: { layout: OfficeLayout; ovreturn () => el.removeEventListener("pointerdown", down, true);}, [gl]);+ // A drag turns the camera and nothing else. R3F still delivers a click when+ // the press ends on the object it started on, so a small turn over the+ // Mission Control wall, a place token or an agent opened it (a handler's own+ // `delta` check only sees start to end, and many had none). The click is+ // swallowed here, in the capture phase, before R3F or a label sees it.+ // The wheel zooms by how far it turned, not a fixed step per event.+ useEffect(() => {+ const el = connected ?? gl.domElement;+ let origin: { x: number; y: number } | null = null;+ let dragged = false;+ const down = (event: PointerEvent) => {+ origin = { x: event.clientX, y: event.clientY };+ dragged = false;+ // A pinch zoom uses the same speed; only the wheel sets it per event.+ if (controls.current) controls.current.zoomSpeed = 1;+ };+ const move = (event: PointerEvent) => {+ if (origin && !dragged && Math.hypot(event.clientX - origin.x, event.clientY - origin.y) > DRAG_CLICK_PX) dragged = true;+ };+ const up = () => { origin = null; };+ const click = (event: MouseEvent) => {+ if (!dragged) return;+ dragged = false;+ event.stopImmediatePropagation();+ event.preventDefault();+ };+ const wheel = (event: WheelEvent) => {+ if (controls.current) controls.current.zoomSpeed = wheelZoomSpeed(event.deltaY, event.deltaMode);+ };+ el.addEventListener("pointerdown", down, true);+ window.addEventListener("pointermove", move, true);+ window.addEventListener("pointerup", up, true);+ el.addEventListener("click", click, true);+ el.addEventListener("wheel", wheel, { capture: true, passive: true });+ return () => {+ el.removeEventListener("pointerdown", down, true);+ window.removeEventListener("pointermove", move, true);+ window.removeEventListener("pointerup", up, true);+ el.removeEventListener("click", click, true);+ el.removeEventListener("wheel", wheel, true);+ };+ }, [connected, gl]);+useFrame((_, rawDt) => {const c = controls.current;if (!c) return;@@ -129,8 +220,13 @@ export function OfficeCameraRig({ layout, overview }: { layout: OfficeLayout; ovconst store = useOfficeStore.getState();// Seated at Mission Control: glide into first person, and back out on standing up.const desk = layout.command;- const inSeat = !!desk && useLeadSeat.getState().seated === desk.id;const fp = seated.current;+ // A fly-to (an agent picked from a list, the minimap) is a request for another view: stand up for it,+ // or it would wait until the person stands up and then fly somewhere stale.+ const flyTo = !!store.focus && store.focus.seq !== lastFocus.current;+ if (flyTo && !dive.current && (fp.blend > 0 || (!!desk && useLeadSeat.getState().seated === desk.id))) leaveFirstPerson();+ const inSeat = !!desk && useLeadSeat.getState().seated === desk.id;+ publishFirstPerson(inSeat || fp.blend > 0);// A monitor dive from the chair runs as usual, starting from the eyes.const diving = !!dive.current || (!!store.zoom && store.zoom.seq !== lastZoom.current);if (desk && (inSeat || fp.blend > 0) && !diving) {@@ -163,11 +259,14 @@ export function OfficeCameraRig({ layout, overview }: { layout: OfficeLayout; ovif (store.zoom && store.zoom.seq !== lastZoom.current) {lastZoom.current = store.zoom.seq;flight.current = null;+ // A second dive within the last one's wait: that wait must not yank the camera back mid-dive.+ clearTimeout(backOff.current);// End squarely in front of the screen, far enough back that it exactly fills the view.const lens = camera as unknown as { fov: number; aspect: number };const reach = screenFillDistance(lens.fov ?? 35, lens.aspect ?? 1.6, ...(store.zoom.size ?? [SCREEN_W, SCREEN_H])) * 1.02;const [tx, ty, tz] = store.zoom.target;- preDive.current = { position: camera.position.toArray() as [number, number, number], target: c.target.toArray() as [number, number, number] };+ // Still set while the last dive's wait runs: the view to come back to is the one before the first dive.+ preDive.current ??= { position: camera.position.toArray() as [number, number, number], target: c.target.toArray() as [number, number, number] };dive.current = { fromEye: camera.position.clone(),toEye: new Vector3(tx + Math.sin(store.zoom.facing) * reach, ty, tz + Math.cos(store.zoom.facing) * reach),fromTarget: c.target.clone(), toTarget: new Vector3(tx, ty, tz), t: 0 };diff --git a/jarvis/ui/web/frontend/src/components/society/office/officeCamera.test.ts b/jarvis/ui/web/frontend/src/components/society/office/officeCamera.test.tsnew file mode 100644index 0000000000..522154d0d1--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/society/office/officeCamera.test.ts@@ -0,0 +1,36 @@+import { describe, expect, it } from "vitest";+import { cameraHome, CAMERA_LIMITS, wheelZoomSpeed } from "./officeCamera";++/** OrbitControls' dolly factor for one wheel event at this zoom speed. */+const step = (speed: number) => 1 / Math.pow(0.95, speed);+/** Wheel events of this size needed to zoom from `from` to `to` metres. */+const eventsFor = (from: number, to: number, deltaY: number, deltaMode = 0) =>+ Math.ceil(Math.log(from / to) / Math.log(step(wheelZoomSpeed(deltaY, deltaMode))));++describe("office wheel zoom", () => {+ it("brings the overview down to the character in a handful of mouse notches", () => {+ const overview = cameraHome({ minX: -14, maxX: 14, minZ: -22, maxZ: 22 }, 16 / 9);+ const distance = Math.hypot(...overview.position.map((v, i) => v - overview.target[i]) as [number, number, number]);+ expect(eventsFor(distance, 15, 100)).toBeLessThanOrEqual(12);+ });++ it("zooms by how far the wheel turned, so a trackpad's small steps stay small", () => {+ expect(wheelZoomSpeed(4)).toBeLessThan(wheelZoomSpeed(100) / 10);+ expect(wheelZoomSpeed(-100)).toBe(wheelZoomSpeed(100));+ // A whole trackpad swipe of 100 px moves about as far as one notch.+ const swipe = Math.pow(step(wheelZoomSpeed(4)), 25);+ expect(swipe).toBeCloseTo(step(wheelZoomSpeed(100)), 1);+ });++ it("reads line and page wheel modes and caps a single huge event", () => {+ expect(wheelZoomSpeed(3, 1)).toBeGreaterThan(wheelZoomSpeed(100));+ expect(wheelZoomSpeed(1, 2)).toBe(wheelZoomSpeed(100_000));+ expect(step(wheelZoomSpeed(100_000))).toBeLessThan(1.4);+ expect(wheelZoomSpeed(0)).toBeGreaterThan(0);+ });++ it("lets the camera come close enough to read a desk, and never inside the character", () => {+ expect(CAMERA_LIMITS.minDistance).toBeLessThanOrEqual(3);+ expect(CAMERA_LIMITS.minDistance).toBeGreaterThanOrEqual(2);+ });+});diff --git a/jarvis/ui/web/frontend/src/components/society/office/officeCamera.ts b/jarvis/ui/web/frontend/src/components/society/office/officeCamera.tsindex 8ab549c69a..f0764aaa17 100644--- a/jarvis/ui/web/frontend/src/components/society/office/officeCamera.ts+++ b/jarvis/ui/web/frontend/src/components/society/office/officeCamera.ts@@ -8,10 +8,34 @@ export const CAMERA_LIMITS = {/** Polar angle from straight down: ~20° (near top-down) to ~72° (near eye level). */minPolar: 0.35,maxPolar: 1.25,- minDistance: 4,+ /** Close enough to read a desk or a wardrobe shelf, far enough to stay outside the character. */+ minDistance: 2.5,maxDistance: 140,} as const;+/**+ * A press that travelled further than this (CSS px) turned the camera; the+ * click it ends in is not a click. Measured over the whole press, so a drag+ * that comes back to where it started still counts as a drag.+ */+export const DRAG_CLICK_PX = 6;++/** One mouse-wheel notch, in CSS px, as browsers report it in pixel mode. */+const WHEEL_NOTCH_PX = 100;+/** How far one notch zooms, as OrbitControls' zoomSpeed: 0.95^2.4 ≈ 12 % closer or further. */+const ZOOM_SPEED_PER_NOTCH = 2.4;+/**+ * OrbitControls' zoomSpeed for one wheel event, proportional to how far the+ * wheel turned. The controls zoom a fixed step per event whatever its size:+ * a mouse notch crawled (~20 notches from the overview to the character) and+ * a trackpad, which sends dozens of tiny events, raced. `deltaMode` 1 is+ * lines, 2 pages (Firefox, some mice).+ */+export function wheelZoomSpeed(deltaY: number, deltaMode = 0): number {+ const px = Math.abs(deltaY) * (deltaMode === 1 ? 40 : deltaMode === 2 ? 800 : 1);+ return Math.min(ZOOM_SPEED_PER_NOTCH * 2.5, Math.max(0.02, (px / WHEEL_NOTCH_PX) * ZOOM_SPEED_PER_NOTCH));+}+/** Look-down angle below the horizon and yaw east of south for the home view. */export const HOME_PITCH_RAD = (40 * Math.PI) / 180;export const HOME_YAW_RAD = (38 * Math.PI) / 180;diff --git a/jarvis/ui/web/frontend/src/components/society/office/officeCameraRig.css b/jarvis/ui/web/frontend/src/components/society/office/officeCameraRig.cssnew file mode 100644index 0000000000..aeffa50519--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/society/office/officeCameraRig.css@@ -0,0 +1,10 @@+/* Seated first person at Mission Control (the camera rig sets data-first-person+ on the viewport): the monitors fill the view, so the floating labels of the+ rest of the floor (names, speech bubbles, place pills, the elevator call)+ step aside. Seat prompts and the live monitor screens stay. */+.office-viewport[data-first-person] .office-plate:not(.office-seat-prompt),+.office-viewport[data-first-person] .office-bubble,+.office-viewport[data-first-person] .office-checkpoint,+.office-viewport[data-first-person] .office-call-pill {+ visibility: hidden;+}diff --git a/jarvis/ui/web/frontend/src/components/society/office/officeStore.ts b/jarvis/ui/web/frontend/src/components/society/office/officeStore.tsindex faf1f78b76..08d1f2cb40 100644--- a/jarvis/ui/web/frontend/src/components/society/office/officeStore.ts+++ b/jarvis/ui/web/frontend/src/components/society/office/officeStore.ts@@ -140,8 +140,12 @@ export const useOfficeStore = create<OfficeState>((set) => ({requestWalk: (point) => set({ walkTo: { point, seq: ++seq }, follow: true }),}));-/** Where the camera looks on the floor, mutated by the camera rig every frame (for the minimap). */-export const cameraView = { x: 0, z: 0, yaw: 0, halfWidth: 0.5, ready: false };+/**+ * Where the camera looks on the floor, mutated by the camera rig every frame (for the minimap).+ * `firstPerson` is true while the camera is (or glides into) the character's eyes at Mission Control:+ * whatever flies beside the character, like Gigi, must step out of that view.+ */+export const cameraView = { x: 0, z: 0, yaw: 0, halfWidth: 0.5, ready: false, firstPerson: false };/*** What the office remembers while the app runs: where the character stands