sgbconverter
SGB is the file format used for Need for Speed: Shift tracks. It containt coordinates for all (?) objects building the track. There is not enough known about XML based version, SGX, to properly convert from SGB to SGX. What this tool does is instead to convert to its own XML format, which it can convert back to sgb.
File Format
The file consists of six sections SGB, OCCL, NODE, FLAT, SUMM and END. Following after the END section is strings referenced from the previous sections.
Section headers
All sections start with a header:
- 4 bytes: name (SGB /OCCL/NODE/FLAT/SUMM/END )
- 4 bytes integer: length of the section
- 4 bytes integer: number of blocks in section
The SGB Section
Consists of just the section head. Number of blocks in section is always 3 (even though there are none).
The OCCL Section
Consists of x blocks
- 4 bytes integer: string reference (offset in file) name
- 4 bytes integer: string reference (offset in file) resource
- 4 bytes float: point1 x
- 4 bytes float: point1 z
- 4 bytes float: point1 y
- 4 bytes float: point2 x
- 4 bytes float: point2 z
- 4 bytes float: point2 y
- 4 bytes float: point3 x
- 4 bytes float: point3 z
- 4 bytes float: point3 y
- 4 bytes float: point4 x
- 4 bytes float: point4 z
- 4 bytes float: point4 y
The NODE Section
The node section consists of two kinds of blocks.
Head:
- 4 bytes integer: no
- 4 bytes integer: str1
- 4 bytes integer: str2
- 4 bytes integer: str3
- 4 bytes integer: num of type in sequence
- 4 bytes integer: unknown (must be two or more smaller fields)
Object:
- 4 bytes integer: str1
- 4 bytes integer: str2
- 4 bytes integer: str3
- 4 bytes integer: num of type in sequence
- 4 bytes float: sphere center x
- 4 bytes float: sphere center z
- 4 bytes float: sphere center y
- 4 bytes float: sphere radius
- 1 bytes integer: matrix number
- 1 bytes integer: always 0
- 1 bytes integer: Number of matrices
- 1 bytes integer: Number of subobjects
- 4 bytes integer: userflags (only if type is OBJECT)
- Matrices (if present according to previous flats, if this is not a subobject there will be one even if the previous number is 0):
- 4 bytes float: offset x
- 4 bytes float: offset z
- 4 bytes float: offset y
- 4 bytes float: orientation x
- 4 bytes float: orientation z
- 4 bytes float: orientation y
- 4 bytes float: unknown1
- 4 bytes float: unknown2
- 4 bytes integer: parentId
- 4 bytes float: one float per subobject (CONTROL Distances?) (Only if type is LOD)
- 4 bytes integer: One int per subobject, containing the start position for the subobject by position in the file.
The FLAT Section
The FLAT section consists of tho kinds of blocks.
A head block:
- 4 bytes float: min point x
- 4 bytes float: min point z
- 4 bytes float: min point y
- 4 bytes float: max point x
- 4 bytes float: max point z
- 4 bytes float: max point y
- 4 bytes integer: number of data blocks following
- 4 bytes integer: length
Total length of this block, including data blocks and sub headers. May be negative but the positive value shoud be used, probably signifies something.
A data block:
- 4 bytes float: sphere1 center x
- 4 bytes float: sphere1 center z
- 4 bytes float: sphere1 center y
- 4 bytes float: sphere1 radius
- 4 bytes float: sphere2 center x
- 4 bytes float: sphere2 center z
- 4 bytes float: sphere2 center y
- 4 bytes float: sphere2 radius
- 4 bytes float: point1 x
- 4 bytes float: point1 z
- 4 bytes float: point1 y
- 4 bytes float: point2 x
- 4 bytes float: point2 z
- 4 bytes float: point2 y
- 4 bytes integer: always 0
- 4 bytes integer: id/index into SUMM?
The SUMM Section
Using the same structure as the node section
The END Section
Just a section header, number of blocks is always 0.
sgbconverter tool
Building sgbconverter
# git clone http://git.pappkartong.se/sgbconverter.git # cd sgbconverter # make
Using sgbconverter
sgbconverter -in=[sgb|xml] <infile> -out=[sgb|xml] <outfile> [-endian=small|big]
Converting from sgb to xml
./sgbconverter -in=sgb alpental.sgb -out=xml alpental.xml
Converting from xml to sgb
./sgbconverter -in=xml alpental.xml -out=sgb alpental.sgb -endian=small
TODO
- Figure out the remaining values
- Cleanup
Download
The source code for sgbconverter.
Clone the git repository
git: # git clone http://git.pappkartong.se/sgbconverter.git
Note: This is a git repository, you need git to use it.
Download using gitweb
Or download the current head sgbconverter-master-*.tar.gz using gitweb.