revised model loading order
[csRadar.git] / vmdl.h
diff --git a/vmdl.h b/vmdl.h
index 51b8f05c19264dff7ae28991fb4ad08c7a1154f8..d6564a3a87dfe4afbb5d1d2eb73d1bb663d51ab8 100644 (file)
--- a/vmdl.h
+++ b/vmdl.h
@@ -460,6 +460,9 @@ typedef struct
        
        float *vertices;
        u32     num_vertices;
+       
+       // Bounding box
+       boxf bounds;
 } 
 mdl_mesh_t;
 
@@ -469,6 +472,14 @@ void mdl_free( mdl_mesh_t *m )
        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 +488,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 +513,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