Skip to content

Instantly share code, notes, and snippets.

@addy1997
Created June 7, 2023 10:00
Show Gist options
  • Save addy1997/20af696fb65799f22d75b6ff5fa7111c to your computer and use it in GitHub Desktop.
Save addy1997/20af696fb65799f22d75b6ff5fa7111c to your computer and use it in GitHub Desktop.
AFRAME.registerComponent('camera-logger', {
schema: {
timestamp: {
type: 'int'
},
seconds: {
type: 'int'
}
},
init: function() {
var cameraEl = this.el.sceneEl.camera.el;
var rotation = cameraEl.getAttribute('rotation');
var worldPos = new THREE.Vector3();
worldPos.setFromMatrixPosition(cameraEl.object3D.matrixWorld);
console.log("Time: " + this.data.seconds +
"; Camera Position: (" + worldPos.x.toFixed(2) + ", " + worldPos.y.toFixed(2) + ", " + worldPos.z.toFixed(2) +
"); Camera Rotation: (" + rotation.x.toFixed(2) + ", " + rotation.y.toFixed(2) + ", " + rotation.z.toFixed(2) + ")");
},
play: function() {
this.data.timestamp = Date.now();
this.init();
},
tick: function() {
if (Date.now() - this.data.timestamp > 1000) {
this.data.timestamp += 1000;
this.data.seconds += 1;
this.init();
}
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment