<commit_before>var ZMDLoader = {};

function ZMDSkeleton() {
  this.bones = [];
  this.dummies = [];
}
/**
 * Creates a skeleton object from this skeleton data.
 */
ZMDSkeleton.prototype.create = function(rootObj) {
  var bones = [];

  var fakeRoot = new THREE.Object3D();

  for (var i = 0; i < this.bones.length; ++i) {
    var b = this.bones[i];

    var boneX = new THREE.Bone(rootObj);
    boneX.name = b.name;
    boneX.position.set(b.position.x, b.position.y, b.position.z);
    boneX.quaternion.set(b.rotation.x, b.rotation.y, b.rotation.z, b.rotation.w);
    boneX.scale.set(1, 1, 1);

    if (b.parent == -1) {
      fakeRoot.add(boneX);
    } else {
      bones[b.parent].add(boneX);
    }

    bones.push(boneX);
  }

  var skel = new THREE.Skeleton(bones);

  // The root object has to be fully updated!
  fakeRoot.updateMatrixWorld();

  // Generate the inverse matrices for skinning
  skel.calculateInverses();

  fakeRoot.remove(bones[0]);
  rootObj.add(bones[0]);

  return skel;
};

ZMDLoader.load = function(path, callback) {
  ROSELoader.load(path, function(rh) {
    var skel = new ZMDSkeleton();

    rh.skip(7);

    var boneCount = rh.readUint32();
    for (var i = 0; i < boneCount; ++i) {
      var bone = {};
      bone.parent = rh.readUint32();
      bone.name = rh.readStr();
      bone.position = rh.readVector3().multiplyScalar(ZZ_SCALE_IN);
      bone.rotation = rh.readBadQuat();

      if (i == 0) {
        bone.parent = -1;
      }

      skel.bones.push(bone);
    }

    //var dummyCount = rh.readUint32();

    callback(skel);
  });
};<commit_msg>Refactor zmd.js<commit_after>/**
 * @constructor
 * @property {Skeleton.Bone[]} bones
 * @property {Skeleton.Bone[]} dummies
 */
var Skeleton = function() {
  this.bones = [];
  this.dummies = [];
};


/**
 * @constructor
 * @property {Number} parent
 * @property {String} name
 * @property {THREE.Vector3} position
 * @property {THREE.Quaternion} rotation
 */
Skeleton.Bone = function() {
};


/**
 * Creates a skeleton object from this skeleton data.
 */
Skeleton.prototype.create = function(rootObj) {
  var bones = [];

  var fakeRoot = new THREE.Object3D();

  for (var i = 0; i < this.bones.length; ++i) {
    var b = this.bones[i];

    var boneX = new THREE.Bone(rootObj);
    boneX.name = b.name;
    boneX.position.set(b.position.x, b.position.y, b.position.z);
    boneX.quaternion.set(b.rotation.x, b.rotation.y, b.rotation.z, b.rotation.w);
    boneX.scale.set(1, 1, 1);

    if (b.parent == -1) {
      fakeRoot.add(boneX);
    } else {
      bones[b.parent].add(boneX);
    }

    bones.push(boneX);
  }

  var skel = new THREE.Skeleton(bones);

  // The root object has to be fully updated!
  fakeRoot.updateMatrixWorld();

  // Generate the inverse matrices for skinning
  skel.calculateInverses();

  fakeRoot.remove(bones[0]);
  rootObj.add(bones[0]);

  return skel;
};


/**
 * @callback Skeleton~onLoad
 * @param {Skeleton} skeleton
 */

/**
 * @param {String} path
 * @param {Skeleton~onLoad} callback
 */
Skeleton.load = function(path, callback) {
  ROSELoader.load(path, function(/** BinaryReader */rh) {
    var bones, dummies, i, magic, version;
    var data = new Skeleton();

    magic = rh.readStrLen(7);
    if (magic === 'ZMD0002') {
      version = 2;
    } else if (magic === 'ZMD0003') {
      version = 3;
    } else {
      throw 'Unexpected ZMD magic header ' + magic + ' in ' + path;
    }

    bones = rh.readUint32();
    for (var i = 0; i < bones; ++i) {
      var bone = new Skeleton.Bone();
      bone.parent   = rh.readUint32();
      bone.name     = rh.readStr();
      bone.position = rh.readVector3().multiplyScalar(ZZ_SCALE_IN);
      bone.rotation = rh.readBadQuat();

      if (i == 0) {
        bone.parent = -1;
      }

      data.bones.push(bone);
    }

    dummies = rh.readUint32();
    for (i = 0; i < dummies; ++i) {
      var dummy = new Skeleton.Bone();
      dummy.name     = rh.readStr();
      dummy.parent   = rh.readUint32();
      dummy.position = rh.readVector3().multiplyScalar(ZZ_SCALE_IN);

      if (version === 3) {
        dummy.rotation = rh.readBadQuat();
      }

      data.dummies.push(dummy);
    }

    callback(data);
  });
};
{'fraction_non_alphanumeric': 0.16491897044804577, 'fraction_numerical': 0.012869399428026692, 'mean_word_length': 2.646394439617724, 'pattern_counts': {'":': 0, '<': 8, '<?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': '4858227', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1493, 'n_words': 323}