分享

DTS Format Specification

 angelbrian 2014-01-16

Contents

Introduction

DTS is the native binary format used by the Torque engine to store shape, mesh and (optionally) sequence data. This document serves as a basic specification for the DTS file format. Very little context is given to the shape, mesh and sequence data fields read from the DTS file so it is recommended that this resource be read along with the Torque 3D source code.


The DTS file format stores most data in separate buffers for 8, 16 or 32-bit sized values in order to speed up loading on non-Intel platforms. A DTS file can be read as shown below; after the 3 data buffers have been created in memory, they are read in interleaved order as needed to extract the desired values (see Data Buffers).


Note: that all values are stored as little-endian, so on non-Intel platforms you will have to handle perform endian conversion for 16 and 32-bit values.


DTS Format

Name# bytesData TypeDescription
DTS version number2S16DTS version of this file. Note that the current DTS version (for files saved by Torque 3D) is 26. Most DTS exporters and the ShowToolPro tool only read/write version 24.
Exporter version number2S16For tracking version of the exporter that generated this file. Can usually be ignored.
sizeAll4S32Size (in 32-bit words) of the 3 data buffers (sum of 8, 16 and 32-bit data buffers). The 32-bit data buffer starts at offset 0x0.
start164S3232-bit word offset into the memory buffer of the start of the 16-bit data.
start84S3232-bit word offset into the memory buffer of the start of the 8-bit data.
data32size32U32*Data buffer for 32-bit values. Size (in bytes) is equal to start16*4
data16size16U16*Data buffer for 16-bit values. Size (in bytes) is equal to (start8 - start16)*4
data8size8U8*Data buffer for 8-bit values. Size (in bytes) is equal to (sizeAll - start8)*4
numSequences4S32Number of sequences in the shape
sequencesnumSequences * ?SequenceArray of numSequences Sequences - size of each sequence depends on which nodes and objects are affected etc. See Sequences for more information
matStreamType1S8Type of material stream (text or binary). Should be 0x1 (binary) for DTS files
numMaterials4S32Number of materials in the shape
matNamesnumMaterials * ?S32 and char[]Names of the materials in the shape. Each name is stored as a 4-byte length followed by the N characters in the string (terminating NULL is not included in the length or N characters).
matFlagsnumMaterials * 4U32Flags for each material*
matReflectanceMapsnumMaterials * 4S32Index of the material to use as a reflectance map for each material* (or -1 for none)
matBumpMapsnumMaterials * 4S32Index of the material to use as a bump map for each material* (or -1 for none)
matDetailMapsnumMaterials * 4S32Index of the material to use as a detail map for each material* (or -1 for none)
dummynumMaterials * 4S32Dummy value. Only present in DTS v25.
matDetailScalesnumMaterials * 4F32Detail scale for each material*
matReflectancenumMaterials * 4F32Reflectance value for each material*

Note: that all material settings (beside the name) are superceded by script Material definitions in T3D.

Sequences

Sequences are stored in the DTS file as follows:

Name# bytesData TypeDescription
nameIndex4S32The name of this sequence as in index into the names array
flags4U32Sequence flags
numKeyframes4S32Number of keyframes in this sequence
duration4F32Duration of the sequence (in seconds)
priority4S32Sequence priority
firstGroundFrame4S32First ground transform keyframe in this sequence (index into the groundTranslations and groundRotation arrays)
numGroundFrames4S32Number of ground transform keyframes in this sequence
baseRotation4S32First node rotation keyframe in this sequence (index into the nodeRotations array)
baseTranslation4S32First node translation keyframe in this sequence (index into the nodeTranslations array)
baseScale4S32First node scale keyframe in this sequence (index into the nodeXXXScales arrays)
baseObjectState4S32First object state keyframe in this sequence (index into the objectStates array)
baseDecalState4S32First decal state keyframe in this sequence (index into the decalStates array). Note that DTS decals are deprecated, and this value should be 0.
firstTrigger4S32First trigger in this sequence (index into the triggers array)
numTriggers4S32Number of triggers in this sequence
toolBegin4F32Value representing the start of this sequence in the exporting tool's timeline (can usually by ignored)
rotationMatters?BitSetBitSet indicating which node rotations are animated by this sequence.
translationMatters?BitSetBitSet indicating which node translations are animated by this sequence.
scaleMatters?BitSetBitSet indicating which node scales are animated by this sequence.
decalMatters?BitSetBitSet indicating which decal states are animated by this sequence. Note that DTS decals are deprecated.
iflMatters?BitSetBitSet indicating which IFL materials are animated by this sequence.
visMatters?BitSetBitSet indicating which object's visibility is animated by this sequence.
frameMatters?BitSetBitSet indicating which mesh's verts are animated by this sequence.
matFrameMatters?BitSetBitSet indicating which mesh's UV coords are animated by this sequence.


BitSets

BitSets are stored in the DTS file as:

Name# bytesData TypeDescription
dummy4S32Dummy value
numWords4S32Number of 32-bit values in the BitSet
bits4 * numWordsU32Array of numWords 32-bit values representing the bits in the BitSet


Data Buffers

The 3space shape data is extracted from the 3 data buffers by maintaining a pointer into each buffer, then reading from the appropriate buffer in order as shown in the table below. The code sample below demonstrates how an array of structures might be read from the 3 buffers.

struct
{
   S8 valueA[4];
   S32 valueB;
   S32 valueC;
   S16 valueD;
} Object;

...

#define checkGuard() assert((*buff32++ == guard32++) && (*buff16++ == guard16++)
 && (*buff8++ == guard8++))

...

numObjects = *buff32++;
objects.resize(numObjects);
for (S32 i = 0; i < numObjects; i++)
{
   for (S32 j = 0; j < 4; j++)
      objects[i].valueA[j] = *buff8++;

   objects[i].valueB = *buff32++;
   objects[i].valueC = *buff32++;
   objects[i].valueD = *buff16++;
}

checkGuard();

The GUARD entries indicate a buffer checkpoint that verifies the buffers are being accessed correctly. Each time the GUARD entry is encountered, an incrementing value should be read from each of the 3 buffers. For example, the first GUARD should read 32-bit 0x0, 16-bit 0x0 and 8-bit 0x0, the next GUARD should read 32-bit 0x1, 16-bit 0x1 and 8-bit 0x1 and so on.

NameBufferData TypeDescription
numNodes32-bitS32Number of nodes in the shape
numObjects32-bitS32Number of objects in the shape
numDecals32-bitS32Number of decals in the shape
numSubShapes32-bitS32Number of subshapes in the shape
numIFLs32-bitS32Number of IFL materials in the shape
numNodeRotations32-bitS32Number of node rotation keyframes
numNodeTranslations32-bitS32Number of node translation keyframes
numNodeUniformScales32-bitS32Number of node uniform scale keyframes
numNodeAlignedScales32-bitS32Number of node aligned scale keyframes
numNodeArbScales32-bitS32Number of node arbitrary scale keyframes
numGroundFrames32-bitS32Number of ground transform keyframes
numObjectStates32-bitS32Number of object state keyframes
numDecalStates32-bitS32Number of decal state keyframes
numTriggers32-bitS32Number of triggers (all sequences)
numDetails32-bitS32Number of detail levels in the shape
numMeshes32-bitS32Number of meshes (all detail levels) in the shape
numNames32-bitS32Number of name strings in the shape
smallestVisibleSize32-bitF32Size of the smallest visible detai level
smallestVisibleDL32-bitS32Index of the smallest visible detail level
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)
radius32-bitF32Shape bounding sphere radius
tubeRadius32-bitF32Shape bounding cylinder radius
center32-bitPoint3F { F32 x, F32 y, F32 z }Center of the shape bounds
bounds32-bitBoxF { Point3F min, Point3F max }Shape bounding box
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)
nodes32-bitNode { S32 nameIndex, S32 parentIndex, S32 firstObject, S32 firstChild, S32 nextSibling }Array of numNodes Nodes
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)
objects32-bitObject { S32 nameIndex, S32 numMeshes, S32 startMeshIndex, S32 nodeIndex, S32 nextSibling, S32 firstDecal }Array of numObjects Objects
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)
decals32-bitDecal { S32 dummy[5] }Array of numDecals Decals. Note that decals are deprecated.
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)
iflMaterials32-bitIflMaterial { S32 nameIndex, S32 materialSlot, S32 firstFrame, S32 firstFrameOffTimeIndex, S32 numFrames }Array of numIFLs IflMaterials
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)
subShapeFirstNode32-bitS32Array of numSubShapes ints representing the index of the first node in each subshape
subShapeFirstObject32-bitS32Array of numSubShapes ints representing the index of the first object in each subshape
subShapeFirstDecal32-bitS32Array of numSubShapes ints representing the index of the first decal in each subshape
subShapeFirstTranslucentObject32-bitS32Array of numSubShapes ints representing the index of the first translucent object in each subshape
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)
defaultRotations16-bitQuat16 { S16 x, S16 y, S16 z, S16 Z }Array of numNodes quaternions for default node rotations
defaultTranslations32-bitPoint3F { F32 x, F32 y, F32 z }Array of numNodes points for default node translations
nodeRotations16-bitQuat16 { S16 x, S16 y, S16 z, S16 Z }Array of numNodeRotations quaternions for node rotation keyframes (all sequences)
nodeTranslations32-bitPoint3F { F32 x, F32 y, F32 z }Array of numNodeTranslations points for node translation keyframes (all sequences)
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)
nodeUniformScales32-bitF32Array of numNodeUniformScales floats for node uniform scale keyframes (all sequences)
nodeAlignedScales32-bitPoint3F { F32 x, F32 y, F32 z }Array of numNodeAlignedScales points for node aligned scale keyframes (all sequences)
nodeArbScaleFactors32-bitPoint3F { F32 x, F32 y, F32 z }Array of numNodeArbScales points for node arbitrary scale factor keyframes (all sequences)
nodeArbScaleRots16-bitQuat16 { S16 x, S16 y, S16 z, S16 w }Array of numNodeArbScales quaternions for node arbitrary scale rotation keyframes (all sequences)
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)
groundTranslations32-bitPoint3F { F32 x, F32 y, F32 z }Array of numGroundFrames points for ground transform keyframes (all sequences)
groundRotations16-bitQuat16 { S16 x, S16 y, S16 z, S16 w }Array of numGroundFrames quaternions for ground transform keyframes (all sequences)
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)
objectStates32-bitObjectState { F32 vis, S32 frameIndex, S32 matFrame }Array of numObjectStates ObjectStates
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)
decalStates32-bitS32Array of numDecalStates dummy integers for decal states
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)
triggers32-bitTrigger { U32 state, F32 pos }Array of numTriggers sequence triggers (all sequences)
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)
details32-bitDetail v25- { S32 nameIndex, S32 subShapeNum, S32 objectDetailNum, F32 size, F32 averageError, F32 maxError, S32 polyCount }
Detail v26+ also includes { S32 bbDimension, S32 bbDetailLevel, S32 bbEquatorSteps, S32 bbPolarSteps, F32 bbPolarAngle, bool bbIncludePoles }
Array of numDetails Details
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)
meshesALLMeshArray of numMeshes Meshes
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)
names8-bitchar[]Array of numNames strings, stored as N characters followed by a terminating NULL for each string.
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)
alphaIn32-bitF32Array of numDetails floats representing alpha-in value for each detail
alphaOut32-bitF32Array of numDetails floats representing alpha-out value for each detail


Meshes

Meshes are stored in the 3 data buffers as follows:

NameBufferData TypeDescription
type32-bitU32Type of mesh
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)
numFrames32-bitS32Number of vertex position keyframes
numMatFrames32-bitS32Number of vertex UV keyframes
parentMesh32-bitS32Index of this mesh's parent (usually -1 for none)
bounds32-bitBoxF { Point3F min, Point3F max }Bounding box for this mesh
center32-bitPoint3F { F32 x, F32 y, F32 z }Bounds center for this mesh
radius32-bitF32Bounding sphere radius for this mesh
numVerts32-bitS32Number of vertex positions
verts32-bitPoint3F { F32 x, F32 y, F32 z }Array of numVerts vertex positions (all keyframes)
numTVerts32-bitS32Number of UV coordinates
tverts32-bitPoint2F { F32 u, F32 v }Array of numTVerts UV coordinates (all keyframes)
numTVerts232-bitS32Number of 2nd UV coordinates (DTS v26+ only)
tverts232-bitPoint2F { F32 u, F32 v }Array of numTVerts2 2nd UV coordinates (DTS v26+ only)
numVColors32-bitS32Number of vertex color values (DTS v26+ only)
colors32-bitColorI { U8 red, U8 green, U8 blue, U8 alpha }Array of numVColors vertex colors (DTS v26+ only)
norms32-bitPoint3F { F32 x, F32 y, F32 z }Array of numVerts vertex normals
encodedNorms8-bitU8Array of numVerts encoded normal indices
numPrimitives32-bitS32Number of mesh primitives (triangles, triangle lists etc)
primitives (v24-)16-bitS16Array of numPrimitives 16-bit Primitive struct data { start, numElements }
primitives (v24-)32-bitU32Array of numPrimitives 32-bit Primitive struct data { maxIndex }
primitives (v25+)32-bitPrimitive { S32 start, S32 numElements, U32 matIndex }Array of numPrimitives Primitives
numIndices32-bitS32Total number of vertex indices (all primitives)
indices (DTS v25-)16-bitS16Array of numIndices vertex indices
indices (DTS v25+)32-bitS32Array of numIndices vertex indices
numMergeIndices32-bitS32Number of merge indices. Note that merge indices have been deprecated.
mergeIndices16-bitS16Array of numMergeIndices merge indices
vertsPerFrame32-bitS32Number of vertices in each keyframe (position or UV)
flags32-bitU32Mesh flags
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)


If the mesh type is TSSkinMesh, the following data is stored in addition to the normal Mesh data:


NameBufferData TypeDescription
numInitialVerts32-bitS32Number of intial vert positions and normals
initialVerts32-bitS32Array of numInitialVerts positions
norms32-bitPoint3F { F32 x, F32 y, F32 z }Array of numInitialVerts vertex normals
encodedNorms8-bitU8Array of numInitialVerts encoded initial normal indices
numInitialTransforms32-bitS32Number of initial transforms
initialTransforms32-bitMatrixF { F32 m[16] }Array of numInitialTransforms transforms
numVertIndices32-bitS32Number of vertex indices
vertIndices32-bitS32Array of numVertIndices vertex indices
numBoneIndices32-bitS32Number of bone indices
boneIndices32-bitS32Array of numBoneIndices bone indices
numWeights32-bitS32Number of weights
weights32-bitF32Array of numWeights bone weights
numNodeIndices32-bitS32Number of node indices
nodeIndices32-bitS32Array of node indices
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)


If the mesh type is TSSortedMesh, the following data is stored in addition to the normal Mesh data:

NameBufferData TypeDescription
numClusters32-bitS32Number of clusters
clusters32-bitCluster { S32 startPrimitive, S32 endPrimitive, Point3F normal, F32 k, S32 frontCluster, S32 backCluster }Array of numClusters Clusters
numStartClusters32-bitS32Number of start cluster indices
startClusters32-bitS32Array of numStartClusters start cluster indices
numFirstVerts32-bitS32Number of first vertex indices
firstVerts32-bitS32Array of numFirstVerts first vertex indices
numNumVerts32-bitS32Number of numVert counts
numVerts32-bitS32Array of numVert counts
numFirstTVerts32-bitS32Number of first TVert indices
firstTVerts32-bitS32Array of numFIrstTVerts first TVert indices
alwaysWriteDepth32-bitS32Always write depth flag
GUARDALLS32, S16, S8Buffer checkpoint (incrementing unit in each buffer)

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多