VVD: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Cat)
m (Syntax highlighting)
Line 1: Line 1:
[[VVD]] ('''V'''alve Studio Model '''V'''ertex '''D'''ata File) is the extension for 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]].
[[VVD]] ('''V'''alve Studio Model '''V'''ertex '''D'''ata File) is the extension for 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==
==Header==
// these structures can be found in <mod folder>/src/public/studio.h
<source lang="cpp">
struct vertexFileHeader_t
// these structures can be found in <mod folder>/src/public/studio.h
{
struct vertexFileHeader_t
int id; // MODEL_VERTEX_FILE_ID -- little-endian "IDSV"
{
int version; // MODEL_VERTEX_FILE_VERSION
int id; // MODEL_VERTEX_FILE_ID
long checksum; // same as studiohdr_t, ensures sync
int version; // MODEL_VERTEX_FILE_VERSION
int numLODs; // num of valid lods
long checksum; // same as studiohdr_t, ensures sync
int numLODVertexes[MAX_NUM_LODS]; // num verts for desired root lod
int numLODs; // num of valid lods
int numFixups; // num of vertexFileFixup_t
int numLODVertexes[MAX_NUM_LODS]; // num verts for desired root lod
int fixupTableStart; // offset from base to fixup table
int numFixups; // num of vertexFileFixup_t
int vertexDataStart; // offset from base to vertex block
int fixupTableStart; // offset from base to fixup table
int tangentDataStart; // offset from base to tangent block
int vertexDataStart; // offset from base to vertex block
};
int tangentDataStart; // offset from base to tangent block
};
</source>


==Fixup Table==
==Fixup Table==
// apply sequentially to lod sorted vertex and tangent pools to re-establish mesh order
<source lang="cpp">
struct vertexFileFixup_t
// 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 lod; // used to skip culled root lod
int numVertexes;
int sourceVertexID; // absolute index from start of vertex/tangent blocks
};
int numVertexes;
};
</source>


How the fixup table is used when loading vertex data:
How the fixup table is used when loading vertex data:
Line 30: Line 34:
==Vertex Data==
==Vertex Data==
A list of vertices follows the header
A list of vertices follows the header
// NOTE: This is exactly 48 bytes
<source lang="cpp">
struct mstudiovertex_t
// NOTE: This is exactly 48 bytes
{
struct mstudiovertex_t
mstudioboneweight_t m_BoneWeights; //see below
{
Vector m_vecPosition;
mstudioboneweight_t m_BoneWeights;
Vector m_vecNormal;
Vector m_vecPosition;
Vector2D m_vecTexCoord;
Vector m_vecNormal;
};
Vector2D m_vecTexCoord;
};


// 16 bytes
// 16 bytes
struct mstudioboneweight_t
struct mstudioboneweight_t
{
{
float weight[MAX_NUM_BONES_PER_VERT]; //MAX_NUM_BONES_PER_VERT is defined as 3
float weight[MAX_NUM_BONES_PER_VERT];
char bone[MAX_NUM_BONES_PER_VERT];  
char bone[MAX_NUM_BONES_PER_VERT];  
byte numbones;
byte numbones;
};
};
</source>
==Tangent Data==
==Tangent Data==
This seems to be an array of 4D vectors, one for each vertex
This seems to be an array of 4D vectors, one for each vertex
vec_t x, y, z, w;
<source lang="cpp">
vec_t x, y, z, w;
</source>
 
==Binary Data==
==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.
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.

Revision as of 12:44, 3 August 2011

VVD (Valve Studio Model Vertex Data File) is the extension for 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
	long	checksum;			// same as studiohdr_t, ensures sync
	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 less than or equal to the required LOD, it loads the vertices associated with that fixup (see sourceVertexID and numVertices).

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, posistion (XYZ), normals (XYZ) and texture co-ordinates (UV).

  • 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-16) [4xbyte] - IDs of the bones the vertex is weighted to. The first bone is the parent with a maximum of 3 child bones. The first child will use the first float number for weighting.
  • Posistion (16-28) [3xfloat] - Floating points numbers for each axis (XYZ) in inches.
  • Normals (28-40) [3xfloat] - Floating points numbers for face normals.
  • Texture Co-ordinates (40-48) [2xfloat] - Floating points numbers for UV map. The value for V may need to inverted and incremented by 1 to get back the original value.

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