feat(viz): named camera presets (Shift+1..5)#12
Conversation
Five keyboard-bound camera framings for demo work (item #6 of the polish plan): Shift+1 OVERVIEW top-down 45° hero shot of the whole swarm Shift+2 TACTICAL 45° oblique at mesh altitude, sim-game angle Shift+3 COCKPIT FPV follow of the selected drone Shift+4 GROUND operator eye-level (1.8 m), looking up Shift+5 INVESTOR toggles the 90s scripted dolly (also Ctrl+Shift+R) Swarm-aware: framings compute swarm centroid + extent from the last VizFrame, so the same keybinds work for single drone, swarm-5, or multi-agency-sar without per-scenario tuning. After a preset lands, user input (orbit, zoom, WASD fly) continues from the new pose. Changes: * `client/cameraPresets.ts` (new) — `CameraPresets` class with the five framings and a shared swarm-bounds helper. * `client/cameraControl.ts` — adds public `UnityCamera.setPose(pos, target)`. Releases scripted and follow modes; resyncs orbit yaw/pitch/distance from the new quaternion so subsequent user input feels continuous. * `client/app.ts` — instantiate + bind `Shift+Digit1..5` before the existing switch; checks shiftKey first so it can't fire the wrong handler. * `client/controls.ts` — early-return on shifted digits so Shift+1 doesn't also run the `single` scenario. Verified: tsc clean, build/format green, 82 / 82 tests passing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 17 minutes and 18 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a camera preset system allowing users to switch between predefined views (Overview, Tactical, Cockpit, Ground, and Investor) using Shift+1..5 keys. It includes a new CameraPresets class, a setPose method in the UnityCamera for smooth state resyncing, and updates to keyboard event handling to prevent shortcut collisions. Feedback was provided regarding the GROUND preset, suggesting that the camera altitude should be calculated relative to the actual terrain height to avoid clipping issues on non-flat maps.
| ground(): void { | ||
| const positions = this._readyPositions(); | ||
| if (positions.length === 0) return; | ||
|
|
||
| const { center, extent } = this._bounds(positions); | ||
| const offset = Math.max(extent * 1.1, 40); | ||
| const pos = new THREE.Vector3(center.x, 1.8, center.z + offset); | ||
| const target = new THREE.Vector3(center.x, center.y + 8, center.z); | ||
| this._d.viz.cameraController.setPose(pos, target); | ||
| } |
There was a problem hiding this comment.
The GROUND preset currently uses a hardcoded altitude of 1.8 for the camera position. On non-flat terrain (e.g., the 'alpine' preset), this will likely place the camera inside the terrain geometry. While the UnityCamera ground-clamping logic will eventually lift the camera to terrainHeight + 2.5, it would be more accurate to calculate the position relative to the actual terrain height at the camera's XZ coordinates to maintain the intended 'operator eye-level' (1.8m).
ground(): void {
const positions = this._readyPositions();
if (positions.length === 0) return;
const { center, extent } = this._bounds(positions);
const offset = Math.max(extent * 1.1, 40);
const camX = center.x;
const camZ = center.z + offset;
// Import terrainHeight from './terrain' if not already available
const groundY = typeof terrainHeight === 'function' ? terrainHeight(camX, camZ) : 0;
const pos = new THREE.Vector3(camX, groundY + 1.8, camZ);
const target = new THREE.Vector3(center.x, center.y + 8, center.z);
this._d.viz.cameraController.setPose(pos, target);
}
Summary
Item #6 of the polish plan. Five keyboard-bound camera framings for demo work:
Shift+1Shift+2Shift+3Shift+4Shift+5Ctrl+Shift+R)Why
Investor mode and the scenario intro landed in the last PRs, but the recording workflow was still "manually drag the camera until it looks right, then hit record." Presets give you named angles to hit before the recording starts; the investor dolly does the rest.
How it works
VizFrame, so the same keybinds work forsingle,swarm-5, ormulti-agency-sarwithout per-scenario tuning.UnityCamera.setPose(position, target)method — snaps to a pose, resyncs orbit state from the resulting quaternion so mouse/wheel input continues smoothly from the new angle. Releases any scripted or follow override first.Shift+Digit1..5is handled inapp.tsbefore the existing switch;controls.tsearly-returns on shifted digits soShift+1doesn't also run thesinglescenario.Changes
client/cameraPresets.ts(new)CameraPresetsclass with five framings +_bounds()helperclient/cameraControl.tssetPose(pos, target)onUnityCamera— additive, resets scripted/followclient/app.tsShift+Digit1..5client/controls.tsBackwards compat
Additive. Unshifted
Digit1..5still runs scenarios (now includingmulti-agency-sarfrom the last PR).Ctrl+Shift+Rstill works for investor mode (bound separately).setPoseis a new public method onUnityCamera— no existing caller affected.Local verification
Test plan
Shift+1..5cycles through the five framingsShift+3with a drone selected — camera follows; with none selected — no-op5still runsmulti-agency-sar;Shift+5toggles investor mode🤖 Generated with Claude Code