home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Late Night VRML 2.0 with Java CD-ROM
/
code.zip
/
Ch13
/
nff
/
Face.java
< prev
next >
Wrap
Text File
|
1997-01-14
|
3KB
|
81 lines
// A class for NFF faces
// Written by Bernie Roehl, November 1996
package nff;
import java.io.*;
import java.util.*;
public class Face {
protected int npoints; // number of points in face
protected int[] points; // indices into array of vertices
protected Color color; // color of this face
protected boolean both = false; // face is visible from both sides
protected int id; // identifier for face
protected Texture texture; // texture map
protected String portal; // portal for this face
public boolean useVertexNormals; // use vertex normals
public boolean useVertexColors; // use vertex colors
public int getNumberOfPoints() { return npoints; }
public int getPoint(int n) { return points[n]; }
public boolean isDoublesided() { return both; }
public Texture getTexture() { return texture; }
public Color getColor() { return color; }
public int getId() { return id; }
public void dump() {
System.out.print(npoints + " points:");
for (int i = 0; i < npoints; ++i)
System.out.print(" " + points[i]);
if (color != null)
System.out.print(" rgb = " + color);
if (texture != null)
System.out.print(" texture = " + texture);
if (portal != null)
System.out.print(" portal = '" + portal + "'");
System.out.print(" both = " + both);
System.out.print(" id = " + id);
System.out.print(" v.normals = " + useVertexNormals);
System.out.print(" v.colors = " + useVertexColors);
System.out.println();
}
public Face(CommentStripperInputStream input)
throws IOException, NffSyntaxException {
String line = input.readLine();
StringTokenizer s = new StringTokenizer(line);
points = new int[npoints = Integer.parseInt(s.nextToken())];
for (int i = 0; i < npoints; ++i)
points[i] = Integer.parseInt(s.nextToken());
if (s.hasMoreTokens()) // color
color = new Color(s.nextToken());
while (s.hasMoreTokens()) {
String cmd = s.nextToken();
if (cmd.equals("both"))
both = true;
else if (cmd.startsWith("id"))
id = Integer.parseInt(cmd.substring(3));
else if (cmd.equals("rot"))
texture.setRotation(Float.valueOf(s.nextToken()).floatValue());
else if (cmd.equals("scale"))
texture.setScale(Float.valueOf(s.nextToken()).floatValue());
else if (cmd.equals("mirror"))
texture.setMirror(true);
else if (cmd.equals("trans")) {
float sval = Float.valueOf(s.nextToken()).floatValue();
float tval = Float.valueOf(s.nextToken()).floatValue();
texture.setTrans(sval, tval);
}
else if (cmd.charAt(0) == '-')
portal = new String(cmd.substring(1));
else
texture = new Texture(cmd);
}
useVertexNormals = true;
useVertexColors = true;
}
}