框架实体可见
Aframe Entity is seen
我想知道如何为任何实体设置一个 Aframe 组件来定义实体是否被相机看到,例如 bool 属性。
"isSeen"= true || false
我尝试了三角函数(知道相机的旋转和实体的位置),但我失败了。
如何 frustums:检查点 (x, y ,z) 是否在相机的视野内。
代码相当simple。要在帧内使用它,您可以创建一个组件,它将检查是否在每个渲染循环中看到该点:
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...
}
}
}
}
在我的 fiddle
中查看
我想知道如何为任何实体设置一个 Aframe 组件来定义实体是否被相机看到,例如 bool 属性。
"isSeen"= true || false
我尝试了三角函数(知道相机的旋转和实体的位置),但我失败了。
如何 frustums:检查点 (x, y ,z) 是否在相机的视野内。
代码相当simple。要在帧内使用它,您可以创建一个组件,它将检查是否在每个渲染循环中看到该点:
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...
}
}
}
}
在我的 fiddle
中查看