<commit_before>/*
Copyright 2014 <NAME>.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
define(["./Constants"],function(Constants) {
  
  var tmpGeometry = new THREE.CubeGeometry(2,4,2);
  var tmpMaterial = new THREE.MeshLambertMaterial( { color: 0xdddddd } );
  
  var materials = {};
  materials[Constants.OWN] = new THREE.MeshLambertMaterial( { color: 0xff0000 } );
  materials[Constants.OTHER] = new THREE.MeshLambertMaterial( { color: 0x0f87ff } );
  
  var mtls = {};
  mtls[Constants.OWN] = "obj/dart.obj.mtl";
  mtls[Constants.OTHER] = "obj/dartb.obj.mtl";
    
  var loader = new THREE.OBJMTLLoader();
  var waiting = {};
  waiting[Constants.OWN] = [];
  waiting[Constants.OTHER] = [];
  var clonable = {};
  function loadClonable(type) {
    loader.load("obj/dart.obj", mtls[type], function ( object ) {
      clonable[type] = object;
      for(var i=0; i<waiting[type].length; i++) {
        waiting[type][i].convertDart();
      }
      waiting[type] = null;
    });
  }
  loadClonable(Constants.OWN);
  loadClonable(Constants.OTHER);
  
  var NICK_OFFSET = {
      x: 2,
      y: 1,
      z: 10,
  };
  
  
  //Dart is 13.598, we want it 96*scale
  var expectedSize = 96*Constants.SCALE;
  var SCALE_TO = expectedSize/13.598;
  
  var Dart = function(key,type,field,showInfo) {
    this.field = field;
    
    this.dart = null;
    this.dinamics =  new THREE.Vector3( 0, 0, 0 );
    
    this.text = null; 
    this.nick = null;
    this.showNickFlag = showInfo;
    
    this.timestamp = 0;
    
    this.serverLocked = true;
    
    this.key = key;
    this.type = type;
    
    this.initDart();
  };
  
  
  Dart.prototype = {
      /**
       * @private
       */
      initDart: function() {
        if (!clonable[this.type]) {
          //wait
          this.dart = new THREE.Mesh(tmpGeometry,tmpMaterial);
          waiting[this.type].push(this);
        } else {
          this.createDart();
        }
        
        this.dart.position.set(0,0,Constants.MAX_SIZE.z-1);
        this.dart.quaternion.set(0.707,0,0,0.707); //0.64,0,0,0.76); //0.57,0,0,0.81
        this.field.addObject(this.dart);
      },
      
      createDart: function() {
        this.dart = clonable[this.type].clone();
                
        this.dart.scale.set(SCALE_TO,SCALE_TO,SCALE_TO);
      },
      
      convertDart: function() {
        var tmp = this.dart;
        this.createDart();
        
        //text already correctly positioned
        this.dart.position = tmp.position;
        this.dart.quaternion = tmp.quaternion;
        
        this.field.removeObject(tmp);
        this.field.addObject(this.dart);
      },
      
      changeType: function(newType) {
        if (newType == this.type) {
          return;
        }
        this.type = newType;

        this.convertDart();
        
        if (this.text) {<commit_msg>fix shadow on obj-loaded darts<commit_after>/*
Copyright 2014 Weswit s.r.l.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
define(["./Constants"],function(Constants) {
  
  var tmpGeometry = new THREE.CubeGeometry(2,4,2);
  var tmpMaterial = new THREE.MeshLambertMaterial( { color: 0xdddddd } );
  
  var materials = {};
  materials[Constants.OWN] = new THREE.MeshLambertMaterial( { color: 0xff0000 } );
  materials[Constants.OTHER] = new THREE.MeshLambertMaterial( { color: 0x0f87ff } );
  
  var mtls = {};
  mtls[Constants.OWN] = "obj/dart.obj.mtl";
  mtls[Constants.OTHER] = "obj/dartb.obj.mtl";
  
  
  function setShadowOnObject(object) {
    object.castShadow = true;
    var children = object.getDescendants();
    for (var i = 0; i < children.length; i++) {
      setShadowOnObject(children[i]);
    }
  }
  
    
  var loader = new THREE.OBJMTLLoader();
  var waiting = {};
  waiting[Constants.OWN] = [];
  waiting[Constants.OTHER] = [];
  var clonable = {};
  function loadClonable(type) {
    loader.load("obj/dart.obj", mtls[type], function ( object ) {
      setShadowOnObject(object);
      clonable[type] = object;
      for(var i=0; i<waiting[type].length; i++) {
        waiting[type][i].convertDart();
      }
      waiting[type] = null;
    });
  }
  loadClonable(Constants.OWN);
  loadClonable(Constants.OTHER);
  
  var NICK_OFFSET = {
      x: 2,
      y: 1,
      z: 10,
  };
  
  
  //Dart is 13.598, we want it 96*scale
  var expectedSize = 96*Constants.SCALE;
  var SCALE_TO = expectedSize/13.598;
  
  var Dart = function(key,type,field,showInfo) {
    this.field = field;
    
    this.dart = null;
    this.dinamics =  new THREE.Vector3( 0, 0, 0 );
    
    this.text = null; 
    this.nick = null;
    this.showNickFlag = showInfo;
    
    this.timestamp = 0;
    
    this.serverLocked = true;
    
    this.key = key;
    this.type = type;
    
    this.initDart();
  };
  
  
  Dart.prototype = {
      /**
       * @private
       */
      initDart: function() {
        if (!clonable[this.type]) {
          //wait
          this.dart = new THREE.Mesh(tmpGeometry,tmpMaterial);
          this.dart.castShadow = true;
          waiting[this.type].push(this);
        } else {
          this.createDart();
        }
        
        this.dart.position.set(0,0,Constants.MAX_SIZE.z-1);
        this.dart.quaternion.set(0.707,0,0,0.707); //0.64,0,0,0.76); //0.57,0,0,0.81
        this.field.addObject(this.dart);
      },
      
      createDart: function() {
        this.dart = clonable[this.type].clone();
        this.dart.scale.set(SCALE_TO,SCALE_TO,SCALE_TO);
      },
      
      convertDart: function() {
        var tmp = this.dart;
        this.createDart();
        
        //text already correctly positioned
        this.dart.position = tmp.position;
        this.dart.quaternion = tmp.quaternion;
        
        this.field.removeObject(tmp);
        this.field.addObject(this.dart);
      },
      
      changeType: function(newType) {
        if (newType == this.type) {
          return;
        }
        this.type = newType;

        this.convertDart();
        
        if (this.text) {
{'fraction_non_alphanumeric': 0.12988866685697972, 'fraction_numerical': 0.021267485012846133, 'mean_word_length': 2.2666666666666666, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 4, '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': '5850539', 'n_tokens_mistral': 2447, 'n_tokens_neox': 2326, 'n_words': 497}