Пример #1
0
 public void updateToObjects(MDL mdlr) {
   // upload the temporary UVLayer and Matrix objects into the vertices themselves
   int sz = numVerteces();
   for (Matrix m : matrix) {
     m.updateBones(mdlr);
   }
   for (int i = 0; i < sz; i++) {
     GeosetVertex gv = vertex.get(i);
     gv.clearTVerts();
     int szuv = uvlayers.size();
     for (int l = 0; l < szuv; l++) {
       try {
         gv.addTVertex(uvlayers.get(l).getTVertex(i));
       } catch (Exception e) {
         JOptionPane.showMessageDialog(
             MDLReader.getDefaultContainer(),
             "Error: Length of TVertices and Vertices chunk differ (Or some other unknown error has occurred)!");
       }
     }
     Matrix mx = getMatrix(gv.getVertexGroup());
     int szmx = mx.size();
     gv.clearBoneAttachments();
     for (int m = 0; m < szmx; m++) {
       gv.addBoneAttachment((Bone) mdlr.getIdObject(mx.getBoneId(m)));
     }
     gv.setNormal(normals.get(i));
     for (Triangle t : triangle) {
       if (t.containsRef(gv)) {
         gv.triangles.add(t);
       }
     }
     gv.geoset = this;
     //             gv.addBoneAttachment(null);//Why was this here?
   }
   try {
     material = mdlr.getMaterial(materialID);
   } catch (ArrayIndexOutOfBoundsException e) {
     JOptionPane.showMessageDialog(null, "Error: Material index out of bounds for geoset!");
   }
   parentModel = mdlr;
 }
Пример #2
0
  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;
  }