VRMLConvert Documentation


Description

VRMLConvert is a Mathematica package that converts Mathematica 3D graphics into VRML format, and writes it to a .wrl file. This file can be viewed using a variety of VRML browsers. You can navigate around and through your graphic. This does not require a Web server.

Examples

Even if you don't have a copy of Mathematica available, you can still look at these examples.

Installation

Installing VRMLConvert

You can download VRMLConvert from ftp site at the Mathematics Department, Indiana University of Pennsylvania, U.S.A. VRMLConvert will also be made available on MathSource.

Configuring your Web Server

If you want to distribute your VRML files over the Web, you can do so by configuring your server to distribute .wrl files as x-world/x-vrml MIME types.

Usage

Examples

Here is an example of how you can use VRMLConvert to convert a graph.

sinplot = Plot3D[Sin[x y], {x,-Pi,Pi}, {y,-Pi,Pi}]
Needs["VRMLConvert`"]
VRMLConvert[sinplot, "sine.wrl",
  PlotLabel -> "This is Sin[x y]",
  SurfaceMaterial -> SurfaceColor[RGBColor[0.5, 0.5, 0.0]]
]

VRMLConvert Options

VRMLConvert has quite a few options primarily because I tried to incorporate as much of Mathematica's rich 3D graphics capabilities as I could.


Advise on Using VRMLConvert

ViewPoint and BoxRatios

The perspective of the VRML image will not be quite the same as the perspective of the Mathematica graphic. Mathematica performs a series of transformations on its Graphics3D objects before it plots them on the screen. The last step is to expand the projected 2D image to fill the display area. VRML browsers perform their own projections into 2D, so VRMLConvert does not do any projections nor an expansion to fill the display area. VRML uses a scaling equivalent to Mathematica's BoxRatios -> Automatic. Some VRML graphs will appear radically different from the corresponding Mathematica graphs. This is likely to happen when

LightSources

The default Mathematica light sources are all in front of the image, leaving the far side of the image dark. If you want the all sides to be illuminated, then include some light sources with negative coordinates, for example,
  LightSources -> {{{1.,0.,1.},RGBColor[1,0,0]},
                   {{1.,1.,1.},RGBColor[0,1,0]},
                   {{0.,1.,1.},RGBColor[0,0,1]},
                   {{-1,-1,-1},RGBColor[1,1,1]}}

Inline VRML worlds

If you want to use a VRMLConvert-generated world inline in another world and if you want the inline world to inherit the properties of the other world, then you may want to exclude the camera, lights, and/or material surface properties in the VRMLConvert-generated world. You can turn off these properties using the options Camera -> False, Lighting -> False, and Surface -> False, respectively.

Future Needs

Axes

It sure would be nice to have the option to include axes. Anyone interested in taking on the challenge?

Mathematica's 3D Text

Mathematica's 3D Text primitives are placed in the correct location in the 3D VRML scene, but VRMLConvert doesn't try to orient the text in any particular direction. It should be oriented so that it faces the initial camera position.

VRML File Size

There are two things that can be done to reduce the size of the VRML file.
  1. Reduce the number of digits written for each number. FortranForm prints quite a few digits. Here is my first attempt at reducing the number of digits, but as you can see, it doesn't always work. There must be a better way!

    In[1]:=

      CompactForm[a, precisiongoal_Integer] :=
        Module[{digits,scalefactor},
          digits = Log[10, Abs[a]];
          scalefactor =
            10^(Sign[digits] Floor[Abs[digits]] - precisiongoal);
          FortranForm[N[ Round[a/scalefactor] scalefactor ]]
        ];
      CompactForm[.0000000005325436656768678,3]
      CompactForm[53254366567686.78,3]
    

    Out[1]=

      5.33e-10
      5.325000000000001e13
    

  2. Each polygonal vertex only needs to be listed once. VRML allows you to list all of the points once in a Coordinate3 construct and then refer to each point multiple times to form polygons in an IndexedFaceSet construct. Currently, VRMLConvert lists all of the vertices for each polygon. Thus, most points are listed 4 times. File sized could be reduced by almost a factor of 4 if someone modifies VRMLConvert to remove the redundant points. If the user chooses to include line segments along the edges of polygons, then line segments that form the edge of two polygons are drawn twice. This reduncancy could also be eliminated. Of course, all of this would add a significant amount of time to VRMLConvert's runtime. So, if anyone wants to implement this, I suggest that it be added as an option. Then users could choose fast runtimes for files that will be used locally and they could choose small file sizes for files that will be widely published on the Internet. The option might be Optimize -> Speed or Optimize -> Size.

Speed of VRMLConvert

I haven't done any tests of VRMLConvert to see if it can run any faster. So I'm sure that its speed can be improved. A ParametricPlot3D graphic with a 15x60 grid required 45 seconds to convert to VRML on my PowerMac 6100/66. If you have some time to do some experimentation, you might want to concentrate on the section that creates the polygons.

Maintained by H. Edward Donley