手部追踪
平台支持 WebXR Hand Input 时,输入源可关联 XrHand,通过 XrFinger 和 XrJoint 提供手腕、手指、关节、指尖及丢失/恢复追踪事件。
模型
创建基本手模型:
const joints = [];
const hand = inputSource.hand;
if (hand) {
for (let i = 0; i < hand.joints.length; i++) {
const entity = new pc.Entity();
entity.joint = hand.joints[i];
entity.addComponent('render', { type: 'box' });
parent.addChild(entity);
joints.push(entity);
}
}
更新
每帧关节位置、旋转及其他数据都可能变化。
for (let i = 0; i < joints.length; i++) {
const entity = joints[i];
const joint = entity.joint;
const radius = joint.radius * 2;
entity.setLocalScale(radius, radius, radius);
entity.setPosition(joint.getPosition());
entity.setRotation(joint.getRotation());
}
追踪
可靠性取决于底层系统。摄像头与手之间遮挡、双手复杂交叠等都可能导致追踪失败。虽然视觉技术持续改进,设计手部交互时仍应考虑这些限制。
蒙皮
可以使用手部蒙皮网格,参考此项目:
