text: var registerComponent = require('../core/component').registerComponent;
  var THREE = require('../lib/three');
  var utils = require('../utils/');
  var warn = utils.debug('components:gltf-model:warn');
  
  /**
   * glTF model loader.
   */
  module.exports.Component = registerComponent('gltf-model', {
    schema: {type: 'model'},
  
    init: function () {
      var dracoLoader = this.system.getDRACOLoader();
      this.model = null;
      this.loader = new THREE.GLTFLoader();
      if (dracoLoader) {
        this.loader.setDRACOLoader(dracoLoader);
      }
    },
  
    update: function () {
      var self = this;
      var el = this.el;
      var src = this.data;
  
      if (!src) { return; }
  
      this.remove();
  
      this.loader.load(src, function gltfLoaded (gltfModel) {
        self.model = gltfModel.scene || gltfModel.scenes[0];
        self.model.animations = gltfModel.animations;
        el.setObject3D('mesh', self.model);
        el.emit('model-loaded', {format: 'gltf', model: self.model});
      }, undefined /* onProgress */, function gltfFailed (error) {
        var message = (error && error.message) ? error.message : 'Failed to load glTF model';
        warn(message);
        el.emit('model-error', {format: 'gltf', src: src});
      });
    },
  
    remove: function () {
      if (!this.model) { return; }
      this.el.removeObject3D('mesh');
    }
  });
  