[Components]: Add debug canvas utilities for R3F scene inspection#101
Open
justkahdri wants to merge 10 commits intomainfrom
Open
[Components]: Add debug canvas utilities for R3F scene inspection#101justkahdri wants to merge 10 commits intomainfrom
justkahdri wants to merge 10 commits intomainfrom
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
37114fe to
f6b5866
Compare
f77fc49 to
e361c4d
Compare
Contributor
Author
|
@greptile |
Extract R3F debug helpers from sazabi into a reusable registry component: - DebugOrbitControls: drei OrbitControls with pointer event management - DebugFlyControls: FPS-style WASD + mouse look with Alt+F toggle - DebugGridHelper: toggleable 100x100 grid - DebugCameraMonitor: real-time camera position/rotation display - DebugPerfMonitor: stats-gl overlay with FPS, TRI, and CALL panels All helpers share a "Canvas" tweakpane folder via useDebugBindings. https://claude.ai/code/session_01HkhaTW7bjR4kZHyehXgW1z
- Demo with a simple 3-object scene showcasing all debug helpers - MDX docs with installation, usage, and component API descriptions https://claude.ai/code/session_01HkhaTW7bjR4kZHyehXgW1z
- Add 'canvas' frontmatter type to source config - Add getCanvasSlugs() helper in lib/source.ts - Thread canvasSlugs through layout → sidebar → section - Render Canvas as a new collapsible subsection with Frame icon - Set debug-canvas.mdx type to 'canvas' https://claude.ai/code/session_01HkhaTW7bjR4kZHyehXgW1z
- Enclose description in quotes for consistency in debug-canvas.mdx - Add "debug-canvas" entry to the components list in meta.json
- Create DebugCanvas as a drop-in R3F Canvas replacement with all debug helpers included (orbit/fly controls, grid, camera monitor, perf stats) - Combine orbit and fly controls into a single DebugControls component with mutual exclusion (enabling one disables the other) - Use default drei OrbitControls - Update demo to use simplified single-import API - Update docs and registry.json https://claude.ai/code/session_01HkhaTW7bjR4kZHyehXgW1z
- Move stats.dispose() and dom.remove() inside .then() to avoid race with async stats.init() on early unmount - Use 'YXZ' euler order in camera monitor to match fly controls convention - Rename PerfMonitor to DebugPerfMonitor for consistent naming - Add preventDefault() on Space key in fly controls to prevent page scroll https://claude.ai/code/session_01HkhaTW7bjR4kZHyehXgW1z
- Add .catch() on cleanupP.then() in perf monitor to handle rejected stats.init() without unhandled promise errors - Replace unnecessary targetRef with local variable in ActiveOrbitControls https://claude.ai/code/session_01HkhaTW7bjR4kZHyehXgW1z
0b5d4c8 to
8f6895b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces a comprehensive set of debug utilities for React Three Fiber scenes, providing interactive controls and monitoring tools for development and debugging workflows.
Key Changes
Debug Fly Controls (
debug-fly-controls.tsx): Implements first-person camera movement with pointer lock, keyboard input (WASD for movement, Space for up, Shift for sprint), and mouse look with pitch/yaw rotation. Toggleable via Alt+F hotkey.Debug Orbit Controls (
debug-orbit-controls.tsx): Wraps@react-three/drei's OrbitControls for intuitive camera orbiting around a target point, with automatic target detection from camera userData or scene direction.Debug Grid Helper (
debug-grid-helper.tsx): Simple grid visualization component for spatial reference in the scene.Debug Camera Monitor (
debug-camera-monitor.tsx): Real-time display of camera position and rotation (in degrees) in the debug panel, updating each frame with formatted values.Performance Monitor (
debug-perf-monitor.tsx): GPU performance tracking usingstats-gl, displaying triangle count and draw call metrics with historical graphs. Positioned as a fixed overlay in the bottom-right corner.Index Export (
index.ts): Barrel export for all debug components.Registry Entry: Added
debug-canvascomponent to registry with dependencies onstats-gland@react-three/drei, plus registry dependency on@joyco/debug.Notable Implementation Details
useDebugBindings/useDebugState) for centralized togglinguseFramewith priority ordering (-Infinity for pre-render, Infinity for post-render) to accurately measure per-frame GPU metricshttps://claude.ai/code/session_01HkhaTW7bjR4kZHyehXgW1z
Greptile Summary
This PR introduces a comprehensive set of R3F debug utilities (
DebugCanvas, fly/orbit controls, grid helper, camera monitor, perf monitor) all wired through the existing@joyco/debugtweakpane store, plus the plumbing to surface a new Canvas sub-section in the sidebar.The implementation is solid overall. Previous review feedback has been incorporated: the camera monitor correctly uses
'YXZ'Euler decomposition to match fly controls,PerfMonitorGLnow carries theDebugPerfMonitorexport name, the Space key callse.preventDefault(), andstats.dispose()is deferred inside.then()rather than called synchronously. The mutual exclusion mechanism between orbit and fly controls works correctly becauseuseDebugBindingswraps the target in a Proxy that propagates mutations back through both the tweakpane UI and the Zustand store.Key findings:
.catch()on async perf-monitor cleanup — ifstats.init(gl)rejects (e.g., WebGL context loss) the.then()branch is skipped and the rejection is unhandled, logging a console error.targetRefinActiveOrbitControls—targetRefis only used inside theuseStateinitializer and is the same object as the returnedtargetstate; the ref can be replaced with a local variable in the initialiser for clarity.Confidence Score: 4/5
.catch()on an edge-case async cleanup (WebGL context loss) and a redundant ref in the orbit controls initialiser — neither affects the happy path.registry/components/debug-canvas/debug-perf-monitor.tsx(missing.catch()),registry/components/debug-canvas/debug-controls.tsx(redundanttargetRef)Important Files Changed
DebugControls,ActiveOrbitControls, andActiveFlyControls. Mutual exclusion via store subscription is correct (proxy inuseDebugBindingspropagates mutations back through Zustand). Fly controls correctly initialize pitch/yaw from the camera quaternion on mount and use YXZ Euler order matching the camera monitor. Minor: redundanttargetRefinActiveOrbitControls(same object astargetstate).stats-gl. Correctly defers DOM cleanup until the asyncinitresolves via.then(). Missing.catch()means a rejectedstats.init(gl)(e.g., context loss) results in an unhandled promise rejection. Pre/post-frame triangle delta logic is functionally correct given Three.js'sautoResetbehaviour.'YXZ'order to match fly controls. Tweakpane bindings are created/disposed correctly viauseDebugFolder. No issues found.Canvasthat composes all four debug helpers. Clean and straightforward; no issues.<gridHelper>primitive. Correctly usesuseDebugBindingswith the shared'Canvas'folder key. No issues.Debugprefix consistently. No issues.canvasSlugsprop and aCollapsibleSubSectionfor Canvas pages, positioned between UI and Effects in the sidebar. Logic mirrors the existing game/effect patterns exactly. No issues.getCanvasSlugs()following the exact same pattern asgetGameSlugs()andgetEffectSlugs(). No issues.DebugCanvasin aDebugProviderwithenabledhardcoded totrue, appropriate for a demo context. Scene contains basic meshes for visual reference. No issues.debug-canvasregistry entry lists all six component files, declaresstats-gland@react-three/dreias dependencies, and@joyco/debugas a registry dependency. Correctly structured.Prompt To Fix All With AI
Last reviewed commit: "Fix review issues in..."