<commit_before>import * as THREE from 'three';
import UberObject from './UberObject';

const Mesh = UberObject(THREE.Mesh);

class ZClippedMesh extends Mesh {
  constructor(geometry, material) {
    super(geometry, material);
    this.castShadow = true;
    this.receiveShadow = true;
  }

  _onBeforeRender(renderer, scene, camera) {
    const _mvLength = new THREE.Vector3();
    const _center = new THREE.Vector3();
    const _modelView = new THREE.Matrix4();

    return function () {
      Mesh.prototype._onBeforeRender.call(this, renderer, scene, camera);

      const geo = this.geometry;
      const { material } = this;
      if (!geo.zClip || !material.uberOptions) {
        return;
      }

      const zClipCoef = 0.5;

      const modelView = _modelView.multiplyMatrices(this.matrixWorld, camera.matrixWorldInverse);
      const s = _mvLength.setFromMatrixColumn(modelView, 0).length();
      const center = _center.copy(geo.boundingSphere.center);

      this.localToWorld(center);
      material.uberOptions.zClipValue = camera.position.z - center.z
        - s * (zClipCoef * geo.boundingSphere.radius);
    };
  }
}

export default ZClippedMesh;
<commit_msg>Correct removing repeated creation of 'new' by using static variables in ZClippedMesh<commit_after>import * as THREE from 'three';
import UberObject from './UberObject';

const Mesh = UberObject(THREE.Mesh);

class ZClippedMesh extends Mesh {
  constructor(geometry, material) {
    super(geometry, material);
    this.castShadow = true;
    this.receiveShadow = true;
  }

  static _mvLength = new THREE.Vector3();

  static _center = new THREE.Vector3();

  static _modelView = new THREE.Matrix4();

  _onBeforeRender(renderer, scene, camera) {
    Mesh.prototype._onBeforeRender.call(this, renderer, scene, camera);

    const geo = this.geometry;
    const { material } = this;
    if (!geo.zClip || !material.uberOptions) {
      return;
    }

    const zClipCoef = 0.5;

    let modelView = ZClippedMesh._modelView;
    const mvLength = ZClippedMesh._mvLength;
    let center = ZClippedMesh._center;

    modelView = modelView.multiplyMatrices(this.matrixWorld, camera.matrixWorldInverse);
    const s = mvLength.setFromMatrixColumn(modelView, 0).length();
    center = center.copy(geo.boundingSphere.center);

    this.localToWorld(center);
    material.uberOptions.zClipValue = camera.position.z - center.z
      - s * (zClipCoef * geo.boundingSphere.radius);
  }
}

export default ZClippedMesh;

{'fraction_non_alphanumeric': 0.11039484286865431, 'fraction_numerical': 0.004834810636583401, 'mean_word_length': 3.5559633027522937, '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': '100696', 'n_tokens_mistral': 797, 'n_tokens_neox': 758, 'n_words': 174}