COMPRESSION

Nathan J. Strange (strange@physics.purdue.edu)
Tue, 30 May 95 19:25:12 EST


I came up with the following algorithm to compress VRML files
I have hand-implemented it on a few smal .wrl files and had the
resulting file be about 1/4 the size of the original file

I am currently writing a C program to implement it but I have
been busy of late, and I thought I might as well send it out
to see what y'all think of it...

* Change header from #VRML V1.0 ASCII to #VRML V1.0 CONDENSED

* Chuck all the comments

* Convert all letters not in " " to lower case

* Repace all "nodename {" sets with a two CAPITAL letter sequence
this allows us about 676 commands, which should do for a while
The nodes are converted in alphabetical order to AA..AZ, BA..BZ, etc.
So AA = asciitext{, AB= cone{, etc...

* Each field name following a node name is replaced with a single
capital letter representing the fields given in the order in the
spec.... These are only 1 capital letter long, and a capital letter
cannot follow it, if that case should ever arise that two captil
letters would be in sequence and NOT represent a node they can
be seperated by a # , but I am convinced that this case will not arise

SO an example:

ABAallB1C2}
would be:

Cone {
parts all
bottomradius 1
height 2
}

A=parts, B=bottomradius, C= height in the context of cone (AB) because
that's the order given in the spec...

* All SFBitMask types are converted to numbers

so the types for for Cone{ parts would be
1=SIDES 2=Bottom 3=All

* Get rid of all leading zeros, 0.9 becomes .9

* Get rid of all whitespace (spaces and returns)
except for that in strings (between " ") and spaces between two
numerals...

All this outputs normal text... These files can be zipped by GZIP
to get basically the same compression ratio as the original VRML file
(this is an estimate from my experiments)

Example:
**************************

#VRML V1.0 ascii
Separator {
DirectionalLight {
direction 0 0 -1 # Light shining from viewer into the scene
}
PerspectiveCamera {
position -8.6 2.1 5.6
orientation -0.1352 -0.9831 -0.1233 1.1417
focaldistance 10.84
}
Separator { # A red sphere
Material {
diffusecolor 1 0 0
}
Translation { translation 3 0 1 }
Sphere { radius 2.3 }
}
}

************************
Becomes:
************************
#VRML V1.0 condensed
AXAFD0 0-1}ASA-8.6 2.1 5.6B-.1352-.9831-.1233 1.1417C10.84}AXAMB1 0 0}
BHA3 0 1}AZA2.3}}}
************************
The line break was added just to make it readable...

Well that's my idea... whaddaya think?

-Nathan