Skip to content

Port Unity stroke personalization source layers#103

Draft
sw1029 wants to merge 1 commit into
codex/two-track-personalization-enginefrom
codex/unity-source-port-06
Draft

Port Unity stroke personalization source layers#103
sw1029 wants to merge 1 commit into
codex/two-track-personalization-enginefrom
codex/unity-source-port-06

Conversation

@sw1029
Copy link
Copy Markdown
Owner

@sw1029 sw1029 commented May 31, 2026

Summary

  • .6 source-only stacked PR on top of Extract two-track personalization engine for survey evals #102: add the Unity-side Input capture, Stroke recognition, Personalization, and Presentation source layers.
  • Commit includes only Unity C# source and C# EditMode test files. It intentionally excludes .meta, Packages, ProjectSettings, screenshots, and capture artifacts.
  • Runtime handoff now flows through StrokeInputSession -> IStrokeRecognitionService -> SpellCastingService, with accepted casts recorded back into the tutorial personalization store.

Related Issues

Why Needed

  • The previous .5 PR isolates the final two-track personalization policy from the survey prototype. This .6 PR ports the Unity source-code side of that boundary without mixing generated Unity metadata or editor/package setup changes into the diff.
  • WorldDrawingController previously combined pointer polling, stroke buffering, line rendering, recognition handoff, and legacy StrokeSample output. The new structure gives each layer a narrow responsibility and gives recognition/personalization a stable session contract.

Changed Boundaries

  • Input capture: unity/MagicExamHall/Assets/MagicExamHall/Scripts/Input/
  • Recognition service: unity/MagicExamHall/Assets/MagicExamHall/Scripts/Recognition/StrokeRecognitionService.cs
  • Personalization store: unity/MagicExamHall/Assets/MagicExamHall/Scripts/Personalization/TutorialPersonalizationProfile.cs
  • Presentation-only stroke visuals: unity/MagicExamHall/Assets/MagicExamHall/Scripts/Presentation/WorldStrokeVisuals.cs
  • Runtime handoff: WorldDrawingController, ExamGameController, SpellCastingService, SpellRuntime, SpellRecognition
  • Supporting Unity runtime cleanup: PixelArtFactory, PixelSpriteView
  • EditMode coverage: StrokeInputRecognitionHandoffTests.cs

Code Change Details

Input Capture Layer

  • StrokeInputTypes.cs adds InputCoordinateSpace, StrokeInputPoint, StrokeInputStroke, and StrokeInputSession as the canonical Unity stroke session data model.
  • StrokeInputSessionExtensions bridges old and new models with FromStrokeSamples, ToStrokeSamples, GetWorldCenter, and EstimateWorldScale, so existing recognizers can be reused while new code depends on session objects.
  • WorldPointerInputSource owns pointer polling only: mouse button selection, UI hit filtering, screen-to-world conversion, min-distance point filtering, and start/update/complete/cancel events.
  • StrokeSessionBuffer groups completed strokes into one session after bufferSeconds, supports direct synthetic session submission, and resets cleanly on cancel.

Stroke Recognition / Personalization Layer

  • StrokeRecognitionService.cs introduces IStrokeRecognitionService, RecognitionContext, StrokeRecognitionResult, and HeuristicStrokeRecognitionService.
  • Recognition now resolves attachable overlays through SpellCastingService.FindAttachableSeal, checks detached overlay candidates, then falls back to base spell recognition.
  • RecordAcceptedResult stores only accepted base or overlay results as tutorial captures, avoiding failed or invalid casts from training the profile.
  • TutorialPersonalizationProfile.cs adds the Unity personalization store: threshold state calculation, capture retention, per-target evaluation, base/overlay personalization application, and feature extraction.
  • The personalization feature vector covers stroke count, point count, corner count, endpoint clusters, closure, circularity, fill ratio, parallelism, and normalized raw angle.
  • The local model combines normalized point-cloud distance and feature similarity, then applies accept/hold/retry thresholds. Invalid recognition status is never promoted to success.

Runtime Handoff

  • WorldDrawingController now composes WorldPointerInputSource, StrokeSessionBuffer, and WorldStrokeVisuals instead of implementing all three concerns inline.
  • It emits StrokeSessionCompleted for the new recognition path and keeps the legacy SpellBuffered event for tests/tools that still consume StrokeSample groups.
  • ExamGameController owns the recognition service, processes completed sessions, exposes personalization counters for tests, records successful outcomes, and keeps legacy synthetic spell submission working via session conversion.
  • SpellCastingService.ProcessRecognitionResult converts a StrokeRecognitionResult into existing SpellCastOutcome variants and attaches the recognition result to the outcome for downstream inspection.
  • SpellRuntime and SpellRecognition now carry TutorialPersonalizationSummary alongside recognition results; base candidate ordering prefers true success before recognized-but-not-success states.

Presentation / Runtime Cleanup

  • WorldStrokeVisuals owns LineRenderer creation, active stroke updates, completed stroke fading, and synthetic session visualization.
  • PixelArtFactory creates generated sprites with SpriteMeshType.FullRect, matching tiled sprite usage expectations.
  • PixelSpriteView defers play-mode OnValidate application to LateUpdate, avoiding Unity editor lifecycle warnings from applying sprite changes during validation.

Test Coverage

  • StrokeInputRecognitionHandoffTests verifies session round-tripping, buffered stroke grouping, recognition-to-personalization capture recording, personalization summary availability after captures, and the guard that prevents invalid input from being promoted to success.
  • Existing GestureRecognizerTests also cover the updated service handoff methods and overlay routing behavior in the same EditMode run.

Handoff

  • This is intentionally stacked on Extract two-track personalization engine for survey evals #102. After Extract two-track personalization engine for survey evals #102 lands, retarget this PR to main or rebase it onto main.
  • Because .meta files are excluded by request, this PR relies on Unity regenerating metadata for new scripts on import. The new runtime components are added dynamically by WorldDrawingController, so no serialized scene references are required in this source-only split.
  • If a later PR needs stable GUIDs or scene/prefab references, add the relevant .meta and scene files there rather than expanding this source-only PR.

Verification

  • npm run validate:docs
  • npm test
  • npm run build
  • Unity EditMode tests: Unity.exe -batchmode -projectPath C:\Users\USER\magic\unity\MagicExamHall -runTests -testPlatform EditMode -testResults %TEMP%\magic-editmode-source-pr.xml -logFile %TEMP%\magic-unity-editmode-source-pr.log (51 passed)
  • Unity PlayMode tests:
  • GitHub checks observed: CI [Child #73] 1층 첫 30초 튜토리얼·ghost gesture #75 passed; CodeQL [Child #73] Exam Mentor 컨텍스트 소환 모델·대사 풀 #78 is still in progress.
  • Not run; reason: PlayMode tests and web/npm checks were not rerun because this PR contains only Unity C# source and is stacked on the already built .5 survey/engine PR.

Notes

  • Scope: Unity source-code migration only.
  • Out of scope / follow-up: Unity .meta, package manifests, project settings, screenshots, capture artifacts, and MCP package files.
  • Risk notes: Source-only Unity diffs are reviewable and compile locally, but generated .meta GUIDs will differ unless committed in a later metadata PR.

Review Checklist

  • This PR changes user-facing UI or behavior.
  • This PR changes recognizer behavior.
  • This PR changes docs, task state, or project process.
  • This PR changes ML artifacts, datasets, generated outputs, or capture/export behavior.
  • This PR changes logging, survey fields, privacy, or research data handling.
  • This PR needs screenshots or a short playtest note.

Screenshots / Playtest Notes

No screenshot attached for this source-only split. Local verification was Unity EditMode test execution; generated screenshots and capture artifacts are intentionally excluded.

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