ccFactory        

the component class Factory

       

getting started with the x3dSnap© compiler

 

this information describes how to compile and view SDK examples using the x3dSnap compiler.

Minimum Requirements

  • Host Platform
    • MS Windows NT/98/ME/2000/XP operating system with minimum 64 Mb system memory.

    • cxc executable

    • VRML (.wrl) source, including all source and resource files referenced by URLs ( Inline nodes, image textures, etc.).

  • Target Platform
    • Operating System supporting OpenGL (MS Windows, HP UX, Irix, Solaris, AIX, LINUX)

    • an ANSI C compiler

    • GLUT utitlity libraries (optional, needed for main routine & application window, see GLUT download page for details)

VRML to ANSI C to Binary
Let's start with the following world definition. Locate the VRML world definition sgi.wrl in the SDK archive (see download compiler).  Before the VRML source file can be successfully compiled, it is important that a copy of all constituent files contributing to the world definition are locatable on the client machine.  This means all Inline node definitions and texture files must be present. 

 

#VRML V2.0 utf8

DEF ROOT Transform {
  children [ 
    DEF Direct01 DirectionalLight {
    intensity 0.8
    direction -0.1808 0.5368 0.2994
    }
    DEF Direct02 DirectionalLight { direction   0.3057 -0.6715 -0.5201 }
    DEF boden-ROOT Transform {
    children [ Shape {
      appearance Appearance
        material DEF M04 Material {
          diffuseColor 0.7059 0.7765 0.7882
          shininess 0.4
        } }
      geometry DEF boden-FACES IndexedFaceSet {
        coord DEF boden-COORD Coordinate {   
        point [ 38990 0 -46140, -38990 0 -46140, -38990 0 46140, 38990 0 46140 ]
        
         °
         °
         °

figure 1.1 - VRML source file SGI.WRL

 

figure 1.2 - OpenGL Rendering of SGI.WRL

Invoking the command line compiler with the source and target parameters starts the translation process:  cxc [source.wrl] [target.c]

 

cxc sgi.wrl sgi.c
cxc 1.0 for Win32 Copyright (c) 2002 ccFactory

parsing input file [sgi.wrl]
[message] : pass 0 begin
[message] : pass 1 begin
[message] : creating texture coodinates
[message] : creating vertex data
[message] : creating color data
[message] : creating view matricies
[message] : compiling texture images/saeulen.jpg
[message] : compiling texture images/m_space.jpg
[message] : compile complete
0 error(s) 0 warning(s) encountered.

 
 

figure 1.3 - sample compile output

 

Compile process

The compiler makes three passes over the scene graph during code generation.  The first pass locates all lighting nodes and translates them into the appropriate matrix transformations and GL lighting calls. The second pass is the main translation pass. The code generator walks the scene graph producing a "snapshot" of VRML world in OpenGL.  The final pass is the blending pass for transparent objects.  If a geometry node is bound to a transparent material node, it will be rendered in the final pass once all opaque objects have been handled. This ensures that translucent polygons in front of opaque polygons are correctly composited.

The draw_model() function

Once the the projection and view matrices have been established, the draw_model() function can be called to render the model defined in the VRML world.  Nodes that have been re-used via the DEF/USE mechanism are packaged into a separate functions to mirror the reuse in the source code.  The beginning of each node translation is demarcated with a comment, showing the type and name of the node before its implementation.  Control is returned to the calling function with all OpenGL state variables preserved.

Examining the compiled world

If the target platform is "GLUT enabled", the compiler can be opted to generate a main routine with glut callback functions to make examining the world easier. Simply drag the mouse over the rendered world to rotate the model along the Y and X axis.

ChangingViewpoints

Each viewpoint node in the world definition describes a camera position and orientation.  These nodes are collected as viewing matrices in the compiled code and can be accessed by the global viewpoints array.

/*
* set_viewpoint
*/

void set_viewpoint(void)
{
  
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  /* turn on headlight */
  glLightfv(GL_LIGHT0, GL_AMBIENT, v4f_table[0]);     /* <0, 0, 0, 1> */
  glLightfv(GL_LIGHT0, GL_DIFFUSE, v4f_table[1]);     /* <1, 1, 1, 1> */
  glLightfv(GL_LIGHT0, GL_SPECULAR, v4f_table[1]);     /* <1, 1, 1, 1> */
  glLightfv(GL_LIGHT0, GL_POSITION, v4f_table[2]);     /* <-0, -0, 1, 0> */
  glEnable(GL_LIGHT0);
  /* load bound viewpoint */
  glLoadMatrixf(viewpoints[0]);

}

figure 1.4 - set_viewpoint function loading viewing matrix


If the GLUT wrapping code was generated, simply right click on the main window to choose a new viewpoint.  All viewpoints defined in the VRML world definition are converted to 16x16 viewing matrices and can be loaded immediately into the GL_MODELVIEW matrix.

figure 1.5 - switching viewpoints via right mouse click

 
       

mailto:info@ccfactory.com

Productivity through component-oriented software development