在我的场景中,我使用脚本来创建一个带有 raycaster 组件的实体。这很好用,并且事件侦听器与我的地面对象碰撞时工作正常。但是我的地面不平坦,我需要知道光线投射器击中的地面高度。据我所知,仅靠 A-Frame 提供的功能是不可能的。我想调用 THREE 的 raycaster.intersectObject,但我无法获得对 THREE raycaster 的工作参考。A-Frame 文档提到了一个名为 raycaster 的成员,但它对我来说是未定义的。我尝试了一些不同的东西,但无济于事。我的下一个计划是制作一个新组件,但我想我会先在这里问。
var ray = document.createElement('a-entity');
ray.setAttribute('id', 'raycaster');
ray.setAttribute('raycaster', 'objects: #ground');
ray.setAttribute('position', pos);
ray.setAttribute('rotation', '-90 0 0');
scene.appendChild(ray);
var ground = document.querySelector('#ground');
ray.addEventListener('raycaster-intersection', function() {
console.log(ray.raycaster); //undefined
console.log(ray.intersectedEls); //undefined
console.log(ray.objects); //undefined
console.log(ray.object3D.id); //gives me the THREE id
console.log(ray.object3D.intersectObject(ground.object3D, false)); //intersectObject not a function
});
有什么线索吗?我确定我在做一些愚蠢的事情。