fix(web): robot rig places bones on the URDF chain and keeps bound worlds
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

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>
This commit is contained in:
mes123456
2026-11-29 19:20:27 +08:00
parent 8f08c1bda9
commit 013ea78a45
7 changed files with 133 additions and 40 deletions

View File

@@ -27,6 +27,7 @@ node tools/web/check-armature-robot-headed.mjs --dir /abs/tests/golden/ARMATURE-
| `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 变化、重复写入幂等、归零复原 |
@@ -58,6 +59,13 @@ node tools/web/check-armature-robot-headed.mjs --dir /abs/tests/golden/ARMATURE-
绑定语义镜像桌面 `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。
@@ -66,11 +74,15 @@ node tools/web/check-armature-robot-headed.mjs --dir /abs/tests/golden/ARMATURE-
## 残余
- rig 阶段骨骼父级的世界保持偏差:绑定后各 link 的世界矩阵与绑定前不一致(`robot-rig-web` 证据
`residuals.worldPreservation.deltas`,最大约 1.26)。按用户指示归入机器人逆解一并处理;该用例当前
只判定 URDF 层级与装配绑定关系(6 骨骼对应 6 个转动关节、每个 link 绑定到自己的关节骨骼、无产品控制台错误)。
- 机器人工具动作「建立骨架(6 骨骼 + 刚性绑定)」已落地:Python 只建骨架与 6 根骨骼,刚性绑定经引擎
`setParent(BONE, keepTransform)` 完成,与 `armature-bind-web` 共用同一实现。
- 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,骨骼 / 父级 / 姿态 / 世界矩阵零偏差。