home *** CD-ROM | disk | FTP | other *** search
/ Late Night VRML 2.0 with Java CD-ROM / code.zip / Ch13 / nff / Face.java < prev    next >
Text File  |  1997-01-14  |  3KB  |  81 lines

  1. // A class for NFF faces
  2.  
  3. // Written by Bernie Roehl, November 1996
  4.  
  5. package nff;
  6.  
  7. import java.io.*;
  8. import java.util.*;
  9.  
  10. public class Face {
  11.     protected int npoints;            // number of points in face
  12.     protected int[] points;           // indices into array of vertices
  13.     protected Color color;            // color of this face
  14.     protected boolean both = false;   // face is visible from both sides
  15.     protected int id;                 // identifier for face
  16.     protected Texture texture;        // texture map
  17.     protected String portal;          // portal for this face
  18.     public boolean useVertexNormals;  // use vertex normals
  19.     public boolean useVertexColors;   // use vertex colors
  20.  
  21.     public int getNumberOfPoints() { return npoints; }
  22.     public int getPoint(int n) { return points[n]; }
  23.     public boolean isDoublesided() { return both; }
  24.     public Texture getTexture() { return texture; }
  25.     public Color getColor() { return color; }
  26.     public int getId() { return id; }
  27.  
  28.     public void dump() {
  29.         System.out.print(npoints + " points:");
  30.         for (int i = 0; i < npoints; ++i)
  31.              System.out.print(" " + points[i]);
  32.         if (color != null)
  33.            System.out.print(" rgb = " + color); 
  34.         if (texture != null)
  35.             System.out.print(" texture = " + texture); 
  36.         if (portal != null)
  37.             System.out.print(" portal = '" + portal + "'");
  38.         System.out.print(" both = " + both);
  39.         System.out.print(" id = " + id);
  40.     System.out.print(" v.normals = " + useVertexNormals);
  41.     System.out.print(" v.colors = " + useVertexColors);
  42.         System.out.println();
  43.     }
  44.  
  45.     public Face(CommentStripperInputStream input)
  46.        throws IOException, NffSyntaxException  {
  47.        String line = input.readLine();
  48.        StringTokenizer s = new StringTokenizer(line);
  49.        points = new int[npoints = Integer.parseInt(s.nextToken())];
  50.        for (int i = 0; i < npoints; ++i)
  51.            points[i] = Integer.parseInt(s.nextToken());
  52.        if (s.hasMoreTokens())  // color
  53.            color = new Color(s.nextToken());
  54.        while (s.hasMoreTokens()) {
  55.             String cmd = s.nextToken();
  56.             if (cmd.equals("both"))
  57.                 both = true;
  58.             else if (cmd.startsWith("id"))
  59.                 id = Integer.parseInt(cmd.substring(3));
  60.             else if (cmd.equals("rot"))
  61.                 texture.setRotation(Float.valueOf(s.nextToken()).floatValue());
  62.             else if (cmd.equals("scale"))
  63.                 texture.setScale(Float.valueOf(s.nextToken()).floatValue());
  64.             else if (cmd.equals("mirror"))
  65.                 texture.setMirror(true);
  66.             else if (cmd.equals("trans")) {
  67.                 float sval = Float.valueOf(s.nextToken()).floatValue();
  68.                 float tval = Float.valueOf(s.nextToken()).floatValue();
  69.                 texture.setTrans(sval, tval);
  70.             }
  71.             else if (cmd.charAt(0) == '-')
  72.                 portal = new String(cmd.substring(1));
  73.             else
  74.                 texture = new Texture(cmd);
  75.        }
  76.        useVertexNormals = true;
  77.        useVertexColors = true;
  78.     }
  79. }
  80.  
  81.