Ptex File Format Specification Version 1.3r1

Revision history:
1.0
9/29/06
Initial Release
1.1
2/27/07
"Edit face data" amended to included precomputed constant value
1.2
1/5/09
Added: subface flag, const neighborhood flag, u/v border modes, separately stored large metadata items.
Clarified triangle texture storage.
1.3
10/20/09
Corrected size of "keysize" and "datatype" in meta data spec to match implementation.
Revised large metadata spec (not previously implemented).
Added "editdatapos" to extended header.
Added "compatibility barrier" for pre-1.3 file readers.
Added minor version to header.
1.3r1
6/2/10
Corrected details of Constant Data block to match implementation.


General Notes:


General File Structure

The file is composed of a number of data blocks stored in the order listed in the table below:

Header
description of file contents (fixed length, will never grow)
Extended Header
additional header data, may grow in future
Face Info
information about each face
Constant Data pre-filtered, constant valued data for each face
Level Info
information about each level
Level Data
data for each level
Meta Data miscellaneous small data stored as single block
Compatibility Barrier
barrier preventing pre-1.3 file readers from reading new data sections
Large Meta Data
separately stored large meta data items
(future expansion)

Edit Data
incremental edits posted to the file

Header

magic
char[4]
magic identifier = string "Ptex"
version
uint32
major version number (=1)
meshtype
uint32
0=triangle, 1=quad
datatype
uint32
0=uint8, 1=uint16, 2=float16, 3=float32
alphachan
uint32
index of alpha channel
 -1 (0xffffffff) indicates no alpha channel
nchannels uint16 number of data channels
nlevels uint16 number of levels
nfaces
uint32
number of faces
extheader size
uint32
size of Extended Header block
faceinfo size
uint32
size of Face Info block
constdata size uint32 size of Constant Data block
levelinfo size
uint32
size of Level Info block
minor version uint32 minor version number
leveldata size uint64 total size of all Level Data blocks
metadata zipsize
uint32
on-disk size of Meta Data block (zipped)
metadata memsize
uint32
in-memory size of Meta Data block (unzipped)

Extended Header


ubordermode
uint32
0=clamp (default), 1=black, 2=periodic
vbordermode uint32 0=clamp (default), 1=black, 2=periodic
largemetadata header zipsize
uint32
on-disk size of Large Meta Data Header (zipped)
largemetadata header memsize
uint32
in-memory size of Large Meta Data Header (unzipped)
largemetadata size
uint64
total on-disk size of Large Meta Data blocks (not including header)
editdata size
uint64
size of edit data blocks
editdata pos
uint64
absolute file position of first edit data block

Face Info

Information about the resolution and topological adjacency of each face.

ures
uint8
log2(number of samples in u direction)
vres
uint8
log2(number of samples in v direction)
adjedges uint8 ids of edges on adjacent faces (0 .. 3) x 4 faces (see notes)
flags
uint8
bit0=constant - all pixels in face have same value
bit1=has edits (not stored in file, for api only)
bit2=constant neighborhood - all neighboring faces have same value as this face
bit3=subface - face is a subface
adjfaces
uint32[4]
faceids of adjacent faces (0 .. nfaces)
-1 (0xffffffff) indicates a border (no adjacent face)
(times number of faces)

Notes:

Constant Data

The constant data block contains a single value per channel for each face.  For non-constant faces, these values represent the average of the values for each face.

Level Info

The data are grouped into levels with the first level representing the full-res data for all of the faces, the next level representing a power-of-two reduction of the first (half the res in both u and v), and subsequent levels representing half the previous level.  The Level Info block lists the number of faces in the level and size of each level's data. 

leveldatasize
uint64
size of level's data block (including level data header)
levelheadersize
uint32
compressed size of level data header
nfaces
uint32
number of faces in level
(times number of levels)

Notes:

Level Data

Each Level Data block (one per level) consists of a header containing a list of face sizes followed by a number of face data blocks of the given sizes.  Non-constant face data is packed (with channels separated) and then optionally differenced and compressed.

Level data header (compressed):
facesize
uint32 (bits 0..29)
sizes of data block for each face
encoding
bits 30..31 of facesize
0 = constant valued (1 sample per channel)
1 = zip compressed
2 = zip compressed w/ differencing
3 = tiled
(times number of faces in level)

For tiled faces, the face data begins with the following pre-header:
tileures
uint8
log2(number of samples per tile in u direction)
tilevres
uint8
log2(number of samples per tile in v direction)
tileheadersize
uint32
compressed size of tile header

and is followed by a compressed header listing the tile sizes and encodings:
tilesizes
uint32 (bits 0..29)
sizes of data block for each tile
encoding
bits 30..31 of tilesize
0 = constant valued (1 sample per channel)
1 = zip compressed
2 = zip compressed w/ differencing
(times number of tiles in face)

Each tile is then stored separately (with tiles in v-major order) in the same manner as the untiled face data.  Note: the number of tiles for a face is determined by comparing the tile_ures and tile_vres with the ures and vres of the face.


Meta Data

Miscellaneous application defined data.  Possibilities include channel names, timestamp, software settings, 3d vertex data, etc.  The meta data is a stream of individual data blocks.

Meta data block
keysize
uint8
length of key string (including null)
key
uint8[keysize]
ascii character string (null-terminated)
datatype
uint8
0=ascii, 1=int8, 2=int16, 3=int32, 4=float, 5=double
datasize
uint32
size of data block (in bytes)
data
uint8[datasize]
data block

Compatibility Barrier

File versions prior to 1.3 lacked the "editdata pos" extended header attribute. Early versions of the file reader would seek to the end of the known data blocks and assume any additional data blocks were edit blocks. The compatibility barrier appears to old reader code as an empty edit block and prevents the old reader from misinterpreting newer data sections. The compatibility barrier is always written.

barrier
uint64
must be zero

Large Meta Data

The large meta data section includes meta data blocks that are stored separately for individual access (presumably because the items are large, though there's no real limit).  The large meta data section consists of a header followed by a series of individually compressed blocks.

Large meta data header (compressed)
keysize
uint8
length of key string (including null)
key
uint8[keysize]
ascii character string (null-terminated)
datatype
uint8
0=ascii, 1=int8, 2=int16, 3=int32, 4=float, 5=double
datasize uint32 size of data block (in bytes)
zipsize
uint32
size of data block on disk
(times number of large meta data blocks)

The individual compressed data blocks follow.


Edit Data

The edit data block includes incremental data edits that are pending to be applied to the file.  The format is designed to allow appending edit blocks to a file without otherwise affecting the file.

Edit data block
edittype
uint8
1=edit face data, 2=edit meta data
editsize
uint32
size of editdata block
editdata
(variable)
based on edit type

Edit face data
faceid
uint32 index of face
faceinfo
FaceInfo block
(as described in FaceInfo section)
facesize & encoding
uint32 (as described in Level Data section)
constval
uint8[pixelsize]
constant value (average pixel value, as described in Constant Data section)
facedata
uint8[facesize]
encoded data block

Edit meta data
metadatazipsize
uint32
compressed size of meta data
metadatamemsize uint32 uncompressed size of meta data
metadata
uint8[metazipsize]
one or more data blocks (as described in Meta Data section)