xb-add-interactions
Design and implement XR Blocks interactions. Use when adding selection, hover, direct touch, grab, gestures, event ownership, propagation, automatic manipulation, or physics-driven object behavior.
- License 许可
- Apache-2.0
- 所属仓库
- google/xrblocks
- 最近更新
- 2026-11-11
- Stars
- ★ 513
- Forks
- 103
01 前言 Front Matter
- name
- xb-add-interactions
- description
- Design and implement XR Blocks interactions. Use when adding selection, hover, direct touch, grab, gestures, event ownership, propagation, automatic manipulation, or physics-driven object behavior.
02 资源文件 4
- 参考文档agents/openai.yaml280 B
- 参考文档references/gesture-events.md1.3 KB
- 参考文档references/manipulation-and-physics.md2.0 KB
- 参考文档references/selection-and-direct-hands.md3.0 KB
03 SKILL.md 正文
Add interactions
Produce a complete interaction contract in code: intent, target, phases, state owner, feedback, cleanup, and test instructions.
1. Inventory each user intent
For every requested action, record the actor, target, trigger, start/update/end or cancel phases, one application state transition, feedback, and desktop/XR test route. Keep separate rows when two actions have different ownership or phase models, even when they use the same object.
Complete this step when every action has a target, phase model, state owner, feedback, and user-test path.
2. Select one event family
Read
../../docs/docs/manual/Interaction.md.
Use:
- global
Scripthooks for scene-owned commands; - object select and hover hooks for resolved ray targets;
- touch and grab hooks for direct hand contact;
- gesture event targets for recognized hand poses or completed head motion;
object.xb.manipulationfor automatic translation, rotation, or scale;- Rapier only for collision, gravity, momentum, throwing, or forces.
Read the selected branch reference:
references/selection-and-direct-hands.mdreferences/gesture-events.mdreferences/manipulation-and-physics.md
Complete this step when every action maps to one public event family without a second raycast loop or a reconstructed higher-level event.
3. Implement ownership and feedback
Put the handler on the script that owns application state or contains the
logical target. Give targets intentional hit geometry. Use the event's
source, target, surface, currentTarget, and intersection instead of
raycasting again. Treat the reticle as presentation of the resolved hit.
Represent useful phases explicitly, such as idle, hovered, active,
held, and disabled. Keep handlers thin: validate the resolved event, change
one domain state, then update feedback. Share the domain method when several
input sources mean the same action.
Complete this step when every intent row has an owner, target geometry, handler, phase state, domain transition, feedback, and release or cancel path.
4. Preserve event and manipulation semantics
Call event.stopPropagation() from a targeted callback only when its ancestor
propagation must stop. For selection events, call
event.stopGlobalPropagation() in onObjectSelectStart to suppress global
selection callbacks for the entire capture without cancelling the control's
default action. Calling it later only affects callbacks that have not run.
Built-in buttons, sliders, text inputs, and scroll views consume selection;
subclasses overriding their selection handlers should call super.
Use event.preventDefault() only where the event
exposes it: touch start can suppress the default touch selection, and
manipulation start can suppress
the automatic transform. Propagation and default behavior are independent.
Automatic manipulation supports independent simultaneous object owners and two-source scale on one owner. Keep per-object state on the object or owning script, not in one global drag slot. Placement scripts suspend during manipulation and rebase on resume.
Guard optional hands, joints, recognizers, and tracked data. Store listener
functions and remove them in dispose(). Provide stable unavailable,
interrupted, disabled, and canceled states.
Complete this step when propagation, default behavior, paired lifecycle phases, concurrent owners, optional data, and cleanup are explicit for every branch.
5. Prove and hand off each action
Build or type-check the app, run focused tests, and start the exact simulator
route when available. Confirm targets, affordances, handlers, event fields,
state transitions, release behavior, and relevant console output. Use
../../templates/02_object_interaction/
as the current interaction foundation.
Give the user one compact test card per action: simulator steps, XR input, target, start/active/result/release feedback, state change, and device-only checks.
Finish when every action can be tested without inferring its controls, expected feedback, or cancellation behavior from source.
04 同仓库更多 Skills
xb-debug-app
Debug and repair XR Blocks applications. Use when an app fails to build or run, produces incorrect UI, interaction, sensing, or rendering behavior, differs between simulator and device, leaks resources, or contains obsolete SDK patterns.
xb-contribute-sdk
Complete an XR Blocks SDK change across implementation, runtime wiring, public exports, proof, build output, examples, and canonical documentation. Use when editing the XR Blocks repository rather than an application that consumes it.
xb-build-app
Build or extend a complete XR Blocks application. Use when the request concerns an app scaffold, a whole experience, several SDK areas, or an end-to-end simulator or XR handoff rather than one focused subsystem.
xb-anchors
Pin content to a real place with WebXR spatial anchors, and bring it back in a later session. Use when virtual content must stay put as the headset refines its map of the room, or when an app should remember where things were left. Covers `enableAnchors()`, `enableAnchorPersistence()`, creating and restoring anchors, the `capability` states, and the desktop fallback that lets anchor code be developed without a headset. Pair with xb-world for detecting what to anchor to.
xb-add-world-sensing
Connect physical-world sensing to XR Blocks application state. Use when adding planes, scene meshes, depth, occlusion, world collision evidence, object or human recognition, face tracking, segmentation, or agent-facing scene context.
xb-add-spatial-ui
Build spatial UI in XR Blocks. Use when adding cards, overlays, panels, text, controls, model-viewer interfaces, layout, styling, themes, or UI placement with the built-in UI system.