<commit_before>/*global THREE*/
(function() {
  'use strict';

  var container;

  var scene, camera, controls, renderer;
  var geometry, material, mesh;

  var skeletonHelper;

  function init() {
    container = document.createElement( 'div' );
    document.body.appendChild( container );

    renderer = new THREE.WebGLRenderer({ antialias: true });
    renderer.setPixelRatio( window.devicePixelRatio );
    renderer.setSize( window.innerWidth, window.innerHeight );
    container.appendChild( renderer.domElement );

    scene = new THREE.Scene();

    camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.01 );
    camera.position.set( 0, 0, 2 );
    scene.add( camera );

    controls = new THREE.OrbitControls( camera, renderer.domElement );

    var matrix = new THREE.Matrix4();
    var vector = new THREE.Vector3();

    geometry = new THREE.Geometry();

    var boxGeometry = new THREE.BoxGeometry( 0.25, 1, 0.25 );
    boxGeometry.applyMatrix( matrix.makeTranslation( 0, 0.5, 0 ) );
    geometry.merge( boxGeometry );

    var angle = Math.PI / 6;

    var tempGeometry = boxGeometry.clone();
    tempGeometry.applyMatrix( matrix.makeRotationZ( angle ) );
    tempGeometry.applyMatrix( matrix.makeTranslation( 0, 1, 0 ) );
    geometry.merge( tempGeometry );

    tempGeometry = boxGeometry.clone();
    tempGeometry.applyMatrix( matrix.makeRotationZ( -angle ) );
    tempGeometry.applyMatrix( matrix.makeTranslation( 0, 1, 0 ) );
    geometry.merge( tempGeometry );

    tempGeometry = boxGeometry.clone();
    tempGeometry.applyMatrix( matrix.makeRotationZ( angle ) );
    tempGeometry.applyMatrix( matrix.makeTranslation( 0, 1, 0 ) );
    tempGeometry.applyMatrix( matrix.makeRotationZ( angle ) );
    tempGeometry.applyMatrix( matrix.makeTranslation( 0, 1, 0 ) );
    geometry.merge( tempGeometry );

    tempGeometry = boxGeometry.clone();
    tempGeometry.applyMatrix( matrix.makeRotationZ( -angle ) );
    tempGeometry.applyMatrix( matrix.makeTranslation( 0, 1, 0 ) );
    tempGeometry.applyMatrix( matrix.makeRotationZ( angle ) );
    tempGeometry.applyMatrix( matrix.makeTranslation( 0, 1, 0 ) );
    geometry.merge( tempGeometry );

    tempGeometry = boxGeometry.clone();
    tempGeometry.applyMatrix( matrix.makeRotationZ( angle ) );
    tempGeometry.applyMatrix( matrix.makeTranslation( 0, 1, 0 ) );
    tempGeometry.applyMatrix( matrix.makeRotationZ( angle ) );
    tempGeometry.applyMatrix( matrix.makeTranslation( 0, 1, 0 ) );
    tempGeometry.applyMatrix( matrix.makeRotationZ( angle ) );
    tempGeometry.applyMatrix( matrix.makeTranslation( 0, 1, 0 ) );
    geometry.merge( tempGeometry );

    geometry.bones = [
      {
        parent: -1,
        name: 'root',
        pos: [ 0, 0, 0 ],
        rotq: [ 0, 0, 0, 1 ]
      },
      {
        parent: 0,
        name: 'bone.0',
        pos: [ 0, 1, 0 ],
        rotq: [ 0, 0, 0, 1 ]
      },
      {
        parent: 1,
        name: 'bone.0.0',
        pos: vector.set( 0, 1, 0 )
          .applyMatrix4( matrix.makeRotationZ( angle ) )
          .toArray(),
        rotq: [ 0, 0, 0, 1 ]
      },
      {
        parent: 1,
        name: 'bone.0.1',
        pos: vector.set( 0, 1, 0 )
          .applyMatrix4( matrix.makeRotationZ( -angle ) )
          .toArray(),
        rotq: [ 0, 0, 0, 1 ]
      },
      {
        parent: 2,
        name: 'bone.0.0.0',
        pos: vector.set( 0, 1, 0 )
          .applyMatrix4( matrix.makeRotationZ( 2 * angle ) )
          .toArray(),
        rotq: [ 0, 0, 0, 1 ]
      },
      {
        parent: 2,
        name: 'bone.0.0.1',
        pos: [ 0, 1, 0 ],
        rotq: [ 0, 0, 0, 1 ]
      },
      {
        parent: 4,
        name: 'bone.0.0.0.0',
        pos: vector.set( 0, 1, 0 )
          .applyMatrix4( matrix.makeRotationZ( 3 * angle ) )
          .toArray(),
        rotq: [ 0, 0, 0, 1 ]
      }
    ];

    function mapVertices( key ) {
      return function( x, y, z, w ) {
        return function() {
          geometry[ key ].push( new THREE.Vector4( x, y, z, w ) );
        };
      };
    }

    var skinIndices = mapVertices( 'skinIndices' );
    var skinWeights = mapVertices( 'skinWeights' );

    // Skin indices.
    boxGeometry.vertices.forEach( skinIndices( 0, 1, 0, 0 ) );
    boxGeometry.vertices.forEach( skinIndices( 1, 2, 0, 0 ) );
    boxGeometry.vertices.forEach( skinIndices( 1, 3, 0, 0 ) );
    boxGeometry.vertices.forEach( skinIndices( 2, 4, 0, 0 ) );
    boxGeometry.vertices.forEach( skinIndices( 2, 5, 0, 0 ) );
    boxGeometry.vertices.forEach( skinIndices( 4, 6, 0, 0 ) );

    // Skin weights.
    boxGeometry.vertices.forEach( skinWeights( 1, 0, 0, 0 ) );
    boxGeometry.vertices.forEach( skinWeights( 1, 0, 0, 0 ) );
    boxGeometry.vertices.forEach( skinWeights( 1, 0, 0, 0 ) );
    boxGeometry.vertices.forEach( skinWeights( 1, 0, 0, 0 ) );
    boxGeometry.vertices.forEach( skinWeights( 1, 0, 0, 0 ) );
    boxGeometry.vertices.forEach( skinWeights( 1, 0, 0, 0 ) );

    material = new THREE.MeshBasicMaterial({
      skinning: true,
      wireframe: true
    });

    mesh = new THREE.SkinnedMesh( geometry, material );
    scene.add( mesh );

    skeletonHelper = new THREE.SkeletonHelper( mesh );
    skeletonHelper.material.linewidth = 4;
    mesh.add( skeletonHelper );
  }

  var scale = new THREE.Vector3();

  function animate() {
    var time = Date.now() * 1e-3;
    var angle = Math.cos( time );
    var length = 0.5 * ( Math.cos( time ) + 1 );

    mesh.skeleton.bones.forEach(function( bone, index ) {
      scale.setFromMatrixScale( bone.parent.matrixWorld );
      bone.scale.setLength( ( length + 0.25 ) / scale.length() );
      bone.updateMatrixWorld();

      // Set angle if not root.<commit_msg>skeleton: Simplify nested transforms and skin creation.<commit_after>/*global THREE*/
(function() {
  'use strict';

  var container;

  var scene, camera, controls, renderer;
  var geometry, material, mesh;

  var skeletonHelper;

  function init() {
    container = document.createElement( 'div' );
    document.body.appendChild( container );

    renderer = new THREE.WebGLRenderer({ antialias: true });
    renderer.setPixelRatio( window.devicePixelRatio );
    renderer.setSize( window.innerWidth, window.innerHeight );
    container.appendChild( renderer.domElement );

    scene = new THREE.Scene();

    camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.01 );
    camera.position.set( 0, 0, 2 );
    scene.add( camera );

    controls = new THREE.OrbitControls( camera, renderer.domElement );

    var matrix = new THREE.Matrix4();
    var vector = new THREE.Vector3();

    geometry = new THREE.Geometry();

    var boxGeometry = new THREE.BoxGeometry( 0.25, 1, 0.25 );
    boxGeometry.applyMatrix( matrix.makeTranslation( 0, 0.5, 0 ) );
    geometry.merge( boxGeometry );

    var angle = Math.PI / 6;

    function rotateZ( geometry, angle ) {
      geometry.applyMatrix( matrix.makeRotationZ( angle ) );
    }

    function translate( geometry, x, y, z ) {
      geometry.applyMatrix( matrix.makeTranslation( x, y, z ) );
    }

    var tempGeometry = boxGeometry.clone();
    rotateZ( tempGeometry, angle );
    translate( tempGeometry, 0, 1, 0 );
    geometry.merge( tempGeometry );

    tempGeometry = boxGeometry.clone();
    rotateZ( tempGeometry, -angle );
    translate( tempGeometry, 0, 1, 0 );
    geometry.merge( tempGeometry );

    tempGeometry = boxGeometry.clone();
    rotateZ( tempGeometry, angle );
    translate( tempGeometry, 0, 1, 0 );
    rotateZ( tempGeometry, angle );
    translate( tempGeometry, 0, 1, 0 );
    geometry.merge( tempGeometry );

    tempGeometry = boxGeometry.clone();
    rotateZ( tempGeometry, -angle );
    translate( tempGeometry, 0, 1, 0 );
    rotateZ( tempGeometry, angle );
    translate( tempGeometry, 0, 1, 0 );
    geometry.merge( tempGeometry );

    tempGeometry = boxGeometry.clone();
    rotateZ( tempGeometry, angle );
    translate( tempGeometry, 0, 1, 0 );
    rotateZ( tempGeometry, angle );
    translate( tempGeometry, 0, 1, 0 );
    rotateZ( tempGeometry, angle );
    translate( tempGeometry, 0, 1, 0 );
    geometry.merge( tempGeometry );

    geometry.bones = [
      {
        parent: -1,
        name: 'root',
        pos: [ 0, 0, 0 ],
        rotq: [ 0, 0, 0, 1 ]
      },
      {
        parent: 0,
        name: 'bone.0',
        pos: [ 0, 1, 0 ],
        rotq: [ 0, 0, 0, 1 ]
      },
      {
        parent: 1,
        name: 'bone.0.0',
        pos: vector.set( 0, 1, 0 )
          .applyMatrix4( matrix.makeRotationZ( angle ) )
          .toArray(),
        rotq: [ 0, 0, 0, 1 ]
      },
      {
        parent: 1,
        name: 'bone.0.1',
        pos: vector.set( 0, 1, 0 )
          .applyMatrix4( matrix.makeRotationZ( -angle ) )
          .toArray(),
        rotq: [ 0, 0, 0, 1 ]
      },
      {
        parent: 2,
        name: 'bone.0.0.0',
        pos: vector.set( 0, 1, 0 )
          .applyMatrix4( matrix.makeRotationZ( 2 * angle ) )
          .toArray(),
        rotq: [ 0, 0, 0, 1 ]
      },
      {
        parent: 2,
        name: 'bone.0.0.1',
        pos: [ 0, 1, 0 ],
        rotq: [ 0, 0, 0, 1 ]
      },
      {
        parent: 4,
        name: 'bone.0.0.0.0',
        pos: vector.set( 0, 1, 0 )
          .applyMatrix4( matrix.makeRotationZ( 3 * angle ) )
          .toArray(),
        rotq: [ 0, 0, 0, 1 ]
      }
    ];

    function mapVertices( key ) {
      return function( x, y, z, w ) {
        return function() {
          geometry[ key ].push( new THREE.Vector4( x, y, z, w || 0 ) );
        };
      };
    }

    var skinIndices = mapVertices( 'skinIndices' );
    var skinWeights = mapVertices( 'skinWeights' );

    // Skin indices.
    boxGeometry.vertices.forEach( skinIndices( 0, 1 ) );
    boxGeometry.vertices.forEach( skinIndices( 1, 2 ) );
    boxGeometry.vertices.forEach( skinIndices( 1, 3 ) );
    boxGeometry.vertices.forEach( skinIndices( 2, 4 ) );
    boxGeometry.vertices.forEach( skinIndices( 2, 5 ) );
    boxGeometry.vertices.forEach( skinIndices( 4, 6 ) );

    // Skin weights.
    boxGeometry.vertices.forEach( skinWeights( 1 ) );
    boxGeometry.vertices.forEach( skinWeights( 1 ) );
    boxGeometry.vertices.forEach( skinWeights( 1 ) );
    boxGeometry.vertices.forEach( skinWeights( 1 ) );
    boxGeometry.vertices.forEach( skinWeights( 1 ) );
    boxGeometry.vertices.forEach( skinWeights( 1 ) );

    material = new THREE.MeshBasicMaterial({
      skinning: true,
      wireframe: true
    });

    mesh = new THREE.SkinnedMesh( geometry, material );
    scene.add( mesh );

    skeletonHelper = new THREE.SkeletonHelper( mesh );
    skeletonHelper.material.linewidth = 4;
    mesh.add( skeletonHelper );
  }

  var scale = new THREE.Vector3();

  function animate() {
    var time = Date.now() * 1e-3;
    var angle = Math.cos( time );
    var length = 0.5 * ( Math.cos( time ) + 1 );

    mesh.skeleton.bones.forEach(function( bone, index ) {
      scale.setFromMatrixScale( bone.parent.matrixWorld );
      bone.scale.setLength( ( length + 0.25 ) / scale.length() );
      bone.updateMatrixWorld();

      // Set angle if not root.
{'fraction_non_alphanumeric': 0.13999460868002517, 'fraction_numerical': 0.03064066852367688, 'mean_word_length': 2.3953630262355095, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '70740', 'n_tokens_mistral': 3894, 'n_tokens_neox': 3514, 'n_words': 904}