X-Git-Url: https://harrygodden.com/git/?p=csRadar.git;a=blobdiff_plain;f=vmdl.h;h=c558d0dbb45fb6152b1f02abbf3cbd007a0a2bf5;hp=51b8f05c19264dff7ae28991fb4ad08c7a1154f8;hb=HEAD;hpb=a97099abba0a239e20929f04ece9d6839c96ac14 diff --git a/vmdl.h b/vmdl.h index 51b8f05..c558d0d 100644 --- a/vmdl.h +++ b/vmdl.h @@ -1,3 +1,38 @@ +// This software is not affiliated with Valve Corporation +// We are not affiliated, associated, authorized, endorsed by, or in any way officially +// connected with Valve Corporation, or any of its subsidiaries or its affiliates. +// +// All trademarks are property of their respective owners + +typedef struct mdl_mesh mdl_mesh_t; + +// High level API +//======================================================================================================================= + +// Load model from vfs +int mdl_from_find_files( const char *mdlname, mdl_mesh_t *ctx ); +void mdl_free( mdl_mesh_t *m ); + +// Set ctx to blank / 0,0 +void mdl_error( mdl_mesh_t *m ); + +// Implementation +//======================================================================================================================= + +struct mdl_mesh +{ + u16 *indices; + u32 num_indices; + + float *vertices; + u32 num_vertices; + + // Bounding box + boxf bounds; +}; + +#ifdef VALVE_IMPLEMENTATION + // VVD //======================================================================================================================= //StudioMDL constants @@ -453,22 +488,20 @@ mstudiobodyparts_t *studiohdr_pBodypart( studiohdr_t *t, int i ) #pragma pack(pop) -typedef struct -{ - u16 *indices; - u32 num_indices; - - float *vertices; - u32 num_vertices; -} -mdl_mesh_t; - void mdl_free( mdl_mesh_t *m ) { free( m->indices ); free( m->vertices ); } +void mdl_error( mdl_mesh_t *m ) +{ + m->num_indices = 0; + m->num_vertices = 0; + m->indices = NULL; + m->vertices = NULL; +} + int mdl_from_find_files( const char *mdlname, mdl_mesh_t *ctx ) { // Read entire files into memory (inline functions map memory) @@ -477,20 +510,24 @@ int mdl_from_find_files( const char *mdlname, mdl_mesh_t *ctx ) strcpy( path, mdlname ); csr_stripext( path ); strcat( path, ".dx90.vtx" ); - VTXFileHeader_t *pVtxHdr = (VTXFileHeader_t *)csr_asset_read( path ); + VTXFileHeader_t *pVtxHdr = (VTXFileHeader_t *)valve_fs_get( path ); - if( !pVtxHdr ) + if( !pVtxHdr ) + { + mdl_error( ctx ); return 0; + } // .VVD strcpy( path, mdlname ); csr_stripext( path ); strcat( path, ".vvd" ); - vertexFileHeader_t *pVvdHdr = (vertexFileHeader_t *)csr_asset_read( path ); + vertexFileHeader_t *pVvdHdr = (vertexFileHeader_t *)valve_fs_get( path ); if( !pVvdHdr ) { free( pVtxHdr ); + mdl_error( ctx ); return 0; } @@ -498,15 +535,19 @@ int mdl_from_find_files( const char *mdlname, mdl_mesh_t *ctx ) strcpy( path, mdlname ); csr_stripext( path ); strcat( path, ".mdl" ); - studiohdr_t *pMdl = (studiohdr_t *)csr_asset_read( path ); + studiohdr_t *pMdl = (studiohdr_t *)valve_fs_get( path ); if( !pMdl ) { free( pVtxHdr ); free( pVvdHdr ); + mdl_error( ctx ); return 0; } + v3_copy( pMdl->hull_min, ctx->bounds[0] ); + v3_copy( pMdl->hull_max, ctx->bounds[1] ); + ctx->num_indices = vtx_count_indices( pVtxHdr ); // Allocate and read indices @@ -577,3 +618,5 @@ int mdl_from_find_files( const char *mdlname, mdl_mesh_t *ctx ) return 1; } + +#endif