Click here to Skip to main content
15,879,535 members
Articles / Desktop Programming / MFC
Article

VRMLTest - Full VRML 1.x parser and partial viewer

Rate me:
Please Sign up or sign in to vote.
4.58/5 (9 votes)
6 Feb 2000 129.6K   7.4K   42   15
VRML parser and Partial viewer
  • Download demo executable - 46 Kb
  • Download project source - 118 Kb
  • Online documentation - 14 Kb

    Image 1Image 2

    This article presents:

    • CVRMLScene a "Scene graph" and all the associated classes, including a full VRML 1. x parser.
    • COGLCanvas my own YAOWM (yet another OpenGL wrapper for MFC ;)).
    • CVRMLCanvas a descendant of COGLCanvas a sample application that renders a limited set of VRML primitives using OpenGL. Samples for the kind of models supported by this canvas can be freely downloaded at http://www.rosl.com (site which I have nothing to do with, at least yet ;)). The .wrl files included in .zip files are from that URL (except allnodes.wrl).
    • vrmltest, the sample application of all the above and which screenshots you can see at the top.

    Index

    Introduction

    I'm developing a CAD-alike environment and debugger for industrial robot programming as the final project of my five year degree in Computer Science. It has to resemble up to some extent Robotech's Workspace . One of its required capabilites is to load VRML models of the robots, so hence this code.

    This article is far from exhaustive but you can peep at the documentation of all the classes, which is autogenerated from the code with Eric Artzt's Autoduck, an incode documentation tool (that's why the weird comments you see in the code). I plan to release an article on this autodocumentation tool some day (or another).

    Full VRML 1.x parser

    I'm not going to say too much about this parser, except that I'm very proud of it :*).

    The main class is CVRMLScene, where resides the VRML file parsing and loading capabilities. All the other classes define the structure needed to traverse the built scene graph (and do whatever you want with it).

    The parser is done with Bison and Flex, so if you modify the sources, take care not to modify the autogenerated files vrml1.cpp (Flex generated) or vrml1_tab.cpp (Bison generated). Only if you don't have at range Bison or Flex, or if you don't want to deal with those beasts, it would be convenient to modify them directly.

    Just to state it clear: you don't need Bison and Flex at all to use and compile this classes, only if you want to modify vrml.l (Flex's token definition file) or vrml.y (Bison's grammar) you will need to regenerate vrml1.cpp and vrml1_tab.cpp. Anyway, only because of bugs you should need to modify those files, as the main functionality of these classes reside in VRML.cpp file.

    I've based the design of the parser in SGI's VRML 2.x parser, which is one of the simplest and smartest things I've seen on the matter: The parser only knows about simple types of VRML (SFxxxx and MFxxxx) and definition nodes, and knows nothing about the nodes themselves. Then it loads a library of default nodes (defined in a totally compliant VRML file, which has the peculiarity that it only defines nodes and not instances of them), and presto!, you are ready to load any VRML 1.x compliant file.
    The included file allnodes.wrl is that library of standard VRML 1.x nodes. The normal operation is to load that library as if it was a normal VRML file (and it IS!), so standard nodes get defined, and then load your desired VRML file/s (you can load as many VRML files as you want in the same scene).

    The error detecting capabilities of this class are quite weak, it only returns FALSE if file is invalid, and I wouldn't find it strange if it hanged with corrupt VRML files :-m.

    The parser has two non-stantard properties: the VRML file needn't to be a unique VRML node (there are plenty of VRML files that have more than one root node), and any node (and not only group nodes) can have children nodes. The latter is a side effect of not knowing beforehand the standard nodes (anyway, this is VRML 1.x standard's fault, because user defined nodes can't mark in any way if they have children nodes or not ... VRML 1.x is quite a dumb language, if I may say it: it's not LALR, and some hacks are needed to parse it with Bison).

    MFC OpenGL wrapper

    This wrapper exports the overridable function Render, so descendants only have to implement that function and this class handles everything else:

    • interaction with mouse: pan (right button), zoom (left button, moving up) and rotation (both buttons)
    • wireframe, solid and smooth rendering
    • lighting (it sets what VRML calls a headlight)

    Someday it will support switching between orthographic and perspective (is just adding the methods, right now the perspective code is commented) and OpenGL selection modes.
    Oh, yes, I almost forget it: the mouse buttons get sticked sometimes.

    VRML partial viewer

    The viewer CVRMLCanvas is based on the classes COGLCanvas and CVRMLScene. It takes a simple CVRMLScene and renders it the best it can ;).

    The supported nodes are Material, IndexedFaceSet and Coordinate3.
    As I said above, you can find free sample supported VRML files at the robots library of Robot Simulations Ltd. and some of them are included in .zip files.

    Sample application

    In the directory ./wrl of the .zip you'll find sample files. Just load one of them and play with it.

  • License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    Written By
    Spain Spain
    This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

    Comments and Discussions

     
    QuestionLicense Pin
    byte_270212-Jan-12 3:57
    byte_270212-Jan-12 3:57 
    GeneralAlpha Value Change Pin
    Digvijay Gupta25-May-07 23:33
    Digvijay Gupta25-May-07 23:33 
    GeneralRe: Alpha Value Change Pin
    hustfzt29-Jul-11 21:45
    hustfzt29-Jul-11 21:45 
    QuestionVRML Pin
    justvish16-Sep-06 19:17
    justvish16-Sep-06 19:17 
    GeneralMissing file vrml1.y Pin
    lebman17-Mar-06 8:46
    lebman17-Mar-06 8:46 
    GeneralRe: Missing file vrml1.y Pin
    John Ulvr16-Nov-06 4:10
    John Ulvr16-Nov-06 4:10 
    GeneralRe: Missing file vrml1.y Pin
    James Lee10-Jul-07 22:04
    James Lee10-Jul-07 22:04 
    Generalclose application Pin
    huyhoang21-Oct-04 6:55
    huyhoang21-Oct-04 6:55 
    QuestionHow to run 2 different(or same) OpenGL objects in one DialogBox? Pin
    Awerter5-Jun-04 21:46
    sussAwerter5-Jun-04 21:46 
    QuestionTransform is not supported? Pin
    w_ting8-Jan-04 21:53
    w_ting8-Jan-04 21:53 
    GeneralQuestion Pin
    Selevercin27-Nov-02 10:31
    Selevercin27-Nov-02 10:31 
    GeneralRe: Question Pin
    Rick York27-Nov-02 11:26
    mveRick York27-Nov-02 11:26 
    Generalproblem Pin
    xujun9-Apr-02 2:04
    xujun9-Apr-02 2:04 
    GeneralProblems Pin
    Steve Carleton17-Feb-00 15:45
    sussSteve Carleton17-Feb-00 15:45 
    The only VRML file that worked was ERV.WRL
    Maybe the zoom factor is way out of range?
    GeneralRe: Problems Pin
    Antonio Tejada Lacaci17-Feb-00 22:36
    Antonio Tejada Lacaci17-Feb-00 22:36 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.