コード例 #1
0
ファイル: Geoset.java プロジェクト: Retera/JWC3
  public void printTo(PrintWriter writer, MDL mdlr, boolean trianglesTogether) {
    purifyFaces();
    writer.println("Geoset {");
    writer.println("\tVertices " + vertex.size() + " {");

    String tabs = "\t\t";
    // Normals cleared here, in case that becomes a problem later.
    normals.clear();
    // UV Layers cleared here
    uvlayers.clear();
    int bigNum = 0;
    int littleNum = -1;
    for (int i = 0; i < vertex.size(); i++) {
      int temp = vertex.get(i).tverts.size();
      if (temp > bigNum) {
        bigNum = temp;
      }
      if (littleNum == -1 || temp < littleNum) {
        littleNum = temp;
      }
    }
    if (littleNum != bigNum) {
      JOptionPane.showMessageDialog(
          null,
          "Error: Attempting to save a Geoset with Verteces that have differing numbers of TVertices! Empty TVertices will be autogenerated.");
    }
    for (int i = 0; i < bigNum; i++) {
      uvlayers.add(new UVLayer());
    }
    for (int i = 0; i < vertex.size(); i++) {
      writer.println(tabs + vertex.get(i).toString() + ",");
      normals.add(vertex.get(i).getNormal());
      for (int uv = 0; uv < bigNum; uv++) {
        try {
          TVertex temp = vertex.get(i).getTVertex(uv);
          if (temp != null) {
            uvlayers.get(uv).addTVertex(temp);
          } else {
            uvlayers.get(uv).addTVertex(new TVertex(0, 0));
          }
        } catch (IndexOutOfBoundsException e) {
          uvlayers.get(uv).addTVertex(new TVertex(0, 0));
        }
      }
    }
    writer.println("\t}");
    writer.println("\tNormals " + normals.size() + " {");
    for (int i = 0; i < normals.size(); i++) {
      writer.println(tabs + normals.get(i).toString() + ",");
    }
    writer.println("\t}");
    for (int i = 0; i < uvlayers.size(); i++) {
      uvlayers.get(i).printTo(writer, 1, true);
    }
    // Clearing matrix list
    matrix.clear();
    writer.println("\tVertexGroup {");
    for (int i = 0; i < vertex.size(); i++) {
      Matrix newTemp = new Matrix(vertex.get(i).bones);
      boolean newMatrix = true;
      for (int m = 0; m < matrix.size() && newMatrix; m++) {
        if (newTemp.equals(matrix.get(m))) {
          newTemp = matrix.get(m);
          newMatrix = false;
        }
      }
      if (newMatrix) {
        matrix.add(newTemp);
        newTemp.updateIds(mdlr);
      }
      vertex.get(i).VertexGroup = matrix.indexOf(newTemp);
      vertex.get(i).setMatrix(newTemp);
      writer.println(tabs + vertex.get(i).VertexGroup + ",");
    }
    writer.println("\t}");
    if (trianglesTogether) {
      writer.println("\tFaces 1 " + (triangle.size() * 3) + " {");
      writer.println("\t\tTriangles {");
      String triangleOut = "\t\t\t{ ";
      for (int i = 0; i < triangle.size(); i++) {
        triangle.get(i).updateVertexIds(this);
        if (i != triangle.size() - 1) {
          triangleOut = triangleOut + triangle.get(i).toString() + ", ";
        } else {
          triangleOut = triangleOut + triangle.get(i).toString() + " ";
        }
      }
      writer.println(triangleOut + "},");
      writer.println("\t\t}");
    } else {
      writer.println("\tFaces " + triangle.size() + " " + (triangle.size() * 3) + " {");
      writer.println("\t\tTriangles {");
      String triangleOut = "\t\t\t{ ";
      for (int i = 0; i < triangle.size(); i++) {
        triangle.get(i).updateVertexIds(this);
        writer.println(triangleOut + triangle.get(i).toString() + " },");
      }
      writer.println("\t\t}");
    }
    writer.println("\t}");
    int boneRefCount = 0;
    for (int i = 0; i < matrix.size(); i++) {
      boneRefCount += matrix.get(i).bones.size();
    }
    writer.println("\tGroups " + matrix.size() + " " + boneRefCount + " {");
    for (int i = 0; i < matrix.size(); i++) {
      matrix.get(i).updateIds(mdlr);
      matrix.get(i).printTo(writer, 2); // 2 is the tab height
    }
    writer.println("\t}");
    if (extents != null) extents.printTo(writer, 1);
    for (int i = 0; i < anims.size(); i++) {
      anims.get(i).printTo(writer, 1);
    }

    writer.println("\tMaterialID " + materialID + ",");
    writer.println("\tSelectionGroup " + selectionGroup + ",");
    for (int i = 0; i < flags.size(); i++) {
      writer.println("\t" + flags.get(i) + ",");
    }

    writer.println("}");
  }
コード例 #2
0
ファイル: Geoset.java プロジェクト: Retera/JWC3
  public static Geoset read(BufferedReader mdl) {
    String line = MDLReader.nextLine(mdl);
    System.out.println("geo begins with " + line);
    if (line.contains("Geoset")) {
      line = MDLReader.nextLine(mdl);
      Geoset geo = new Geoset();
      if (!line.contains("Vertices")) {
        JOptionPane.showMessageDialog(
            MDLReader.getDefaultContainer(), "Error: Vertices not found at beginning of Geoset!");
      }
      while (!((line = MDLReader.nextLine(mdl)).contains("\t}"))) {
        geo.addVertex(GeosetVertex.parseText(line));
      }
      line = MDLReader.nextLine(mdl);
      if (line.contains("Normals")) {
        // If we have normals:
        while (!((line = MDLReader.nextLine(mdl)).contains("\t}"))) {
          geo.addNormal(Normal.parseText(line));
        }
      }
      while (((line = MDLReader.nextLine(mdl)).contains("TVertices"))) {
        geo.addUVLayer(UVLayer.read(mdl));
      }
      if (!line.contains("VertexGroup")) {
        JOptionPane.showMessageDialog(
            MDLReader.getDefaultContainer(), "Error: VertexGroups missing or invalid!");
      }
      int i = 0;
      while (!((line = MDLReader.nextLine(mdl)).contains("\t}"))) {
        geo.getVertex(i).setVertexGroup(MDLReader.readInt(line));
        i++;
      }
      line = MDLReader.nextLine(mdl);
      if (!line.contains("Faces")) {
        JOptionPane.showMessageDialog(
            MDLReader.getDefaultContainer(), "Error: Faces missing or invalid!");
      }
      line = MDLReader.nextLine(mdl);
      if (!line.contains("Triangles")) {
        System.out.println(line);
        JOptionPane.showMessageDialog(
            MDLReader.getDefaultContainer(), "Error: Triangles missing or invalid!");
      }
      geo.setTriangles(Triangle.read(mdl, geo));
      line = MDLReader.nextLine(mdl); // Throw away the \t} closer for faces
      line = MDLReader.nextLine(mdl);
      if (!line.contains("Groups")) {
        JOptionPane.showMessageDialog(
            MDLReader.getDefaultContainer(), "Error: Groups (Matrices) missing or invalid!");
      }
      while (!((line = MDLReader.nextLine(mdl)).contains("\t}"))) {
        geo.addMatrix(Matrix.parseText(line));
      }
      MDLReader.mark(mdl);
      line = MDLReader.nextLine(mdl);
      while (!line.contains("}") || line.contains("},")) {
        if (line.contains("Extent") || line.contains("BoundsRadius")) {
          System.out.println("Parsing geoset extLog:" + line);
          MDLReader.reset(mdl);
          geo.setExtLog(ExtLog.read(mdl));
          System.out.println("Completed geoset extLog.");
        } else if (line.contains("Anim")) {
          MDLReader.reset(mdl);
          geo.add(Animation.read(mdl));
          MDLReader.mark(mdl);
        } else if (line.contains("MaterialID")) {
          geo.materialID = MDLReader.readInt(line);
          MDLReader.mark(mdl);
        } else if (line.contains("SelectionGroup")) {
          geo.selectionGroup = MDLReader.readInt(line);
          MDLReader.mark(mdl);
        } else {
          geo.addFlag(MDLReader.readFlag(line));
          System.out.println("Reading to geoFlag: " + line);
          MDLReader.mark(mdl);
        }
        line = MDLReader.nextLine(mdl);
      }
      //             JOptionPane.showMessageDialog(MDLReader.getDefaultContainer(),"Geoset reading
      // completed!");
      System.out.println("Geoset reading completed!");

      return geo;
    } else {
      JOptionPane.showMessageDialog(
          MDLReader.getDefaultContainer(),
          "Unable to parse Geoset: Missing or unrecognized open statement '" + line + "'.");
    }
    return null;
  }