Grab an object in the WebXR scene using emulated controllers. Use when the user wants to pick up, move, or test grabbing an object. Supports OneHandGrabbable and TwoHandsGrabbable components which use proximity-based grip (squeeze button), not trigger.
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "iwsdk-grab" 技能: 1. 下载 https://raw.githubusercontent.com/facebook/immersive-web-sdk/main/packages/starter-assets/claude-injections/skills/iwsdk-grab/SKILL.md 2. 保存为 ~/.claude/skills/iwsdk-grab/SKILL.md 3. 装好后重载技能,告诉我可以用了
Grab an object in the XR scene using the IWER emulated controllers. The workflow has a required core (steps 1-5) that must always execute, and optional extensions (steps 6-9) that depend on the user's intent.
User request is in $ARGUMENTS.
These steps always execute in order. A grab cannot succeed without them.
Check session status. If not in an active XR session, accept and enter.
xr_get_session_status → if not sessionActive → xr_accept_session
Find the object by name in the scene hierarchy. Use scene_get_hierarchy and match against the name from $ARGUMENTS.
scene_get_hierarchy → find node matching the target name
If the object is not found, report the available named objects and stop.
Get the object's world position using its UUID from step 2.
scene_get_object_transform(uuid) → use positionRelativeToXROrigin
Animate the controller to the object's position. Default to "controller-right" unless the user specified left.
xr_animate_to({
device: "controller-right",
position: { x, y, z },
duration: 0.5,
})
OneHandGrabbable and TwoHandsGrabbable are proximity-based and use the squeeze/grip button (index 1), not the trigger.
xr_set_gamepad_state({
device: "controller-right",
buttons: [{ index: 1, value: 1 }],
})
The object is now grabbed. If the user only asked to grab (not move), stop here.
Apply these based on the user's request.
If the user specified a destination position, animate the controller there. If no position was given but the user asked to "move" the object, animate it to in front of the headset.
To find "in front of headset": xr_get_transform({ "device": "headset" }) → place at (head.x, head.y - 0.2, head.z - 0.5) adjusted for head orientation.
xr_animate_to({
device: "controller-right",
position: { x, y, z },
duration: 0.5,
})
Release the squeeze button to drop the object.
xr_set_gamepad_state({
device: "controller-right",
buttons: [{ index: 1, value: 0 }],
})
Animate the controller back to its resting position so it's not overlapping the dropped object.
xr_animate_to({
device: "controller-right",
position: { x: 0.2, y: 1.4, z: -0.3 },
duration: 0.5,
})
Default resting positions: right (0.2, 1.4, -0.3), left (-0.2, 1.4, -0.3).
Take a screenshot to confirm the result.
browser_screenshot
xr_set_device_state to move controllers — it teleports instead of animating, which can break grab state.xr_select or trigger (button index 0) for grabs — OneHandGrabbable/TwoHandsGrabbable respond to squeeze (button index 1).mesh.name = "MyObject" in code before createTransformEntity.Test grab system (distance grab, one-hand grab, two-hand grab) against the grab example using the iwsdk CLI.
Test XR interactions (ray, poke/touch, dual-mode, audio, UI panel) against the poke example using the iwsdk CLI.
Find and click a target object in XR. Use when testing UI interactions, clicking buttons, or verifying interactable elements work correctly.
IWSDK project planning and best practices guide. Use when planning new IWSDK features, designing systems/components, reviewing IWSDK code architecture, or when the user asks about IWSDK patterns, ECS design, signals, or reactive programming in this codebase.
Develop and iterate on IWSDK UI panels efficiently. Use when working on PanelUI components, debugging UI layout, or improving UI design in IWSDK applications.
Test level system (LevelRoot, LevelTag, default lighting, scene hierarchy) against the poke example using the iwsdk CLI.