home *** CD-ROM | disk | FTP | other *** search
/ Late Night VRML 2.0 with Java CD-ROM / code.zip / Ch13 / nff / Obj.java < prev    next >
Text File  |  1996-11-27  |  2KB  |  52 lines

  1. // A class for NFF objects
  2.  
  3. // Written by Bernie Roehl, November 1996
  4.  
  5. package nff;
  6.  
  7. import java.io.*;
  8.  
  9. public class Obj {
  10.     protected String name;
  11.     protected int nvertices, nfaces;
  12.     protected Vertex[] vertices;
  13.     protected Face[] faces;
  14.  
  15.     public String getName() { return name; }
  16.     public int getNumberOfVertices() { return nvertices; }
  17.     public int getNumberOfFaces() { return nfaces; }
  18.     public Vertex getVertex(int n) { return vertices[n]; }
  19.     public Face getFace(int n) { return faces[n]; } 
  20.  
  21.     public void dump() {
  22.         System.out.println("Object name = '" + name + "'");
  23.         System.out.println("\t" + nvertices + " vertices, " + nfaces + " faces");
  24.         System.out.println("vertices:");
  25.         for (int i = 0; i < nvertices; ++i)
  26.             vertices[i].dump();
  27.         System.out.println("faces:");
  28.         for (int i = 0; i < nfaces; ++i)
  29.             faces[i].dump();
  30.     }
  31.  
  32.     public Obj(String namevalue, CommentStripperInputStream input)
  33.         throws IOException, NffSyntaxException  {
  34.         name = new String(namevalue);
  35.         vertices = new Vertex[nvertices = Integer.parseInt(input.readLine())];
  36.         for (int i = 0; i < nvertices; ++i)
  37.              vertices[i] = new Vertex(input);
  38.         faces = new Face[nfaces = Integer.parseInt(input.readLine())];
  39.         for (int i = 0; i < nfaces; ++i) {
  40.              faces[i] = new Face(input);
  41.              for (int j = 0; j < faces[i].getNumberOfPoints(); ++j) {
  42.                  Vertex v = vertices[faces[i].getPoint(j)];
  43.                  if (v.getColor() == null)   // at least one has no color
  44.                     faces[i].useVertexColors = false;
  45.                  if (v.getNormal() == null)  // at least one has no normal
  46.                     faces[i].useVertexNormals = false;
  47.              }
  48.         }
  49.     }
  50. }
  51.  
  52.