gltf cursor-listener click event in A-frame

删除回忆录丶 提交于 2019-12-01 00:26:03

You've run into the issue described here: After a model loads, the raycaster used to detect clicks needs to be refreshed, so that it knows about the model.

We have a more robust solution on the way for A-Frame 0.8.0, but in the meantime you can work around the problem with something like this:

AFRAME.registerComponent('raycaster-autorefresh', {
  init: function () {
    var el = this.el;
    this.el.addEventListener('model-loaded', function () {
      var cursorEl = el.querySelector('[raycaster]');
      cursorEl.components.raycaster.refreshObjects();
    });
  }
});

You would then need to add the raycaster-autorefresh to your scene element. Here is a Codepen showing the solution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!