src/systems/camera.js
function () {
    var cameraEls;
    var i;
    var sceneEl = this.sceneEl;
    var self = this;

    // Camera already defined or the one defined it is an spectator one.
    if (sceneEl.camera && !sceneEl.camera.el.getAttribute('camera').spectator) {
      sceneEl.emit('cameraready', {cameraEl: sceneEl.camera.el});
      return;
    }

    // Search for initial user-defined camera.
    cameraEls = sceneEl.querySelectorAll('a-camera, [camera]');

    // No user cameras, create default one.
    if (!cameraEls.length) {
      this.createDefaultCamera();
      return;
    }

    this.numUserCameras = cameraEls.length;
    for (i = 0; i < cameraEls.length; i++) {
      cameraEls[i].addEventListener('object3dset', function (evt) {
        if (evt.detail.type !== 'camera') { return; }
        self.checkUserCamera(this);
      });

      // Load camera and wait for camera to initialize.
      if (cameraEls[i].isNode) {
        cameraEls[i].load();
      } else {
        cameraEls[i].addEventListener('nodeready', function () {
          this.load();
        });
      }
    }
  }
function () {
    var cameraEls;
    var i;
    var sceneEl = this.sceneEl;
    var self = this;

    // Camera already defined or the one defined it is an spectator one.
    if (sceneEl.camera && !sceneEl.camera.el.getAttribute('camera').spectator) {
      sceneEl.emit('cameraready', {cameraEl: sceneEl.camera.el});
      return;
    }

    // Search for initial user-defined camera.
    cameraEls = sceneEl.querySelectorAll('a-camera, [camera]');

    // No user cameras, create default one.
    if (!cameraEls.length) {
      this.createDefaultCamera();
      return;
    }

    this.numUserCameras = cameraEls.length;
    for (i = 0; i < cameraEls.length; i++) {
      cameraEls[i].addEventListener('object3dset', function (evt) {
        if (evt.detail.type !== 'camera') { return; }
        self.checkUserCamera(this);
      });

      // Load camera and wait for camera to initialize.
      if (cameraEls[i].isNode) {
        cameraEls[i].load();
      } else {
        cameraEls[i].addEventListener('nodeready', function () {
          this.load();
        });
      }
    }
  }
function ( ) { var cameraEls ; var i ; var sceneEl = this . sceneEl ; var self = this ; // Camera already defined or the one defined it is an spectator one. if ( sceneEl . camera && ! sceneEl . camera . el . getAttribute ( 'camera' ) . spectator ) { sceneEl . emit ( 'cameraready' , { cameraEl : sceneEl . camera . el } ) ; return ; } // Search for initial user-defined camera. cameraEls = sceneEl . querySelectorAll ( 'a-camera, [camera]' ) ; // No user cameras, create default one. if ( ! cameraEls . length ) { this . createDefaultCamera ( ) ; return ; } this . numUserCameras = cameraEls . length ; for ( i = 0 ; i < cameraEls . length ; i ++ ) { cameraEls [ i ] . addEventListener ( 'object3dset' , function ( evt ) { if ( evt . detail . type !== 'camera' ) { return ; } self . checkUserCamera ( this ) ; } ) ; // Load camera and wait for camera to initialize. if ( cameraEls [ i ] . isNode ) { cameraEls [ i ] . load ( ) ; } else { cameraEls [ i ] . addEventListener ( 'nodeready' , function ( ) { this . load ( ) ; } ) ; } } }
Setup initial camera, either searching for camera or
creating a default camera if user has not added one during the initial scene traversal.
We want sceneEl.camera to be ready, set, and initialized before the rest of the scene
loads.

Default camera offset height is at average eye level (~1.6m).
Setup initial camera either searching for camera or creating a default camera if user has not added one during the initial scene traversal . We want sceneEl . camera to be ready set and initialized before the rest of the scene loads .