<commit_before>'use strict';

function VertexAnimation(geom, anim) {
  this.geom = geom;
  this.anim = anim;
  this.time = 0;
  this.frame = 0;
  this.playing = false;

  // Validate the animation
  for (var l = 0; l < anim.channels.length; ++l) {
    var channel = anim.channels[l];
    if (channel.type === Animation.CHANNEL_TYPE.Position) {
    } else if (channel.type === Animation.CHANNEL_TYPE.Alpha) {
      if (!this.geom.attributes['alpha']) {
        var posByteLen = this.geom.attributes['position'].array.byteLength;
        var vertexCount = posByteLen / 4 / 3;
        var alphaAttrib = new THREE.BufferAttribute(new Float32Array(vertexCount), 1);
        this.geom.addAttribute('alpha', alphaAttrib);
      }
    } else if (channel.type === Animation.CHANNEL_TYPE.Normal) {
    } else if (channel.type === Animation.CHANNEL_TYPE.Uv1) {
    } else {
      console.warn('Encountered unhandled vertex animation channel type:', channel.type);
    }
  }
}

VertexAnimation.prototype.resetBlendWeights = function() {
};

VertexAnimation.prototype.update = function(delta) {
  if (!this.playing) {
    return;
  }

  this.time += delta;

  var newFrame = Math.floor(this.time * this.anim.fps);
  while (newFrame >= this.anim.frameCount) {
    this.time -= this.anim.frameCount / this.anim.fps;
    newFrame -= this.anim.frameCount;
  }
  if (newFrame === this.frame) {
    return;
  }
  this.frame = newFrame;

  for (var i = 0; i < this.anim.channels.length; ++i) {
    var channel = this.anim.channels[i];
    var frame = channel.frames[this.frame];

    if (channel.type === Animation.CHANNEL_TYPE.Position) {
      var attrib = this.geom.attributes['position'];
      attrib.array[channel.index * 3 + 0] = frame.x;
      attrib.array[channel.index * 3 + 1] = frame.y;
      attrib.array[channel.index * 3 + 2] = frame.z;<commit_msg>Added better error handling for VertexAnimation system.<commit_after>'use strict';

function VertexAnimation(geom, anim) {
  this.geom = geom;
  this.anim = anim;
  this.time = 0;
  this.frame = 0;
  this.playing = false;

  // Validate the animation
  for (var l = 0; l < anim.channels.length; ++l) {
    var channel = anim.channels[l];
    if (channel.type === Animation.CHANNEL_TYPE.Position) {
      if (!this.geom.attributes['position']) {
        console.warn('Encountered vertex position animation with no attribute on mesh.');
        this.anim = null;
        break;
      }
    } else if (channel.type === Animation.CHANNEL_TYPE.Alpha) {
      // Alpha doesn't exist on ZMS, so we manually create it when needed.
      if (!this.geom.attributes['alpha']) {
        var posByteLen = this.geom.attributes['position'].array.byteLength;
        var vertexCount = posByteLen / 4 / 3;
        var alphaAttrib = new THREE.BufferAttribute(new Float32Array(vertexCount), 1);
        this.geom.addAttribute('alpha', alphaAttrib);
      }
    } else if (channel.type === Animation.CHANNEL_TYPE.Normal) {
      // Normals are disabled at the moment, so ignore them.
    } else if (channel.type === Animation.CHANNEL_TYPE.Uv1) {
      if (!this.geom.attributes['uv']) {
        console.warn('Encountered vertex uv animation with no attribute on mesh.');
        this.anim = null;
        break;
      }
    } else {
      console.warn('Encountered unhandled vertex animation channel type:', channel.type);
    }
  }
}

VertexAnimation.prototype.resetBlendWeights = function() {
};

VertexAnimation.prototype.update = function(delta) {
  if (!this.playing || !this.anim) {
    return;
  }

  this.time += delta;

  var newFrame = Math.floor(this.time * this.anim.fps);
  while (newFrame >= this.anim.frameCount) {
    this.time -= this.anim.frameCount / this.anim.fps;
    newFrame -= this.anim.frameCount;
  }
  if (newFrame === this.frame) {
    return;
  }
  this.frame = newFrame;

  for (var i = 0; i < this.anim.channels.length; ++i) {
    var channel = this.anim.channels[i];
    var frame = channel.frames[this.frame];

    if (channel.type === Animation.CHANNEL_TYPE.Position) {
      var attrib = this.geom.attributes['position'];
      attrib.array[channel.index * 3 + 0] = frame.x;
      attrib.array[channel.index * 3 + 1] = frame.y;
      attrib.array[channel.index * 3 + 2] = frame.z;
{'fraction_non_alphanumeric': 0.14252005663048609, 'fraction_numerical': 0.0075507314771118455, 'mean_word_length': 2.9616822429906544, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '5537164', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1346, 'n_words': 309}