MDLParser
Simple and modern library for parsing the Source engine model formats
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
MdlParser::Mdl Class Reference

#include <mdl.hpp>

Classes

struct  BodyPart
 
struct  Bone
 
struct  Mesh
 
struct  Model
 
struct  Texture
 

Public Member Functions

 Mdl (const std::weak_ptr< std::vector< std::byte > > &data, const std::optional< int32_t > &checksum=std::nullopt)
 
int32_t getChecksum () const
 
const std::vector< BodyPart > & getBodyParts () const
 
const std::vector< std::string > & getTextureDirectories () const
 
const std::vector< Texture > & getTextures () const
 
const std::vector< std::vector< int16_t > > & getSkinLookupTable () const
 
const std::vector< Bone > & getBones () const
 

Detailed Description

Parses a .mdl file from a buffer into an easier to traverse structure using STL containers.

Constructor & Destructor Documentation

◆ Mdl()

MdlParser::Mdl::Mdl ( const std::weak_ptr< std::vector< std::byte > > &  data,
const std::optional< int32_t > &  checksum = std::nullopt 
)
explicit

Parses a .mdl file contained in the given buffer into an easier to use and more modern structure. No ownership of the data is taken as all contents are copied into new structs.

Parameters
data
checksumOptional checksum to validate against the header's

Member Function Documentation

◆ getBodyParts()

const std::vector< Mdl::BodyPart > & MdlParser::Mdl::getBodyParts ( ) const

Gets the list of body parts (body groups) that make up the model.

Returns
List of body parts.

◆ getBones()

const std::vector< Mdl::Bone > & MdlParser::Mdl::getBones ( ) const

Gets the list of bones in the model.

Remarks
Models which you wouldn't expect to be rigged may still have a root bone, and that bone may be rotated relative to the model's overall origin (usually 90 degrees around the z axis).
Returns
List of bones.

◆ getChecksum()

int32_t MdlParser::Mdl::getChecksum ( ) const

Gets the checksum shared by the MDL, VTX and VVD from the header.

Remarks
Can be used to loosely verify that a collection of MDL, VTX and VVD files were compiled from the same asset.
Returns
int32_t checksum

◆ getSkinLookupTable()

const std::vector< std::vector< int16_t > > & MdlParser::Mdl::getSkinLookupTable ( ) const

Gets the skin lookup table as a row-major 2-dimensional array. To map from a material index to a texture index for a given skin, simply do:

mdl.getSkinLookupTable()[skinFamily][mesh.material]
Returns
Skin lookup table as a 2D array.

◆ getTextureDirectories()

const std::vector< std::string > & MdlParser::Mdl::getTextureDirectories ( ) const

Gets the list of directories (relative to /materials) which contain the textures used by the model. As each texture only includes its filename, you must search through this list of directories to find the actual path to the image asset.

Returns
List of paths relative to /materials.

◆ getTextures()

const std::vector< Mdl::Texture > & MdlParser::Mdl::getTextures ( ) const

Gets the list of textures used by this model. As each texture only stores its filename, you must use getTextureDirectories() to determine the actual path.

Returns
List of textures.

The documentation for this class was generated from the following files: