.GFX File Format Description
3D model/scene format based on .OBJ, .GOD, .ALC formats
A few new features (for your convenience) by Ge Wang
The .gfx (short for 'graphics') file format is used to describe/define
3D polygonal models, (both simple and composite), light sources, and scenes. it is an
ASCII format that is based on the .OBJ, .GOD, .ALC file formats, with new features for your
convenience and for added flexibility. You can use existing .OBJ files to define polygonal
models that can be used in the .GFX format to construct larger, more complex models and
scenes.
The .gfx file format allows you, at the highest level, do the following:
- OBJECT definitions - each of which can be one of the two following types:
SIMPLE - this defines a rigid, polyhedral, 3D model using (by default)
the .OBJ file format. This allows you to define polygon faces using vertices,
texture coordinates (optional), normals (optional), and colors (optional). There
is no limit on the complexity of this type of OBJECT as long as it is a rigid model.
The syntax is as follows:
OBJECT name SIMPLE
FILE filename
END
This defines a (SIMPLE) OBJECT with the unique identifier name, and
where filename is the name of a .OBJ file where the 3D model
data is stored. Please review the .OBJ format specifications
for details on .OBJ files. Alternately, you directly specify the content of the .OBJ file
inline in the OBJECT definition, as follows:
OBJECT name SIMPLE
v 0 0 0
v 1 0 0
v 1 0 -1
v 0 0 -1
vt 0 0
vt 1 0
vt 1 1
vt 0 1
vn 0 1 0
vc 0.4 1.0 0.4 1.0
f 1/1/1/1 2/2/1/1 3/3/1/1 4/4/1/1
END
The OBJECT defined in this method should be identical in result
as specifying a file name containing the same 3D data.
COMPOSITE - this defines a composite 3D model using
existing OBJECTS (both SIMPLE and COMPOSITE), built-in GLUT/GLU primitives,
and modeling transformations. A composite object definition begins the same
way as a simple object definition, except the keyword 'SIMPLE' is replaced by
'COMPOSITE'. The following commands are recognized inside a composite object
definition:
- TRANSLATE tx ty tz
Translate the subsequent subobjects by tx ty tz
- ROTATE angle lx ly lz
Rotate the subsequent subobjects by angle with respect to lx ly lz
- SCALE sx sy sz
Scale the subsequent subobjects by scaling factors sx sy sz
- COLOR r g b a
Specifies the color for subsequent objects. the alpha component a,
if not given, defaults to 1.0.
- SUBOBJ name
Draw a previously defined object (simple or composite) called name.
This object may be previously defined in the same file or in a file that
the current file includes by using the INCLUDE command.
- GLU shape parameter(s)
Draw a GLU primitive. parameter(s) depend on the shape given.
the valid shapes are:
- SPHERE radius slices stacks
- CYLINDER baseRadius topRadius height slices stacks
- DISK innerRadius outerRadius slices stacks
- PARTIALDISK innerRadius outerRadius slices rings startAngle sweetAngle
- GLUT shape parameter(s)
Draw a GLUT primitive. paramter(s) depend on the shape given.
the valid shapes are:
- SPHERE radius slices stacks
- CUBE size
- TORUS innerRadius outerRadius nsides rings
- ICOSAHEDRON
- OCTAHEDRON
- TETRAHEDRON
- DODECAHEDRON
- CONE radius height slices stacks
- TEAPOT size
- PUSH
Saves a copy of current local transformations.
- POP
Restores the matrix saved by the previous PUSH command (and pops
the transformation stack). In a composite
object definition, there can be more PUSH commands than POP
commands (the extra PUSH commands should be implicitly handled at
the end of the definition). However, it is illegal to have more POP
commands than PUSH commands.
- SEPARATOR
Resets the local transformation to the state of the last PUSH
command (without popping it off the transformation stack) or, in the
case that the SEPARATOR does not occur between a PUSH
and POP, to the state of the local transformation at the beginning
of the current object definition.
LIGHT definitions (from .ALC format) can specified in one
of two ways - either read from a file or define inline in the current file (similar
to SIMPLE OBJECT definition). To describe a light source from file (a .LIT file):
LIGHT name
FILE filename
END
To describe a light source inline, simply put the content of the
.LIT file in the definition:
LIGHT name
AMBIENT r g b a
DIFFUSE r g b a
SPECULAR r g b a
CA ca_val
LA la_val
QA qa_val
END
AMBIENT, DIFFUSE, and SPECULAR specify the color properties
of the light. If any are omitted, the values default to (1.0 1.0 1.0 1.0).
CA, LA, and QA specifies the constant, linear, and quadratic attenuations
of the light respectively. If not specified, CA default to 1.0 and LA, QA
each default to 0.0
SCENE defines a scene with cameras, lights, and objects.
It can be thought of as a special type of COMPOSITE OBJECT, and in fact shares many
of the same commands. Since light objects and light, a scene requires a (unique) name,
There may be multiple scene definitions in a .GFX file. However, a scene cannot be
used as SUBOBJ inside a COMPOSITE OBJECT or another SCENE. The following commands
are recognized in a SCENE definition:
- LOOKAT ex ey ez lx ly lz ux uy uz
This specifies the camera location (ex, ey, ez), where it's looking at (lx, ly, lz),
and an up vector (ux, uy, uz).
- LIGHT name
Places light with the identifier name at the origin of current scene
transformation.
- The following commands are identical to COMPOSITE OBJECT commands, please
refer to composite objects specifications for details:
- TRANSLATE tx ty yz
- ROTATE angle x y z
- SCALE sx sy sz
- SUBOBJ name
- PUSH
- POP
- SEPARATOR
The following is a sample .GFX file:
INCLUDE myshapes.gfx
OBJECT quad SIMPLE
FILE quad.obj
END
OBJECT sphere_over_quad COMPOSITE
TRANSLATE -0.5 0.0 .5
SUBOBJ quad
SEPARATOR
TRANSLATE 0.0 1.0 0.0
COLOR .8 .8 0
GLUT SPHERE .25 16 16
END
LIGHT light_red
FILE light_red.lit
END
SCENE main
LOOKAT 0 2 5 0 1 0 0 1 0
LIGHT light_red 2 5 0 1
TRANSLATE 0 0 -2
SUBOBJ sphere_over_quad
SEPARATOR
ROTATE 45 0 1 0
SUBOBJ sphere_over_quad
SEPARATOR
END
|
The above sample .gfx file does the following:
- INCLUDE the contents of another .gfx file: 'myshapes.gfx'
- defines a SIMPLE OBJECT, named 'quad', using data from file: 'quad.obj'
- defines a COMPOSITE OBJECT, named 'sphere_over_quad', using
transformations and already defined OBJECT: 'quad'.
- defines a light named 'light_red', using data from file: 'light_red.lig'
- defines a scene, placing the camera, lights, and exisiting OBJECTS.
Questions? Email Gary or post to 124/296 newsgroup.
|