threejs Raycast 与 xr 控制器的碰撞不起作用

threejs Raycast collisions with xr controller not working

提问人:Samuel 提问时间:9/20/2023 更新时间:9/20/2023 访问量:17

问:

使用鼠标时,我能够在场景中进行光线投射碰撞检测,如下面的第一个代码块所示。但是,在 WebXR 中使用我的 oculus 控制器(使用下面第二个代码块中的代码)时,我无法让光线投射器与场景中的对象相交。我唯一能检测到的是控制器本身的物体,比如光束线和控制杆,所以至少我知道光线投射器指向一个方向

使用鼠标进行交叉路口检测(工作):

let raycaster = new Raycaster();
let pickedObject = null;
// cast a ray through the frustrum
raycaster.setFromCamera(this.pointer, this.camera)
let intersectioned = raycaster.intersectObjects(this.scene.children)
if(intersectioned.length){
      console.log(intersectioned)
}

使用 VR 控制器进行交叉路口检测(不工作)

// cast a ray from the controller
let raycaster = new Raycaster();
this.tempMatrix.identity().extractRotation( this.xrCtlRight.controller.matrixWorld );
raycaster.ray.origin.setFromMatrixPosition( this.xrCtlRight.controller.matrixWorld );
raycaster.ray.direction.set( 0, 0, -1 ).applyMatrix4( this.tempMatrix )

const intersections = raycaster.intersectObjects( this.scene.children );
if( intersections.length ){
      for( let i=0; i<intersections.length; i++ ){
            if(intersections[i].object.name !== 'xrControllerRaycastBeam' && intersections[i].object.name !== 'thumbstick' && intersections[i].object.name !== 'controller'){
                        console.log(intersections[i])
            }
      }
}

提前感谢大家的回答:)

我已经尝试了上面的代码。并希望任何精通threejs / vr的人都能回答。谢谢。

虚拟现实 光线投射 WebXR

评论


答: 暂无答案