Newer
Older
reroad-test / 2020-ryusei / aframe-master / src / lib / rStatsAframe.js
@ryusei ryusei on 22 Oct 2020 1 KB パノラマ表示
window.aframeStats = function (scene) {
  var _rS = null;
  var _scene = scene;
  var _values = {
    te: {
      caption: 'Entities'
    },
    lt: {
      caption: 'Load Time'
    }
  };
  var _groups = [ {
    caption: 'A-Frame',
    values: [ 'te', 'lt' ]
  } ];

  function _update () {
    _rS('te').set(getEntityCount());
    if (window.performance.getEntriesByName) {
      _rS('lt').set(window.performance.getEntriesByName('render-started')[0].startTime.toFixed(0));
    }
  }

  function getEntityCount () {
    var elements = _scene.querySelectorAll('*');
    Array.prototype.slice.call(elements).filter(function (el) {
      return el.isEntity;
    });
    return elements.length;
  }

  function _start () {}

  function _end () {}

  function _attach (r) {
    _rS = r;
  }

  return {
    update: _update,
    start: _start,
    end: _end,
    attach: _attach,
    values: _values,
    groups: _groups,
    fractions: []
  };
};

if (typeof module === 'object') {
  module.exports = {
    aframeStats: window.aframeStats
  };
}