Aframe Entity is seen

£可爱£侵袭症+ 提交于 2020-01-13 20:37:31

问题


I wanted to know how to have a Aframe Component for any entity that define if the entity is seen by the camera, like a bool attribute.

"isSeen"= true || false

I tried with trigonometry (knowing the rotation of the camera, and the Entities' positions), but I failed.


回答1:


How about frustums: checking out if a point(x, y ,z) is within the camera's field of view .

The code is quite simple. To use it within a-frame, You could create a component, which will check if the point is seen on each render loop:

AFRAME.registerComponent('foo', {
  tick: function() {
   if (this.el.sceneEl.camera) {
      var cam = this.el.sceneEl.camera
      var frustum = new THREE.Frustum();
      frustum.setFromMatrix(new THREE.Matrix4().multiplyMatrices(cam.projectionMatrix, 
      cam.matrixWorldInverse));  

      // Your 3d point to check
      var pos = new THREE.Vector3(x, y, z);
      if (frustum.containsPoint(pos)) {
        // Do something with the position...
      }
   }
  }
}

Check it out in my fiddle



来源:https://stackoverflow.com/questions/49902680/aframe-entity-is-seen

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