VVD

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

VVD (Valve Studio Model Vertex Data File) is the extension for Source Source's proprietary model vertex data format. It stores position independent flat data for the bone weights, normals, vertices, tangents and texture coordinates used by the MDL.

Header

// these structures can be found in <mod folder>/src/public/studio.h
struct vertexFileHeader_t
{
	int	id;				// MODEL_VERTEX_FILE_ID
	int	version;			// MODEL_VERTEX_FILE_VERSION
	int	checksum;			// same as studiohdr_t, ensures sync      ( Note: maybe long instead of int in versions other than 4. )
	int	numLODs;			// num of valid lods
	int	numLODVertexes[MAX_NUM_LODS];	// num verts for desired root lod
	int	numFixups;			// num of vertexFileFixup_t
	int	fixupTableStart;		// offset from base to fixup table
	int	vertexDataStart;		// offset from base to vertex block
	int	tangentDataStart;		// offset from base to tangent block
};

Fixup Table

// apply sequentially to lod sorted vertex and tangent pools to re-establish mesh order
struct vertexFileFixup_t
{
	int	lod;			// used to skip culled root lod
	int	sourceVertexID;		// absolute index from start of vertex/tangent blocks
	int	numVertexes;
};

How the fixup table is used when loading vertex data:

  • If there's no fixup table (numFixups is 0) then all the vertices are loaded
  • If there is, then the engine iterates through all the fixups. If the LOD of a fixup is superior or equal to the required LOD, it loads the vertices associated with that fixup (see sourceVertexID and numVertices).
  • A fixup seems to be generated for instance if a vertex has a different position from a parent LOD.

Vertex Data

A list of vertices follows the header

// NOTE: This is exactly 48 bytes
struct mstudiovertex_t
{
	mstudioboneweight_t	m_BoneWeights;
	Vector			m_vecPosition;
	Vector			m_vecNormal;
	Vector2D		m_vecTexCoord;
};

// 16 bytes
struct mstudioboneweight_t
{
	float	weight[MAX_NUM_BONES_PER_VERT];
	char	bone[MAX_NUM_BONES_PER_VERT]; 
	byte	numbones;
};

Tangent Data

This seems to be an array of 4D vectors, one for each vertex

vec_t x, y, z, w;

Binary Data

When the model is compiled all vertex data is stored inside the VVD file. If the model has LoD then a LoD fixup table is created and the order of vertexes will be effected by this. The compiler will only keep the vertexes for each LoD that are different to the ones in the reference mesh to maximize efficiency and to keep file sizes down. This optimization can sometimes create mesh problems in the LoD transitions.

Vertex Table

All vertexes are stored inside 48 byte blocks. This block contains data for each single vertex which includes bone weighting, position (XYZ), normals (XYZ) and texture coordinates (UV).

#define MAX_NUM_BONES_PER_VERT 3

struct mstudioboneweight_t
{
	float	weight[MAX_NUM_BONES_PER_VERT];
	char	bone[MAX_NUM_BONES_PER_VERT]; 
	byte	numbones;
};

// NOTE: This is exactly 48 bytes
struct mstudiovertex_t
{
	mstudioboneweight_t	m_BoneWeights;
	Vector				m_vecPosition;
	Vector				m_vecNormal;
	Vector2D			m_vecTexCoord;
};


  • Bone weighting (0-12) [3xfloat] - Contains a maximum of 3 floating points numbers, one for each bone. The engine allows a maximum of 3 bones per vert. Older formats such as version 37 used 4 bones.
  • Bone IDs (12-15) [3xbyte] - IDs of the bones the vertex is weighted to. The first bone will use the first float number for weighting.
  • Bone count (15-16) [byte] - Number of bones the vertex is weighted to. This should be at least 1.
  • Position (16-28) [3xfloat] - Floating points numbers for each axis (XYZ) in inches.
  • Normals (28-40) [3xfloat] - Floating points numbers for vertex normals.
  • Texture Co-ordinates (40-48) [2xfloat] - Floating points numbers for UV map. If the model is being rendered in right-handed coordinate systems using OpenGL or WebGL, the value for V may need to be subtracted from 1 to flip the UV map vertically.

Tangent Table

Below the vertex block is the tangent table. The tangents are calculated on compile and are used for normal mapping. Each tangent is stored inside a 16 byte block.

  • Transformations (0-16) [4xfloat] - Floating points numbers for each transform calculation for each axis (XYZ). Last float (W) is either 1 or -1.

See also