[프로그램] VRML2GL parser for OS/2 2.x, 3.0, 4.0 & WIN32.

마루 0 15,460 2008.04.29 09:31
________________________________________________________________________________

               VRML2GL parser for OS/2 2.x, 3.0, 4.0 & WIN32.
________________________________________________________________________________

Version 1.2 (Freeware/Shareware)

A programmers tool that convert Virtual Reality Markup Language (VRML) files
to OpenGL source code.


Written by Leigh McRae.

(C) Copyright 1997, Now Enterprises.
All rights reserved.

________________________________________________________________________________

INTRODUCTION
________________________________________________________________________________

   VRML2GL was written initially with myself in mind. I was learning how to write
OpenGL code so I developed a quick no brains tool to generate models from VRML
meshes. This allowed me to explore many different areas of OpenGL without having
to look worry over models. Along the way I also made a small library of OpenGL
related functions that I have added to this package. This package is Freeware
with an option to regisitered for $20.00. The regisitered version is more
complete and supported. I might also be able to add some features that regisitered
users may want as long as the feature doesn't require doing too much major code.

________________________________________________________________________________

What does VRML2GL not do?
________________________________________________________________________________

VRML2GL only does VRML v1.0 files. The following VRML v1.0 nodes (tags) are not
implemeanted:
                  AsciiText, FontStyle, Info, LOD, WWWAcnhor and WWWInline.

Also VRML files that have non-simple polygons are supported (undefined results).

   ***** Loop building (see below) is only for the registered version. *****

NOTE: that these restrictions are reasonable considering this tool was not meant
to create final models. Although the models produced are accurate and reasonably
fast there are many optimization that could be done (see Optimizations). This
tool was made to be paste only two lines of code into yours.
________________________________________________________________________________

What does VRML2GL do?
________________________________________________________________________________

VRML2GL does all other nodes for VRML v1.0. It is hoped that you will be able
to simply run the parser and and two lines to you OpenGL code to get the model
up and going. The parse even supports texture mapping. Note that texture mapping
primitives is best as it doesn't require texture coordinates.
________________________________________________________________________________

VRML2GL Configuration FIle                  
________________________________________________________________________________

   VRML2GL uses a configuration file to set some user switches. The file must
be called VRML2GL.cfg. The file is simply a text file that you can edit. The
config file also must be in the working directory. The VRML2gl profile uses
the same rules as VRML. An explanation of the profile is as follows:

FUNC_PREFIX       SFString    # Names functions 'void <SFString>X29( void );'.
FILE_PREFIX       SFString    # Names files '<SFString>X29.c'.

SEPARATOR         SFBool      # TRUE -> 'Separator' is unchanged.
                              # FALSE -> 'Separator' = 'SeparatorTransform'.
                              Treat 'Separator' AS 'TransformSeparator'. This
                              was added as I felt that many objects only really
                              need (and maybe mean) to save position. With
                              'Separator' the parser must save whole meshes and
                              many lists. This is huge over head that cause the
                              parser to slow down and the source code produced
                              to be slightly larger.

LIGHTS_OFF        SFBool      # TRUE -> lights get shut off after 'Separator'.
                              # FALSE -> lights remain on once turned on.
IGNORE_LIGHTS     SFBool      # TRUE -> all light nodes are ignored.
                              # FALSE -> generate lights in the source code.
GL_COLOR          SFBool      # TRUE -> use glColorMaterial(); and glColor3f();.
                              # FALSE -> use regular mglMaterialfv(); calls.
BUILD             SFEnum      # STATIC -> plot commands as received.
                              # LOOP -> use loops and arrays to build objects.
                              Loop or static building of meshes. Have an array
                              of vertices and use a loop to plot the mesh (LOOP)
                              or use many vertex3f(); calls (STATIC). Actually
                              you can set the parser to both (LOOP only for meshes
                              with more than x vertices).

MIN_LOOP          SFLong      # This is the minimum size mesh to LOOP.
PRECISION         SFLong      # Number of digits to the right of the decimal place.

AMBIENT           SFBool      # FALSE -> ignore ambient materials.
DIFFUSE           SFBool      # FALSE -> ignore diffuse materials.
SPECULAR          SFBool      # FALSE -> ignore specular materials.
EMISSIVE          SFBool      # FALSE -> ignore emissive materials.
TRANSPARENCY      SFBool      # FALSE -> ignore transparency materials.
SHININESS         SFBool      # FALSE -> ignore shininess materials.
                              Ignore one or more material types. This is useful as
                              I have found that the SHININESS is usually too low.
                              Also if you use glColorMaterial(); and the DIFFUSE
                              is different from AMBIENT then you will get two
                              glColor3f(); because the parser thinks its a new
                              color. In order to get around this you can ignore
                              either DIFFUSE or AMBIENT.

________________________________________________________________________________

Example: given a popular VRML file such as X29.WRL
________________________________________________________________________________

vrml2gl x29.wrl

Produces:

vglObjX29.h             - these are the main source and header files that call
vglObjX29.c               the rest of the source files.

vglObjCanard.c           - Note that each function is stand alone. This allows
vglObjCockpit.c           you to extract parts from scenes.
vglObjMfuse.c
vglObjNose.c
vglObjRfuse.c
vglObjVane.c
vglObjVertstab.c
vglObjWings.c

To use the new mesh you include the header file 'vglObjX29.h' and call the
function 'vglDrawX29();'. It is up to the user to set the makefile and make
sure any platform specific includes or defines are set.
NOTE: you must build the default 'glObjects.c' or supply your own in order
to support drawing of primitives. The functions used are as follows:

   void  glObjCube( float width, float height, float depth, int parts );
   void  glObjCylinder( float radius, float height, int parts );
   void  glObjCone( float radius, float height, int parts );
   void  glObjSphere( float radius, int parts );

________________________________________________________________________________

Trouble Shooting:
________________________________________________________________________________

1) Nothing shows up. This is most likely a focus problem. Look on my web page
   for a 'aux' frame work that allows you too try many things out.

2) Source generated is too big and won't compile. See Optimizations.

3) Materials don't seem to work. Some materials won't work for LOOP building
   simply because the code is more trouble than its worth. Use STATIC build.

4) The VRML file might have non-simply polygons.

5) Trace through to see if you have glFrontFace() set right. If this is set too
   GL_CW then you should reset it to GL_CCW when all clockwise meshes are
   finished.

6) Turn up the shininess factor in the source VRML file. It seems that this is
   always too low for my taste.

7) Are the Lights on? Use my function in the 'glObj.h' file to set the light
   positon.

   glObjSetLight( 0,                   /* Light number.               */
                  GL_FALSE,            /* Show lamp. Could be better. */
                  GL_TRUE,             /* Is positional.              */
                  0.0, 0.0, 0.0 );     /* Vector position.            */

________________________________________________________________________________

Optimizations:
________________________________________________________________________________

1) Create a display list for the main 'vglDraw' function when your program
   starts up. The just call the display list in your paint routine. The reason
   I chose not to use display lists is because I think it assumes too much. I
   found it to best to brake parts into functions (stand alone functions) and
   let you put the display lists in where you feel.

2) Remove empty functions. Functions like SceneInfo are usually empty. I guess
   I could have made sure that functions that are empty get parsed but I felt
   this was overkill (insert cop out here).

3) Play with the MIN_LOOP value. This STATIC to LOOP cut off can really reduce
   code size. Some files over use 'Seperator' for small meshes. Note that the
   file 'bop.wrl' is responsible for that feature.

4) If the code generate is too big be to compile then you can take the source
   VRML file and do some find and replaces. Look for any 'Seperator' nodes. For
   each 'Seperator' node (or the big ones) you want to change them to read
   'DEF x Seperator' where 'x' will be the object name (bop_1, bop_2, bop_3).
   What this will do is brake the mesh up into different files, as a new source
   file is only create for 'DEF' nodes. This problem is because the object has
   parts that were not named when create (or lost in some conversion).

5) Parse out some of the material that are redundant or not desired.

6) Try and remove some precision using the PRECISION value in the VRML2GL.cfg.
   Note that this could really ruine the model.

7) Remove some variable declarations that are not used and maybe redo the main
   variable declarations to suit your program.

8) If normal binding is PER_x_INDEXED then change the normal binding to PER_FACE
   too force the parser to generate normals via a function call. This makes the
   code way smaller but most likely not as nice looking as the original normals
   provided are for smooth shading.

Comments

Category
State
  • 현재 접속자 244 명
  • 오늘 방문자 1,457 명
  • 어제 방문자 1,308 명
  • 최대 방문자 11,402 명
  • 전체 방문자 2,851,300 명
  • 전체 게시물 3,149 개
  • 전체 댓글수 4,648 개
  • 전체 회원수 116 명

- 쇼핑몰 : Softbox
- 예전 문서 / Old docs
- FTP Server: http://ftp.hanmesoft.com
Facebook Twitter GooglePlus KakaoStory NaverBand