Skip to content

feat: Screenshot tool can now annotate 3D physics raycast candidates#1661

Merged
hatayama merged 3 commits into
v3-betafrom
feat/screenshot-raycast-annotation
Jul 9, 2026
Merged

feat: Screenshot tool can now annotate 3D physics raycast candidates#1661
hatayama merged 3 commits into
v3-betafrom
feat/screenshot-raycast-annotation

Conversation

@hatayama

@hatayama hatayama commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • The screenshot tool can now annotate 3D physics raycast candidate points (or clustered colliders when a layer filter is given) directly on rendering-mode screenshots, in addition to the existing UI element annotation.
  • Rendering screenshots return a ready-to-use formula (ScreenshotToInputFormula) for converting image pixels into simulate-mouse-input/raycast coordinates, removing the need to reverse-engineer the previous CoordinateSystem/YOffset fields.

User Impact

  • Before: only UI elements could be annotated on a screenshot, and callers had to compute the mouse-input Y offset themselves from CoordinateSystem/YOffset.
  • After: passing AnnotateRaycastGrid=true overlays a 5x5 grid of physics raycast hits (or, with RaycastLayerMask set, clustered outlines of the actual hit colliders) on the screenshot, and the response includes the exact formula plus Game View size needed to drive simulate-mouse-input/raycast from the image.

Changes

  • ScreenshotSchema/ScreenshotResponse gained AnnotateRaycastGrid, RaycastLayerMask, GameViewWidth/Height, ScreenshotToInputFormula, UnityInputFormula, RaycastGridPoints, and RaycastLayerSummaries. CoordinateSystem/YOffset were renamed to ImageCoordinateSystem/ImageToInputOffsetY.
  • EditorWindowCaptureUtility now shares a GameRenderingImageInfo struct between the raycast-grid path and the PNG capture path so both reuse the same settled RenderTexture geometry, while keeping the existing frame-wait timeout safety net.
  • UIElementAnnotator now shares one UiRaycastHelper.RaycastContext while collecting elements (replacing an ad-hoc per-call raycast check) and draws physics-collider outlines in a separate pass from box borders/labels.
  • ScreenshotUseCase wires raycast-grid collection into rendering capture with matching parameter validation, and default-tools.json's screenshot entry was updated in the same change (required immediately by DefaultToolsCatalogDriftTests).

Verification

  • uloop compile — 0 errors, 0 warnings
  • Full EditMode suite — 1774 passed, 0 failed (7 pre-existing skips)
  • PlayMode regression (SimulateMouseUiTests, SimulateMouseUiInputSystemTests, InputReplayVerificationE2ETests) — all passed, confirming no behavior change for existing UiRaycastHelper callers

Review in cubic

…nd coordinate metadata

Ported main's final-state screenshot extension onto v3-beta's per-tool
architecture: ScreenshotSchema/ScreenshotResponse gain AnnotateRaycastGrid,
RaycastLayerMask, GameViewWidth/Height, ScreenshotToInputFormula,
UnityInputFormula, RaycastGridPoints, and RaycastLayerSummaries.
ScreenshotResponse's CoordinateSystem/YOffset fields were renamed to
ImageCoordinateSystem/ImageToInputOffsetY to match main and support both
window and rendering capture modes explicitly.

EditorWindowCaptureUtility.CaptureGameRenderingAsync now shares a
GameRenderingImageInfo struct with a new GetGameRenderingImageInfoAsync,
so the raycast-grid path and the PNG-capture path reuse the same settled
RenderTexture geometry without recomputing it twice, while preserving
v3-beta's EditorFrameWaiter timeout-safety mechanism (not present in main).
EditorWindowCaptureService, the public ToolContracts extension-API
facade's internal bridge, now adapts to the new signature without
changing its own public (texture, yOffset, timedOut) contract.

UIElementAnnotator.CollectInteractiveElements threads a
UiRaycastHelper.RaycastContext through element collection (replacing
v3-beta's ad-hoc SharedPointerEventData reachability check), and
CreateAnnotationOverlay now draws in two passes (all borders, then all
labels) with a new outline-based border branch for PhysicsCollider
elements, ported from main's e67dcba.

ScreenshotUseCase.CaptureRenderingAsync integrates raycast-grid
collection (grid points, layer summaries, or clustered physics-collider
elements depending on RaycastLayerMask) gated on AnnotateRaycastGrid,
with matching parameter validation and a default-tools.json schema
update needed immediately because DefaultToolsCatalogDriftTests compares
the live tool schema against it.

Verified: uloop compile (0 errors/0 warnings), full EditMode suite
(1774 passed, 0 failed, 7 pre-existing skips), and PlayMode regression
for SimulateMouseUi/InputReplayVerification to confirm no behavior
change in existing UiRaycastHelper callers.
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@hatayama, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 33 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 331bebda-acd9-430c-aec7-a61768d40bd5

📥 Commits

Reviewing files that changed from the base of the PR and between a5c66ac and 6492414.

📒 Files selected for processing (6)
  • .agents/skills/uloop-screenshot/SKILL.md
  • .agents/skills/uloop-screenshot/references/annotated-elements.md
  • .claude/skills/uloop-screenshot/SKILL.md
  • .claude/skills/uloop-screenshot/references/annotated-elements.md
  • Packages/src/Editor/FirstPartyTools/Screenshot/Skill/SKILL.md
  • Packages/src/Editor/FirstPartyTools/Screenshot/Skill/references/annotated-elements.md
📝 Walkthrough

Walkthrough

This PR extends the screenshot tool with raycast-grid and physics-collider annotation support, plus richer image/window coordinate metadata. It updates capture utilities, use-case orchestration and validation, public tool contracts, and UI annotation rendering.

Changes

Screenshot Coordinate and Raycast Annotation Refactor

Layer / File(s) Summary
Screenshot response/schema contracts and constants
Packages/src/Editor/ToolContracts/ScreenshotResponse.cs, ScreenshotSchema.cs, UnityCliLoopConstants.cs, UnityCliLoopScreenshotTypes.cs, cli/common/tools/default-tools.json
ScreenshotInfo renames coordinate fields and adds game-view size, formula, and raycast-grid collection fields; ScreenshotSchema gains AnnotateRaycastGrid and RaycastLayerMask; the old coordinate-system static class is removed; constants and tool docs describe the updated coordinate formulas.
Game rendering capture utility and GameRenderingImageInfo
Packages/src/Editor/FirstPartyTools/Screenshot/EditorWindowCaptureUtility.cs, EditorWindowCaptureService.cs, Assets/Tests/Editor/EditorWindowCaptureUtilityTests.cs
CaptureGameRenderingAsync returns a GameRenderingImageInfo struct instead of a raw Y-offset, with helpers for computing and falling back to that info; EditorWindowCaptureService and new unit tests are updated accordingly.
ScreenshotUseCase raycast-grid orchestration and validation
Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotUseCase.cs, Assets/Tests/Editor/ScreenshotUseCaseTests.cs
CaptureRenderingAsync and CaptureWindowsAsync collect raycast-grid points, layer summaries, and physics-collider elements, apply coordinate metadata helpers, and merge annotated elements; ValidateParameters enforces the new parameter combination rules, covered by new editor tests.
UIElementAnnotator raycast-context reuse and outline rendering
Packages/src/Editor/FirstPartyTools/Screenshot/UIElementAnnotator.cs, Assets/Tests/Editor/UIElementAnnotatorTests.cs
Element collection and reachability checks now share one UiRaycastHelper.RaycastContext; overlay rendering is refactored to compute AnnotationDrawInfo and render borders, outlines, and labels from it, with new outline geometry helpers and tests.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ScreenshotTool
  participant ScreenshotUseCase
  participant EditorWindowCaptureUtility
  participant UIElementAnnotator

  Client->>ScreenshotTool: ExecuteAsync(parameters)
  ScreenshotTool->>ScreenshotUseCase: ValidateParameters(schema)
  alt invalid combination
    ScreenshotUseCase-->>ScreenshotTool: throw UnityCliLoopToolParameterValidationException
  else valid
    ScreenshotUseCase->>EditorWindowCaptureUtility: CaptureGameRenderingAsync
    EditorWindowCaptureUtility-->>ScreenshotUseCase: (texture, GameRenderingImageInfo, timedOut)
    ScreenshotUseCase->>UIElementAnnotator: collect/annotate elements
    UIElementAnnotator-->>ScreenshotUseCase: annotated elements + raycast grid data
    ScreenshotUseCase->>ScreenshotUseCase: ApplyRenderingCoordinateMetadata
    ScreenshotUseCase-->>ScreenshotTool: ScreenshotResponse
  end
Loading

Possibly related PRs

  • hatayama/unity-cli-loop#1333: Both PRs modify EditorWindowCaptureUtility.CaptureGameRenderingAsync's return shape and downstream ScreenshotUseCase mapping.
  • hatayama/unity-cli-loop#1465: Both PRs refactor UIElementAnnotator to use the shared UiRaycastHelper.RaycastContext for raycast reachability.
  • hatayama/unity-cli-loop#1502: Both PRs change UIElementAnnotator outline-segment conversion and CalculateOutlineSegmentRect behavior.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.53% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding 3D physics raycast candidate annotation to the screenshot tool.
Description check ✅ Passed The description is directly related to the changeset and accurately describes the new screenshot annotation and metadata behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/screenshot-raycast-annotation

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotUseCase.cs`:
- Around line 387-405: The screenshot response contract has changed in
ScreenshotUseCase, so update the CLI protocol version to match the breaking
wire-format change. Bump the protocol in cli/common/clicontract/contract.json
and keep Packages/src/Editor/Domain/CliConstants.cs
REQUIRED_CLI_PROTOCOL_VERSION in sync, since ScreenshotInfo now uses the new
coordinate and metadata fields exposed by ApplyRenderingCoordinateMetadata and
ApplyWindowCoordinateMetadata.
- Around line 185-187: The annotation conversion in ScreenshotUseCase is using
the initially sampled Game View height instead of the settled capture height,
which can make the response metadata and ScreenshotToInputFormula disagree if
the Game View changes during the wait. Update the ConvertToSimCoordinates call
in the screenshot flow to use captureRenderingInfo.GameViewSize consistently,
and keep the annotated elements conversion aligned with the same settled height
used for the response data.

In `@Packages/src/Editor/FirstPartyTools/Screenshot/UIElementAnnotator.cs`:
- Around line 499-512: The physics-collider overlay is re-reading the current
Game View height instead of using the captured render height, which can desync
the Y flip from the screenshot geometry. Update `CreateAnnotationOverlay` to
accept and pass through the captured `GameViewSize.y` from `ScreenshotUseCase`,
and change `CalculatePhysicsAnnotationScreenHeight` to use that value instead of
calling `GameViewCoordinateUtility.GetMainGameViewSize()`. Keep the existing
`IsPhysicsColliderElement` flow, but ensure all physics-collider bounds/outline
conversion uses the screenshot’s original Game View height.

In `@Packages/src/Editor/ToolContracts/ScreenshotResponse.cs`:
- Around line 16-29: The screenshot response contract changed field names
without a protocol update, breaking older consumers. In ScreenshotResponse, keep
the existing wire names compatible by adding aliases or preserving the
serialized names for CoordinateSystem and YOffset equivalents, and make sure the
protocol version is bumped if the contract is intentionally changed. Update the
related contract definition and CliConstants.REQUIRED_CLI_PROTOCOL_VERSION
together so ScreenshotInfo remains interoperable across versions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b42e88d5-dae1-4147-8a98-cd537453c21c

📥 Commits

Reviewing files that changed from the base of the PR and between ac381ba and 8aacb7e.

⛔ Files ignored due to path filters (2)
  • Assets/Tests/Editor/EditorWindowCaptureUtilityTests.cs.meta is excluded by none and included by none
  • Assets/Tests/Editor/ScreenshotUseCaseTests.cs.meta is excluded by none and included by none
📒 Files selected for processing (12)
  • Assets/Tests/Editor/EditorWindowCaptureUtilityTests.cs
  • Assets/Tests/Editor/ScreenshotUseCaseTests.cs
  • Assets/Tests/Editor/UIElementAnnotatorTests.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/EditorWindowCaptureService.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/EditorWindowCaptureUtility.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotUseCase.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/UIElementAnnotator.cs
  • Packages/src/Editor/ToolContracts/ScreenshotResponse.cs
  • Packages/src/Editor/ToolContracts/ScreenshotSchema.cs
  • Packages/src/Editor/ToolContracts/UnityCliLoopConstants.cs
  • Packages/src/Editor/ToolContracts/UnityCliLoopScreenshotTypes.cs
  • cli/common/tools/default-tools.json
💤 Files with no reviewable changes (1)
  • Packages/src/Editor/ToolContracts/UnityCliLoopScreenshotTypes.cs

Comment thread Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotUseCase.cs Outdated
Comment thread Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotUseCase.cs
Comment thread Packages/src/Editor/ToolContracts/ScreenshotResponse.cs
…w size

CodeRabbit flagged that ConvertToSimCoordinates used the pre-capture
gameViewSize sample instead of captureRenderingInfo.GameViewSize, which
is already used for the response's GameViewWidth/Height metadata a few
lines later. If the Game View resizes during the overlay-render wait,
the two values diverge and the returned AnnotatedElements coordinates
become inconsistent with the formula the response advertises.
CoordinateSystem/YOffset were renamed to ImageCoordinateSystem/
ImageToInputOffsetY earlier in this PR, but the screenshot skill
docs (and their .claude/.agents generated copies) still referenced
the old field names, actively guiding agents toward fields that no
longer exist on the response. Regenerated the installed copies via
`uloop skills install --claude --agents`.
@hatayama
hatayama merged commit c5d2fd0 into v3-beta Jul 9, 2026
10 checks passed
@hatayama
hatayama deleted the feat/screenshot-raycast-annotation branch July 9, 2026 11:14
@github-actions github-actions Bot mentioned this pull request Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant