03-31-2005, 04:33 AM
Until now, I've never had a reason to open a file in binary mode that was created by another application, besides a bitmap loader I made.
I'm trying to extract the data in a Lightwave(.lwo) file. I've got the documentation and a start, but I've pretty much hit a brick wall.
Lightwave saves it's object files in binary chunks. Each chunk starts with an identity tag and the length of the data that follows.
Basically, I've created a type definition to mimic CHUNK.
This was just for testing purposes. I am only trying to get the polygon count at this point.
POLY is the ID tag for polygons, so I scan the file, byte by byte, until it encounters "POLY"....
Chunk.Tag still returns POLY, but Chunk.tLen returns some wild value, even if the obect only has one polygon.
Can somebody tell me what I'm doing wrong?
Thanx.
I'm trying to extract the data in a Lightwave(.lwo) file. I've got the documentation and a start, but I've pretty much hit a brick wall.
Lightwave saves it's object files in binary chunks. Each chunk starts with an identity tag and the length of the data that follows.
Code:
CHUNK ::= tag[ID4], length[U4], data[...], pad[U1]
ID Tag
ID4
An ID tag is a sequence of 4 bytes interpreted as 7-bit ASCII values, usually upper-case. These tags are used to identify the type of data which follows. FORM, SURF, POLS, and LWOB are all examples of ID tags.
Signed Integer
I1, I2, I4
Unsigned Integer
I1, I2, I4
Integers can have 1, 2 or 4 bytes and can be signed or unsigned. The most significant byte comes first in the file, so bytes read into memory should be reversed before being interpreted on Intel and compatible CPUs.
Float
F4
Floats are written as 4 byte IEEE floating-point values. The bytes should generally be reversed before being interpreted on Intel and compatible CPUs.
String
S0
Names or other character strings are written as a series of ASCII character values followed by a zero (or null) byte. If the length of the string plus the null terminating byte is odd, an extra null is added to make the total length even.
Basically, I've created a type definition to mimic CHUNK.
Code:
'CHUNK ::= tag[ID4], length[U4], data[...], pad[U1]
Type DataChunkType
Tag as String*4
tLen as UINTEGER
End Type
Dim Chunk as DataChunkType
This was just for testing purposes. I am only trying to get the polygon count at this point.
POLY is the ID tag for polygons, so I scan the file, byte by byte, until it encounters "POLY"....
Code:
DO
i = i + 1
Get #1, i, Chunk.Tag
If Chunk.Tag = "POLY" THEN
Get #1, i, Chunk
Print Chunk.Tag
Print Chunk. tLen
End If
LOOP
Chunk.Tag still returns POLY, but Chunk.tLen returns some wild value, even if the obect only has one polygon.
Can somebody tell me what I'm doing wrong?
Thanx.