看到了Aframe实体 [英] Aframe Entity is seen

查看:99
本文介绍了看到了Aframe实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何为定义实体是否可以被相机看到的任何实体使用Aframe组件,例如bool属性。

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.

推荐答案

视锥体:检查点(x,y,z)是否在相机的视野内。

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...
      }
   }
  }
}

在我的小提琴中查看

这篇关于看到了Aframe实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆