<commit_before>/**
* @license
* Copyright © 2016 <NAME>, <NAME>.
* This file is part of rti.js.
* rti.js is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* rti.js is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with rti.js. If not, see <http://www.gnu.org/licenses/>.
*/

/**
 * @constant {bool} RTI_LOG - print log messages made with RTILog() to console
 * @default false
*/
/**
 * @constant {bool} RTI_ERROR_LOG - print error messages made with RTIError() to
 *  console
 * @default true
*/
/**
 * @constant {bool} RTI_ERROR_ALERT - alert the user on error messages made with
 *  RTIError()
 * @default true
*/
/**
 * @constant {bool} RTI_LIGHTCONTROL_IN_VIEWCONTAINER - enable toggling between
 *  dragging and light direction control in view container
 * @default true
*/
/**
 * @constant {bool} RTI_SHOW_BSPHERES - render bounding spheres of individual
 *  tiles for debugging
 * @default false
*/

RTI_LOG = false;
RTI_ERROR_LOG = true;
RTI_ERROR_ALERT = true;

/**
 * Allows the rendering of PTMs in WebPTM format in a web browser.
 *
 * @class
 * @param {PTMReference} ptmReference - A PTMReference linking to the WebPTM
 *  which should be rendered on startup.
 * @param {div} container - The div element where the viewer's WebGL canvas
 *  should be placed.
 *
 * @property {PTM} ptm - the currently displayed ptm
*/
function RTIViewer(ptmReference, container) {
  this.ptm = null;

  this._lightDir = null;
  this._directionalLightColor = null;
  this._directionalLight = null;
  this._ambientLightColor = null;
  this._ambientLight = null;

  this.H = null;

  this._container = null;
  this._scene = null;
  this._camera = null;
  this._renderer = null;
  this._sceneMesh = null;
  this._raycaster = null;
  this._internalController = null;
  this._externalController = null;

  this._rendering = false;

  this._init(ptmReference, container);
  return this;
} // RTIViewer

RTIViewer.prototype = {
  _init: function(ptmReference, container) {
    if (typeof(ptmReference) === 'string') {
      ptmReference = JSON.parse(ptmReference);
    }

    this._container = container;
    var width = container.clientWidth;
    var height = container.clientHeight;

    var fov = 45;
    var aspect = width / height;
    var near = 0.1;
    var far = 1000;

    this._raycaster = new THREE.Raycaster();

    this._scene = new THREE.Scene();
    this._camera = new THREE.PerspectiveCamera( fov, aspect, near, far );

    this._scene.add(this._camera);
    this._camera.position.set(0,0,5);
    this._camera.lookAt(this._scene.position);

    this._renderer =  new THREE.WebGLRenderer();
    this._renderer.setSize( width, height );
    container.appendChild( this._renderer.domElement );

    this._H = new THREE.Vector3();

    this._lightDir = new THREE.Vector3(0.0, 0.0, 1.0);
    this._directionalLightColor = new THREE.Vector3( 1.5, 1.5, 1.5 );
    this._directionalLight = new THREE.DirectionalLight( 0xffffff, 1.0 );
    this.setDirectionalLightDirection(this._lightDir);
    this.setDirectionalLightColor(this._directionalLightColor);
    this._scene.add( this._directionalLight );

    this._ambientLightColor = new THREE.Vector3(0.0, 0.0, 0.0);
    this._ambientLight = new THREE.AmbientLight(0xffffff);
    this.setAmbientLightColor(this._ambientLightColor);
    this._scene.add(this._ambientLight);

    this.ptm = new PTM(ptmReference);

    this._scene.add(this.ptm.renderObject);
    this._initSceneMesh(ptmReference);
    this._initialSettings = this.getSettings();
    this._requestTextures();
    this._internalController = new RTIViewerController(this);
    this._rendering = false;
  },

/**
 * Loads a new WebPTM.
 *
 * @param {PTMReference} ptmReference - A PTMReference linking to the WebPTM
 *  which should be loaded.
 */
  loadPTM: function(ptmReference) {
    var newPTM = new PTM(ptmReference);
    if (!newPTM.initialized) {
      newPTM.dispose();
      return false;
    }

    if (this.ptm) {
      this._scene.remove(this.ptm.renderObject);
      this.ptm.dispose();
    }

    if (this._sceneMesh) {
      this._scene.remove(this._sceneMesh);
      this._sceneMesh.material.dispose();
      this._sceneMesh.geometry.dispose();
      this._sceneMesh = null;
    }

    this.ptm = newPTM;
    this._scene.add(this.ptm.renderObject);
    this._initSceneMesh(ptmReference);

    this.setDirectionalLightDirection(new THREE.Vector3(0.0, 0.0, 0.1));
    this.setDirectionalLightColor(new THREE.Vector3(  1.5, 1.5, 1.5 ));
    this.setAmbientLightColor(new THREE.Vector3(0.0, 0.0, 0.0));

    this._initialSettings = this.getSettings();

    this.resetCamera();
    return true;
  },

/**
 * Loads a different shader.
 *
 * @param {ShaderReference} shaderReference - A ShaderReference linking to the<commit_msg>[FIX] fix lDir reset on loadPTM<commit_after>/**
* @license
* Copyright © 2016 <NAME>, <NAME>.
* This file is part of rti.js.
* rti.js is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* rti.js is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with rti.js. If not, see <http://www.gnu.org/licenses/>.
*/

/**
 * @constant {bool} RTI_LOG - print log messages made with RTILog() to console
 * @default false
*/
/**
 * @constant {bool} RTI_ERROR_LOG - print error messages made with RTIError() to
 *  console
 * @default true
*/
/**
 * @constant {bool} RTI_ERROR_ALERT - alert the user on error messages made with
 *  RTIError()
 * @default true
*/
/**
 * @constant {bool} RTI_LIGHTCONTROL_IN_VIEWCONTAINER - enable toggling between
 *  dragging and light direction control in view container
 * @default true
*/
/**
 * @constant {bool} RTI_SHOW_BSPHERES - render bounding spheres of individual
 *  tiles for debugging
 * @default false
*/

RTI_LOG = false;
RTI_ERROR_LOG = true;
RTI_ERROR_ALERT = true;

/**
 * Allows the rendering of PTMs in WebPTM format in a web browser.
 *
 * @class
 * @param {PTMReference} ptmReference - A PTMReference linking to the WebPTM
 *  which should be rendered on startup.
 * @param {div} container - The div element where the viewer's WebGL canvas
 *  should be placed.
 *
 * @property {PTM} ptm - the currently displayed ptm
*/
function RTIViewer(ptmReference, container) {
  this.ptm = null;

  this._lightDir = null;
  this._directionalLightColor = null;
  this._directionalLight = null;
  this._ambientLightColor = null;
  this._ambientLight = null;

  this.H = null;

  this._container = null;
  this._scene = null;
  this._camera = null;
  this._renderer = null;
  this._sceneMesh = null;
  this._raycaster = null;
  this._internalController = null;
  this._externalController = null;

  this._rendering = false;

  this._init(ptmReference, container);
  return this;
} // RTIViewer

RTIViewer.prototype = {
  _init: function(ptmReference, container) {
    if (typeof(ptmReference) === 'string') {
      ptmReference = JSON.parse(ptmReference);
    }

    this._container = container;
    var width = container.clientWidth;
    var height = container.clientHeight;

    var fov = 45;
    var aspect = width / height;
    var near = 0.1;
    var far = 1000;

    this._raycaster = new THREE.Raycaster();

    this._scene = new THREE.Scene();
    this._camera = new THREE.PerspectiveCamera( fov, aspect, near, far );

    this._scene.add(this._camera);
    this._camera.position.set(0,0,5);
    this._camera.lookAt(this._scene.position);

    this._renderer =  new THREE.WebGLRenderer();
    this._renderer.setSize( width, height );
    container.appendChild( this._renderer.domElement );

    this._H = new THREE.Vector3();

    this._lightDir = new THREE.Vector3(0.0, 0.0, 1.0);
    this._directionalLightColor = new THREE.Vector3( 1.5, 1.5, 1.5 );
    this._directionalLight = new THREE.DirectionalLight( 0xffffff, 1.0 );
    this.setDirectionalLightDirection(this._lightDir);
    this.setDirectionalLightColor(this._directionalLightColor);
    this._scene.add( this._directionalLight );

    this._ambientLightColor = new THREE.Vector3(0.0, 0.0, 0.0);
    this._ambientLight = new THREE.AmbientLight(0xffffff);
    this.setAmbientLightColor(this._ambientLightColor);
    this._scene.add(this._ambientLight);

    this.ptm = new PTM(ptmReference);

    this._scene.add(this.ptm.renderObject);
    this._initSceneMesh(ptmReference);
    this._initialSettings = this.getSettings();
    this._requestTextures();
    this._internalController = new RTIViewerController(this);
    this._rendering = false;
  },

/**
 * Loads a new WebPTM.
 *
 * @param {PTMReference} ptmReference - A PTMReference linking to the WebPTM
 *  which should be loaded.
 */
  loadPTM: function(ptmReference) {
    var newPTM = new PTM(ptmReference);
    if (!newPTM.initialized) {
      newPTM.dispose();
      return false;
    }

    if (this.ptm) {
      this._scene.remove(this.ptm.renderObject);
      this.ptm.dispose();
    }

    if (this._sceneMesh) {
      this._scene.remove(this._sceneMesh);
      this._sceneMesh.material.dispose();
      this._sceneMesh.geometry.dispose();
      this._sceneMesh = null;
    }

    this.ptm = newPTM;
    this._scene.add(this.ptm.renderObject);
    this._initSceneMesh(ptmReference);

    this.setDirectionalLightDirection(new THREE.Vector3(0.0, 0.0, 1.0));
    this.setDirectionalLightColor(new THREE.Vector3(  1.5, 1.5, 1.5 ));
    this.setAmbientLightColor(new THREE.Vector3(0.0, 0.0, 0.0));

    this._initialSettings = this.getSettings();

    this.resetCamera();
    return true;
  },

/**
 * Loads a different shader.
 *
 * @param {ShaderReference} shaderReference - A ShaderReference linking to the
{'fraction_non_alphanumeric': 0.11441735457861393, 'fraction_numerical': 0.0120944519101555, 'mean_word_length': 3.514298093587522, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7214075', 'n_tokens_mistral': 3447, 'n_tokens_neox': 3299, 'n_words': 902}