home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Late Night VRML 2.0 with Java CD-ROM
/
code.zip
/
Ch13
/
scul2wrl.java
< prev
next >
Wrap
Text File
|
1997-01-14
|
4KB
|
79 lines
// Convert a SCUL file to VRML
// Written by Bernie Roehl, November 1996
import java.io.*;
import java.util.*;
import hash.*;
public class scul2wrl {
public static void main(String args[]) {
try {
Segment seg = new Segment(new DataInputStream(System.in));
System.out.println("#VRML V2.0 utf8");
System.out.println("\n# Generated by SCUL2WRL\n");
System.out.println("Transform {");
System.out.println("\ttranslation " + seg.getPivotX() + " " + seg.getPivotY() + " " + seg.getPivotZ());
System.out.println("\tchildren [");
System.out.println("\t\tShape {");
System.out.println("\t\t\tappearance Appearance { material Material { emissiveColor 1 1 1 } }");
System.out.println("\t\t\tgeometry IndexedLineSet {");
// gather the vertices
Vector coordinates = new Vector();
for (int i = 0; i < seg.getNumberOfSplines(); ++i) {
Spline spline = seg.getSpline(i);
for (int j = 0; j < spline.getNumberOfControlPoints(); ++j) {
ControlPoint cp = spline.getControlPoint(j);
if (cp.isAttached() == false)
coordinates.addElement(cp);
}
}
// and emit them
System.out.println("\t\t\t\tcoord Coordinate {");
System.out.println("\t\t\t\t\tpoint [");
for (int k = 0; k < coordinates.size(); ++k) {
ControlPoint pt = (ControlPoint) coordinates.elementAt(k);
System.out.println("\t\t\t\t\t\t"
+ pt.getX() + " " + pt.getY() + " " + pt.getZ()
+ " # " + pt.getCPID());
}
System.out.println("\t\t\t\t\t]");
System.out.println("\t\t\t\t}");
System.out.println("\t\t\t\tcoordIndex [");
for (int i = 0; i < seg.getNumberOfSplines(); ++i) {
Spline spline = seg.getSpline(i);
int firstpoint = 0;
boolean lastlooped = false;
System.out.print("\t\t\t\t\t\t");
for (int j = 0; j < spline.getNumberOfControlPoints(); ++j) {
ControlPoint cp = spline.getControlPoint(j);
lastlooped = cp.isLooped();
while (cp.isAttached())
cp = seg.findControlPoint(cp.getAttachedCPID());
int n = coordinates.indexOf(cp);
System.out.print(n + " ");
if (j == 0)
firstpoint = n;
}
if (lastlooped)
System.out.print(firstpoint + " ");
System.out.println("-1");
}
System.out.println("\t\t\t\t]");
System.out.println("\t\t\t}");
System.out.println("\t\t}");
System.out.println("\t]");
System.out.println("}");
}
catch (IOException e) { System.out.println(e); }
catch (HashSyntaxException e) { System.out.println(e); }
}
}