提取与 raycaster 相交的组件信息的最佳方法是什么?
What is the best way to extract component information that is intersected with raycaster?
有什么方法可以提取与 raycaster 相交的实体信息(id、class 等)?
我试图从 evt.detail.el 中查找信息,但没有成功。
AFRAME.registerComponent('collider-check', {
init: function () {
this.el.addEventListener('raycaster-intersected', function (evt) {
console.log(evt.detail.el);
});
}
});
问题在于上面的代码记录了 raycasting 实体,而不是 raycasted 实体,因此它正在记录游标。
使用上面的代码,您可以通过登录evt.detail.intersection.object.el
来访问您需要的数据。因此,您可以执行类似以下操作来分别访问 id
和 class
:
console.log(evt.detail.intersection.object.el.id);
console.log(evt.detail.intersection.object.el.className);
下面是代码的演示:https://codepen.io/dansinni/pen/bjjbWv
如果你没有绑定this
到handler,只需要基本的属性数据,你应该也可以做到以下几点,但是YMMV:
console.log(this.id);
console.log(this.className);
您还应该能够使用带有光标的组件,并依赖于 raycaster-intersection
事件。请注意文档中的差异:https://aframe.io/docs/master/components/raycaster.html#events
有什么方法可以提取与 raycaster 相交的实体信息(id、class 等)? 我试图从 evt.detail.el 中查找信息,但没有成功。
AFRAME.registerComponent('collider-check', {
init: function () {
this.el.addEventListener('raycaster-intersected', function (evt) {
console.log(evt.detail.el);
});
}
});
问题在于上面的代码记录了 raycasting 实体,而不是 raycasted 实体,因此它正在记录游标。
使用上面的代码,您可以通过登录evt.detail.intersection.object.el
来访问您需要的数据。因此,您可以执行类似以下操作来分别访问 id
和 class
:
console.log(evt.detail.intersection.object.el.id);
console.log(evt.detail.intersection.object.el.className);
下面是代码的演示:https://codepen.io/dansinni/pen/bjjbWv
如果你没有绑定this
到handler,只需要基本的属性数据,你应该也可以做到以下几点,但是YMMV:
console.log(this.id);
console.log(this.className);
您还应该能够使用带有光标的组件,并依赖于 raycaster-intersection
事件。请注意文档中的差异:https://aframe.io/docs/master/components/raycaster.html#events