Skip to content

Latest commit

 

History

History
122 lines (86 loc) · 5.22 KB

NOTES.md

File metadata and controls

122 lines (86 loc) · 5.22 KB

Valve File Loaders

A small effort to try to decode and load valve 3d file formats.

Get models from SFMLab.

Formats

Open Questions

TODO

  • Parse Bone Structure

Other References

Source with struct definitions used in the mdl and other files.

Source with struct definitions used in the vtx files.

Source with some file loading vertex reading logic.

Especially the loop defined at lines 1504-1688, which shows the relationship between the MDL and VTX file data.

Things To Note

  • THREE assumes counter clockwise triangle winding order while DirectX (and probably the vtx files) assume clockwise order.
  • There's a lot of indirection in the way vertex data is defined. Look in the loop and at the mstudio_meshvertexdata_t struct in studio.h to unpack it.

Understanding Vertices

Key Structs and Functions

.VVD

Defined in studio.h.

struct vertexFileHeader_t

The header provides a pointer to a buffer of interlaced bone weight, position, normal, and uv data.

struct mstudiovertex_t

Defines the data layout for the vertex data buffer.

struct mstudio_modelvertexdata_t

The struct to access all the vertex data in the given buffer via functions like Position(i), Normal(i), Vertex(i), etc.

TODO: To get the vertex index the function GetGlobalVertexIndex is used.

.MDL

Defined in studio.h.

struct studiohdr_t

Provides pointers to various model data including texture data and "body parts".

struct mstudiobodyparts_t

Defines a groups of models.

struct mstudiomodel_t

Defines a group of meshes and contains a handle to the mstudio_modelvertexdata_t from the VVD class (right??).

struct mstudiomesh_t

Defines a mesh to be rendered and contains a handle to mstudio_meshvertexdata_t (NOT model), which indirectly accesses data in the mstudio_modelvertexdata_t struct of the meshes parent model.

This struct defines vertoffset and vertindex to index into the model data. Possibly this is cached or duplicated data from the VTX strip data?

struct mstudio_meshvertexdata_t

Defines accessors into the model vertex data for vertices using the vertOffset field (see getModelVertexIndex function).

.VTX

Defined in optimize.h

Defines indices and render approaches for the model in a set of bodyparts, meshes, strips, etc that mirrors the structure of the data in the MDL file.

Putting it all together

From the loop linked to above the order to go from strip to final vertex is as follows:

// From Strip
// iterate over every index in the strip
index = pStrip -> indexOffset + i;

// From StripGroup
// index into the strip group's index buffer (defined as `(byte*)this + this.indexoffset)`)
// see stripGroup -> pIndex
index2 = pStripGroup -> indexBuffer[ index ];

// index into the group's vertex buffer (defined as `(byte*)this + this.vertoffset)`)
// see stripGroup -> pVertex
index3 = pStripGroup -> vertexBuffer[ index2 ] -> origMeshVertID;

// From mstudiomesh_t
// index into the meshes indices
// see mstudio_meshvertexdata_t::Position and mstudio_meshvertexdata_t::GetModelVertexIndex
index4 = pMesh -> vertexoffset + index3;

// From mstudiomodel_t
// see mstudio_modelvertexdata_t::Position and mstudio_modelvertexdata_t::GetGlobalVertexIndex
index5 = index4 + pModel -> vertexindex / sizeof( vertex );