Files
workinf_Blender_Wasm/docs/web/ARMATURE-ROBOT-HEADED-TESTS.md
mes123456 013ea78a45
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
fix(web): robot rig places bones on the URDF chain and keeps bound worlds
The rig step placed every bone at its parent-link-relative URDF offset and
the engine's keep_transform world recursion treated already-bound ancestors
as plain PAROBJECT, so binding in chain order dropped the ancestor bone
matrix and every link jumped on the rig click (deltas up to 1.26).

- set_parent: refresh the pose before computing the world and compose
  PARBONE ancestors like BKE_object_calc_parent/ob_parbone.
- robot-workflow rig: accumulate URDF joint frames from rootLink (fixed
  joints included) and place head/axis on the real joint position.
- robot-rig-web now asserts zero world drift, bone pivots on the URDF
  joints, bone Y on the joint axes, joint_3 rotation moving only its
  subtree about the true axis, and 恢复零位 restoring every link.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-29 19:20:27 +08:00

96 lines
7.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 骨骼 / ABB IRB120 有头测试
面向浏览器真实操作的有头(headed)验证:Chromium 打开产品入口、走真实的加载/装配/姿态路径,
断言从引擎快照读回,回执绑定候选构件哈希且标记 `NOT_CLAIMED`(不宣称验收通过)。
## 运行
```bash
# 全量(需要 X11,默认 headed;candidate 默认 web/dist)
DISPLAY=:1 node tools/web/run-armature-robot-headed.mjs --candidate /abs/path/to/web/dist
# 单例
DISPLAY=:1 node tools/web/run-armature-robot-headed.mjs --candidate web/dist --grep armature-viewport-web
# 校验最新回执
node tools/web/check-armature-robot-headed.mjs
node tools/web/check-armature-robot-headed.mjs --dir /abs/tests/golden/ARMATURE-ROBOT-HEADED-<stamp>
```
退出码:`0` 通过、`1` 失败、`2` 前置检查 BLOCKED(缺 DISPLAY/Chrome/候选/机器人样例 provenance)、`64` 参数错误。
回执写入 `tests/golden/ARMATURE-ROBOT-HEADED-<YYYYMMDD-HHMMSS>/`,同名冲突追加 `-HHMMSS`,历史回执不覆盖。
## 用例
| id | 入口 | 断言 |
| --- | --- | --- |
| `robot-sample-web` | 六轴机器人工具 → 加载 ABB IRB120 样例 | provenance/URDF 哈希一致,零件导入后各 link 挂在根对象下 |
| `robot-assemble-check-web` | 建立 URDF 层级 → 六轴检查 | 真实父子链与六轴检查通过 |
| `robot-pose-web` | joint_1 30° → 应用关节角度 → 恢复零位 | link_1 world 变化、复位还原 |
| `robot-rig-web` | 建立骨架 → joint_3 30° → 恢复零位 | 6 骨骼与 6 转动关节一一对应;绑定前后 link 世界矩阵零漂移(<1e-5);骨骼 pivot = URDF 链累积关节位置、骨 Y = 关节轴;joint_3 旋转只带动 link_3 子树、关节 pivot 不平移、joint_5 绕关节轴等半径圆周运动;恢复零位还原 |
| `armature-bones-web` | 引擎命令 `setArmatureBones` | Root/Child 骨链、rest/pose 通道读回 |
| `armature-bind-web` | `setParent` + `parentType:"BONE"` | 刚性绑定后 world 不变;未知骨名返回 `PARENT_BONE_INVALID` |
| `armature-pose-web` | `setPoseBoneTransform` | poseMatrix/子物体 world 变化、重复写入幂等、归零复原 |
| `armature-viewport-web` | 属性面板姿态表单 → Apply Pose | 画布 `data-armature-bone-count`、截图前后不同 |
| `armature-decimal-input-web` | 用户逐键输入 `0.5` | `缩放 X` 与姿态 `Scale X` 保留小数;姿态提交后 poseScale 读回 0.5 |
| `armature-ui-readback-web` | 物体模式 → 进入姿态模式;姿态表单回填;Ctrl+Tab 往返 | 物体模式只读(无 rest 操作/姿态表单);UI 显示角度/缩放 = 引擎 pose 通道(弧度×180/π),`data-testid="armature-pose-readback"`;Ctrl+Tab 回到物体模式并再进姿态 |
| `armature-reopen-web` | 文件 → 保存到浏览器 OPFS → 最近打开 | worker `openBlend` 成功回复为前置;重开后骨骼、骨骼父级、姿态与世界矩阵与保存前一致 |
## 门禁(checker 硬校验)
- `bundleHasRobotTool`:候选包含「加载 ABB IRB120 样例」入口。
- `engineHasArmatureCommands`:wasm 含 `ARMATURE_BONES_INVALID`。
- `engineHasBoneParent`:wasm 含 `PARENT_BONE_INVALID`。
- `enginePoseEvaluated`:wasm 含 `ARMATURE_POSE_EVALUATED`。
- `bundleHasArmatureReadback`:候选包含姿态读回表单。
- `matchesSyncedRuntime`:候选 wasm 与 `web/app/public/vendor/blender` 同步产物一致。
## ABB IRB120 骨骼映射(关节 → 骨骼 → 刚性绑定)
| 关节 | 骨骼 | 子 link | 说明 |
| --- | --- | --- | --- |
| joint_1 | J1 | link_1 | 基座回转,URDF 轴 Z |
| joint_2 | J2 | link_2 | 大臂,轴 Y |
| joint_3 | J3 | link_3 | 小臂,轴 Y |
| joint_4 | J4 | link_4 | 腕回转,轴 Z |
| joint_5 | J5 | link_5 | 腕摆动,轴 Y |
| joint_6 | J6 | link_6 | 法兰,轴 Z |
绑定语义镜像桌面 `ob_parbone`:`pose_mat` 的 Y 列 × 骨长 × `parent_bone_head_tail_factor`(DNA 默认 1.0),
`partype = PARBONE`,`parsubstr = <骨名>`;world = 骨架对象 world × 骨骼矩阵 × `parentinv` × basis。
骨骼放置按 URDF 链累积(`robot-workflow.py`):从 `rootLink` 单位阵起,逐关节
`frames[child] = frames[parent] @ origin(joint)`(含 fixed 关节),转动关节骨骼的 head = 该关节累积原点,
tail = head + (帧旋转 @ 关节轴) × 0.12(骨 Y 即关节轴)。IRB120 实测 pivot:
J1 (0,0,0)、J2 (0,0,0.29)、J3 (0,0,0.56)、J4 (0,0,0.63)、J5 (0.302,0,0.63)、J6 (0.374,0,0.63),
与各子 link 绑定前的世界平移一致。引擎 `setParent(BONE, keepTransform)` 递归时对已绑定的祖先按
PARBONE 组合骨骼矩阵(镜像 `BKE_object_calc_parent`),因此按链序绑定不会丢祖先骨骼矩阵。
## 约束
- 全部落盘走 OPFS;禁用 IDBFS/IndexedDB;测试产物不写入 OPFS。
- 下载 `.blend` 只能由用户手动触发独立入口,保存/编辑流程不得自动下载。
- 回执 `acceptance:"NOT_CLAIMED"`,绑定候选哈希,不覆盖历史回执;不以单例通过宣称整体验收。
## 残余
- rig 阶段骨骼父级的世界保持偏差已修复(原最大值约 1.26):根因是引擎 `set_parent` 的 `keep_transform`
世界递归把已绑定的祖先当作 PAROBJECT,丢掉祖先骨骼矩阵;现按 PARBONE 组合(对齐 `BKE_object_calc_parent`),
绑定前后各 link 世界矩阵零漂移(`robot-rig-web` 证据 `worldDelta`,全部 <1e-5)。
- 关节角度调整只围绕该关节:姿态经骨骼通道(`Quaternion((0,1,0), angle)` 绕骨 Y = 关节轴)写入,
`BKE_pose_where_is` 驱动子骨骼,子 link 经 PARBONE 组合自动跟随;three.js 消费快照世界矩阵。`robot-rig-web`
实测 joint_3 30°:link_1/link_2 不变,link_3..link_6 跟随,joint_3 pivot 不平移,joint_5 沿关节轴等半径
圆周运动,恢复零位全部还原。
- 机器人工具动作「建立骨架(6 骨骼 + 刚性绑定)」已落地:Python 只建骨架与 6 根骨骼(按 URDF 链放置 pivot 与轴向),
刚性绑定经引擎 `setParent(BONE, keepTransform)` 完成,与 `armature-bind-web` 共用同一实现。
- `armature-reopen-web` 已落地:保存走「文件 → 保存到浏览器 OPFS」,重开走「文件 → 最近打开」。
断言前必须等到 worker 的 `openBlend` 成功回复计数增长(证据 `openBlendReplies` 1→2),否则活着的
Main 会直接回答快照、比较恒真;实测重开前 r4 → 重开后 r1,骨骼 / 父级 / 姿态 / 世界矩阵零偏差。
- 姿态表单已按 `uiState.context.mode` 分离,与桌面骨骼模式一致:编辑模式显示 rest 编辑(添加骨骼、
逐骨 rest 变换、`armature-edit-operations` 五项操作);姿态模式显示姿态读回/提交表单
(`armature-pose-readback`);物体模式只读,显示 `armature-mode-actions` 与「进入编辑模式 / 进入姿态模式」
按钮。工作台根节点带 `data-armature-mode`,便于断言当前模式。
- 快捷键:骨骼对象上 Ctrl+Tab 在姿态 / 物体间切换,Tab 仍进入编辑模式。原生 `object.mode_set`
进行中(状态栏显示「正在切换到 … 模式…」)时 App 会忽略快捷键,属刻意的 pending 守卫;物体模式按钮
始终可用,切换完成后再按快捷键生效。