Game Development Reference
In-Depth Information
loading any objects that are described along with the animation these
objects perform. In order to use a scene file we need to be able to load an
object file, so we will begin our examination of importing Lightwave data
by looking at how to read and load an object file.
Importing a Lightwave object file
First we are going to create a new class CLWObject ; this class will
contain all the information about an object that we will use: points,
polygons and surface data. Initially, we will start with a stripped down
application that will load a single object and allow the user to rotate the
object. In terms of surface data we will simply load the colour of a
surface. Later we will look at the Toon3D source code to learn how to
extract texture information. The rationale behind splitting the process up
is that the more code in an application, the more difficult it is to learn
from this source in order to apply the techniques to your own
application. When loading the full data out of a Lightwave object file for
a low polygon application, the main complexity lies in the parsing of the
surface data. For this reason we look at the problem in two stages,
basic object geometry and then surface details.
One of the best features of Lightwave 3D is the documentation
available. Lightwave 3D has a free and very useful mailing list which I
encourage the interested reader to become a part of (see the information
at the end of the topic for further details). A Lightwave 3D file uses the IFF
file format that was used extensively on the Commodore Amiga. This file
format uses a chunk format. A chunk starts with a four-letter code that
describes what the chunk is about, followed by an integer value that
defines the length of the code. A parser first reads the chunk ID and the
chunk length, checks whether it understands this chunk and if it does then
reads the chunk. If it does not understand the chunk, then the parser uses
the chunk length to tell the file pointer to skip the next section, where it can
then happily read the next chunk. So here is how the first chunk in a
Lightwave 6+ file looks:
46 4F 52 4D 00 00 01
4C 57 4F 32
First we find four characters that define the file as an IFF 'FORM'.
Then 4 bytes that are the length of the file minus 8 bytes. The final part
of the header chunk is the form type, which for a Lightwave 6 object
file will contain the four characters 'LWO2'; the 'O' stands for object, it
Search Nedrilad ::

Custom Search