<commit_before>part of orange;





class GltfLoader2 {
  gl.RenderingContext _ctx;
  Mesh _root;
  Uri _uri;
  Map<String, dynamic> _resources;
  Map<String, Skeleton> _skeletons;
  Map<String, Joint> _joints;
  Map<String, List<String>> _childrenOfNode;
  Map<String, List<String>> _jointsOfSkeleton;
  Map<String, Map> _skinOfNode;
  Animation _animation;

  Future<Mesh> load(gl.RenderingContext ctx, String url) {
    _ctx = ctx;
    _uri = Uri.parse(url);
    _root = new Mesh();
    _resources = {};
    _skeletons = {};
    _joints = {};
    _childrenOfNode = {};
    _jointsOfSkeleton = {};
    _skinOfNode = {};
    var completer = new Completer<Mesh>();
    html.HttpRequest.getString(url).then((rsp) {
      var json = JSON.decode(rsp);
      var loadBufferFutures = [];
      json["buffers"].forEach((k, v) => loadBufferFutures.add(_loadBuffer(k, v)));
      Future.wait(loadBufferFutures).then((List buffers) {
        _parseNodes(json);
        _parseSkins(json);
        _parseAnimations(json);
        _parseScene(json);
        completer.complete(_root);
      });
    }).catchError((Error e) => print([e, e.stackTrace]));
    return completer.future;
  }

  void _parseAnimations(Map doc) {
    if (doc.containsKey("animations")) {
      var animation = new Animation();
      animation.name = "default";
      animation.tracks = [];
      animation.length = 0.0;
      doc["animations"].forEach((String k, Map ani) {
        var track = new Track();
        var channels = ani["channels"] as List;
        track.jointName = channels.first["target"]["id"];
        var joint = _resources["Node_${track.jointName}"] as Joint;
        track.jointId = joint.jointId;
        track.keyframes = [];

        var parameters = {};
        ani["parameters"].forEach((k, p) => parameters[k] = _getAttribute(doc, p, k).data as Float32List);
        // track
        var count = ani["count"];
        for (var i = 0; i < count; i++) {
          var keyframe = new Keyframe();
          channels.forEach((Map ch) {
            var target = ch["target"];
            var path = target["path"];
            var list = parameters[path];
            if (path == "rotation") {
              var idx = i * 4;
              keyframe.rotate = new Quaternion.axisAngle(new Vector3(list[idx], list[idx + 1], list[idx + 2]), list[idx + 3]);
            } else if (path == "scale") {
              var idx = i * 3;
              keyframe.scaling = new Vector3(list[idx], list[idx + 1], list[idx + 2]);
            } else if (path == "translation") {
              var idx = i * 3;
              keyframe.translate = new Vector3(list[idx], list[idx + 1], list[idx + 2]);
            }
          });
          keyframe.time = parameters["TIME"][i];
          track.keyframes.add(keyframe);
        }

        animation.tracks.add(track);
      });
      if (animation.tracks.length > 0) {
        animation.length = animation.tracks.first.keyframes.last.time;
        _animation = animation;
      }
    }
  }

  void _parseSkins(Map doc) {
    if (doc.containsKey("skins")) {
      _skeletons = {};
      doc["skins"].forEach((String k, Map v) {
        var skeleton = new Skeleton();
        skeleton.name = k;
        skeleton.joints = [];
        for (var i = 0; i < v["joints"].length; i++) {
          var joint = _joints[v["joints"][i]];
          joint.jointId = i;
          skeleton.joints.add(joint);
        }
        skeleton.joints.forEach((joint) {
          if (joint.parent == null) joint.parentId = -1; else if (joint.parent is Joint) joint.parentId = joint.parent.jointId;<commit_msg>cleanup<commit_after>part of orange;





class GltfLoader2 {
  gl.RenderingContext _ctx;
  Mesh _root;
  Uri _uri;
  Map<String, dynamic> _resources;
  Map<String, Skeleton> _skeletons;
  Map<String, Joint> _joints;
  Map<String, List<String>> _childrenOfNode;
  Map<String, List<String>> _jointsOfSkeleton;
  Map<String, Map> _skinOfNode;
  Animation _animation;

  Future<Mesh> load(gl.RenderingContext ctx, String url) {
    _ctx = ctx;
    _uri = Uri.parse(url);
    _root = new Mesh();
    _resources = {};
    _skeletons = {};
    _joints = {};
    _childrenOfNode = {};
    _jointsOfSkeleton = {};
    _skinOfNode = {};
    var completer = new Completer<Mesh>();
    html.HttpRequest.getString(url).then((rsp) {
      var json = JSON.decode(rsp);
      var loadBufferFutures = [];
      json["buffers"].forEach((k, v) => loadBufferFutures.add(_loadBuffer(k, v)));
      Future.wait(loadBufferFutures).then((List buffers) {
        _parseNodes(json);
        _parseSkins(json);
        _parseAnimations(json);
        _parseScene(json);
        completer.complete(_root);
      });
    }).catchError((Error e) => print([e, e.stackTrace]));
    return completer.future;
  }

  void _parseAnimations(Map doc) {
    if (doc.containsKey("animations")) {
      var animation = new Animation();
      animation.name = "default";
      animation.tracks = [];
      animation.length = 0.0;
      doc["animations"].forEach((String k, Map ani) {
        var track = new Track();
        var channels = ani["channels"] as List;
        track.jointName = channels.first["target"]["id"];
        var joint = _resources["Node_${track.jointName}"] as Joint;
        track.jointId = joint.jointId;
        track.keyframes = [];

        var parameters = {};
        ani["parameters"].forEach((k, p) => parameters[k] = _getAttribute(doc, p, k));
        // track
        var count = ani["count"];
        for (var i = 0; i < count; i++) {
          var keyframe = new Keyframe();
          channels.forEach((Map ch) {
            var path = ch["target"]["path"];
            var buffer = parameters[path] as VertexBuffer;
            var list = buffer.data as Float32List;
            var idx = i * buffer.size;
            if (path == "rotation") {
              keyframe.rotate = new Quaternion.axisAngle(new Vector3(list[idx], list[idx + 1], list[idx + 2]), list[idx + 3]);
            } else if (path == "scale") {
              keyframe.scaling = new Vector3(list[idx], list[idx + 1], list[idx + 2]);
            } else if (path == "translation") {
              keyframe.translate = new Vector3(list[idx], list[idx + 1], list[idx + 2]);
            }
          });
          keyframe.time = parameters["TIME"].data[i];
          track.keyframes.add(keyframe);
        }
        animation.tracks.add(track);
      });
      if (animation.tracks.length > 0) {
        animation.length = animation.tracks.first.keyframes.last.time;
        _animation = animation;
      }
    }
  }

  void _parseSkins(Map doc) {
    if (doc.containsKey("skins")) {
      _skeletons = {};
      doc["skins"].forEach((String k, Map v) {
        var skeleton = new Skeleton();
        skeleton.name = k;
        skeleton.joints = [];
        for (var i = 0; i < v["joints"].length; i++) {
          var joint = _joints[v["joints"][i]];
          joint.jointId = i;
          skeleton.joints.add(joint);
        }
        skeleton.joints.forEach((joint) {
          if (joint.parent == null) joint.parentId = -1; else if (joint.parent is Joint) joint.parentId = joint.parent.jointId;
{'fraction_non_alphanumeric': 0.15016778523489932, 'fraction_numerical': 0.005732662192393736, 'mean_word_length': 2.351921274601687, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 31, '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': '3377412', 'n_tokens_mistral': 2291, 'n_tokens_neox': 2207, 'n_words': 493}