Last Modified: 11/07/99
[Previous] [Home] [Next]

VRML by Hand or Program



Hand Coded VRML

You can easily create VRML code by hand, or through a program such as Perl, if you know the syntax. You need only preface your code with the right header, give the resulting file the extension .wrl, and drag it over any browser window (if you have Cosmo Player) to see the result. Perhaps the easiest way to do this is:
  • Use a VRML program such as V*RealmBuilder to create samples of the types of objects that you wish to display
  • Use a text editor to view the resulting .wrl file
  • Use the syntax that you see as a template for hand or program generated code
  • Concatenate a valid header to your file and give it the extension .wrl
The tricky part is the valid header. VRML seems to be very picky about the header in terms of return and newline characters. The following is an expanded view of a valid VRML header that shows each character. Note that return and newline characters are represented by \r and \n , respectively:
 #  V  R  M  L     V  2  .  0     u  t  f  8 \r
\r \n \n  #  C  r  e  a  t  e  d     w  i  t  h
    V  -  R  e  a  l  m     B  u  i  l  d  e  r
    v  2  .  1 \n  #  L  i  g  o  s     C  o  r
 p  o  r  a  t  i  o  n \n  #  w  w  w  .  l  i
 g  o  s  .  c  o  m \n \n
So, lets assume that you have obtained a valid VRML header, say hdr.wrl, and have created a syntactically correct program body named body.wrl. You create a valid VRML file, named, say, my.wrl, as follows:
unix% cat hdr.wrl body.wrl > my.wrl

A Perl VRML Program

Here are two Perl programs that convert raw 3D data sets into VRML code that can be viewed in 3D with Cosmo Player. The first program, phase1, prepares raw 3D data for processing by the second program, phase2, which actually generates the VRML code. The procedure is described in this writeup. These programs should run on any Unix system.

The system works like this:

  • Obtain a raw data file that has columns of numbers representing potential X-Y-Z coordinates. To make it specific, lets call it heart.raw for the raw data file that might contain data about heart rates.
  • Create a special file named heart.spc that specifies information about the data file, in terms of what columns are to be used, the representation of the data points, the description of the axes, and any title or legend information. At this point you have two files heart.raw and heart.spc.
  • Execute the Perl programs in this sequence:
    unix% phase1 heart.spc heart.raw heart.data 
    unix% phase2 < heart.data > heart.wrl           
    
    and then drag the heart.wrl file over any browser window. Note that phase1 reads in the files heart.spc, heart.raw and writes the file heart.data, whereas phase2 reads heart.data and creates heart.wrl, the final VRML file.
In practive, you usually do some minor hand editing between phase1 and phase2. For example, you may display most of the points as size 4 in Blue, but select a special point to be size 7 in Yellow, for emphasis. Or you may wish to run phase1 several time to extract different data sets and then combine them into one data set for processwing by phase2.

Here are a set of sample data files taken from SAS along with the VRML output that can be viewed with Cosmo Player. The files are:


[Previous] [Home] [Next]