事件对象 IShapeTouchEvent 中仅包含二维 canvas 坐标,业务中需要获取对应的三维坐标,能触发事件我猜想应当是有碰撞三维坐标的。
https://developers.weixin.qq.com/miniprogram/dev/api/xr-frame/interfaces/IShapeTouchEvent.html
我注意到事件对象中有射线和方向,尝试使用物理系统的 raycast 函数获取,但返回都是 false,使用方式应该并不正确。另外也找不到 RaycastHit 构造函数在哪获取。
希望能够提供交互点三维坐标获取的方式。
<xr-mesh
node-id="mesh-cube"
position="0 -2 -1"
rotation="0 0 0"
scale="1 0.1 1"
geometry="cube"
uniforms="u_baseColorFactor:0.6 0.8 0.6 1, u_metallicRoughnessValues: 0.0 0.0"
mesh-shape
id="test"
physics-system="enableSimulation: true"
bind:touch-shape="testClick"
></xr-mesh>
testClick(event) {
const { detail } = event;
const { origin, dir } = detail.value;
const physicsSystem = this.scene.getElementById("test").getComponent("physics-system");
const Vector3 = physicsSystem.gravity.constructor;
const RaycastDesc = {
origin: new Vector3(origin),
unitDir: new Vector3(dir)
}
const res = physicsSystem.raycast(RaycastDesc);
console.log('res', res)
},
