<commit_before>var THREE = require('three');

var OrbitControls = require('./OrbitControls');
var Scene = require('./Scene');
var EventGenerator = require('../events/EventGenerator');
var ThreeJSViewEventGenerator = require('../events/ThreeJSViewEventGenerator');

function ThreeJSScene($container, options) {
  Scene.call(this, $container);
  this.eventGenerator = new EventGenerator($container);
  this.viewEventGenerator = new ThreeJSViewEventGenerator(this);
  this.views = [];
  this.init($container, options);
}

ThreeJSScene.prototype = Object.create(Scene.prototype);

ThreeJSScene.prototype.init = function($container, options) {
  options = (options === undefined) ? {} : options;
  if (options.cameraPosition === undefined) {
    options.cameraPosition = {
      x: 0.2,
      y: -2,
      z: 1.5,
    };
  }

  var width = $container.width();
  var height = $container.height();

  // camera
  var camera = new THREE.PerspectiveCamera(60, width / height, 0.1, 1000);
  camera.up.set(0, 0, 1);
  camera.position.x = options.cameraPosition.x;
  camera.position.y = options.cameraPosition.y;
  camera.position.z = options.cameraPosition.z;
  this.camera = camera;

  // scene
  var scene = new THREE.Scene();

  // lights
  var directionalLight = new THREE.DirectionalLight(0xffffff);
  directionalLight.position.set(-1, -1, -1);
  scene.add(directionalLight);
  scene.add(new THREE.AmbientLight(0x222222));

  // renderer
  var renderer = new THREE.WebGLRenderer({antialias: true});
  renderer.setClearColor(0xffffff, 1);
  renderer.setSize(width, height);
  $container[0].appendChild(renderer.domElement);

  // controls
  var controls = new OrbitControls(camera, renderer.domElement);
  controls.damping = 0.2;
  if (options.disableRotate) {
    controls.noRotate = true;
  }
  this.controls = controls;

  // debug
  // scene.add(new THREE.Mesh(
  //   new THREE.BoxGeometry(1,1,1),
  //   new THREE.MeshLambertMaterial({color: 0x0000ff, transparent: true, opacity: 0.5})));

  function animate() {
    requestAnimationFrame(animate);
    controls.update();
    render();
  }

  var redraw = true;

  function render() {
    if (redraw) {
      directionalLight.position.copy(camera.position);
      renderer.render(scene, camera);
      redraw = false;
    }
  }

  function resize() {
    var width = $container.width();
    var height = $container.height();
    camera.aspect = width / height;
    camera.updateProjectionMatrix();
    renderer.setSize(width, height);
    render();
  }

  this.add = function(view) {
    this.views.push(view);
    scene.add(view.sceneObject);
    render();
  };

  this.remove = function(view) {
    this.views.push(view);
    var index = this.views.indexOf(view);
    if (index === -1) {
      throw new Error('veiw not found');
    }
    this.views.splice(index, 1);
    scene.remove(view.sceneObject);
    render();
  };

  window.addEventListener('resize', resize, false);
  controls.addEventListener('change', function() {
    redraw = true;
  });

  this.redraw = function() {
    redraw = true;
  };

  animate();

  // Resize on the next event loop tick since a scroll bar may have been added
  // in the meantime.
  setTimeout(resize, 0);
};
<commit_msg>Fix bug with scene object add/remove <commit_after>var THREE = require('three');

var OrbitControls = require('./OrbitControls');
var Scene = require('./Scene');
var EventGenerator = require('../events/EventGenerator');
var ThreeJSViewEventGenerator = require('../events/ThreeJSViewEventGenerator');

function ThreeJSScene($container, options) {
  Scene.call(this, $container);
  this.eventGenerator = new EventGenerator($container);
  this.viewEventGenerator = new ThreeJSViewEventGenerator(this);
  this.views = [];
  this.init($container, options);
}

ThreeJSScene.prototype = Object.create(Scene.prototype);

ThreeJSScene.prototype.init = function($container, options) {
  options = (options === undefined) ? {} : options;
  if (options.cameraPosition === undefined) {
    options.cameraPosition = {
      x: 0.2,
      y: -2,
      z: 1.5,
    };
  }

  var width = $container.width();
  var height = $container.height();

  // camera
  var camera = new THREE.PerspectiveCamera(60, width / height, 0.1, 1000);
  camera.up.set(0, 0, 1);
  camera.position.x = options.cameraPosition.x;
  camera.position.y = options.cameraPosition.y;
  camera.position.z = options.cameraPosition.z;
  this.camera = camera;

  // scene
  var scene = new THREE.Scene();

  // lights
  var directionalLight = new THREE.DirectionalLight(0xffffff);
  directionalLight.position.set(-1, -1, -1);
  scene.add(directionalLight);
  scene.add(new THREE.AmbientLight(0x222222));

  // renderer
  var renderer = new THREE.WebGLRenderer({antialias: true});
  renderer.setClearColor(0xffffff, 1);
  renderer.setSize(width, height);
  $container[0].appendChild(renderer.domElement);

  // controls
  var controls = new OrbitControls(camera, renderer.domElement);
  controls.damping = 0.2;
  if (options.disableRotate) {
    controls.noRotate = true;
  }
  this.controls = controls;

  // debug
  // scene.add(new THREE.Mesh(
  //   new THREE.BoxGeometry(1,1,1),
  //   new THREE.MeshLambertMaterial({color: 0x0000ff, transparent: true, opacity: 0.5})));

  function animate() {
    requestAnimationFrame(animate);
    controls.update();
    render();
  }

  var redraw = true;

  function render() {
    if (redraw) {
      directionalLight.position.copy(camera.position);
      renderer.render(scene, camera);
      redraw = false;
    }
  }

  function resize() {
    var width = $container.width();
    var height = $container.height();
    camera.aspect = width / height;
    camera.updateProjectionMatrix();
    renderer.setSize(width, height);
    redraw = true;
  }

  this.add = function(view) {
    this.views.push(view);
    scene.add(view.sceneObject);
    redraw = true;
  };

  this.remove = function(view) {
    this.views.push(view);
    var index = this.views.indexOf(view);
    if (index === -1) {
      throw new Error('veiw not found');
    }
    this.views.splice(index, 1);
    scene.remove(view.sceneObject);
    render();
  };

  window.addEventListener('resize', resize, false);
  controls.addEventListener('change', function() {
    redraw = true;
  });

  this.redraw = function() {
    redraw = true;
  };

  animate();

  // Resize on the next event loop tick since a scroll bar may have been added
  // in the meantime.
  setTimeout(resize, 0);
};

{'fraction_non_alphanumeric': 0.14690402476780184, 'fraction_numerical': 0.01393188854489164, 'mean_word_length': 3.4930458970792766, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5971670', 'n_tokens_mistral': 2142, 'n_tokens_neox': 2025, 'n_words': 436}