<commit_before>'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _Three = require('./Three');

var _Three2 = _interopRequireDefault(_Three);

var _reactDom = require('react-dom');

var _reactDom2 = _interopRequireDefault(_reactDom);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var OrbitControls = require('three-orbit-controls')(_Three2.default);

var DIRECTIONAL_LIGHT = 'directionalLight';

var Paint = function () {
  function Paint() {
    _classCallCheck(this, Paint);

    this.loader = new _Three2.default.STLLoader();
    this.scene = new _Three2.default.Scene();
    this.renderer = new _Three2.default.WebGLRenderer({
      antialias: true
    });
    this.reqNumber = 0;
  }

  _createClass(Paint, [{
    key: 'init',
    value: function init(context) {
      this.component = context;
      this.url = context.props.url;
      this.width = context.props.width;
      this.height = context.props.height;
      this.modelColor = context.props.modelColor;
      this.backgroundColor = context.props.backgroundColor;
      this.orbitControls = context.props.orbitControls;
      this.rotate = context.props.rotate;
      this.cameraX = context.props.cameraX;
      this.cameraY = context.props.cameraY;
      this.cameraZ = context.props.cameraZ;
      this.rotationSpeeds = context.props.rotationSpeeds;
      this.lights = context.props.lights;
      this.lightColor = context.props.lightColor;

      if (this.mesh !== undefined) {
        this.scene.remove(this.mesh);
        this.mesh.geometry.dispose();
        this.mesh.material.dispose();
      }
      var directionalLightObj = this.scene.getObjectByName(DIRECTIONAL_LIGHT);
      if (directionalLightObj) {
        this.scene.remove(directionalLightObj);
      }

      if (this.animationRequestId) {
        cancelAnimationFrame(this.animationRequestId);
      }

      //Detector.addGetWebGLMessage();
      this.distance = 10000;

      // lights processing
      var hasMultipleLights = this.lights.reduce(function (acc, item) {
        return acc && Array.isArray(item);
      }, true);
      if (hasMultipleLights) {
        this.lights.forEach(this.addLight.bind(this));
      } else {
        this.addLight(this.lights);
      }

      this.reqNumber += 1;
      this.addSTLToScene(this.reqNumber);
    }
  }, {
    key: 'addLight',
    value: function addLight(lights) {
      var _directionalLight$pos;

      var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;

      var directionalLight = new _Three2.default.DirectionalLight(this.lightColor);
      (_directionalLight$pos = directionalLight.position).set.apply(_directionalLight$pos, _toConsumableArray(lights));
      directionalLight.name = DIRECTIONAL_LIGHT + index;
      directionalLight.position.normalize();
      this.scene.add(directionalLight);
    }
  }, {
    key: 'addSTLToScene',
    value: function addSTLToScene(reqId) {
      var _this = this;

      this.loader.crossOrigin = '';
      this.loader.load(this.url, function (geometry) {
        if (_this.reqNumber !== reqId) {
          return;
        }
        // Calculate mesh noramls for MeshLambertMaterial.
        geometry.computeFaceNormals();
        geometry.computeVertexNormals();

        // Center the object
        geometry.center();

        _this.mesh = new _Three2.default.Mesh(geometry, new _Three2.default.MeshLambertMaterial({
          overdraw: true,
          color: _this.modelColor
        }));
        // Set the object's dimensions
        geometry.computeBoundingBox();
        _this.xDims = geometry.boundingBox.max.x - geometry.boundingBox.min.x;
        _this.yDims = geometry.boundingBox.max.y - geometry.boundingBox.min.y;
        _this.zDims = geometry.boundingBox.max.z - geometry.boundingBox.min.z;

        if (_this.rotate) {
          _this.mesh.rotation.x = _this.rotationSpeeds[0];
          _this.mesh.rotation.y = _this.rotationSpeeds[1];
          _this.mesh.rotation.z = _this.rotationSpeeds[2];
        }

        _this.scene.add(_this.mesh);

        _this.addCamera();
        _this.addInteractionControls();
        _this.addToReactComponent();

        // Start the animation
        _this.animate();
      });
    }
  }, {<commit_msg>colored tests - enable showing binary colors of STL file<commit_after>'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _Three = require('./Three');

var _Three2 = _interopRequireDefault(_Three);

var _reactDom = require('react-dom');

var _reactDom2 = _interopRequireDefault(_reactDom);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var OrbitControls = require('three-orbit-controls')(_Three2.default);

var DIRECTIONAL_LIGHT = 'directionalLight';

var Paint = function () {
  function Paint() {
    _classCallCheck(this, Paint);

    this.loader = new _Three2.default.STLLoader();
    this.scene = new _Three2.default.Scene();
    this.renderer = new _Three2.default.WebGLRenderer({
      antialias: true
    });
    this.reqNumber = 0;
  }

  _createClass(Paint, [{
    key: 'init',
    value: function init(context) {
      this.component = context;
      this.url = context.props.url;
      this.width = context.props.width;
      this.height = context.props.height;
      this.modelColor = context.props.modelColor;
      this.backgroundColor = context.props.backgroundColor;
      this.orbitControls = context.props.orbitControls;
      this.rotate = context.props.rotate;
      this.cameraX = context.props.cameraX;
      this.cameraY = context.props.cameraY;
      this.cameraZ = context.props.cameraZ;
      this.rotationSpeeds = context.props.rotationSpeeds;
      this.lights = context.props.lights;
      this.lightColor = context.props.lightColor;

      if (this.mesh !== undefined) {
        this.scene.remove(this.mesh);
        this.mesh.geometry.dispose();
        this.mesh.material.dispose();
      }
      var directionalLightObj = this.scene.getObjectByName(DIRECTIONAL_LIGHT);
      if (directionalLightObj) {
        this.scene.remove(directionalLightObj);
      }

      if (this.animationRequestId) {
        cancelAnimationFrame(this.animationRequestId);
      }

      //Detector.addGetWebGLMessage();
      this.distance = 10000;

      // lights processing
      var hasMultipleLights = this.lights.reduce(function (acc, item) {
        return acc && Array.isArray(item);
      }, true);
      if (hasMultipleLights) {
        this.lights.forEach(this.addLight.bind(this));
      } else {
        this.addLight(this.lights);
      }

      this.reqNumber += 1;
      this.addSTLToScene(this.reqNumber);
    }
  }, {
    key: 'addLight',
    value: function addLight(lights) {
      var _directionalLight$pos;

      var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;

      var directionalLight = new _Three2.default.DirectionalLight(this.lightColor);
      (_directionalLight$pos = directionalLight.position).set.apply(_directionalLight$pos, _toConsumableArray(lights));
      directionalLight.name = DIRECTIONAL_LIGHT + index;
      directionalLight.position.normalize();
      this.scene.add(directionalLight);
    }
  }, {
    key: 'addSTLToScene',
    value: function addSTLToScene(reqId) {
      var _this = this;
      var material;

      this.loader.crossOrigin = '';
      this.loader.load(this.url, function (geometry) {
        if (_this.reqNumber !== reqId) {
          return;
        }
        // Calculate mesh noramls for MeshLambertMaterial.
        geometry.computeFaceNormals();
        geometry.computeVertexNormals();

        // Center the object
        geometry.center();

        if (geometry.hasColors) {
          material = new _Three2.default.MeshPhongMaterial({
            opacity: geometry.alpha,
            vertexColors: _Three2.default.VertexColors
          });
        } else {
          material = new _Three2.default.MeshLambertMaterial({
            overdraw: true,
            color: _this.modelColor
          });
        }

        _this.mesh = new _Three2.default.Mesh(geometry, material);
        // Set the object's dimensions
        geometry.computeBoundingBox();
        _this.xDims = geometry.boundingBox.max.x - geometry.boundingBox.min.x;
        _this.yDims = geometry.boundingBox.max.y - geometry.boundingBox.min.y;
        _this.zDims = geometry.boundingBox.max.z - geometry.boundingBox.min.z;

        if (_this.rotate) {
          _this.mesh.rotation.x = _this.rotationSpeeds[0];
          _this.mesh.rotation.y = _this.rotationSpeeds[1];
          _this.mesh.rotation.z = _this.rotationSpeeds[2];
        }

        _this.scene.add(_this.mesh);

        _this.addCamera();
        _this.addInteractionControls();
        _this.addToReactComponent();

        // Start the animation
        _this.animate();
      });
    }
  }, {
{'fraction_non_alphanumeric': 0.12417694519150514, 'fraction_numerical': 0.00537883705833256, 'mean_word_length': 3.0104127928597992, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4065463', 'n_tokens_mistral': 3237, 'n_tokens_neox': 3173, 'n_words': 616}