Skip to content

XKT Format

Lindsay Kay edited this page Jul 16, 2019 · 21 revisions

V1.0

Overview

The table below lists the elements within V1.0 of the .xkt file format.

For convence we're using a symbolic name, eg. index_size, for each element.

Element Type Description
version Uint32 The .xkt file format version. This is the first four bytes in the file.
index_size Uint32 Byte size of the index. The index is is the following block, which provides a table of the sizes of certain subsequent elements within the file.
positions_size Uint32 Byte size of positions. This is the start of the index.
normals_size Uint32 Byte size of normals.
indices_size Uint32 Byte size of indices.
mesh_positions_size Uint32 Byte size of mesh_positions.
mesh_normals_size Uint32 Byte size of mesh_normals.
mesh indices size Uint32 Byte size of mesh_indices.
mesh_colors_size Uint32 Byte size of mesh_colors.
entity_ids_size Uint32 Byte size of entity_ids.
entity_meshes_size Uint32 Byte size of entity_meshes.
entity_is_objects_size Uint32 Byte size ofentity_is_objects.
positions_decode_matrix_size Uint32 Byte size of positions_decode_matrix. This is the end of the index.
positions Uint16[] Quantized positions for all meshes.
normals Uint8[] Oct-encoded normals for all meshes.
indices Uint32[] Geometry indices for all meshes.
mesh_positions Uint32[] For each mesh, base index of a portion in positions.
mesh_normals Uint32[] For each mesh, base index of a portion in normals.
mesh_indices Uint32[] For each mesh, base index of a portion in indices
mesh_colors Uint8[] For each mesh, an RGBA color (four elements)
entity_ids String ID for each entity, as a string-encoded JSON array of strings
entity_meshes Uint32[] For each entity, base index of a portion in mesh_positions, mesh_normals, mesh_indices and mesh_colors.
entity_is_objects_size Uint8[] For each entity, a flag indicating whether or not it represents an object
positions_decode_matrix Uint32[] De-quantization matrix to decompress positions

Implicit Mesh Order

positions, normals and indices are the concatenation of the geometry arrays for all the meshes in the model. There is an implicit order in which meshes appear in these arrays.

mesh_positions, mesh_normals and mesh_indices indicate which portion of those arrays is used for each mesh. These rely on the implicit mesh order just mentioned.

For example, the first position used by mesh n would be:

let i = mesh_positions[ n ];
let x = positions[ i + 0 ];
let y = positions[ i + 1 ];
let z = positions[ i + 2 ];

while the last position used by mesh n would be:

let i2 = mesh_positions[ n + 1 ] - 1;
let x2 = positions[ i2 + 0 ];
let y2 = positions[ i2 + 1 ];
let z2 = positions[ i2 + 2 ];

Indices

TODO

let i = mesh_indices[ n ];
let i2 = mesh_positions[ n ];

let a = indices[ i + 0 ];
let b = indices[ i + 1 ];
let c = indices[ i + 2 ];

let ax = positions[ i2 + (a * 3) + 0];
let ay = positions[ i2 + (a * 3) + 1];
let az = positions[ i2 + (a * 3) + 2];

let bx = positions[ i2 + (b * 3) + 0];
let by = positions[ i2 + (b * 3) + 1];
let bz = positions[ i2 + (b * 3) + 2];

let cx = positions[ i2 + (c * 3) + 0];
let cy = positions[ i2 + (c * 3) + 1];
let cz = positions[ i2 + (c * 3) + 2];

The first mesh used by entity m would be:

Clone this wiki locally