To get the camera position:
var pos = document.querySelector('#camera').getAttribute('position');
To get the world position of the camera, we can transform the local position of the camera:
var cameraEl = document.querySelector('#camera'); var worldPos = new THREE.Vector3(); worldPos.setFromMatrixPosition(cameraEl.object3D.matrixWorld); console.log(worldPos.x);
To listen for changes, use the componentchanged event:
cameraEl.addEventListener('componentchanged', function (evt) { if (evt.detail.name !== 'position') { return; } console.log(evt.detail.newData); });
More polls may be polls:
AFRAME.registerComponent('camera-listener', { tick: function () { var cameraEl = this.el.sceneEl.camera.el; cameraEl.getAttribute('position'); cameraEl.getAttribute('rotation');
source share