Example #1
0
  public static MD5Mesh parse(List<String> meshBlock) {
    MD5Mesh mesh = new MD5Mesh();
    List<MD5Vertex> vertices = mesh.getVertices();
    List<MD5Triangle> triangles = mesh.getTriangles();
    List<MD5Weight> weights = mesh.getWeights();

    for (String line : meshBlock) {
      if (line.contains("shader")) {
        Matcher textureMatcher = PATTERN_SHADER.matcher(line);
        if (textureMatcher.matches()) {
          mesh.setTexture(textureMatcher.group(1));
        }
      } else if (line.contains("vert")) {
        Matcher vertexMatcher = PATTERN_VERTEX.matcher(line);
        if (vertexMatcher.matches()) {
          MD5Vertex vertex = new MD5Vertex();
          vertex.setIndex(Integer.parseInt(vertexMatcher.group(1)));
          float x = Float.parseFloat(vertexMatcher.group(2));
          float y = Float.parseFloat(vertexMatcher.group(3));
          vertex.setTextCoords(new Vector2f(x, y));
          vertex.setStartWeight(Integer.parseInt(vertexMatcher.group(4)));
          vertex.setWeightCount(Integer.parseInt(vertexMatcher.group(5)));
          vertices.add(vertex);
        }
      } else if (line.contains("tri")) {
        Matcher triMatcher = PATTERN_TRI.matcher(line);
        if (triMatcher.matches()) {
          MD5Triangle triangle = new MD5Triangle();
          triangle.setIndex(Integer.parseInt(triMatcher.group(1)));
          triangle.setVertex0(Integer.parseInt(triMatcher.group(2)));
          triangle.setVertex1(Integer.parseInt(triMatcher.group(3)));
          triangle.setVertex2(Integer.parseInt(triMatcher.group(4)));
          triangles.add(triangle);
        }
      } else if (line.contains("weight")) {
        Matcher weightMatcher = PATTERN_WEIGHT.matcher(line);
        if (weightMatcher.matches()) {
          MD5Weight weight = new MD5Weight();
          weight.setIndex(Integer.parseInt(weightMatcher.group(1)));
          weight.setJointIndex(Integer.parseInt(weightMatcher.group(2)));
          weight.setBias(Float.parseFloat(weightMatcher.group(3)));
          float x = Float.parseFloat(weightMatcher.group(4));
          float y = Float.parseFloat(weightMatcher.group(5));
          float z = Float.parseFloat(weightMatcher.group(6));
          weight.setPosition(new Vector3f(x, y, z));
          weights.add(weight);
        }
      }
    }
    return mesh;
  }