This article's documentation is for anything that uses the Source engine. Click here for more information.

VTX

From Valve Developer Community
(Redirected from Vtx)
Jump to: navigation, search

VTX is the extension for Source Source's proprietary mesh strip format. It stores hardware optimized material, skinning and triangle strip/fan information for each LOD of each mesh in the MDL.

VTX files use a two-part file extension; the first part varies depending upon the renderer, although StudioMDL usually makes identical VTX files for dx80, dx90, and sw.

PC formats
Extension Used when?
.dx90.vtx dxlevel ≥ 90
.dx80.vtx dxlevel ≥ 80
.sw.vtx dxlevel < 80

  

Console formats
Extension Console
.xbox.vtx Original Xbox Original Xbox
.360.vtx
.dx90.360.vtx
Xbox 360 Xbox 360

The Left 4 Dead series Left 4 Dead series originally used just .VTX files, as of the Sacrifice update for these two games they now use the .dx90.vtx for the Mac OSX and re-used the .VTX only for Portal 2 Portal 2 [Clarify].

Confirm:
Warning.pngWarning:In games that support DX8, if a map is compiled with the parameter -staticproplighting and a prop doesn't have a .dx80.vtx file, the game will crash when loading the map.

File Structure

Header

// this structure is in <mod folder>/src/public/optimize.h
struct FileHeader_t
{
	// file version as defined by OPTIMIZED_MODEL_FILE_VERSION (currently 7)
	int version;

	// hardware params that affect how the model is to be optimized.
	int vertCacheSize;
	unsigned short maxBonesPerStrip;
	unsigned short maxBonesPerTri;
	int maxBonesPerVert;

	// must match checkSum in the .mdl
	int checkSum;

	int numLODs; // Also specified in ModelHeader_t's and should match

	// Offset to materialReplacementList Array. one of these for each LOD, 8 in total
	int materialReplacementListOffset;

        //Defines the size and location of the body part array
	int numBodyParts;
	int bodyPartOffset;
};

This is the header structure for the current VERSION7 .vtx file

Body array

The body array is a list of BodyPartHeader_t objects.

  • Size: numBodyParts.
  • Location: bodyPartOffset.
Note.pngNote:Since this value is in the header it can be interpreted as an absolute location

BodyPartHeader_t

struct BodyPartHeader_t
{
	//Model array
	int numModels;
	int modelOffset;
};

Model array

The model array is a list of ModelHeader_t objects.

  • Size: numModels.
  • Location: bodyPartOffset.

ModelHeader_t

// This maps one to one with models in the mdl file.
struct ModelHeader_t
{
	//LOD mesh array
	int numLODs;   //This is also specified in FileHeader_t
	int lodOffset;
};

LOD Mesh Array

The LOD mesh array is a list of ModelLODHeader_t objects.

  • Size: numLODS.
  • Location: lodOffset.

ModelLODHeader_t

struct ModelLODHeader_t
{
    //Mesh array
	int numMeshes;
	int meshOffset;

	float switchPoint;
};

Mesh array

The mesh array is a list of MeshHeader_t objects.

  • Size: numMeshes.
  • Location: meshOffset.

Switch Point

The point at which the engine should switch to this LOD mesh is defined by switchPoint.

MeshHeader_t

struct MeshHeader_t
{
	int numStripGroups;
	int stripGroupHeaderOffset;

	unsigned char flags;
};

Strip Group Array

The strip group array is a list of StripGroupHeader_t objects.

  • Size: numStripGroups.
  • Location: stripGroupHeaderOffset.

Flags

The unsigned char flags value can be read from this table:

Value Meaning
0x01 STRIPGROUP_IS_FLEXED
0x02 STRIPGROUP_IS_HWSKINNED
0x04 STRIPGROUP_IS_DELTA_FLEXED
0x08 STRIPGROUP_SUPPRESS_HW_MORPH

StripGroupHeader_t

struct StripGroupHeader_t
{
	// These are the arrays of all verts and indices for this mesh.  strips index into this.
	int numVerts;
	int vertOffset;

	int numIndices;
	int indexOffset;

	int numStrips;
	int stripOffset;

	unsigned char flags;

	// The following fields are only present if MDL version is >=49
	// Points to an array of unsigned shorts (16 bits each)
	int numTopologyIndices;
	int topologyOffset;
};

MDL versions 49 and above (found in Counter-Strike: Global Offensive Counter-Strike: Global Offensive) have an extra two int fields (totaling 8 bytes). This is not reflected in the VTX header version, which remains at 7.

Todo: What do these indices do?

Vertex & Indices arrays

Indices Array - This is a set of unsigned short integers that index the position of the real vertex data in the .VVD's vertex array

  • Size: numIndices
  • Location: indexOffset

Vertex Array - The vertex array inside the .VTX file holds some extra information related to skinning

  • Size: numVerts
  • Location: vertOffset

Strip Array

The strip array is a list of StripHeader_T objects

  • Size: numStrips
  • Location: stripOffset

StripHeader_t

// A strip is a piece of a stripgroup which is divided by bones 
struct StripHeader_t
{
	int numIndices;
	int indexOffset;

	int numVerts;    
	int vertOffset;

	short numBones;

	unsigned char flags;

	int numBoneStateChanges;
	int boneStateChangeOffset;

	// MDL Version 49 and up only
	int numTopologyIndices;
	int topologyOffset;
};

Like in StripGroupHeader_t, the last eight bytes/two int fields are present if the MDL file's header shows version 49 or higher. Presumably, (

Todo: Verify

) these index into the parent strip group's list of topology indices, similar to vertices and indices.

Indices & Vertex Groupings

Each group (Indices and Vertices respectively), specify what position to read from the vertex pool, as well as the indices pool. These pools come from the parent StripGroupHeader object

Vertex_t

struct Vertex_t
{
	// these index into the mesh's vert[origMeshVertID]'s bones
	unsigned char boneWeightIndex[3];
	unsigned char numBones;

	unsigned short origMeshVertID;

	// for sw skinned verts, these are indices into the global list of bones
	// for hw skinned verts, these are hardware bone indices
	char boneID[3];
};

origMeshVertID defines the index of this vertex that is to be read from the linked .VVD file's vertex array

Note.pngNote:This value needs to be added to the total vertices read, since it is relative to the mesh and won't work as an absolute key.

When parsing, note that a Vertex contains nine bytes of information, but will usually be padded to 10 bytes. Within the VTX file, the length of each vertex's data will still be 9. For example, one should call in C:

fread(vertexBuf, vertexCount, 9, fileptr);

Instead of:

fread(vertexBuf, vertexCount, sizeof(Vertex_t), fileptr);

The latter sample will cause data corruption, unless your model has only one vertex (unlikely).

See also