vrml
Intro
Parser
Source
Graphics Interpretation of VRML
TODO
VRML parser implemented. A hierarchical parser was built to read VRML data structures.
The parser uses tokenizer. I first built it with a vector which took so long to process a file I thought there was a bug in the parser, only when I got time to look at it (6 months later) did I find that there was nothing wrong with the parser code.
I found this out by rewriting the tokenizer. Further I did not cleanly separate my development code from the application because of time constraints, and paid a price. Instead of debugging in the correct area I was loading the vrml file and seeing it graphically. When I separated testing the tokenizer from the parser things became easier, resulting in much faster testing time.
The lesson for me is to do the job properly in the first place, it would have worked and saved my time. Even though it appeared like extra work.
However this is just getting them in - it is another matter altogether to implement features.
In 3D graphics everything is triangles. Well maybe
lines too. With this philosophy I choose to
write a general geometry format for triangles.
vrmlshape was the result.
A limited subset of VRML of points with normals was supported. ie the IndexedFaceSet node. Here is typical output from Rhino a 3D graphics modeling package.
I was asked how fast does this go (displaying the VRML ) which I replied as fast as you can draw triangles. Well this is not the honest truth, no attempt to optimize shapes with the same attributes was made. Rhino exports crap by writing quads as a vrmlshape, for models with hundreds of quads, with a one to one correspondence between the shape and the graphics shape each time the shapes color is written...
So its in beta stage but with a little effort I will write the optimization and it will go many times faster for that situation of exported VRML being crap. If the VRML is already good then it will go fast. The other obvious possible optimization is to use an array calls to transfer the data down the graphics pipeline. <TODO> create an experiment to time the difference, use lots of triangles to stuff the pipeline and rotate the shape n times.
#VRML V2.0 utf8
Shape { # triangle mesh
appearance Appearance {
material Material {ambientIntensity 0.41176 diffuseColor 0.41176 0.41176 0.41176 specularColor 1 1 1 emissiveColor 0 0 0 shininess 0.98 transparency 0}
} # appearance
geometry IndexedFaceSet { # triangle mesh
ccw TRUE
convex TRUE
solid FALSE
coordIndex [
3,2,1,-1,2,0,1,-1, ] # 2 triangles
coord Coordinate { point [
419 -122 -255.5,595 -122 -255.5,419 -118 -255.51,595 -118 -255.51
] } # 4 coord rmesh.points
normal Normal { vector [
0 0.002688 1,0 0.002688 1,2.9843e-019 0.002688 1,2.9843e-019 0.002688 1
] } # 4 normal vectors
} # geometry
} # triangle mesh
$./main file=head.wrl winding=true
See the triangles winding. If two sides match in color
then there is a problem.
$./main file=head.wrl
Normal viewing of .wrl file.
$./main seenormals=true file=head.wrl
See the normals.
$./main seenormals=true file=head.wrl winding=true
Material
{
ambientIntensity 0.3
diffuseColor 0.1 0.2 0.3
emissiveColor 0.0 0.0 0.0
shininess 0.3
specularColor 0.0 0.0 0.0
transparency 0.0
}
Shape
{
appearance Appearance
{ ...
}
geometry IndexedFaceSet
{ ...
}
}