Subject: parser available
From: Ben Elgin <elgin@cs.unc.edu>
To: comp238@cs.unc.edu


This mail has 3 sections: compiling the parser
                          hooking up to your code
                          why use this?
                          other files

****


I have made the rayshade parser (yacc and lex files) as well as more
header info than you could possibly want available.
It can all be found here:

 ~elgin/public/comp238/rayParser/

So what do you do with this mess?  Well, the basic commands you'll
need (stripped from the rayshade makefile) are

 bison -y -d yacc.y
 lex -t lex.l > lex.c

This will give you lex.c and y.tab.c, which you then use as normal c
code.

Note that bison lives at:

  /usr/local/contrib/moderated/bin/

and lex lives at 

  /usr/ccs/bin/

(anyone know what the heck /ccs/ is?  I had to add it to my path to
get both lex and ar, which the rayshade makefiles use.)

Also note I have heard yacc and lex interpreters are easily available
for Windoze platforms, but don't have a pointer just yet.


****


So now you can compile yacc, how does it link into your code?
Let's start with an example.

If we search the yacc file for "Sphere" at the beginning of a line we
find:

Sphere          : tSPHERE OptSurface Expr Vector
                {
                        $$ = GeomSphereCreate($3, &($4));
                        if ($$)
                                $$->surf = $2;
                }
                ;


So the parser is looking for Sphere followed by a (optional) surface
name, a float[1] and a vector.  It then calls the
GeomSphereCreate(r,pos) function, which can be found in sphere.h.

So you could hook this up to your code either by keeping the rayshade
.h files and implementing the GeomSphereCreate function, or just
inserting your own function name into the yacc file.

[1] How did I know "Expr" was a float?
"Float d;"              (line 102 of yacc.y)
"%type <d> Expr"        (line 137)


***


So why use this huge infrastructure?

Jef made some good points in that its easy to write a *simple* ASCII
scene parser by hand.  The main advantage of a pre-written parser is
for complex scenes, and those usually have objects with tex coords,
which we still haven't found a way to import.

Well, we can still import complex objects without texture (and indeed
we could define a texture for the by editing the resulting ASCII
file).  I'll bet we could find an OBJ model of the old well, which
might make a nice test subject.

Another big win is the yacc parser's ability to name and re-use
surfaces and groups of objects.  This can make medium-complexity
scenes much easier to build and edit.

(Personally, I'm half-convinced.  We can talk about it with
Prof. Lastra more in class on Monday.)


***


Meanwhile, I dumped some other files in /rayParser/ to help get you
started with the rayshade format:

 quickref.txt   //defines the rayshade format (ignore the flags)

 balls.ray      //two simple example scenes in the format
 solids.ray

For more complex examples, see
<http://www.cs.cmu.edu:80/afs/cs/misc/rayshade/all_mach/omega/doc/Examples/rayimages.html>

And if you need more info, don't forget the main rayshade page at
<http://www-graphics.stanford.edu/~cek/rayshade/>
which has full PDF docs, etc.

Also in the same folder is:

 obj2ray.c      //a simple .OBJ -> .ray converter.


***

-- 
// Ben Elgin     elgin@cs.unc.edu          http://www.cs.hmc.edu/~belgin \\
| UNC Chapel Hill, Dept of Computer Science          ^_^   Anime Forever! |
\\ Office: 343 Sitterson, 962-1782  Home: 180 BPW Club Rd C-11, 960-0764 //

     "listen: there's a hell of a good universe next door; let's go"